<?php
function ValBatal() {

    if (($_REQUEST['ftcategory_code'] == 0) || ($_REQUEST['ftcategory_code'] == 4)) {
        echo "<script>
                alert('Kategori Stock Keluar ini harus dibatalkan dari dokumen sumber nya. ');
                window.history.back();
              </script>";
        die("");
    }
}

function SaveData() {         
    $strSQL=array();
    
    switch($_REQUEST[mode]) {
        case "simpan":
            for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                 $m=SaveStock('-',$_REQUEST['ftitem_codeD0'][$j],'',$_REQUEST['ftwarehouse_codeD0'][$j],$_REQUEST['ftlocation_codeD0'][$j],$_REQUEST['fdexp_dateD0'][$j],CCur($_REQUEST['fnqtyD0'][$j]),CCur($_REQUEST['fnqtyD0'][$j]));
                 $strSQL=array_merge_recursive($strSQL,$m);
            }
            break;
        }
    # pr($strSQL);die("mm");
    return $strSQL;
}
  
function CancelData() {
    ValBatal();
        
    global $objAxpDB;
    // $objAxpDB->Allow_Cancel(false);  
    $strSQL=array();
    
    switch($_REQUEST[mode]) {
        case "batal":           
            for($i=1; $i<count($_REQUEST['ftitem_codeD0']); $i++) {
                $m=SaveStock('+',$_REQUEST['ftitem_codeD0'][$i],'',$_REQUEST['ftwarehouse_codeD0'][$i],$_REQUEST['ftlocation_codeD0'][$i],$_REQUEST['fdexp_dateD0'][$i],CCur($_REQUEST['fnqtyD0'][$i]),CCur($_REQUEST['fnqtyD0'][$i]));
                $strSQL=array_merge_recursive($strSQL,$m);
            }
            break;
        }
    return $strSQL;
  }


function RevisiData() {
    global $objAxpDB;
    // $objAxpDB->Allow_Revisi(false);
    $strSQL=array();
    switch($_REQUEST[mode]) {
        case "simpan_revisi":
            $ssql1="SELECT IFNULL(MAX(ftstock_out_no),'')  AS M
                    FROM txstock_out_hdr
                    WHERE ftstock_out_no LIKE '{$_REQUEST['ftstock_out_no']}-%'";
            $no=RetRstField($ssql1);
            if($no!="") 
            {
                $no1=explode("-",$no);
                $no=(int)$no1[1]+1;
                $str1="-{$no}";
            }
            else 
            {
                $str1="-1";
            }
            $fttrans_no_new="{$_REQUEST['ftstock_out_no']}{$str1}";

            // Pengembalian Stock transaksi lama              
            $rs=mysql_query("SELECT * FROM txstock_out_det WHERE ftstock_out_no='{$_REQUEST['ftstock_out_no']}'");
            while($r=mysql_fetch_assoc($rs)) {
                $m=SaveStock('+',$r['ftitem_code'],'',$r['ftwarehouse_code'],$r['ftlocation_code'],'',$r['fnqty_base'],$r['fnqty_base']);
                $strSQL=array_merge_recursive($strSQL,$m);
            }
            
            $strSQL["Revisi"][]="UPDATE txstock_out_hdr
                                    SET fdmodified_date=now(),ftmodified_user='{$_SESSION['username']}',
                                    fnstatus=3,ftstock_out_no='{$fttrans_no_new}'
                                    WHERE ftstock_out_no='{$_REQUEST['ftstock_out_no']}'";
            $strSQL["Revisi"][]="UPDATE txstock_out_det
                                    SET ftstock_out_no='{$fttrans_no_new}'
                                    where ftstock_out_no='{$_REQUEST['ftstock_out_no']}'";

            // Save Stock transaksi baru                        
            for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                $m=SaveStock('-',$_REQUEST['ftitem_codeD0'][$j],'',$_REQUEST['ftwarehouse_codeD0'][$j],$_REQUEST['ftlocation_codeD0'][$j],'',CCur($_REQUEST['fnqty_baseD0'][$j]),CCur($_REQUEST['fnqty_baseD0'][$j]));
                $strSQL=array_merge_recursive($strSQL,$m);
            }
            
            // Call Function Revisi General Ledger
            if(function_exists("RevisiGL")) {
                $m = RevisiGL($fttrans_no_new);
                if ($m != '') { $strSQL=array_merge_recursive($strSQL,$m); }
            }
          
            break;
    }
    return $strSQL;
}
 

?>