<?php

 function ValBankKeluar() {
           for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
                 if($_REQUEST['ftgiro_no']!="") {
                      $ssql="select fnid
                            from txgiro2_hist
                            where ftdocument_no<>'".$_REQUEST['ftbankpym_no']."' and  fnstatus_giro<>9 and
                                   ftgiro_no='".$_REQUEST['ftgiro_no']."'";


                      $rs=mysql_query($ssql);
                        $r=mysql_fetch_assoc($rs);
                        if($r['fnid']) {
                            echo "<script>
                                      alert('No. Giro sudah pernah dipakai ...');
                                      window.history.back();
                                 </script>";
                                die("No. Reff sudah pernah dipakai ...");
                        }
                  }
           }

     }


   function SaveData() {
       ValBankKeluar();
        global $objAxpDB;
//        $objAxpDB->Allow_Save(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":
            $strSQL["Insert txbankpym_hdr"][] =
                    "INSERT INTO txbankpym_hdr
                    (fnid,ftbankpym_no,ftjournal_no,
                    ftbranch_code,fdtrans_date,ftacc_no1,
                    ftacc_desc,ftreference,fcamount,
                    fccomparison_amount,ftremarks,fnstatus,
                    ftprint_counter,fnprint_status,
                    ftcreated_user,fdcreated_date,ftmodified_user,
                    fdmodified_date
                    )
                    SELECT
                    '' AS fnid,'{$_REQUEST['ftbankpym_no']}' AS ftbankpym_no,'{$_REQUEST['ftjournal_no']}' AS ftjournal_no,
                    '{$_SESSION['strbranch']}' AS ftbranch_code,'".CDate($_REQUEST['fdtrans_date'])."' AS fdtrans_date,'{$_REQUEST['ftacc_no']}' AS ftacc_no,
                    '' AS ftacc_desc,'{$_REQUEST['ftloan_no']}' AS ftreference,'".CCur($_REQUEST['fcloan_balance'])."' AS fcamount,
                   '".CCur($_REQUEST['fcloan_balance'])."'  AS fccomparison_amount,'{$_REQUEST['ftnotes']}' AS ftremarks,'1' AS fnstatus,
                    '' AS ftprint_counter,'' AS fnprint_status,
                   '{$_SESSION['username']}' AS ftcreated_user,NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,
                    NOW() AS fdmodified_date";

                $strSQL["Insert txbankpym_det"][] ="
                    INSERT INTO txbankpym_det
                    (
                    fnid,ftbranch_code,fnindex,
                    ftbankpym_no,fdtrans_date,ftacc_no,
                    ftacc_desc,fnpayment_method,ftgiro_no,
                    fdgiro_date,fdgiro_cliring_date,fnstatus_giro,
                    ftdescription,fcamount,ftcreated_user,
                    fdcreated_date,ftmodified_user,fdmodified_date
                    )
                    SELECT
                    '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'1' AS fnindex,
                    '{$_REQUEST['ftbankpym_no']}' AS ftbankpym_no,'".CDate($_REQUEST['fdtrans_date'])."' AS fdtrans_date, '' AS ftacc_no,
                    '' AS ftacc_desc,'{$_REQUEST['fnpayment_method']}' AS fnpayment_method,'{$_REQUEST['ftgiro_no']}' AS ftgiro_no,
                    '".CDate($_REQUEST['fdgiro_date'])."' AS fdgiro_date,'".CDate($_REQUEST['fdgiro_cliring_date'])."' AS fdgiro_cliring_date,'{$_REQUEST['fnstatus_giro']}' AS fnstatus_giro,
                     '{$_REQUEST['ftnotes']}' AS ftdescription, '".CCur($_REQUEST['fcloan_balance'])."'  AS fcamount,'{$_SESSION['username']}' AS ftcreated_user,
                    NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,NOW() AS fdmodified_date";



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

   }

  function FinalData() {
//        ValBankKeluar();
        global $objAxpDB;
        $objAxpDB->Allow_Final(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "final":
             $strSQL["Insert txloan"][] =
                    "update txloan
                    set
                    ftfinal_user='{$_SESSION['username']}',
                    fdfinal_date=NOW() ,
                    ftemployee_code='{$_REQUEST['ftemployee_code']}',
                    fdtrans_date='".CDate($_REQUEST['fdtrans_date'])."',
                    ftloan_type_code='{$_REQUEST['ftloan_type_code']}',
                    fnpayroll_slip='{$_REQUEST['fnpayroll_slip']}',
                    fdloan_period_from='".CDate($_REQUEST['fdloan_period_from'])."',
                    fdloan_period_to='".CDate($_REQUEST['fdloan_period_to'])."',
                    fcloan_max='".CCur($_REQUEST['fcloan_max'])."',
                    fcloan_amount='".CCur($_REQUEST['fcloan_amount'])."',
                    fcloan_balance='".CCur($_REQUEST['fcloan_balance'])."',
                    fcloan_payment='".CCur($_REQUEST['fcloan_payment'])."',
                    fcloan_outstanding='".CCur($_REQUEST['fcloan_outstanding'])."',
                    ftnotes='{$_REQUEST['ftnotes']}',
                    fnloan_payment_status='{$_REQUEST['fnloan_payment_status']}',
                    fnstatus='2',
                    ftbankpym_no='{$_REQUEST['ftbankpym_no']}',
                    ftjournal_no='{$_REQUEST['ftjournal_no']}',
                    ftacc_no='{$_REQUEST['ftacc_no']}',
                    fnpayment_method='{$_REQUEST['fnpayment_method']}',
                    ftgiro_no='{$_REQUEST['ftgiro_no']}',
                    fdgiro_date='".CDate($_REQUEST['fdgiro_date'])."',
                    fdgiro_cliring_date='".CDate($_REQUEST['fdgiro_cliring_date'])."',
                    fnstatus_giro ='{$_REQUEST['fnstatus_giro']}'
					where ftloan_no='{$_REQUEST['ftloan_no']}'";


	       $strSQL["Insert txbankpym_hdr"][] =
                    "update txbankpym_hdr
                    set ftfinal_user='{$_SESSION['username']}',
                    fdfinal_date=NOW() ,
					ftjournal_no='{$_REQUEST['ftjournal_no']}',
                    fdtrans_date='".CDate($_REQUEST['fdtrans_date'])."',
                    ftacc_no1='{$_REQUEST['ftacc_no']}',
                    ftacc_desc='',ftreference='{$_REQUEST['ftreference']}',
                    fcamount='".CCur($_REQUEST['fcloan_balance'])."',
                    fccomparison_amount='".CCur($_REQUEST['fcloan_balance'])."',
					ftremarks='{$_REQUEST['ftnotes']}',
					fnstatus='2',
                    ftprint_counter='',fnprint_status='',
                    ftmodified_user='{$_SESSION['username']}',
                    fdmodified_date=NOW(),
                    ftremarks='{$_REQUEST['ftnotes']}' 
					where ftbankpym_no='{$_REQUEST['ftbankpym_no']}'";

		   	 $strSQL["Insert txbankpym_det"][] ="delete from txbankpym_det where ftbankpym_no ='{$_REQUEST['ftbankpym_no']}'";
           	 $strSQL["Insert txgiro_hist"][] ="delete from txgiro2_hist where ftdocument_no ='{$_REQUEST['ftbankpym_no']}'";


                if(($_REQUEST['fnpayment_method']==0)||($_REQUEST['fnpayment_method']==1)) {
                      $fnstatus="0";
                  }
                  else {
                      $fnstatus="1";
                  }

                   if(($_REQUEST['fnpayment_method']==0)||($_REQUEST['fnpayment_method']==1)) {
                           $strSQL['Insert txgiro_hist'][]="
                            INSERT INTO txgiro2_hist (
                                fnid,ftbranch_code,ftacc_no,ftacc_desc,
                                ftdocument_no,ftsupplier_code,ftsupplier_name,
                                ftdebit_no,fnpayment_method,ftgiro_no,
                                fdgiro_date,fdgiro_cliring_date,fdtrans_date,
                                ftremarks,fnstatus_giro,fncategory,
                                fncategory2,fcamount,fcdebit_memo,fcother_cost,
                                ftother_sign,fctotal,ftprint_counter,
                                fnprint_status,ftcreated_user,fdcreated_date,
                                ftmodified_user,fdmodified_date,fttype
                                )
                                SELECT
                                '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftacc_no']}' AS ftacc_no,'' AS ftacc_desc,
                                '{$_REQUEST['ftbankpym_no']}' AS ftdocument_no,'' AS ftsupplier_code,'' AS ftsupplier_name,
                                '' AS ftdebit_no,'{$_REQUEST['fnpayment_method']}' AS fnpayment_method,'{$_REQUEST['ftgiro_no']}' AS ftgiro_no,
                                '".CDate($_REQUEST['fdgiro_date'])."' AS fdgiro_date,'".CDate($_REQUEST['fdgiro_cliring_date'])."' AS fdgiro_cliring_date,'".CDate($_REQUEST['fdtrans_date'])."' AS fdtrans_date,
                                '' AS ftremarks,'0' AS fnstatus_giro,'' AS fncategory,
                                '' AS fncategory2,'".CCur($_REQUEST['fcloan_balance'])."' AS fcamount,'' AS fcdebit_memo,0 AS fcother_cost,
                                '' AS ftother_sign,'".CCur($_REQUEST['fcloan_balance'])."' AS fctotal,'' AS ftprint_counter,
                                '' AS fnprint_status,'{$_SESSION['username']}' AS ftcreated_user,NOW() AS fdcreated_date,
                                '{$_SESSION['username']}' AS ftmodified_user,NOW() AS fdmodified_date ,
                                'BK' AS fttype";
                      }

                $strSQL["Insert txbankpym_det"][] ="
                    INSERT INTO txbankpym_det
                    (
                    fnid,ftbranch_code,fnindex,
                    ftbankpym_no,fdtrans_date,ftacc_no,
                    ftacc_desc,fnpayment_method,ftgiro_no,
                    fdgiro_date,fdgiro_cliring_date,fnstatus_giro,
                    ftdescription,fcamount,ftcreated_user,
                    fdcreated_date,ftmodified_user,fdmodified_date
                    )
                    SELECT
                    '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'{$j}' AS fnindex,
                    '{$_REQUEST['ftbankpym_no']}' AS ftbankpym_no,'".CDate($_REQUEST['fdtrans_date'])."' AS fdtrans_date, '{$_REQUEST['ftacc_no']}' AS ftacc_no,
                    '{$_REQUEST['ftacc_desc']}' AS ftacc_desc,'{$_REQUEST['fnpayment_method']}' AS fnpayment_method,'{$_REQUEST['ftgiro_no']}' AS ftgiro_no,
                    '".CDate($_REQUEST['fdgiro_date'])."' AS fdgiro_date,'".CDate($_REQUEST['fdgiro_cliring_date'])."' AS fdgiro_cliring_date,'{$fnstatus}' AS fnstatus_giro,
                     '{$_REQUEST['ftnotes']}' AS ftdescription, '".CCur($_REQUEST['fcloan_balance'])."'  AS fcamount,'{$_SESSION['username']}' AS ftcreated_user,
                    NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,NOW() AS fdmodified_date";




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

   }


      function CancelData() {
        global $objAxpDB;
//       $objAxpDB->Allow_Cancel(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
          case "batal":

           if(($_REQUEST['fnpayment_method']==0)||($_REQUEST['fnpayment_method']==1)) {
                   $strSQL['Update txgiro_hist'][]="
                          UPDATE txgiro2_hist SET fnstatus_giro=9 WHERE ftgiro_no='{$_REQUEST['ftgiro_no']}' AND ftdocument_no='{$_REQUEST['ftbankpym_no']}'";

              }

         //-----------------------------------------------------
         // batal -%
          $ssql1="SELECT IFNULL(MAX(ftjournal_no),'')  AS M
                      FROM txbankpym_hdr
                      WHERE ftjournal_no LIKE '{$_REQUEST['ftjournal_no']}-%'";
            $no=RetRstField($ssql1);
            if($no!="") {
                $no=$no+1;
                $str1="-{$no}";
            }
            else {
                $str1="-1";
            }

             $ftbankpym_no_new="{$_REQUEST['ftbankpym_no']}{$str1}";
             $ftjournal_no_new="{$_REQUEST['ftjournal_no']}{$str1}";

              $strSQL["batal"][]="update txbankpym_hdr
                                            set fnstatus=9,
                                                ftjournal_no='{$ftjournal_no_new}'
                                            where ftbankpym_no='{$_REQUEST['ftbankpym_no']}'";


        break;
        }

        return $strSQL;
      }


?>