<?php
 
$objAxpDB->ViewName("Daftar Production Order Sheet Custom");
$objAxpDB->ViewTable("vPRPOSheetCustom");


$objAxpDB->ViewCaption("ID, No. POS, Date, Forecasted Production Time, No. Reff, Quantity, Note, Status");
$objAxpDB->ViewPeriod(TRUE);

$objAxpDB->FormName("Production Order Sheet Custom");
$objAxpDB->FormSQL("SELECT ftpos_no, fdtrans_date,fdforecasted_date, ftpor_no, fftotal_qty, ftnotes, fnstatus FROM txproduction_order_sheet_hdr");
$objAxpDB->FormCaption(" No. POS, Date,Forecasted Production Time, No. Reff,  Quantity, Note, Status");
$objAxpDB->FormPosition(" TL, TL,TL, TR,  BR, BL, BR");
 
$objAxpDB->GridSQL(0, "SELECT a.fnindex, a.ftitem_code, a.ftstock_group_code,a.ftcolor_code,a.ffqty FROM txproduction_order_sheet_det a ORDER BY a.fnindex");
$objAxpDB->GridCaption(0, "No, Kode Barang, Group Barang, Kode Warna,Qty");
//$objAxpDB->GridSize(0, " , 15, 50, 10, 10,10,10");
    

$objAxpDB->Lookup("ft_item_code", "SELECT ftitem_code, ftitem_name FROM tlstock", "ftitem_code", "ftitem_name", -1,false);
$objAxpDB->Lookup("ft_stock_group_code", "SELECT ftstock_group_code, ftstock_group_name FROM tlstock_group", "ftstock_group_code", "ftstock_group_name", -1,false);
$objAxpDB->Lookup("ftcolor_code", "SELECT ftcolor_code, ftcolor_name FROM tlcolor", "ftcolor_code", "ftcolor_name", -1,false);
$objAxpDB->Lookup("fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 2", "fntrans_status_code", "fttrans_status_name", 0,true);

$objAxpDB->SetStatus("id, fnstatus");
if ($objAxpDB->GetStatus("id") == "") {
       $objAxpDB->ButtonShow(" baru, cetak_daftar, export_excel ,tutup");
} elseif ($objAxpDB->GetStatus("fnstatus") == 0) {
        $objAxpDB->ButtonShow("simpan,tutup");
        $objAxpDB->FormLocked("1, 1, 0,1, 1,0,  1, 1");
        $objAxpDB->GridLocked(0, "1,0,1,1,0");
        $objAxpDB->FormJS(" ValPOS(); ");
        $objAxpDB->GridDelJS(0,"ValPOS();");
        $objAxpDB->GridScript(0,1,"onChange='ValPOS();'");
        $objAxpDB->GridScript(0,5,"onChange='ValPOS();'");
}
 elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
        $objAxpDB->Lookup( "fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE (fntrans_status_code=1 OR fntrans_status_code=4 OR fntrans_status_code=6) AND fntrans_group_code = 2", "fntrans_status_code", "fttrans_status_name", 0,true);
        $objAxpDB->ButtonShow("update_status,cetak,tutup");
        $objAxpDB->FormLocked("1, 1, 1,1, 1,1,  0, 1");
        $objAxpDB->GridLocked(0, "1,1,1,1,1");
}
 elseif ($objAxpDB->GetStatus("fnstatus") == 4) {
        $objAxpDB->Lookup( "fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE (fntrans_status_code=1 OR fntrans_status_code=4 OR fntrans_status_code=6) AND fntrans_group_code = 2", "fntrans_status_code", "fttrans_status_name", 0,true);
        $objAxpDB->ButtonShow("update_status,cetak,tutup");
        $objAxpDB->FormLocked("1, 1, 1,1, 1,1,  0, 1");
        $objAxpDB->GridLocked(0, "1,1,1,1,1");
 }
 elseif ($objAxpDB->GetStatus("fnstatus") == 6) {
        $objAxpDB->Lookup( "fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE (fntrans_status_code=1 OR fntrans_status_code=4 OR fntrans_status_code=6) AND fntrans_group_code = 2", "fntrans_status_code", "fttrans_status_name", 0,true);
         $objAxpDB->ButtonShow("update_status,cetak,tutup");
        $objAxpDB->FormLocked("1, 1, 1,1, 1,1,  0, 1");
        $objAxpDB->GridLocked(0, "1,1,1,1,1");
 }
$objAxpDB->Process();

$ssql="SELECT fnstatus
        FROM txproduction_order_sheet_hdr
        WHERE fnid='".$_REQUEST['id']."'";
#die("$ssql");
if(RetRstField($ssql)==0) {
    /*
  $ssql="SELECT ftpos_no FROM txproduction_order_sheet_hdr WHERE fnid='".$_REQUEST['id']."'";
    $ftpos_no=RetRstField($ssql);
    $ssql="SELECT fdtrans_date FROM txproduction_order_sheet_hdr WHERE fnid='".$_REQUEST['id']."'";
    $date=RetRstField($ssql);

    $ssql="SELECT SUM(IFNULL(ffqty,fnqty_por)) AS fftotal_qty FROM txproduction_order_sheet_det WHERE ftpos_no='{$ftpos_no}' ";

    $rs=mysql_query($ssql);
    $r=mysql_fetch_assoc($rs);
    if($r['fftotal_qty']>=2000) {
        $n=0;
        while($n!=60) {
            $ssql_1="SELECT date_add('{$date}',INTERVAL 1 DAY)";
            $date=RetRstField($ssql_1);
            $ssql_2="SELECT  DATE_FORMAT('{$date}','%W')";
            $day=RetRstField($ssql_2);
            if(($day=="Saturday")||($day=="Sunday")) {

            }
            else {
                $n++;
            }
        }

    }
    else {
         $n=0;
        while($n!=30) {
            $ssql_1="SELECT date_add('{$date}',INTERVAL 1 DAY)";
            $date=RetRstField($ssql_1);
            $ssql_2="SELECT  DATE_FORMAT('{$date}','%W')";
            $day=RetRstField($ssql_2);
            if(($day=="Saturday")||($day=="Sunday")) {

            }
            else {
                $n++;
            }
        }

    }
*/

   // $strAutoNumber0="  ValPOS(); document.getElementById('fdforecasted_date').value='".CdateRev($date)."';";

    $objAxpDB->FormJS($strAutoNumber0);

}


$objAxpDB->WriteHtmlTable();

?>
