<?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();
            /* $strSQL["del txcashpym_hdr "][]="delete
                                                from txcashpym_hdr
                                                where ftcashpym_no='{$_REQUEST['ftcashpym_no']}'";
            $strSQL["del txcashpym_det "][]="delete
                                        from txcashpym_det
                                        /where ftcashpym_no='{$_REQUEST['ftcashpym_no']}'"; */
            break;
    }
    return $strSQL;

}

function RevisiData(){
    global $objAxpDB;
    //$objAxpDB->Allow_Revisi(false);
    $strSQL=array();
    switch($_REQUEST[mode]) {
        case "simpan_revisi":
            $trans_no_new = getAutoRevisiNo('txcashpym_hdr', 'ftcashpym_no', $_REQUEST['ftcashpym_no']);

            $strSQL["Revisi"][]="update txcashpym_hdr
                    set fdrevisi_date=now(), ftrevisi_user='{$_SESSION['username']}',
                            fnstatus=3, ftcashpym_no='{$trans_no_new}'
                    where ftcashpym_no='{$_REQUEST['ftcashpym_no']}'";

            $strSQL["Revisi"][]="update txcashpym_det
                    set ftcashpym_no='{$trans_no_new}'
                    where ftcashpym_no='{$_REQUEST['ftcashpym_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 txcashpym_hdr"][] =
                        "update txcashpym_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 ftcashpym_no='{$_REQUEST['ftcashpym_no']}'";


            $strSQL["Insert txcashpym_hdr"][] ="delete from txcashpym_det
                                                where ftcashpym_no='{$_REQUEST['ftcashpym_no']}'";
          
            for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
                $strSQL["Insert txcashpym_hdr"][] ="
                        INSERT INTO txcashpym_det
                        (
                        fnid,ftbranch_code,fnindex,
                        ftcoa_code,ftcashpym_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['ftcashpym_no']}' AS ftcashpym_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 FinalDataLast() {
//        global $objAxpDB;
//        $objAxpDB->Allow_Final(true);
//        $strSQL=array();
//        switch($_REQUEST[mode]) {
//        case "final":
//            $strSQL["update txcashpym_hdr "][]="update
//                                                 txcashpym_hdr set fnstatus=2
//                                                where ftcashpym_no='{$_REQUEST['ftcashpym_no']}'";
//
//        break;
//    }
//    return $strSQL;
//
//   }

*/

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

        break;
    }

    return $strSQL;
}