<?php

 function ValBatalAbsensi() {
        $ssql="select ftovertime_no
                from txovertime_hdr
                where  fnstatus<>9 and ftattendance_no='{$_REQUEST['ftattendance_no']}'";

        $rs=mysql_query($ssql) or die ("query error {$ssql}");
        $ftovertime_no="";
        while($r=mysql_fetch_assoc($rs)) {
           $ftovertime_no.="- {$r['ftovertime_no']}\\n";

        }
        if($ftovertime_no!="") {
             $massage=" Perhitungan Lebur berikut harus dibatalkan terlebih dahulu \\n";
             $massage.="---------------------------------------------------------\\n";
             $massage.=$ftovertime_no;
        }
        if($massage!="") {
          echo "<script>
                alert('{$massage}');
                window.history.back();
            </script>";
            die("");
        }
      
    }
    
   if($_REQUEST[mode]=='update') $_REQUEST[mode]="simpan";
   
   function SaveData() {
        global $objAxpDB;
//        $objAxpDB->Allow_Save(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":
                $strSQL["DEL txattendance_hdr"][]="DELETE FROM txattendance_hdr WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";
                $strSQL["DEL txattendance_det"][]="DELETE FROM txattendance_det WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";
                
                break;
         }
    return $strSQL;
   }
   function SaveDataLast() {
        global $objAxpDB;
//        $objAxpDB->Allow_Save(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":
//                $strSQL["DEL txattendance_hdr"][]="DELETE FROM txattendance_hdr WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";
//                $strSQL["DEL txattendance_det"][]="DELETE FROM txattendance_det WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";

                $strSQL["A"][]=" update txattendance_det  a,tlemployee b
                                set a.fnsalary_type=b.fnsalary_type,
                                a.ftdivision_code=b.ftdivision_code,
                                a.ftposition_code=b.ftposition_code ,
                                a.ftdepartment_code=b.ftdepartment_code
                                where a.ftemployee_code=b.ftemployee_code and
                                a.ftattendance_no='{$_REQUEST['ftattendance_no']}'";
               
                $strSQL["A"][]=" update txattendance_det  a
                                set a.fnsalary_type2=1
                                where exists(select b.fnid from tlemployee_salary_inc_plus2 b where a.ftemployee_code=b.ftemployee_code) and
                                a.ftattendance_no='{$_REQUEST['ftattendance_no']}'";

                $strSQL["A"][]=" update txattendance_det  a
                                set a.fnsalary_type2=0
                                where not exists(select b.fnid from tlemployee_salary_inc_plus2 b where a.ftemployee_code=b.ftemployee_code) and
                                a.ftattendance_no='{$_REQUEST['ftattendance_no']}'";


                


                break;
         }
    return $strSQL;
   }
    function UpdateData() {
        global $objAxpDB;
        $objAxpDB->Allow_Update(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "update":
              

             break;
         }
    return $strSQL;
   }

 function FinalData() {
        global $objAxpDB;
        $objAxpDB->Allow_Final(true);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "final":
                $_REQUEST['fnstatus']=1;
                $strSQL["DEL txattendance_hdr"][]="DELETE FROM txattendance_hdr WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";
                $strSQL["DEL txattendance_det"][]="DELETE FROM txattendance_det WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";
          break;
	 }
    return $strSQL;
   }
function FinalDataLast() {
        global $objAxpDB;
        $objAxpDB->Allow_Final(true);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "final":
                $_REQUEST['fnstatus']=1;
//                $strSQL["DEL txattendance_hdr"][]="DELETE FROM txattendance_hdr WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";
//                $strSQL["DEL txattendance_det"][]="DELETE FROM txattendance_det WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";

                 $strSQL["A"][]=" update txattendance_det  a,tlemployee b
                                set a.fnsalary_type=b.fnsalary_type,
                                a.ftdivision_code=b.ftdivision_code,
                                a.ftposition_code=b.ftposition_code ,
                                a.ftdepartment_code=b.ftdepartment_code
                                where a.ftemployee_code=b.ftemployee_code and
                                a.ftattendance_no='{$_REQUEST['ftattendance_no']}'";

                $strSQL["A"][]=" update txattendance_det  a
                                set a.fnsalary_type2=1
                                where exists(select b.fnid from tlemployee_salary_inc_plus2 b where a.ftemployee_code=b.ftemployee_code) and
                                a.ftattendance_no='{$_REQUEST['ftattendance_no']}'";

                $strSQL["A"][]=" update txattendance_det  a
                                set a.fnsalary_type2=0
                                where not exists(select b.fnid from tlemployee_salary_inc_plus2 b where a.ftemployee_code=b.ftemployee_code) and
                                a.ftattendance_no='{$_REQUEST['ftattendance_no']}'";


          break;
	 }
    return $strSQL;
   }


function CancelData() {
        ValBatalAbsensi();
        global $objAxpDB;
        $objAxpDB->Allow_Cancel(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
          case "batal":
              $strSQL["batal txattendance_hdr"][] =
                    "update txattendance_hdr
                            set ftmodified_user='{$_SESSION['username']}',fdmodified_date=now(), 
                                fnstatus=9
                                WHERE ftattendance_no='{$_REQUEST['ftattendance_no']}'";



        break;
        }

        return $strSQL;
      }
      

?>
