<?php

Getsecurity("production_order_request_custom");

$str = "SELECT * FROM tlstock_hdr WHERE ftstock_category_code = 'inv' AND ftstock_group_code != 'ASSET' AND ftstock_group_code != 'EXP'";
        
if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM txproduction_order_request_hdr WHERE ftpor_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 "item":
                $ssql="SELECT ftstock_group_code, ftstock_group_name, ftcolor_code, ftcolor_name FROM ({$str}) a 
                            WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";
                $rs=mysql_query($ssql);
                $r=mysql_fetch_assoc($rs);
		$ftstockgroupcode=$r['ftstock_group_code'];
                $ftstockgroupname=$r['ftstock_group_name'];
                $ftcolorcode=$r['ftcolor_code'];
                $ftcolorname=$r['ftcolor_name'];

                ?>
                document.getElementById('ftstock_group_codeD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftstockgroupcode; ?>';
                document.getElementById('ftstock_group_nameD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftstockgroupname; ?>';
                //document.getElementById('ftcolor_codeD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftcolorcode; ?>';
                //document.getElementById('ftcolor_nameD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftcolorname; ?>';
                <?php
               
                die("");
            break;


        }

    }

$objAxpDB->LookupMagicQuotes(True);
$objAxpDB->ViewName("Daftar Production Order Request(Custom)");
$objAxpDB->ViewTable("vPRPORequestCustom");
$objAxpDB->ViewCaption("ID, No. POR, No. Reff, Tanggal, Tanggal Selesai, Catatan, Status");
$objAxpDB->ViewPeriod(TRUE);

$objAxpDB->FormName("Production Order Request Custom");
$objAxpDB->FormSQL("SELECT  ftpor_no,fntype, ftmpor_no,fdtrans_date, fdfinished_date, ftnotes, fnstatus FROM txproduction_order_request_hdr");
$objAxpDB->FormCaption("No. POR, Tipe POR, No Reff, Tanggal, Tanggal Selesai,Catatan, Status");
$objAxpDB->FormPosition(" TL,TL,TL,TR,TR,BL, BR");
$objAxpDB->SetStatus("id, fnstatus");

$objAxpDB->GridSQL(0, "SELECT fnindex, ftitem_code, ftstock_group_code,ftstock_group_name,ffqty from txproduction_order_request_det");
$objAxpDB->GridCaption(0, "No, Kode Barang, Kode Group, Nama Group, Qty");

if($objAxpDB->GetStatus("id") ==0) {
         $strAutoNumber1=" ajax_do('query2.php?code=2&ftmodule_code=preprod002&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftpor_no&no_trans=ftpor_no&table_name=txproduction_order_request_hdr&ftbranch_code={$_SESSION['strbranch']}');";
         $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                                                   {$strAutoNumber1}
                                                         }
                                                 OnChangeDate_fdtrans_date();

                                                ";
        $objAxpDB->FormJS($strAutoNumber0);
}

$ajaxItem="ajax_do('preproduksi.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&ftitem_code=' + this.value + '&index=_N_');";
$objAxpDB->GridScript(0,1," onChange=\"{$ajaxItem}\"");

$objAxpDB->Lookup("fntype", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 51", "fntrans_status_code", "fttrans_status_name", 1,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("ftitem_code", "SELECT ftitem_code, ftitem_name FROM ({$str}) a ORDER BY ftitem_code", "ftitem_code", "ftitem_name", -1, False);

//$objAxpDB->GridReindex(0, false);

if ($objAxpDB->GetStatus("id") == "") {
     $objAxpDB->ButtonShow(" baru, cetak_daftar, export_excel , tutup");
}
elseif ($objAxpDB->GetStatus("id") ==0) {
     $objAxpDB->ButtonShow("simpan, tutup");
     $objAxpDB->FormLocked("0,1,0,0,0,0,1");
     $objAxpDB->GridLocked(0, "1,0,1,1,0");
     $objAxpDB->GridHidden(0, "0,0,1,1,0");
     $objAxpDB->GridAllowAddNew(0,true);
     $objAxpDB->GridAllowDelete(0,true);
}
elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
     $objAxpDB->ButtonShow("cetak,batal,tutup");
     $objAxpDB->FormLocked("1,1,1,1,1,1,1");
     $objAxpDB->GridLocked(0, "1,1,1,1,1");
     $objAxpDB->GridHidden(0, "0,0,1,1,0");
}


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