<?php
   Getsecurity("pembelian_purchase_order_import");

    // initialize variable for multiple tables
//    $tablename = "";
//    if($_REQUEST['fnpo_type3']==0) {
//        $tablename = "_bahan_baku";
//        $ftstock_type_code = 'invbb';
//    } elseif ($_REQUEST['fnpo_type3']==1) {
//        $tablename = "_setengah_jadi";
//        $ftstock_type_code = 'invsj';
//    } elseif ($_REQUEST['fnpo_type3']==2) {
//        $tablename = "_sparepart";
//        $ftstock_type_code = 'invsp';
//    } elseif ($_REQUEST['fnpo_type3']==3) {
//        $tablename = "";
//        $ftstock_type_code = 'inv';
//    }

    if($_REQUEST['ajax']) {
            switch($_REQUEST['code']) {
                    case "transno":
                            if(RetRstField("SELECT fnid FROM txpurchase_order_hdr WHERE ftpo_no='{$_REQUEST['fttrans_no']}'"))  {
                                    ?>
                                            alert('No. transaksi sudah dipakai...\n System akan mengenerate No. transaksi kembali ...\n Silahkan ulangi proses penyimpanan...  ');
                                            OnChangeDate_fdtrans_date();
                                    <?php
                            }
                            else {
                                    ?>
                                            submitbutton('Simpan','','','','');
                                    <?php
                            }
                            die("");
                            break;
                    case "termpayment":
                            $ssql="select ifnull(ftterm_of_payment,'') as ftterm_of_payment from tlsupplier  where ftsupplier_code='{$_REQUEST['ftsupplier_code']}' ";
                            $ftterm_payment=RetRstField($ssql);

                            if($ftterm_payment=="") {
                                $ftterm_payment="0";
                            }
                            ?>
                                document.getElementById('ftterm_payment').value='<?php echo ($ftterm_payment); ?>';
                            <?php

                            $ssql="SELECT DATE_ADD('".CDate($_REQUEST['fdtrans_date'])."',INTERVAL {$ftterm_payment} DAY)";
                            ?>
                                document.getElementById('fddue_date').value='<?php echo CDateRev(RetRstField($ssql)); ?>';
                            <?php
                            
                            $ssql="select ifnull(ftdelivery_address,'') as ftdelivery_address from tlsupplier  where ftsupplier_code='{$_REQUEST['ftsupplier_code']}' ";
                            $ftdelivery_address=RetRstField($ssql);
                            ?> 
                                document.getElementById('ftship_address').value='<?php echo js_esc($ftdelivery_address); ?>';
                            <?php
                            
                            die(""); 
                            break;

                    case "formula":
                            $ssql="SELECT IFNULL(SUM(ffformula),1) as ffformula
                                            FROM tlstock_multi_det{$tablename}
                                            WHERE ftitem_code='{$_REQUEST['ftitem_code']}'
                                            and ftuom_code_multi='{$_REQUEST['ftuom_code']}'
                                            ";

                            $ffformula=RetRstField($ssql);
                            $ffQtyMulti=(double)$ffformula*(double)CCur($_REQUEST['fnqty']);
                            ?>
                            document.getElementById('ffformulaD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ffformula; ?>';
                            document.getElementById('fnqty_baseD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ffQtyMulti; ?>';
                            <?php
                            die("");
                            break;

                    case "item":
                           
                            $fcprice=RetRstField("SELECT fcbuying_price FROM tlbuying_price WHERE ftitem_code='{$_REQUEST['ftitem_code']}' and ftstock_type_code = '{$ftstock_type_code}' and ftcurrency_code = '{$_REQUEST['ftcurrency_code']}' ");
                            $ffdiscount=RetRstField("SELECT ffbuying_discount FROM tlbuying_price  WHERE ftitem_code='{$_REQUEST['ftitem_code']}' and ftstock_type_code = '{$ftstock_type_code}' and ftcurrency_code = '{$_REQUEST['ftcurrency_code']}' ");
                            
                            if ($ffdiscount=="") { $ffdiscount=0; } 
                            ?>
                            document.getElementById('fcpriceD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $fcprice; ?>';
                            document.getElementById('ffdiscountD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ffdiscount; ?>';
                            document.getElementById('ffformulaD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ffdefault; ?>';
                            document.getElementById('fnstatusD0<?php echo $_REQUEST['index']; ?>').value='1';

                            PurchaseOrderImportRecalDiscDetailPercent('<?php echo $_REQUEST['index']; ?>');
                            PurchaseOrderImportRecalPrice();
                            PurchaseOrderImportRecalDiscPercent();
                            ElementCurrencyALL();
                            
                            <!-- uom code list -->
                            ajax_do('query2.php?code=uom_list&ftitem_code=<?php echo $_REQUEST['ftitem_code']; ?>&ObjLokasi=<?php echo $_REQUEST['ObjLokasi']; ?>');
                            
                            <?php
                            die("");
                            break;

                      case "pr_item":

                            ?>
                            ajax_do('pembelian.php?form=<?php echo $_REQUEST['form']?>&mode=<?php echo $_REQUEST['mode']?>&id=0&ajax=1&code=order&ftproses_pr=' + document.getElementById('ftproses_pr').value + '&ftitem_code_pr=' + document.getElementById('ftitem_code_pr').value + '&fnpo_type3=' + document.getElementById('fnpo_type3').value + '&ftcurrency_code=' + document.getElementById('ftcurrency_code').value);
                            <?php

                            die("");
                            break;
             case "tgl":
                $ssql="select date_add('".CDate($_REQUEST['tgl'])."',INTERVAL ".intval($_REQUEST['ftterm_payment'])." DAY)";
                $date=RetRstField($ssql);
                ?>
                     document.getElementById('fddue_date').value='<?php echo CDateRev($date); ?>';
                <?php
            break;
             case "tgltempo":
                $ssql="select date_add('".CDate($_REQUEST['fdtrans_date'])."',INTERVAL ".intval($_REQUEST['ftterm_payment'])." DAY)";
                $date=RetRstField($ssql);
                ?>
                     document.getElementById('<?php echo $_REQUEST["fddue_date"]; ?>').value='<?php echo CDateRev($date); ?>';
                <?php
            break;

             case "idr":
                $ssql="SELECT fcrate FROM tlcurrency_hdr WHERE ftsimbol='{$_REQUEST["ftcurrency_code"]}'";
                $mysql=mysql_query($ssql) or die ($ssql);
                $r=mysql_fetch_assoc($mysql);
                ?>
                        var i=document.getElementsByName('fnindexD0[]').length;

                        for(var j=1;j < i;j++) {
                            ajax_do('pembelian.php?form=<?php echo $_REQUEST['form']; ?>&mode=<?php echo $_REQUEST['mode']; ?>&id=0&ajax=1&code=item&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value +'&ObjLokasi=ftuom_codeD0' + j + '&ftitem_code=' + document.getElementsByName('ftitem_codeD0[]')[j].value + '&index=' + j + '&fnpo_type3='+ document.getElementById('fnpo_type3').value);
                        }

                        PurchaseOrderImportRecalPrice();
                        PurchaseOrderImportRecalDiscPercent();

                        ElementCurrencyALL();
                        document.getElementById('fcrate').value='<?php echo number_format($r["fcrate"], 4); ?>';
                        <?php
                break;

              case "hdr_category":
                  if($_REQUEST['fnhdr_category']==2){
                ?>
                  document.getElementById('fnpo_type3').value='3';
                  ajax_do_grid0('pembelian.php?form=<?php echo $_REQUEST['form'] ;?>&mode=<?php echo $_REQUEST['mode'] ;?>&id=0&ajax=1&code=grid&fnpo_type3=3&fnhdr_category=<?php echo $_REQUEST['fnhdr_category'] ;?>');
                  ajax_do('pembelian.php?form=<?php echo $_REQUEST['form'] ;?>&mode=<?php echo $_REQUEST['mode'] ;?>&id=0&ajax=1&code=purchaserequest&fnpo_type3=3&fnhdr_category=<?php echo $_REQUEST['fnhdr_category'] ;?>');
              <?php
                  }else{
                ?>
                  ajax_do_grid0('pembelian.php?form=<?php echo $_REQUEST['form'] ;?>&mode=<?php echo $_REQUEST['mode'] ;?>&id=0&ajax=1&code=grid&fnpo_type3=<?php echo $_REQUEST['fnpo_type3'];?>&fnhdr_category=<?php echo $_REQUEST['fnhdr_category'] ;?>');
                  ajax_do('pembelian.php?form=<?php echo $_REQUEST['form'] ;?>&mode=<?php echo $_REQUEST['mode'] ;?>&id=0&ajax=1&code=purchaserequest&fnpo_type3=<?php echo $_REQUEST['fnpo_type3'];?>&fnhdr_category=<?php echo $_REQUEST['fnhdr_category'] ;?>');
              <?php
                  }
              break;
            case "typestock":
              if($_REQUEST["fnhdr_category"] == 2 && $_REQUEST["fnpo_type3"]!=3){
              ?>
                document.getElementById('fnhdr_category').value='0';
              <?php
              }
              break;
            }
    }


    function GetRequest() {

        $x="";

        $ssql="SELECT a.ftbranch_code,a.ftpr_no,a.fnpr_type,c.fttrans_status_name as ftpr_type_name,a.fdtrans_date,b.fnindex,b.ftitem_code,b.fnqty-ifnull(b.fnqty_accept,0) as fnqty
                    FROM txpurchase_request_hdr a inner join txpurchase_request_det b
                    ON a.ftpr_no = b.ftpr_no inner join tstransaction_status c
                    ON a.fnpr_type = c.fntrans_status_code
                    WHERE a.ftbranch_code='{$_SESSION['strbranch']}' AND a.fnstatus=1 and b.fnstatus=1 AND fntrans_group_code = 35 AND fnpr_type=".$_REQUEST['fnpo_type3'];

        $rs=mysql_query($ssql);
        $x.= "<BR>
            <table class='ewTable' id='TransactionDetail2' name='TransactionDetail2' border='0' width='100%' cellspacing='0' celpadding='0'>
            <tr class='ewTableHeader'><td colspan=7>Purchase Request</td></tr>
            <tr class='ewTableHeader'>
             <td  valign='top'>No</th>
             <td  valign='top'>No. PR</th>
             <td  valign='top'>Tipe PR</th>
             <td  valign='top'>Tgl. PR</th>
             <td  valign='top'>Kode Barang</th>
             <td  valign='top'>Qty</th>
             <td  valign='top'>#</th>
            </tr>";

        $i=0;
        $j=0;
        while($r = mysql_fetch_assoc($rs))
        {
            $j++;
            if ($i%2) {
                    $class1="ewTableRow";
                    $class2="ISGridTDeven";
            } else {
                    $class1="ewTableRow";
                    $class2="ISGridTDodd";
            }

            $x.= "<tr class='$class1'>
                    <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='fnindexD2[]' id='fnindexD2[]' value='{$j}' size=3></td>
                    <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='ftpr_noD2[]' id='ftpr_noD2[]' value='" . $r['ftpr_no'] . "'  size=25></td>
                    <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='hidden' name='fnpr_typeD2[]' id='fnpr_typeD2[]' value='" . $r['fnpr_type'] . "'  size=25>
                                        <input readonly style='background-color: #E0E0E0'  type='text' name='ftpr_type_nameD2[]' id='ftpr_type_nameD2[]' value='" . $r['ftpr_type_name'] . "'  size=25></td>
                    <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='fdtrans_dateD2[]' id='fdtrans_dateD2[]' value='" . $r['fdtrans_date'] . "'   size=20></td>
                    <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='ftitem_codeD2[]' id='ftitem_codeD2[]' value='" . $r['ftitem_code'] . "'  size=20></td>
                    <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='fnqtyD2[]' id='fnqtyD2[]' value='" . $r['fnqty'] . "'  size=50></td>
                    <td class='$class2'><input type='checkbox' name='ftpr_listD2[]' id='ftpr_listD2[]' value=\"{$r['ftpr_no']}|{$r['ftitem_code']}\"</td>
                  </tr>
                  ";

            $i++;
         }

         $ajaxItem="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=pr_item&fnpo_type3='+ document.getElementById('fnpo_type3').value +'&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value);";
         $ajaxPR="  document.getElementById('ftproses_pr').value = '';
                    document.getElementById('ftitem_code_pr').value = '';
                    for (var idx=0; idx < document.getElementsByName('ftpr_listD2[]').length; idx++)
                            {
                                 if (document.getElementsByName('ftpr_listD2[]')[idx].checked) {
                                    var vprlist = document.getElementsByName('ftpr_listD2[]')[idx].value;
                                    var res = vprlist.split('|',2);
                                    document.getElementById('ftproses_pr').value=document.getElementById('ftproses_pr').value+',\'' + res[0] + '\'';
                                    document.getElementById('ftitem_code_pr').value=document.getElementById('ftitem_code_pr').value+',\'' + res[1] + '\'';
                                 }
                            }";
         $ajax1=" OnClick=\"{$ajaxPR}{$ajaxItem}\"";

         $x.= " <tr class='$class1'>
                    <td class='$class2' colspan=7 align='right'><input type=button name='proses_pr' id='proses_pr' value='Proses PR' {$ajax1}></td>
                             <input type='hidden' name='ftproses_pr' id='ftproses_pr' value=''>
                             <input type='hidden' name='ftitem_code_pr' id='ftitem_code_pr' value=''></td>
                    </td></tr>
                </table>
                <input id='TransactionDetailCount2' name='TransactionDetailCount2' value='$num_rows' type='hidden'>";

         return $x;
    }

    $objAxpDB->LookupMagicQuotes(True);

    $objAxpDB->ViewName("Daftar Purchase Order Import");
    //$objAxpDB->ViewTable("vPUPOImport");
    $objAxpDB->ViewSQL("select a.fnid,a.fdtrans_date, a.ftpo_no, IF(a.fnpo_type=0,'LOCAL','IMPORT') AS fnpo_type,
                        b.ftsupplier_name, a.fcamount, a.ftcurrency_code, a.ftnotes, d.fttrans_status_name as ftshipment_status,
                        c.fttrans_status_name as ftstatus
                        from txpurchase_order_hdr a
                        left join tlsupplier b on a.ftsupplier_code = b.ftsupplier_code
                        left join tstransaction_status c on a.fnstatus = c.fntrans_status_code and c.fntrans_group_code = 2
                        left join tstransaction_status d on a.fnreceipt_status = d.fntrans_status_code and d.fntrans_group_code = 18
                        left join tstransaction_status e on a.fnpo_type3 = e.fntrans_status_code and e.fntrans_group_code = 35
                        WHERE a.fnpo_type=1
                            AND (('{$_SESSION['strbranch']}' <> 'PUSAT' AND a.ftbranch_code = '{$_SESSION['strbranch']}') OR '{$_SESSION['strbranch']}' = 'PUSAT') 
                        order by a.fdtrans_date desc, a.ftpo_no desc");

    $objAxpDB->ViewCaption("ID, Tgl. PO,No. PO, Jenis PO, Nama Supplier, Jumlah, Mata Uang, Catatan, Status Kirim, Status");
    $objAxpDB->ViewPeriod(TRUE);
    
    $objAxpDB->FormName("Purchase Order Import");
    $objAxpDB->FormSQL("SELECT ftpo_no, '1' AS fnpo_type, fnpo_type3, ftsupplier_code, ftship_address, 
                        fnhdr_print, fnhdr_category, ftreference, ftterm_payment1, fdtrans_date, ftterm_payment,
                        fddue_date, fddelivery_date, ftcurrency_code, fcrate, fnreceipt_status,
                        fntax_code, fdpayment_schedule_date, fnsiap_bayar, ftdelivery_address, ftnotes,
                        fcsub_amount, ffdiscount, fcdiscount, fcother_cost, ffvat, fcvat,
                        fcamount,fnstatus, fnpo_type2
                        FROM txpurchase_order_hdr");
    $objAxpDB->FormCaption("No. PO, Jenis PO, Tipe PO, Supplier, Alamat,
                            Header Cetakan, Kategori PO, No. Reff, Term payment, Tgl. PO, Syarat Pembayaran,
                            Tgl. Jatuh Tempo, Tgl. Kirim,Mata Uang, Kurs, Status Pengiriman,
                            Kode Pajak,Jadwal Pembayaran, Siap Bayar, Alamat Pengiriman, Catatan,
                            Sub Total, Disc (%), Disc, Biaya Lain-Lain, Pajak (%),
                            Pajak,Grand Total, Status, Pembayaran PO");
    $objAxpDB->FormPosition("TL,HD,TL,TL,TL,HD,TL,TR,HD,TR,TR,HD,HD,TR,TR,TR,TR,HD,HD,HD,BL,BR,BR,BR,BR,BR,BR,BR,BL,HD");
    //$objAxpDB->FormLayout(10,"&nbsp;Hari <input type='hidden' id='ftitem_supplier' name='ftitem_supplier'>");
   	
    $objAxpDB->GridSQL(0, "SELECT fnindex, ftitem_code,fnqty,CAST(fnqty - IFNULL(fnqty_accept, 0) AS DECIMAL(19,2)) AS fnqty_outstanding, ffformula,fnqty_base, ftuom_code, fcprice, ffdiscount, fcdiscount, fcamount,fnvat, ftdescription,fdclosing_date,fnstatus FROM txpurchase_order_det");
    $objAxpDB->GridCaption(0, "No., Kode Barang, Qty, Qty Sisa, Qty Formula, Qty Base, Satuan, Harga, Discount(%),Discount,Jumlah, Include Pajak, Keterangan,Tgl. Status, Status");
    $objAxpDB->GridSize(0, "5,5,5,5,5,5,5,10,5,10,10,5,15,5,5");

    $objAxpDB->GridName(1, "Schedule Delivery");
    $objAxpDB->GridSQL(1, "SELECT fnindex,fdschedule_delivery_date, fnlock FROM txpurchase_order_schedule_delivery");
    $objAxpDB->GridCaption(1, "No., Schedule Delivery, Sudah Dikirim");
    		
    if (($_REQUEST['id']=='0') OR (isset($_REQUEST['revisi']))){
        $where_ftsupplier_Code=" WHERE fnstatus=1 AND fnsupplier_type=1 ";
        $where_ftitem_code=" WHERE fnstatus=1";

        $objAxpDB->GridName(2, "Purchase Request");
        $objAxpDB->GridSQL(2, "select '','','','' from txpurchase_order_det ");
        $objAxpDB->GridCaption(2, "No., No. PR, Tipe PR, Tgl. PR");
        $objAxpDB->GridLocked(2,"1,1,1,1");
        $objAxpDB->GridAutoAdd(2, False);
        
    }

    $ajaxKurs="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=idr&ftcurrency_code='+ document.getElementById('ftcurrency_code').value);";

    if($_REQUEST['id']=="") {
        // Form Daftar -- no script yet
    } else if(!$_REQUEST['id']){
            $ajaxTransDate="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=tgl&tgl=' + document.getElementById(\"fdtrans_date\").value + '&ftterm_payment='+ document.getElementById(\"ftterm_payment\").value);";
            $strAutoNumber1="if(document.getElementById('fntax_code').value=='1') {
                                ajax_do('query2.php?code=2&ftmodule_code=pu008&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftpo_no&no_trans=ftpo_no&table_name=txpurchase_order_hdr&type_po=local&vat=' + document.getElementById(\"fntax_code\").value + '&ftbranch_code={$_SESSION['strbranch']}');
                             }
                             else {
                                ajax_do('query2.php?code=2&ftmodule_code=pu008&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftpo_no&no_trans=ftpo_no&table_name=txpurchase_order_hdr&type_po=local&vat=' + document.getElementById(\"fntax_code\").value + '&ftbranch_code={$_SESSION['strbranch']}');
                             }" ;

            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                   {$strAutoNumber1} {$ajaxTransDate}
                                }
                                try
                                {
                                        document.getElementById('ftterm_payment').value='0';
                                }
                                catch (er)
                                {

                                }

                                document.getElementById(\"fnpo_type\").value='1';
                                OnChangeDate_fdtrans_date();
                                document.getElementById('ftcurrency_code').value='IDR';
                                {$ajaxKurs}
                                ElementCurrencyOnBlur(document.getElementById('fcrate'));
                            ";

            $objAxpDB->FormJS($strAutoNumber0);
    } else {
            // revisi
            if(isset($_REQUEST['revisi'])) {
                $UpdateUOM="function UpdateUOM() {
                                var i=document.getElementsByName('fnindexD0[]').length;

                                for(var j=1;j < i;j++) {
                                ajax_do('query2.php?code=uom_list&ftitem_code='+document.getElementsByName('ftitem_codeD0[]')[j].value+'&ObjLokasi=ftuom_codeD0' + j);
                            }
                            }
                            UpdateUOM();
                            ElementCurrencyALL();    
                            ";        
                               
                $ssql="select a.ftpurchase_invoice_no from txpurchase_invoice_hdr a inner join txpurchase_order_hdr b ON a.ftpo_no = b.ftpo_no 
                        WHERE b.fnid = '{$_REQUEST['id']}' AND a.fnstatus !=3 AND a.fnstatus != 9  AND b.fnstatus !=3 AND b.fnstatus != 9 ";

                $ftpurchase_invoice_no = RetRstField($ssql);

                if ($ftpurchase_invoice_no != "") {
                    $msg="alert('Sudah ada transaksi Purchase Invoice Import. {$ftpurchase_invoice_no} harus dibatalkan terlebih dahulu.');window.history.back();";
                    $objAxpDB->FormJS($msg);
                } else {
                    $objAxpDB->FormJS($UpdateUOM);
                }

            } else {
                $objAxpDB->FormJS("ElementCurrencyALL();");
            }    
    }
    
    $objAxpDB->Lookup("ftsupplier_code", "SELECT ftsupplier_Code, ftsupplier_name FROM tlsupplier $where_ftsupplier_Code ORDER BY ftsupplier_Code ASC", "ftsupplier_Code", "ftsupplier_name", -1, False);
    $objAxpDB->Lookup("fnhdr_print", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 57", "fntrans_status_code", "fttrans_status_name",0, True);
    $objAxpDB->Lookup("fnhdr_category", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 58 AND fntrans_status_code IN (0, 2)", "fntrans_status_code", "fttrans_status_name",0, True);
    $objAxpDB->Lookup("fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 2", "fntrans_status_code", "fttrans_status_name",1, True);
    $objAxpDB->Lookup("fnreceipt_status", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 18", "fntrans_status_code", "fttrans_status_name", 1, True);
    $objAxpDB->Lookup("fntax_code", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 15", "fntrans_status_code", "fttrans_status_name", 1,true);
    $objAxpDB->Lookup("fnsiap_bayar", "SELECT '1' AS A,'TRUE' AS B UNION ALL SELECT '0' AS A,'FALSE' AS B ", "A", "B", -1,true);
    $objAxpDB->Lookup("ftuom_code", "SELECT ftuom_code, ftuom_name FROM tluom", "ftuom_code", "ftuom_name", -1,true);
    $objAxpDB->Lookup("fnpo_type", "SELECT 0 AS A,'LOCAL' AS B UNION ALL SELECT 1 AS A,'IMPORT' AS B", "A", "B", 1,true);        
    $objAxpDB->Lookup("fnpo_type2", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 31", "fntrans_status_code", "fttrans_status_name", 0,true);
    $objAxpDB->Lookup("fnpo_type3", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 35 AND fntrans_status_code='3'", "fntrans_status_code", "fttrans_status_name", 0,true);
    $objAxpDB->Lookup("ftcurrency_code", "SELECT  ftsimbol, ftdescription  FROM tlcurrency_hdr ORDER BY ftsimbol", "ftsimbol", "ftdescription", 0, True);
    $objAxpDB->Lookup("ftterm_payment", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 75 ORDER BY fntrans_status_code ", "fntrans_status_code", "fttrans_status_name", 1,true);
    $objAxpDB->LookupGrid(0,"fnvat", "SELECT '1' AS A,'TRUE' AS B UNION ALL SELECT '0' AS A,'FALSE' AS B ", "A", "B", 1,true);
    $objAxpDB->LookupGrid(1,"fnlock", "SELECT '1' AS A,'TRUE' AS B UNION ALL SELECT '0' AS A,'FALSE' AS B ", "A", "B", 1,true);
    $objAxpDB->LookupGrid(0,"fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 2 and (fntrans_status_code=1 or fntrans_status_code=9 or fntrans_status_code=5)", "fntrans_status_code", "fttrans_status_name",1, True);
    $objAxpDB->LookupGrid(0,"ftuom_code", "SELECT ftuom_code, ftuom_name FROM tluom WHERE fnstatus=1", "ftuom_code", "ftuom_name", -1,true);
    //$objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name,ftsupplier_code FROM tlstock_hdr_bahan_baku {$where_ftitem_code} ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False,"' AND ftsupplier_code=\''+ document.getElementById('ftsupplier_code').value + '\''");
    
    //$ajaxAddress="ajax_do('query2.php?code=bb6&ftsupplier_code=' + this.value + '&objAddress=ftship_address');";
    $ajaxtermpayment="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=termpayment&ftsupplier_code='+ document.getElementById('ftsupplier_code').value + '&fttrans_date='+ document.getElementById('fdtrans_date').value);";
    $ajaxGrid1="ajax_do_grid0('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&fnpo_type3='+ document.getElementById('fnpo_type3').value +'&fnhdr_category='+ document.getElementById('fnhdr_category').value);";
    $ajaxGrid2="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=hdr_category&fnhdr_category='+ this.value + '&fnpo_type3=' + document.getElementById('fnpo_type3').value);";
    $ajaxGrid3="ajax_do_grid0('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=typestock&fnpo_type3='+ document.getElementById('fnpo_type3').value +'&fnhdr_category='+ document.getElementById('fnhdr_category').value);";
    $ajaxPR="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=purchaserequest&fnpo_type3='+ document.getElementById('fnpo_type3').value);";

    $objAxpDB->FormScript(2, "onChange=\"{$ajaxGrid3}{$ajaxGrid1}{$ajaxPR}{OnChangeDate_fdtrans_date()}\"");
    //$objAxpDB->FormScript(1, "onChange=\"{$ajaxGrid1}{$ajaxPR}{OnChangeDate_fdtrans_date()}\"");
    $objAxpDB->FormScript(3,"onChange=\"{$ajaxtermpayment}\"");
    $objAxpDB->FormScript(6,"onChange=\"{$ajaxGrid2}\"");
    $objAxpDB->FormScript(15,"onChange=\"OnChangeDate_fdtrans_date();\"");
    $objAxpDB->FormScript(22, "onChange=\"PurchaseOrderImportRecalDiscPercent();\"");
    $objAxpDB->FormScript(23, "onChange=\"PurchaseOrderImportRecalDiscRp();\"");
    $objAxpDB->FormScript(24, "onChange=\"PurchaseOrderImportRecalQty0();\"");
    $objAxpDB->FormScript(25, "onChange=\"PurchaseOrderImportRecalQty0();\"");
    $ajax_due="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&code=tgltempo&ajax=1&fdtrans_date=' + document.getElementById('fdtrans_date').value + '&ftterm_payment=' + document.getElementById('ftterm_payment').value + '&fddue_date=fddue_date');";
    $objAxpDB->FormScript(10, "onChange=\"{$ajax_due}\"");
    $objAxpDB->FormScript(13, "OnChange=\"{$ajaxKurs}\"");
    
    $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr WHERE fnstatus=1 ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False);
    $ajaxItem="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&fnpo_type3='+ document.getElementById('fnpo_type3').value +'&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value +'&ObjLokasi=ftuom_codeD0_N_&ftitem_code=' + this.value + '&index=_N_');";
    $objAxpDB->GridScript(0,1," onChange=\"{$ajaxItem}\"");
                        
//    $ajaxItem="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value +'&ObjLokasi=ftuom_codeD0_N_&ftitem_code=' + this.value + '&index=_N_&fnpo_type3='+ document.getElementById('fnpo_type3').value);";
//    $objAxpDB->GridScript(0,1," onChange=\"{$ajaxItem}\"");
    
    $ajax1=" onChange=\"PurchaseOrderImportRecalDiscDetailPercent(_N_);PurchaseOrderImportRecalDiscPercent();ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=formula&index=_N_&index=_N_&ftitem_code='+ document.getElementById('ftitem_codeD0_N_').value+'&ftuom_code='+ document.getElementById('ftuom_codeD0_N_').value+'&fnqty='+ document.getElementById('fnqtyD0_N_').value+'&ffformula='+ document.getElementById('ffformulaD0_N_').value);\"  ";
    $objAxpDB->GridScript(0,2, $ajax1);
    $ajaxFormula="OnChange=\"ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=formula&index=_N_&index=_N_&ftitem_code='+ document.getElementById('ftitem_codeD0_N_').value+'&ftuom_code='+ document.getElementById('ftuom_codeD0_N_').value+'&fnqty='+ document.getElementById('fnqtyD0_N_').value+'&ffformula='+ document.getElementById('ffformulaD0_N_').value);\"";
    $objAxpDB->GridScript(0,6, $ajaxFormula );
    $ajax1=" onChange=\"PurchaseOrderImportRecalDiscDetailPercent(_N_);PurchaseOrderImportRecalDiscPercent();\"  ";
    $objAxpDB->GridScript(0,7, $ajax1);
    $ajax1=" onChange=\"PurchaseOrderImportRecalDiscDetailPercent(_N_);PurchaseOrderImportRecalDiscPercent();\"   ";
    $objAxpDB->GridScript(0,8, $ajax1);
    $ajax1="   onChange=\"PurchaseOrderImportRecalDiscDetailRp(_N_);PurchaseOrderImportRecalDiscPercent();\"  ";
    $objAxpDB->GridScript(0,9, $ajax1);
    $objAxpDB->GridDelJS(0,"PurchaseOrderImportRecalQty0();");
    
    $objAxpDB->SetStatus("id, fnreceipt_status, fnstatus");

    if ($objAxpDB->GetStatus("id") == "") {
		$objAxpDB->ButtonShow("baru");
    } 
    elseif ($objAxpDB->GetStatus("id") == 0) {
		$objAxpDB->ButtonShow("reset, simpan, tutup");
		$objAxpDB->FormLocked("1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,1,1");
		$objAxpDB->GridLocked(0, "1,0,0,1,1,1,0,0,0,0,1,0,0,0");
                $objAxpDB->GridHidden(0, "0,0,0,1,1,1,0,0,0,0,0,1,0,0");
		$objAxpDB->GridLocked(1, "1,0,0");
		$objAxpDB->GridAllowAddNew(0, TRUE);
		$objAxpDB->GridAllowDelete(0, TRUE);
		//$objAxpDB->GridAllowAddNew(1, TRUE);
		//$objAxpDB->GridAllowDelete(1, TRUE);
    } 
    elseif ($objAxpDB->GetStatus("fnstatus") == 0) {
        $objAxpDB->GridSQL(0, "SELECT fnindex, ftitem_code,fnqty,ffformula,fnqty_base,fnqty_limit, fnqty-ifnull(fnqty_accept,0) as fnqty_accept,fnqty_base-ifnull(fnqty_accept_base,0) as fnqty_accept_base, ftuom_code, fcprice, ffdiscount, fcdiscount, fcamount, fnvat,ftdescription,fdclosing_date,fnstatus FROM txpurchase_order_det");
        $objAxpDB->GridCaption(0, "No., Kode Barang, Qty,Qty Formula, Qty Base,Qty Limit Outsource,Qty Sisa,Qty Sisa Base, Satuan, Harga, Discount(%),Discount,Jumlah, Include Pajak, Keterangan, Tgl. Status, Status");
        
        $ajax1=" onChange=\"PurchaseOrderImportRecalPrice();PurchaseOrderImportRecalDiscDetailPercent(_N_)\"  ";
        $objAxpDB->GridScript(0,2, $ajax1);
        $ajaxFormula="OnChange=\"ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=formula&index=_N_&index=_N_&ftitem_code='+ document.getElementById('ftitem_codeD0_N_').value+'&ftuom_code='+ document.getElementById('ftuom_codeD0_N_').value+'&fnqty='+ document.getElementById('fnqtyD0_N_').value+'&ffformula='+ document.getElementById('ffformulaD0_N_').value);\"";
        $objAxpDB->GridScript(0,8, $ajaxFormula );
        $ajax1=" onChange=\"PurchaseOrderImportRecalPrice();PurchaseOrderImportRecalDiscDetailPercent(_N_); \"  ";
        $objAxpDB->GridScript(0,9, $ajax1);
        $ajax1=" onChange=\"PurchaseOrderImportRecalDiscDetailPercent(_N_);\"   ";
        $objAxpDB->GridScript(0,10, $ajax1);
        $ajax1="   onChange=\"PurchaseOrderImportRecalDiscDetailRp(_N_);\"  ";
        $objAxpDB->GridScript(0,11, $ajax1);

        $objAxpDB->ButtonShow("baru, cetak, cetak_non_harga, update, update_siap_bayar, update_schedule_delivery, final, batal, tutup");
        //$objAxpDB->ButtonShow("reset, simpan, tutup");
        $objAxpDB->FormLocked("1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,1,1");
        $objAxpDB->GridLocked(0,"1,0,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0");
        $objAxpDB->GridHidden(0,"0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0");
        $objAxpDB->GridLocked(1, "1,0,0");
        $objAxpDB->GridAllowAddNew(0, TRUE);
        $objAxpDB->GridAllowDelete(0, TRUE);
        //$objAxpDB->GridAllowAddNew(1, TRUE);
        //$objAxpDB->GridAllowDelete(1, TRUE);
    }
    elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
        // revisi
        if(isset($_REQUEST['revisi'])) 
        {
            $objAxpDB->FormLocked("1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,1,1");
            $objAxpDB->GridLocked(0, "1,0,0,1,1,1,0,0,0,0,1,0,0,0");
                
            $objAxpDB->GridAllowAddNew(0, TRUE);
            $objAxpDB->GridAllowDelete(0, TRUE); 
            
            $objAxpDB->ButtonShow("simpan_revisi,tutup");
        } else {
          
            if($objAxpDB->GetStatus("fnreceipt_status") == 3)
            {
                    $objAxpDB->ButtonShow("baru, cetak, cetak_non_harga, update_schedule_delivery, revisi, batal, tutup");

            }
            // Status item masih bisa dirubah manual menjadi close kalau diperlukan
            else
            {
                    $objAxpDB->ButtonShow("baru, cetak, cetak_non_harga, close_po, update_schedule_delivery, revisi, batal, tutup");
            }

            $objAxpDB->FormLocked("1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1");
            $objAxpDB->GridLocked(0, "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1");
            $objAxpDB->GridHidden(0, "0,0,0,0,1,1,0,0,0,0,0,1,0,0,0");
            $objAxpDB->GridLocked(1,"1,0,0");
            //$objAxpDB->GridAllowAddNew(1, TRUE);
            //$objAxpDB->GridAllowDelete(1, TRUE);
        }    
    }
    elseif ($objAxpDB->GetStatus("fnstatus") == 2) 
    {
            $objAxpDB->ButtonShow("baru, cetak, cetak_non_harga, tutup");
            $objAxpDB->FormLocked("1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1");
            $objAxpDB->GridLocked(0,"1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1");
            $objAxpDB->GridHidden(0,"0,0,0,1,1,1,0,1,0,0,0,0,0,1,0,0,0");
            $objAxpDB->GridLocked(1,"1, 1, 1");
    }
    elseif (($objAxpDB->GetStatus("fnstatus") == 3) || ($objAxpDB->GetStatus("fnstatus") == 5) || ($objAxpDB->GetStatus("fnstatus") == 9)) {
        $objAxpDB->ButtonShow("baru, tutup");
        $objAxpDB->FormLocked("1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1");
        $objAxpDB->GridLocked(0, "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1");
        $objAxpDB->GridHidden(0, "0,0,0,0,1,1,0,0,0,0,0,1,0,0,0");
        $objAxpDB->GridLocked(1, "1,1,1");
    }
    
    if($_REQUEST['ajax'])
    {
		switch($_REQUEST['code'])
		{
                    case "grid":
                        ob_start();
                        $_REQUEST['id']=0;

                        if(($_REQUEST['fnhdr_category']==0) || ($_REQUEST['fnhdr_category']==1)) {
                          $where_ftitem_code = " WHERE ftstock_category_code<>'srv'";
                        }
                        else if($_REQUEST['fnhdr_category']==2){
                          $where_ftitem_code = " WHERE ftstock_category_code='srv'";
                        }

                        $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr{$tablename} {$where_ftitem_code} ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False);
                        $ajaxItem="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&fnpo_type3='+ document.getElementById('fnpo_type3').value +'&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value +'&ObjLokasi=ftuom_codeD0_N_&ftitem_code=' + this.value + '&index=_N_');";
                        $objAxpDB->GridScript(0,1," onChange=\"{$ajaxItem}\"");

                        $objAxpDB->GridSQL(0, "SELECT fnindex, ftitem_code,fnqty,fnqty - IFNULL(fnqty_accept, 0) AS fnqty_outstanding, ffformula,fnqty_base, ftuom_code, fcprice, ffdiscount, fcdiscount, fcamount, fnvat,ftdescription,fdclosing_date,fnstatus FROM txpurchase_order_det");
                        $objAxpDB->Process();
                        $objAxpDB->setGrid2(0);
                        $html = ob_get_contents();
                        ob_end_clean();
                        ?>
                            div = document.getElementById('txtHint0');
                            var m='<?php echo js_esc($html); ?>';
                            m= m.replace(/^\s*|\s*$/g,"");
                            div.innerHTML =m;
                            RowBuild0();
                        <?php
                        break;

                    case "purchaserequest":

                            $html = GetRequest();

                            ?>
                            div = document.getElementById('txtHint2');
                            var m='<?php echo js_esc($html); ?>';
                            m= m.replace(/^\s*|\s*$/g,"");
                            div.innerHTML =m;
                            reSize();
                            <?php


                       break;

                   case "order":
                            $_REQUEST['id']=0.5;

                            ob_start();

                            $ssql="SELECT a.fnid as fnindex, a.ftitem_code, SUM(a.fnqty) AS fnqty ,ffformula,SUM(fnqty_base) AS fnqty_base,
                                        a.ftuom_code AS ftuom_code,b.fcbuying_price AS fcprice,b.ffbuying_discount AS ffdiscount,0.0 AS fcdiscount,0.0 AS fcamount, 0 AS fnvat, a.ftdescription,DATE(NOW()) AS fdclosing_date,'1' AS fnstatus
                                    FROM txpurchase_request_det a INNER JOIN txpurchase_request_hdr c ON a.ftpr_no = c.ftpr_no
                                    LEFT JOIN tlbuying_price b
                                        ON a.ftitem_code = b.ftitem_code AND b.ftcurrency_code = '{$_REQUEST['ftcurrency_code']}'
                                    WHERE a.fnstatus = 1  
                                            AND (a.ftpr_no in ('0'{$_REQUEST['ftproses_pr']})) and (a.ftitem_code in ('0'{$_REQUEST['ftitem_code_pr']}))
                                            AND CASE c.fnpr_type WHEN '0' THEN  b.ftstock_type_code = 'invbb'
                                                                 WHEN '1' THEN  b.ftstock_type_code = 'invsj'
                                                                 WHEN '2' THEN  b.ftstock_type_code = 'invsp'
                                                                 WHEN '3' THEN  b.ftstock_type_code = 'inv'
                                                END 
                                    GROUP BY a.ftitem_code #";
                            // echo $ssql;

                                    
                            $objAxpDB->GridSQL(0,$ssql);
                            $objAxpDB->GridCaption(0, "No., Kode Barang, Qty,Qty Formula, Qty Base, Satuan, Harga, Discount(%),Discount,Jumlah, Include Pajak, Keterangan, Tgl. Status, Status, Uom Code Hidden");
                            $objAxpDB->GridAutoAdd(0, False);

                            $objAxpDB->GridLocked(0,"1,0,0,1,1,0,0,0,0,1,0,0,0,0");
                            $objAxpDB->GridHidden(0,"0,0,0,1,1,0,0,0,0,0,1,0,0,0");
                            $objAxpDB->GridAllowAddNew(0, TRUE);
                            $objAxpDB->GridAllowDelete(0, TRUE);

                            $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr{$tablename} {$where_ftitem_code} ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False);

                            $ajax1=" onChange=\"PurchaseOrderImportRecalDiscDetailPercent(_N_);PurchaseOrderImportRecalDiscPercent();\"  ";
                            $ajaxItem="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value +'&ObjLokasi=ftuom_codeD0_N_&ftitem_code=' + this.value + '&index=_N_&fnpo_type3='+ document.getElementById('fnpo_type3').value);";
                            $objAxpDB->GridScript(0,1," onChange=\"{$ajaxItem}\"");
                            $objAxpDB->GridScript(0,2, $ajax1);
                            $ajaxFormula="OnChange=\"ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=formula&index=_N_&index=_N_&ftitem_code='+ document.getElementById('ftitem_codeD0_N_').value+'&ftuom_code='+ document.getElementById('ftuom_codeD0_N_').value+'&fnqty='+ document.getElementById('fnqtyD0_N_').value+'&ffformula='+ document.getElementById('ffformulaD0_N_').value);\"";
                            $objAxpDB->GridScript(0,5, $ajaxFormula);
                            $objAxpDB->GridScript(0,6, $ajax1);
                            $ajax1=" onChange=\"PurchaseOrderImportRecalDiscDetailPercent(_N_);\"   ";
                            $objAxpDB->GridScript(0,7, $ajax1);
                            $ajax1="   onChange=\"PurchaseOrderImportRecalDiscDetailRp(_N_);\"  ";
                            $objAxpDB->GridScript(0,8, $ajax1);
                            $ajax1="   onChange=\"PurchaseOrderImportRecalDiscDetailRp(_N_);\"  ";
                            $objAxpDB->GridScript(0,8, $ajax1);
                            
                            $objAxpDB->Process();

                            $objAxpDB->setGrid2(0);

                            $html = ob_get_contents();
                            ob_end_clean();

                            ?>
                            div = document.getElementById('txtHint0');
                            var m='<?php echo js_esc($html); ?>';
                            m= m.replace(/^\s*|\s*$/g,"");
                            div.innerHTML =m;
                            TransactionDetailRowID0 =document.getElementsByName('fnindexD0[]').length;
                            RowIndex0();
                            reSize();

                            var i=document.getElementsByName('fnindexD0[]').length;
                            for(var j=0;j < i;j++) {
                                ajax_do('pembelian.php?form=<?php echo $_REQUEST['form']; ?>&mode=<?php echo $_REQUEST['mode']; ?>&id=0&ajax=1&code=item&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value +'&ObjLokasi=ftuom_codeD0' + j + '&ftitem_code=' + document.getElementsByName('ftitem_codeD0[]')[j].value + '&index=' + j + '&fnpo_type3='+ document.getElementById('fnpo_type3').value);
                            }

                            PurchaseOrderImportRecalPrice();
                            PurchaseOrderImportRecalDiscPercent();
                            <?php

                    break;
                }
                die("");
                exit;
    }
    
    if(isset($_REQUEST['id'])&&($_REQUEST['id'])!=0)
    {
        $ssql="SELECT fnpo_type3
                    FROM txpurchase_order_hdr
                    WHERE fnid='{$_REQUEST['id']}'";
        $fnpo_type3=RetRstField($ssql);

//        if ($fnpo_type3=="0")
//            $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr_bahan_baku {$where_ftitem_code} ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False);
//        elseif ($fnpo_type3=="1")
//            $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi {$where_ftitem_code} ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False);
//        elseif ($fnpo_type3=="2")
//            $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr_sparepart {$where_ftitem_code} ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False);
//        elseif ($fnpo_type3=="3")
            $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr {$where_ftitem_code} ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False);

        //$ajaxItem="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&fnpo_type3='+ document.getElementById('fnpo_type3').value +'&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value +'&ftitem_code=' + this.value + '&index=_N_');";
        $ajaxItem="ajax_do('pembelian.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&fnpo_type3='+ document.getElementById('fnpo_type3').value +'&ftcurrency_code='+ document.getElementById('ftcurrency_code').value +'&fcrate='+ document.getElementById('fcrate').value +'&ObjLokasi=ftuom_codeD0_N_&ftitem_code=' + this.value + '&index=_N_');";
        $objAxpDB->GridScript(0,1," onChange=\"{$ajaxItem}\"");
    }

    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();