<?php

function SaveData() {
    global $objAxpDB;
    $strSQL=array();
    switch($_REQUEST[mode]) {
    case "simpan":
        /*
        for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
             $m=SaveStock_bahan_baku('-',$_REQUEST['ftitem_codeD0'][$j],'',$_REQUEST['ftwarehouse_fromD0'][$j],$_REQUEST['ftlocation_fromD0'][$j],CCur($_REQUEST['fnqtyD0'][$j]),CCur($_REQUEST['fnqtyD0'][$j]));
             $strSQL=array_merge_recursive($strSQL,$m);
             $m=SaveStock('+',$_REQUEST['ftitem_codeD0'][$j],'',$_REQUEST['ftwarehouse_toD0'][$j],$_REQUEST['ftlocation_toD0'][$j],CCur($_REQUEST['fnqtyD0'][$j]),CCur($_REQUEST['fnqtyD0'][$j]));
             $strSQL=array_merge_recursive($strSQL,$m);
        }
        */
       break;

    }

    return $strSQL;
}


function SaveDataAfter() {
    global $objAxpDB;
    $strSQL=array();

    switch($_REQUEST[mode]) {
        case "simpan":
            $strSQL['Update tlstock_det_bahan_baku'][]= "
                UPDATE tlstock_det_bahan_baku a
                INNER JOIN (SELECT ftitem_code,ftwarehouse_from,ftlocation_from, fdexp_date, SUM(fnqty) AS fnqty
                                FROM txstock_mutation_det_bbtobj
                                WHERE ftstock_mutation_no = '".$_REQUEST['ftstock_mutation_no']."'
                                GROUP BY ftitem_code,ftwarehouse_from,ftlocation_from,fdexp_date) b
                       ON a.ftitem_code=b.ftitem_code AND
                          a.ftWarehouse_Code=b.ftwarehouse_from AND
                          a.ftlocation_code=b.ftlocation_from AND
                          a.fdexp_date=b.fdexp_date
                SET a.fnqty_available=a.fnqty_available - b.fnqty";

            $strSQL['Update tlstock_det'][]= "
                UPDATE tlstock_det a
		INNER JOIN (SELECT ftitem_code,ftwarehouse_to,ftlocation_to,fdexp_date, SUM(fnqty) AS fnqty
				FROM txstock_mutation_det_bbtobj
				WHERE ftstock_mutation_no = '".$_REQUEST['ftstock_mutation_no']."'
				GROUP BY ftitem_code,ftwarehouse_to,ftlocation_to,fdexp_date) b
		       ON a.ftitem_code=b.ftitem_code AND
			  a.ftWarehouse_Code=b.ftwarehouse_to AND
			  a.ftlocation_code=b.ftlocation_to AND
                          a.fdexp_date=b.fdexp_date
                SET a.fnqty_available=a.fnqty_available + b.fnqty";

        break;
    }

 return $strSQL;
}


function CancelData() {
    global $objAxpDB;
    $strSQL=array();

    switch($_REQUEST[mode]) {
        case "batal":

        break;
    }
  
    return $strSQL;
}