<?php
 function SaveData() {
        global $objAxpDB;
        $objAxpDB->Allow_Save(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":

              for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
                    $strSQL['txpayroll_slip_inc'][]="
                            UPDATE txpayroll_slip_inc
                            SET fcamount='".CCur($_REQUEST['fcamountD0'][$j])."',
                                ftmodified_user='{$_SESSION['username']}',
                                fdmodified_date=NOW()
                            WHERE ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                                    ftemployee_code='{$_REQUEST['ftemployee_code']}' AND
                                     ftsalary_code='{$_REQUEST['ftsalary_codeD0'][$j]}'";

             }
              for($j=1; $j<count($_REQUEST['fnindexD1']); $j++) {
                    $strSQL['txpayroll_slip_dec'][]="
                            UPDATE txpayroll_slip_dec
                            SET fcamount='".CCur($_REQUEST['fcamountD1'][$j])."',
                                ftmodified_user='{$_SESSION['username']}',
                                fdmodified_date=NOW()
                            WHERE ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                                    ftemployee_code='{$_REQUEST['ftemployee_code']}' AND
                                     ftsalary_code='{$_REQUEST['ftsalary_codeD1'][$j]}'";

             }

             $where=" WHERE ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                       ftemployee_code='{$_REQUEST['ftemployee_code']}'";
             $ssql="UPDATE  txpayroll_slip_emp a,
                        (
                            SELECT ftpayroll_slip_no,ftemployee_code,SUM(fcamount) AS fcamount
                            FROM txpayroll_slip_inc
                            {$where}
                            GROUP BY ftpayroll_slip_no,ftemployee_code
                        ) b,
                        (
                            SELECT ftpayroll_slip_no,ftemployee_code,SUM(fcamount) AS fcamount
                            FROM txpayroll_slip_dec
                             {$where}
                            GROUP BY ftpayroll_slip_no,ftemployee_code
                        ) c
                    SET a.fcincome_amount=b.fcamount,
                        a.fcdeduction_amount=c.fcamount,
                        a.fcamount=b.fcamount-c.fcamount

                    WHERE a.ftpayroll_slip_no=b.ftpayroll_slip_no and
                        a.ftpayroll_slip_no=c.ftpayroll_slip_no and
                        a.ftemployee_code=b.ftemployee_code and
                        a.ftemployee_code=c.ftemployee_code  and
                        a.ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                        a.ftemployee_code='{$_REQUEST['ftemployee_code']}'";

             $strSQL['txpayroll_slip_hdr'][]=$ssql;

              $ssql="UPDATE  txpayroll_slip_emp a,
                        (
                            SELECT ftpayroll_slip_no,ftemployee_code,SUM(fcamount) AS fcamount
                            FROM txpayroll_slip_inc
                            {$where}
                            GROUP BY ftpayroll_slip_no,ftemployee_code
                        ) b
                    SET a.fcincome_amount=b.fcamount

                    WHERE a.ftpayroll_slip_no=b.ftpayroll_slip_no and

                        a.ftemployee_code=b.ftemployee_code and

                        a.ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                        a.ftemployee_code='{$_REQUEST['ftemployee_code']}'";

             $strSQL['txpayroll_slip_hdr'][]=$ssql;


               $ssql="UPDATE  txpayroll_slip_emp a,

                        (
                            SELECT ftpayroll_slip_no,ftemployee_code,SUM(fcamount) AS fcamount
                            FROM txpayroll_slip_dec
                             {$where}
                            GROUP BY ftpayroll_slip_no,ftemployee_code
                        ) c
                    SET
                        a.fcdeduction_amount=c.fcamount


                    WHERE
                        a.ftpayroll_slip_no=c.ftpayroll_slip_no and

                        a.ftemployee_code=c.ftemployee_code  and
                        a.ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                        a.ftemployee_code='{$_REQUEST['ftemployee_code']}'";

             $strSQL['txpayroll_slip_hdr'][]=$ssql;

               $ssql="UPDATE  txpayroll_slip_emp
                    SET
                        fcamount=fcincome_amount-fcdeduction_amount

                    WHERE
                        ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                        ftemployee_code='{$_REQUEST['ftemployee_code']}'";

              $strSQL['txpayroll_slip_hdr'][]=$ssql;

             $ssql="UPDATE
                        txpayroll_slip_hdr ,(SELECT ftpayroll_slip_no,
                                                SUM(fcincome_amount) AS  fcincome_amount,
                                                SUM(fcdeduction_amount) AS fcdeduction_amount,
                                                SUM(fcamount) AS fcamount
                                                FROM txpayroll_slip_emp
                                                WHERE ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'
                                                GROUP BY ftpayroll_slip_no
                                                ) txpayroll_slip_emp
                        SET txpayroll_slip_hdr.fcgrand_income_amount=txpayroll_slip_emp.fcincome_amount,
                                txpayroll_slip_hdr.fcgrand_deduction_amount=txpayroll_slip_emp.fcdeduction_amount,
                                        txpayroll_slip_hdr.fcgrand_total=txpayroll_slip_emp.fcamount
                        WHERE txpayroll_slip_hdr.ftpayroll_slip_no=txpayroll_slip_emp.ftpayroll_slip_no AND
                                   txpayroll_slip_hdr.ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'
                                                ";

              $strSQL['txpayroll_slip_hdr'][]=$ssql;

          break;

	 }
//     pr($strSQL);
//     die("");
    return $strSQL;
   }

?>