<?php

    
function ValKas() {
    for($j=1; $j<count($_REQUEST['ftcoa_codeD0']); $j++) {
        
        $ftcoa_code=RetRstField("select ftcoa_code from tlcoa where ftcoa_code='".$_REQUEST['ftcoa_codeD0'][$j]."'");

        if ($ftcoa_code == "") {

            echo "  <script>
                        alert('No Perkiraan tidak valid ...');
                        window.history.back();
                    </script>";
            die("");
        }

    }

}

function SaveData() {
    global $objAxpDB;
    $strSQL=array();
    switch($_REQUEST[mode]) {
        case "simpan":
            ValKas();
            break;
    }
    
    return $strSQL;
}


   function RevisiData(){
      global $objAxpDB;
      //$objAxpDB->Allow_Revisi(false);
      $strSQL=array();
      switch($_REQUEST[mode]) {
          case "simpan_revisi":
            $trans_no_new = getAutoRevisiNo('txcashrcp_hdr', 'ftcashrcp_no', $_REQUEST['ftcashrcp_no']);
            
            $strSQL["Revisi"][]="update txcashrcp_hdr
                    set fdrevisi_date=now(), ftrevisi_user='{$_SESSION['username']}',
                    fnstatus=3, ftcashrcp_no='{$trans_no_new}'
                    where ftcashrcp_no='{$_REQUEST['ftcashrcp_no']}'";

            $strSQL["Revisi"][]="update txcashrcp_det
                    set ftcashrcp_no='{$trans_no_new}'
                    where ftcashrcp_no='{$_REQUEST['ftcashrcp_no']}'";

            // Call Function Revisi General Ledger
            if(function_exists("RevisiGL")) {
                $m = RevisiGL($trans_no_new);
                if ($m != '') { $strSQL=array_merge_recursive($strSQL,$m); }
            }
            break;
      }

      return $strSQL;
   }

    function FinalData() {
        global $objAxpDB;
        $objAxpDB->Allow_Final(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "final":
             /*$strSQL["Insert txcashrcp_hdr"][] =
                    "update txcashrcp_hdr
                            set ftfinal_user='{$_SESSION['username']}',fdfinal_date=now(),
                                ftjournal_no='{$_REQUEST['ftjournal_no']}',
                                fdtrans_date='".CDate($_REQUEST['fdtrans_date'])."',ftacc_no1='{$_REQUEST['ftacc_no1']}',
                                ftacc_desc='',ftdoc_no='{$_REQUEST['ftdoc_no']}',fcamount='".CCur($_REQUEST['fcamount'])."',
                                fccomparison_amount='".CCur($_REQUEST['fccomparison_amount'])."',
                                ftremarks='{$_REQUEST['ftremarks']}',fnstatus='2',
                                ftprint_counter='',fnprint_status='',
                                ftmodified_user='{$_SESSION['username']}',
                                fdmodified_date=NOW()
                                WHERE ftcashrcp_no='{$_REQUEST['ftcashrcp_no']}'";*/
          $strSQL["Insert txcashrcp_hdr"][] =
                    "update txcashrcp_hdr
                            set ftfinal_user='{$_SESSION['username']}',fdfinal_date=now(),
                                fdtrans_date='".CDate($_REQUEST['fdtrans_date'])."',ftacc_no1='{$_REQUEST['ftacc_no1']}',
                                ftacc_desc='',ftdoc_no='{$_REQUEST['ftdoc_no']}',fcamount='".CCur($_REQUEST['fcamount'])."',
                    ftcurrency_code='{$_REQUEST['ftcurrency_code']}', fcrate='".CCur($_REQUEST['fcrate'])."',
                                fccomparison_amount='".CCur($_REQUEST['fccomparison_amount'])."',
                                ftremarks='{$_REQUEST['ftremarks']}',fnstatus='2',
                                ftprint_counter='',fnprint_status='',
                                ftreceive_name='{$_REQUEST['ftreceive_name']}',
                                ftmodified_user='{$_SESSION['username']}',
                                fdmodified_date=NOW()
                                WHERE ftcashrcp_no='{$_REQUEST['ftcashrcp_no']}'";

         
             $strSQL["Insert txcashrcp_hdr"][] ="delete
                                                    from txcashrcp_det
                                                    where ftcashrcp_no='{$_REQUEST['ftcashrcp_no']}'";
              for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
                 /*$strSQL["Insert txcashrcp_hdr"][] ="
                            INSERT INTO txcashrcp_det 
                            (
                            fnid,ftbranch_code,fnindex,
                            ftcashrcp_no,ftacc_no,
                            ftacc_desc,                         
                            ftdescription,fcamount,ftcreated_user,
                            fdcreated_date,ftmodified_user,fdmodified_date
                            )
                            SELECT
                            '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'{$j}' AS fnindex,
                            '{$_REQUEST['ftcashrcp_no']}' AS ftcashrcp_no,'{$_REQUEST['ftacc_noD0'][$j]}' AS ftacc_no,
                            '{$_REQUEST['ftacc_descD0'][$j]}' AS ftacc_desc,                          
                             '{$_REQUEST['ftdescriptionD0'][$j]}' AS ftdescription, '".CCur($_REQUEST['fcamountD0'][$j])."'  AS fcamount,'{$_SESSION['username']}' AS ftcreated_user,
                            NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,NOW() AS fdmodified_date";*/

                  $strSQL["Insert txcashrcp_hdr"][] ="
                            INSERT INTO txcashrcp_det
                            (
                            fnid,ftbranch_code,fnindex,ftcoa_code,
                            ftcashrcp_no,ftacc_no,
                            ftacc_desc,
                            ftdescription,fcamount,ftcreated_user,
                            fdcreated_date,ftmodified_user,fdmodified_date
                            )
                            SELECT
                            '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'{$j}' AS fnindex,
                            '{$_REQUEST['ftcoa_codeD0'][$j]}' AS ftcoa_code,'{$_REQUEST['ftcashrcp_no']}' AS ftcashrcp_no,'{$_REQUEST['ftacc_noD0'][$j]}' AS ftacc_no,
                            '{$_REQUEST['ftacc_descD0'][$j]}' AS ftacc_desc,
                             '{$_REQUEST['ftdescriptionD0'][$j]}' AS ftdescription, '".CCur($_REQUEST['fcamountD0'][$j])."'  AS fcamount,'{$_SESSION['username']}' AS ftcreated_user,
                            NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,NOW() AS fdmodified_date";

              }
              
        break;
    }
   
    return $strSQL;

   }
   
 function CancelData() {
        global $objAxpDB;
        $objAxpDB->Allow_Cancel(false);
        $strSQL=array();
        switch($_REQUEST[mode]) {
          case "batal":
             $strSQL["batal"][]="update txcashrcp_hdr set fnstatus=9
                                    where ftcashrcp_no='{$_REQUEST['ftcashrcp_no']}'";


        break;
        }

        return $strSQL;
      }