<?php
   function ValCM() {

        $ssql="SELECT a.fnid as fnid FROM tlcoa_setting a LEFT JOIN tlcoa b ON a.ftcoa_code = b.ftcoa_code
                WHERE ftmodule_code = 'keuangan' AND b.ftcoa_code IS NULL ";

        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        if($r['fnid']) {
            echo "<script>
                      alert('Inputan COA Setting tidak valid ...');
                      window.history.back();
                 </script>";
            die("Inputan COA Setting tidak valid ...");
        }
    }

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

                $dt=getDateYmd($_REQUEST['fdtrans_date']);               

                $ssql="SELECT COUNT(fnid) as jml FROM  txcredit_memo_hist WHERE ftcustomer_code='{$_REQUEST['ftcustomer_code']}'";
                $rs=mysql_query($ssql);
                $r=mysql_fetch_assoc($rs);
                if($r['jml']) {
                     $strSQL['Update txcredit_memo_hist'][]="
                                    UPDATE txcredit_memo_hist  SET
                                    fccm_amount=fccm_amount+".CCur($_REQUEST['fcinvoice_amount'])." 
                                    WHERE ftcustomer_code='{$_REQUEST['ftcustomer_code']}'";         
                }
                else {
                   $strSQL['Insert txcredit_memo_hist'][]="
                               INSERT INTO txcredit_memo_hist (
                                        fnid,ftbranch_code,ftcustomer_code,
                                        fdtrans_date,fccm_amount,ftcreated_user,
                                        fdcreated_date,ftmodified_user,fdmodified_date
                                     ) 
                                    SELECT 
                                        '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftcustomer_code']}' AS ftcustomer_code,
                                         '{$dt}' AS fdtrans_date,'".CCur($_REQUEST['fcinvoice_amount'])."' AS fccm_amount,'{$_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['Update txcredit_memo_hist'][]="
                                    UPDATE txcredit_memo_hist  SET
                                    fccm_amount=fccm_amount-".CCur($_REQUEST['fcinvoice_amount'])."  
                                    WHERE ftcustomer_code='{$_REQUEST['ftcustomer_code']}'";  
        }
         
       //-----------------------------------------------------
         // batal -%
//         $ssql1="SELECT IFNULL(MAX(ftcm_no),'')  AS M
//                      FROM txcredit_memo_hdr
//                      WHERE ftcm_no LIKE '{$_REQUEST['ftcm_no']}-%'";
//            $no=RetRstField($ssql1);
//            if($no!="") {
//                $no=$no+1;
//                $str1="-{$no}";
//            }
//            else {
//                $str1="-1";
//            }
//
//             $ftcm_no_new="{$_REQUEST['ftcm_no']}{$str1}";
//
//
//             $strSQL["batal"][]="update txcredit_memo_hdr
//                                set fnstatus=9,ftcm_no='{$ftcm_no_new}'
//                                where ftcm_no='{$_REQUEST['ftcm_no']}'";
//
//             $strSQL["batal"][]="update txcredit_memo_det
//                                set ftcm_no='{$ftcm_no_new}'
//                                where ftcm_no='{$_REQUEST['ftcm_no']}'";
         //--------------------------------------------
         
        return $strSQL;
  }

?>
