<?php



 function SaveDataLast() {
        global $objAxpDB;       
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":
              if($_FILES['ftphoto1']['type']=="image/jpeg") {
                    @unlink(_APP_PATH."employee_photo/{$_REQUEST['ftemployee_code']}.jpg");
                    move_uploaded_file($_FILES['ftphoto1']['tmp_name'], _APP_PATH."employee_photo/{$_REQUEST['ftemployee_code']}.jpg");
                }
                $strSQL['update tlemployee_salary_dec'][]=" UPDATE tlemployee_salary_dec,tlsalary
                                                            SET tlemployee_salary_dec.ftsalary_category_code=tlsalary.ftsalary_category_code
                                                            WHERE tlemployee_salary_dec.ftsalary_code=tlsalary.ftsalary_code
                                                                AND tlemployee_salary_dec.ftemployee_code='{$_REQUEST['ftemployee_code']}'";
             
                  $strSQL['update tlemployee_salary_inc'][]=" UPDATE tlemployee_salary_inc,tlsalary
                                                            SET tlemployee_salary_inc.ftsalary_category_code=tlsalary.ftsalary_category_code
                                                            WHERE tlemployee_salary_inc.ftsalary_code=tlsalary.ftsalary_code
                                                                AND tlemployee_salary_inc.ftemployee_code='{$_REQUEST['ftemployee_code']}'";


                $strSQL['update tlemployee_salary_inc'][]="update tlemployee set fntype=1, fnsalary_type=0 where ftemployee_code='{$_REQUEST['ftemployee_code']}'";
                break;
         }
    return $strSQL;
 }
 
  function UpdateData() {
        global $objAxpDB;
        $objAxpDB->Allow_Update(true);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "update":
              
                if($_FILES['ftphoto1']['type']=="image/jpeg") {
                    #die(_APP_PATH."employee_photo/{$_REQUEST['ftemployee_code']}.jpg");
                    unlink(_APP_PATH."employee_photo/{$_REQUEST['ftemployee_code']}.jpg");
                    move_uploaded_file($_FILES['ftphoto1']['tmp_name'], _APP_PATH."employee_photo/{$_REQUEST['ftemployee_code']}.jpg");
                }
             
               
                $strSQL['a'][]="DELETE FROM tlemployee_load WHERE ftemployee_code='{$_REQUEST['ftemployee_code']}'";
				$strSQL['a'][]="DELETE FROM tlemployee_notes WHERE ftemployee_code='".$_REQUEST['ftemployee_code']."'";

                if(isset($_REQUEST['fnindexD2'])) {
                    $strSQL['a'][]="DELETE FROM tlemployee_salary_inc WHERE ftemployee_code='".$_REQUEST['ftemployee_code']."'";		
                }
                if(isset($_REQUEST['fnindexD3'])) {
                    $strSQL['a'][]="DELETE FROM tlemployee_salary_dec WHERE ftemployee_code='".$_REQUEST['ftemployee_code']."'";
                }
                
				
                 for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
                    $strSQL['tlemployee_load'][]="INSERT INTO  tlemployee_load(
                                                ftbranch_code,ftemployee_code, fnindex,ftload_name,
                                                fdload_birthday,ftload_status,ftcreated_user,fdcreated_date,
                                                ftmodified_user,fdmodified_date)
                                                SELECT
                                                '{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftemployee_code']}' AS  ftemployee_code,'{$j}' AS fnindex,'{$_REQUEST['ftload_nameD0'][$j]}' AS ftload_name,
                                                '".CDate($_REQUEST['fdload_birthdayD0'][$j])."' AS fdload_birthday,'{$_REQUEST['ftload_statusD0'][$j]}' AS ftload_status,'{$_SESSION['username']}' AS ftcreated_user,now() as fdcreated_date,
                                                '{$_SESSION['username']}' AS ftmodified_user,now() as fdmodified_date  ";
                }
                
                  for($j=1; $j<count($_REQUEST['fnindexD1']); $j++) {
                    $strSQL['tlemployee_notes'][]="INSERT INTO  tlemployee_notes(
                                                    ftbranch_code,ftemployee_code,fnindex,fdnotes_date,
                                                    ftnotes_type_code,ftnotes_type_name,ftnotes_content,ftcreated_user,
                                                    fdcreated_date,ftmodified_user,fdmodified_date)
                                                SELECT
                                                '{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftemployee_code']}' AS  ftemployee_code,'{$j}' AS fnindex,'".CDate($_REQUEST['fdnotes_dateD1'][$j])."' AS fdnotes_date,
                                                '{$_REQUEST['ftnotes_type_codeD1'][$j]}' AS ftnotes_type_code, '{$_REQUEST['ftnotes_type_nameD1'][$j]}' AS ftnotes_type_name,'{$_REQUEST['ftnotes_contentD1'][$j]}' as ftnotes_content, '{$_SESSION['username']}' AS ftcreated_user,
                                                now() as fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,now() as fdmodified_date  ";
                }
              
               for($j=1; $j<count($_REQUEST['fnindexD2']); $j++) {
                    $strSQL['tlemployee_salary_inc'][]="INSERT INTO  tlemployee_salary_inc(
                                                ftbranch_code,fnindex,ftemployee_code,ftsalary_code,
                                                fcamount,fnsalary_period,fnpayroll_slip,ftcreated_user,
                                                fdcreated_date,ftmodified_user,fdmodified_date)
                                                SELECT
                                                '{$_SESSION['strbranch']}' AS ftbranch_code,'{$j}' AS fnindex,'{$_REQUEST['ftemployee_code']}' AS  ftemployee_code,'{$_REQUEST['ftsalary_codeD2'][$j]}' AS ftsalary_code,
                                                '".CCur($_REQUEST['fcamountD2'][$j])."' AS fcamount,'{$_REQUEST['fnsalary_periodD2'][$j]}' AS fnsalary_period,'{$_REQUEST['fnpayroll_slipD2'][$j]}' AS fnpayroll_slip,'{$_SESSION['username']}' AS ftcreated_user,
                                                now() as fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,now() as fdmodified_date  ";
                }
               
                 for($j=1; $j<count($_REQUEST['fnindexD3']); $j++) {
                    $strSQL['tlemployee_salary_dec'][]="INSERT INTO  tlemployee_salary_dec(
                                                ftbranch_code,fnindex,ftemployee_code,ftsalary_code,
                                                fcamount,fnsalary_period,fnpayroll_slip,ftcreated_user,
                                                fdcreated_date,ftmodified_user,fdmodified_date)
                                                SELECT
                                                '{$_SESSION['strbranch']}' AS ftbranch_code,'{$j}' AS fnindex,'{$_REQUEST['ftemployee_code']}' AS  ftemployee_code,'{$_REQUEST['ftsalary_codeD3'][$j]}' AS ftsalary_code,
                                                '".CCur($_REQUEST['fcamountD3'][$j])."' AS fcamount,'{$_REQUEST['fnsalary_periodD3'][$j]}' AS fnsalary_period,'{$_REQUEST['fnpayroll_slipD3'][$j]}' AS fnpayroll_slip,'{$_SESSION['username']}' AS ftcreated_user,
                                                now() as fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,now() as fdmodified_date  ";
                }

                $strSQL['update tlemployee_salary_dec'][]=" UPDATE tlemployee_salary_dec,tlsalary
                                                            SET tlemployee_salary_dec.ftsalary_category_code=tlsalary.ftsalary_category_code
                                                            WHERE tlemployee_salary_dec.ftsalary_code=tlsalary.ftsalary_code
                                                                AND tlemployee_salary_dec.ftemployee_code='{$_REQUEST['ftemployee_code']}'";

                  $strSQL['update tlemployee_salary_inc'][]=" UPDATE tlemployee_salary_inc,tlsalary
                                                            SET tlemployee_salary_inc.ftsalary_category_code=tlsalary.ftsalary_category_code
                                                            WHERE tlemployee_salary_inc.ftsalary_code=tlsalary.ftsalary_code
                                                                AND tlemployee_salary_inc.ftemployee_code='{$_REQUEST['ftemployee_code']}'";


                break;
        }
    return $strSQL;
   }
   
   
   function DeleteData() {    
        global $objAxpDB;
         $objAxpDB->Allow_Delete(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "hapus":
                        @unlink(_APP_PATH."employee_photo/{$_REQUEST['ftemployee_code']}.jpg");
			$strSQL['DELETE tlemployee'][]="DELETE FROM tlemployee WHERE ftemployee_code='".$_REQUEST['ftemployee_code']."'";
			$strSQL['DELETE tlemployee_load'][]="DELETE FROM tlemployee_load WHERE ftemployee_code='".$_REQUEST['ftemployee_code']."'";
			$strSQL['DELETE tlemployee_salary_inc'][]="DELETE FROM tlemployee_salary_inc WHERE ftemployee_code='".$_REQUEST['ftemployee_code']."'";
                        $strSQL['DELETE tlemployee_salary_dec'][]="DELETE FROM tlemployee_salary_dec WHERE ftemployee_code='".$_REQUEST['ftemployee_code']."'";
			$strSQL['DELETE tlemployee_notes'][]="DELETE FROM tlemployee_notes WHERE ftemployee_code='".$_REQUEST['ftemployee_code']."'";	
            break;  
		 }
    return $strSQL;

   }




?>
