<?php
   switch($_REQUEST[mode]) {
    case "hapus":
        if(RetRstField("SELECT SUM(fnid) AS fnid FROM (
                SELECT fnid FROM tlstock_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}' AND (fnqty_on_hand <> 0 OR fnqty_available <> 0)
                UNION ALL SELECT fnid FROM txinnitial_stock_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txstock_adjustment_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txstock_mutation_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txstock_out_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'

                UNION ALL SELECT fnid FROM tlstock_package WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM tlstock_set WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txdelivery_order_set WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txdelivery_order_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txestimation_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txestimation_poduksi_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txproduction_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txproduction_order_request_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txpurchase_order_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txpurchase_request_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txpurchase_invoice_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txpurchase_return_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txsales_order_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txsales_invoice_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txsales_return_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txpurchase_order_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                UNION ALL SELECT fnid FROM txstock_in_det WHERE ftitem_code = '{$_REQUEST['ftitem_code']}'
                ) X ")) {

                echo "<script>
                    alert('data tidak dapat di delete karena sudah digunakan dalam transaksi ...');
                    window.history.back();
                </script>";
                die("");
        }

    break;    
   }

    function SaveDataLast() {
    global $objAxpDB;
    $strSQL=array();
    switch($_REQUEST[mode]) {
    case "simpan":
            
            $strSQL["n"][]="update tlstock_hdr
                            set ftstock_group_name='".$_REQUEST['hidden_ftstock_group_code']."',
                                fnpo_include='".$_REQUEST['fnpo_include']."'
                            where  ftitem_code='".$_REQUEST['ftitem_code']."'";
        break;

    }

    return $strSQL;
 }

   function UpdateDataLast() {
    global $objAxpDB;
    $strSQL=array();
    switch($_REQUEST[mode]) {
    case "update":
            $strSQL["n"][]="update tlstock_hdr
                            set ftstock_group_name='{$_REQUEST['hidden_ftstock_group_code']}',
                                fnpo_include={$_REQUEST['fnpo_include']}
                            where  ftitem_code='{$_REQUEST['ftitem_code']}'";

            $strSQL["n"][]="delete from tlstock_multi_det
                            where  ftitem_code='{$_REQUEST['ftitem_code']}'";

            for($j=1; $j<count($_REQUEST['ftuom_code_multiD1']); $j++) {
                $strSQL["uom multi"][]="insert into tlstock_multi_det
                                        (ftbranch_code,ftitem_code,ftitem_name,ftuom_code_multi,ffformula,ftketerangan,fdcreated_date,ftcreated_user,fdmodified_date,ftmodified_user)
                                        values ('{$_SESSION[strbranch]}','{$_REQUEST['ftitem_code']}','{$_REQUEST['ftitem_name']}',
                                            '{$_REQUEST['ftuom_code_multiD1'][$j]}',{$_REQUEST['ffformulaD1'][$j]},'{$_REQUEST['ftketeranganD1'][$j]}',
                                            NOW(),'{$_SESSION[username]}',NOW(),'{$_SESSION[username]}') ";
            }

            break;
    }

    return $strSQL;
 }

?>
