<?php
    if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM txproduction_outstanding_weekly_hdr WHERE ftpow_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;
            
        }
       
    }

 Getsecurity(30);
$objAxpDB->ViewName("Daftar Outstanding Mingguan");
$objAxpDB->ViewTable("vPROutstandingMingguan");
$objAxpDB->ViewSQL("SELECT A.fnid, A.ftpow_no,a.ftmpor_no, A.fdtrans_date, c.ftcustomer_name,d.fttrans_status_name as fttrans_type, A.ftnotes,  A.fftotal_qty, B.fttrans_status_name FROM txproduction_outstanding_weekly_hdr
                          A INNER JOIN tstransaction_status B ON a.fnstatus=b.fntrans_status_code and b.fntrans_group_code=2
                          INNER JOIN tlcustomer C ON a.ftcustomer_code=c.ftcustomer_code
                          inner join  tstransaction_status d on a.fntrans_type=d.fntrans_status_code and d.fntrans_group_code = 16
                          ORDER BY A.ftpow_no DESC, A.fdtrans_date DESC");

$objAxpDB->ViewCaption("ID, No. POW,No. MPOR, Tanggal,Customer,Cara Kirim,  Catatan, Total Qty, Status");
$objAxpDB->ViewPeriod(TRUE);

$objAxpDB->FormSQL("SELECT ftpow_no,fntrans_type, ftcustomer_code, fdtrans_date,ftnotes,  fftotal_qty, fnstatus FROM txproduction_outstanding_weekly_hdr");
$objAxpDB->FormCaption("No. POW, Cara Kirim,Customer, Tanggal,  Catatan,  Total Qty, Status");
$objAxpDB->FormPosition("TL, TL, TL, TR,BL,  BR, BR");

$objAxpDB->FormName("Outstanding Mingguan");
$objAxpDB->GridSQL(0, "SELECT fnindex, ftitem_code, ffqty FROM txproduction_outstanding_weekly_det");
$objAxpDB->GridCaption(0, "No, Kode Barang, Jml. Order");
$objAxpDB->GridReindex(0, false);
//
//#$objAxpDB->GridScript(0,2,"onChange='OutstandingMingguanRecalQty();'");
// # $objAxpDB->GridDelJS(0,"OutstandingMingguanRecalQty();");
  
//$objAxpDB->GridScript(0,3,"onChange='OutstandingMingguanRecalQty();'");
//$objAxpDB->GridScript(0,4,"onChange='OutstandingMingguanRecalQty();'");

$objAxpDB->Lookup("ftcustomer_code", "SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer", "ftcustomer_code", "ftcustomer_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", 1,true);
$objAxpDB->Lookup("fntrans_type", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 16", "fntrans_status_code", "fttrans_status_name", -1,true);
 
//----------------------------------
if(!$_REQUEST['id']) {

//    if(($_SESSION['username']=="rika")||($_SESSION['username']=="RIKA")) {
//
//    }
//    else {
     $ajaxGrid="ajax_do_grid0('preproduksi.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&fdtrans_date='+ document.getElementById('fdtrans_date').value +'&fntrans_type='+document.getElementById('fntrans_type').value+'&ftcustomer_code='+ document.getElementById('ftcustomer_code').value +'');";
     $objAxpDB->FormScript(1, "onChange=\"{$ajaxGrid}\"");
     $objAxpDB->FormScript(2, "onChange=\"{$ajaxGrid}\"");
//    }
    $strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=TN101&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftpow_no&no_trans=ftpow_no&table_name=txproduction_outstanding_weekly_hdr');";
    $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                   {$strAutoNumber1}
                                  
                    }
                    OnChangeDate_fdtrans_date();
                    
                        ";

    $objAxpDB->FormJS($strAutoNumber0);

  
 
}
 $objAxpDB->SetStatus("id, fnstatus");
 if($objAxpDB->GetStatus("fnstatus")==1) {
     $m="  WHERE fnstatus=1   ORDER BY ftitem_code ";
 }
 if(!$_REQUEST['id']) {
        $m="  WHERE fnstatus=1   ORDER BY ftitem_code ";
	}
 if($_REQUEST['ajax']) {
           switch($_REQUEST['code']) {
           case "grid":
                $m="  WHERE fnstatus=1   ORDER BY ftitem_code ";
               break;
           }
 }


$objAxpDB->Lookup("ftitem_code", "SELECt ftitem_code, ftitem_name FROM tlstock_hdr $m", "ftitem_code", "ftitem_name", -1,false);



   
    if ($objAxpDB->GetStatus("id") == "")
            $objAxpDB->ButtonShow("baru, cetak_daftar, export_excel , tutup");
    elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->GridAllowAddNew(0,true);
            $objAxpDB->GridAllowDelete(0,true);
            $objAxpDB->GridLocked(0, "1, 0, 0");
            $objAxpDB->ButtonShow("simpan, tutup");
            $objAxpDB->FormLocked("0, 0, 0, 0, 0, 1, 1");
            
    } 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");
               $objAxpDB->GridAllowAddNew(0,true);
            $objAxpDB->GridAllowDelete(0,true);
            $objAxpDB->ButtonShow("cetak,update, batal, tutup");
           $objAxpDB->FormLocked("1, 1, 1,0, 1, 1, 1, 1");
             $objAxpDB->GridLocked(0, "1, 0, 0");
