<?php

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

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

        break;
    }

 return $strSQL;
}


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

    switch($_REQUEST[mode]) {
        case "simpan":
            $strSQL['Update tlstock_det_sparepart1'][]= "
                UPDATE tlstock_det_sparepart a
                INNER JOIN (SELECT ftitem_code,ftwarehouse_from,ftlocation_from, fdexp_date, SUM(fnqty) AS fnqty
                                FROM txstock_mutation_det_sparepart
                                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_sparepart2'][]= "
                UPDATE tlstock_det_sparepart a
		INNER JOIN (SELECT ftitem_code,ftwarehouse_to,ftlocation_to, fdexp_date, SUM(fnqty) AS fnqty
				FROM txstock_mutation_det_sparepart
				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;
}
