

    <?php

 function SaveData() {
        global $objAxpDB;
        $objAxpDB->Allow_Save(true);
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":
         #===================================
    
            for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                $m=SaveStock_setengah_jadi('+',$_REQUEST['ftitem_codeD0'][$j],'',$_REQUEST['ftwarehouse_codeD0'][$j],$_REQUEST['ftlocation_codeD0'][$j],CCur($_REQUEST['fnqtyD0'][$j]),CCur($_REQUEST['fnqtyD0'][$j]));
                $strSQL=array_merge_recursive($strSQL,$m);
                $fntotal_qty=$fntotal_qty+(double)CCur($_REQUEST['fnqtyD0'][$j]);
            }

            $jj=0;
            $ftstock_in_no=getAutoNumber($_SESSION['strbranch'],'sjtn001','txstock_in_hdr_setengah_jadi','ftstock_in_no',$_REQUEST['fdtrans_date']);

            $ssql="INSERT INTO txstock_in_hdr_setengah_jadi
                    (
                        ftstock_in_no, ftcategory_code, ftstock_in_company, ftdocument_no,
                        fdschedule_delivery_date, fdtrans_date, ftreff_no, ftchecked_user,
                        ftnotes,  fntotal_qty, fnstatus
                    )
                    SELECT
                        '{$ftstock_in_no}' AS ftstock_in_no, '5' AS ftcategory_code, '{$_REQUEST['ftsupplier_code']}' AS ftstock_in_company, '{$_REQUEST['ftstock_in_no']}'  AS ftdocument_no,
                        '".CDate($_REQUEST['fdtrans_date'])."' AS fdschedule_delivery_date, '".CDate($_REQUEST['fdtrans_date'])."' AS fdtrans_date, '' AS ftreff_no, '' AS ftchecked_user,
                        '{$_REQUEST['ftnotes']}' AS ftnotes,  '{$fntotal_qty}' AS fntotal_qty, '1' AS fnstatus";

             $strSQL['Insert txstock_in_hdr_setengah_jadi'][]=$ssql;

                $index=0;
                for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                     if(CCur($_REQUEST['fnqtyD0'][$j])>0) {
                         $index++;
                          $ssql="INSERT INTO txstock_in_det_setengah_jadi
                                    (
                                        ftstock_in_no, fnindex, ftitem_code, ftwarehouse_code, ftlocation_code, fnqtypo,
                                        fnqtysisapo, fnqty, ftuom_code
                                    )
                                    SELECT
                                        '{$ftstock_in_no}' AS ftstock_in_no, '{$index}' AS fnindex, '{$_REQUEST['ftitem_codeD0'][$j]}' AS ftitem_code, '{$_REQUEST['ftwarehouse_codeD0'][$j]}' AS ftwarehouse_code, '{$_REQUEST['ftlocation_codeD0'][$j]}' AS ftlocation_code, '' AS fnqtypo,
                                        '' AS fnqtysisapo, '".CCur($_REQUEST['fnqtyD0'][$j])."' AS fnqty, '{$_REQUEST['ftuom_codeD0'][$j]}' AS ftuom_code";
                             $strSQL['Insert txstock_in_det_setengah_jadi'][]=$ssql;
                     }
                }

                $index=0;
                for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                     if(CCur($_REQUEST['fnqtyD0'][$j])>0) {
                         $index++;
                          $ssql="UPDATE txspk_det
                                        SET
                                            fnqty_produksi = fnqty_produksi + '".CCur($_REQUEST['fnqtyD0'][$j])."'
                                            WHERE ftspk_no = '{$_REQUEST['ftspk_noD0'][$j]}'  
                                            AND ftitemdetail_code = '{$_REQUEST['ftitem_codeD0'][$j]}'";

                          $strSQL['Update txspk_det'][]=$ssql;
                     }
                }

        break;
    }
    return $strSQL;
   }

 function CancelData() {

        global $objAxpDB;
        $objAxpDB->Allow_Cancel(True);

        $strSQL=array();
        switch($_REQUEST[mode]) {
          case "batal":
           
                       $ssql="UPDATE txstock_in_hdr_setengah_jadi
                                SET fnstatus=9
                             WHERE ftdocument_no= '{$_REQUEST['ftstock_in_return_no']}' AND
                                    ftcategory_code='5'";
                    $strSQL['Batal txstock_in_hdr_bahan_baku'][]=$ssql;

                     for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                         $m=SaveStock_setengah_jadi('-',$_REQUEST['ftitem_codeD0'][$j],'',$_REQUEST['ftwarehouse_codeD0'][$j],$_REQUEST['ftlocation_codeD0'][$j],CCur($_REQUEST['fnqtyD0'][$j]),CCur($_REQUEST['fnqtyD0'][$j]));
                         $strSQL=array_merge_recursive($strSQL,$m);
                     }

                    $index=0;
                    for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                         if(CCur($_REQUEST['fnqtyD0'][$j])>0) {
                             $index++;
                              $ssql="UPDATE txspk_det
                                            SET
                                                fnqty_produksi = fnqty_produksi - '".CCur($_REQUEST['fnqtyD0'][$j])."'
                                                WHERE ftspk_no = '{$_REQUEST['ftspk_noD0'][$j]}'
                                                AND ftitemdetail_code = '{$_REQUEST['ftitem_codeD0'][$j]}'";

                              $strSQL['Update txspk_det'][]=$ssql;
                         }
                    }

        break;
    }
    return $strSQL;
   }



?>