//              #$objAxpDB->FormJS(" var jj =document.getElementsByName('fnindexD0[]').length;
//                            for(var ii=1;ii<jj;ii++) {
//                               document.getElementsByName('fnindexD0[]')[ii].value=ii;
//                            }
//                         ");
          #$m="  WHERE fnstatus=1   ORDER BY ftitem_code ";
  } elseif ($objAxpDB->GetStatus("fnstatus") == 4) {
            $objAxpDB->ButtonShow("cetak, batal, tutup");
           $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1");
             $objAxpDB->GridLocked(0, "1, 1, 1");

 } elseif ($objAxpDB->GetStatus("fnstatus") == 5) {
            $objAxpDB->ButtonShow("cetak, batal, tutup");
           $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1");
             $objAxpDB->GridLocked(0, "1, 1, 1");

    } elseif ($objAxpDB->GetStatus("fnstatus") == 9) {
              $objAxpDB->GridLocked(0, "1, 1, 1,1,1,1");
              $objAxpDB->FormLocked("1, 1, 1");
            $objAxpDB->ButtonShow("tutup");
    }


     if($_REQUEST['ajax']) {
           switch($_REQUEST['code']) {
           case "grid":
             
               ob_start();
//               if($_REQUEST['idx']==0) {
                       $date=RetRstField("select fdtrans_date
                                            from txproduction_outstanding_weekly_hdr
                                            where ftcustomer_code='{$_REQUEST['ftcustomer_code']}' and
                                                  fnstatus<>9 and   fntrans_type='{$_REQUEST['fntrans_type']}' and
                                                  ftmpor_no<>''
                                            order by fdtrans_date desc");

                       if(CDateRev($_REQUEST['fdtrans_date'])==$date) {
                           exit;
                       }
//                       if($_REQUEST['ftcustomer_code']=='BT01') {
//                           $ssql1="select 0.1 as fnindex, b.ftitem_code,b.ffqty
//                                    from txproduction_outstanding_weekly_hdr a,
//                                        txproduction_outstanding_weekly_det b
//                                    where a.ftpow_no=b.ftpow_no and a.fdtrans_date='$date' and
//                                         a.fnstatus<>9  and   a.fntrans_type='{$_REQUEST['fntrans_type']}' and
//                                     a.ftcustomer_code='{$_REQUEST['ftcustomer_code']}'
//                                    ORDER BY b.ftitem_code  /* ";
//
//                       }
//                       else {
                     $ssql1="select b.fnindex as fnindex, b.ftitem_code,b.ffqty
                                    from txproduction_outstanding_weekly_hdr a,
                                        txproduction_outstanding_weekly_det b,
										tlstock_hdr c
                                    where b.ftitem_code=c.ftitem_code and c.fnstatus=1 and  a.ftpow_no=b.ftpow_no and a.fdtrans_date='$date' and
                                         a.fnstatus<>9  and   a.fntrans_type='{$_REQUEST['fntrans_type']}' and
                                     a.ftcustomer_code='{$_REQUEST['ftcustomer_code']}'
                                    ORDER BY b.ftstock_group_name asc,b.ftstock_subgroup_name asc,b.ftdecal_name asc,b.ftcolor_name asc,b.ftsize_name asc  # ";
//                       }
                       //die($ssql1)   ;
                        $objAxpDB->GridSQL(0, $ssql1);
                        $objAxpDB->GridCaption(0, "No, Kode Barang, Jml. Order");
//                        #$objAxpDB->GridScript(0,2,"onChange='OutstandingMingguanRecalQty();'");
//                        $objAxpDB->GridDelJS(0,"OutstandingMingguanRecalQty();");
                        $objAxpDB->GridAllowAddNew(0,true);
                        $objAxpDB->GridAllowDelete(0,true);
                        $objAxpDB->GridLocked(0, "1, 0, 0");
//               }
               $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-1;
                    
               <?

               break;
          
           }
           die("");
           exit;
    }
    
    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();

?>
