<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM txrekap_delivery_order_hdr WHERE ftrekap_do_no='{$_REQUEST['fttrans_no']}'")) {
                  ?>

                  alert('No. Estimasi sudah dipakai... ');
            <?php
              }
              else {
                    ?>

                  submitbutton('Simpan','','','','');

            <?php
              }
               die("");
            break;
        
        }
        //die("");
    }


    $objAxpDB->ViewName("Daftar Rekap Delivery Order");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.ftrekap_do_no,a.fdtrans_date,a.ftcustomer_code, a.ftnotes, c.fttrans_status_name AS ftstatus
                        FROM txrekap_delivery_order_hdr a
                        LEFT JOIN tstransaction_status c ON a.fnstatus = c.fntrans_status_code AND c.fntrans_group_code = 2");
    $objAxpDB->ViewCaption("ID, No. Rekap Delivery Order, Tgl. Transaksi, Customer, Catatan, Status");
    $objAxpDB->ViewPeriod(TRUE);
	
	 // Deklarasi Header
    $objAxpDB->FormName("Rekap Delivery Order");
    $objAxpDB->FormSQL("select ftrekap_do_no,ftcustomer_code, ftship_address,fdtrans_date,ftnotes,fnstatus from txrekap_delivery_order_hdr");
    $objAxpDB->FormCaption("No. Rekap DO, Customer, Alamat, Tgl. Rekap DO, Catatan, Status");
    $objAxpDB->FormPosition("TL,TL,TL,TR,BL,BR");
								
     // Deklarasi Detail
    #$objAxpDB->GridName(0, "Daftar Delivery Order");
    $objAxpDB->GridSQL(0, "SELECT fnindex, ftdo_no, ftdo_type, fddue_date, ftdelivery_method,fftotal_qty, ftrekap_status FROM txrekap_delivery_order_det");
    $objAxpDB->GridCaption(0,"No., No. DO, Tipe Surat Jalan, Tgl. Jatuh Tempo ,Metode Pengiriman ,Qty, Rekap Status" );
    $objAxpDB->GridAutoAdd(0, false);
	$objAxpDB->GridHidden(0, "0, 0, 0,0,0,0,1,");
   
    $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->LookupGrid(0,"ftdelivery_method", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 7", "fntrans_status_code", "fttrans_status_name", -1,true);			
    $objAxpDB->LookupGrid(0,"ftdo_type", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 30", "fntrans_status_code", "fttrans_status_name", -1,true);

    $ajaxGrid="ajax_do_grid0('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&ftcustomer_code='+ document.getElementById('ftcustomer_code').value + '&fdtrans_date='+ document.getElementById('fdtrans_date').value);";
    $ajaxAddress="ajax_do('query2.php?code=611&ftcustomer_code=' + this.value + '&objAddress=ftship_address');";	
	$objAxpDB->FormScript(1, "onChange=\"{$ajaxGrid} {$ajaxAddress}\"");    
	
    $objAxpDB->SetStatus("id, fnstatus");
	
       if(!$_REQUEST['id']) {
            $strAutoNumber1="  ajax_do('query2.php?code=2&ftmodule_code=tn122&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftrekap_do_no&no_trans=ftrekap_do_no&table_name=txrekap_delivery_order_hdr');

                             ";


            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                           {$strAutoNumber1}
											{$ajaxGrid}
                                     }
                                     OnChangeDate_fdtrans_date();
									
                                ";

            $objAxpDB->FormJS($strAutoNumber0);
     }

    if ($objAxpDB->GetStatus("id") == "")
            $objAxpDB->ButtonShow("baru, cetak_daftar, export_excel ,  tutup");
    elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->FormLocked("0, 0, 0, 0,0, 1");

            $objAxpDB->ButtonShow("reset, simpan, tutup");
			$objAxpDB->GridLocked(0, "1, 1, 1,1,1,1,1,1,1");

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

    if($_REQUEST['ajax']) {
           switch($_REQUEST['code']) {
           case "grid":
               ob_start();
                       $objAxpDB->GridSQL(0, "SELECT  @rownum:=@rownum+1 'fnindex',a.ftdo_no, a.ftdo_type, a.fddue_date, a.ftdelivery_method, a.fftotal_qty , c.ftrekap_status
												FROM txdelivery_order_hdr a ,(SELECT @rownum:=0) r
													LEFT JOIN txrekap_delivery_order_hdr b ON 0=1
													left join txrekap_delivery_order_det c on b.ftrekap_do_no=c.ftrekap_do_no 
													#LEFT JOIN tstransaction_status D ON D.fntrans_group_code = 30 #AND d.fntrans_status_code=a.ftdelivery_method
													#LEFT JOIN tstransaction_status E ON E.fntrans_group_code = 7 #AND E.fntrans_status_code=a.ftdo_type
												WHERE a.ftdo_no NOT IN (SELECT a.ftdo_no 
																		FROM txrekap_delivery_order_det a 
																			INNER JOIN txrekap_delivery_order_hdr b
																			ON a.ftrekap_do_no=b.ftrekap_do_no
																		WHERE b.fnstatus=1) 
												AND a.fnstatus=1	AND 
												a.ftcustomer_code='{$_REQUEST['ftcustomer_code']}' AND
                                                DATE_FORMAT(a.fdtrans_date,'%d/%m/%Y')='{$_REQUEST['fdtrans_date']}' #");
			   
    $objAxpDB->LookupGrid(0,"ftdelivery_method", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 7", "fntrans_status_code", "fttrans_status_name", -1,false);			
    $objAxpDB->LookupGrid(0,"ftdo_type", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 30", "fntrans_status_code", "fttrans_status_name", -1,false);

			   $objAxpDB->GridLayout(0,0,"&nbsp;<input type='hidden' id='hd_includeD0_N_' name='hd_includeD0[]' value='0'> <input type='checkbox'  id='chk_includeD0_N_' name='chk_includeD0[]' onclick='valInclude(_N_);'>");
			   $objAxpDB->GridHidden(0, "0, 0, 0,0,0,0,1,1");
			   $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;
                    RowIndex0();
                    reSize();
				
               <?php

               break;
           }
           die("");
           exit;
    }
	
  if(isset($_REQUEST['id'])&&($_REQUEST['id'])!=0) {
			   $objAxpDB->Lookup("ftdelivery_method", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 7", "fntrans_status_code", "fttrans_status_name", -1,true);			
               $objAxpDB->Lookup("ftdo_type", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 30", "fntrans_status_code", "fttrans_status_name", 0,true);
	}
    
    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();


?>