<?php
$a=$_REQUEST["q"];
$b=$_REQUEST["a"];

include "include/config.php";
include "include/functions.php";
include "class/UctVw.php";
$objAxpDB = new UctVw();

    
switch ($a)
{
        case "17":       
              $html=GetUser();
              echo "$html";             
             break;
        case "07": // Harga Jual
        //
        
        //Pilih DO Disales Invoice
        case "01":
                $ssql="SELECT a.fnindex as fnindex,a.ftitem_code,a.ftitem_name,a.ftuom_code,a.ftwarehouse_code,a.ftlocation_code,a.fnqty,
                            0 as fcprice,0 as fcDisc,0 as fcamount
                    FROM txdelivery_order_det a 
                    WHERE a.ftdo_no='{$b}' ";
                    
                $rs=mysql_query($ssql);
                
                echo "<table class='ewTable' id='TransactionDetail' name='TransactionDetail' border='0' width='100%' cellspacing='0' celpadding='0'>
                    <tr class='ewTableHeader'>
                    <td valign='top'>No</th>
                    <td  valign='top'>Kode Barang</th>                   
                    <td  valign='top'>Gudang</th>
                    <td  valign='top'>Lokasi</th>
                    <td  valign='top'>Qty</th>
                    <td  valign='top'>Satuan</th>
                    <td  valign='top'>Harga</th>
                    <td  valign='top'>Disc(%)</th>
                    <td  valign='top'>Disc(Rp)</th>
                    <td th valign='top'>Jml. Total</th>
                    </tr>";
        
                $i=0;
		while($r = mysql_fetch_assoc($rs))
		 {
                    if ($i%2) {
                            $class1="ewTableRow";
                            $class2="ISGridTDeven";
                    } else {						
                            $class1="ewTableRow";
                            $class2="ISGridTDodd";
                    }

                     echo "<tr class='$class1'>";
                     echo "<td class='$class2'><input readonly type='text' name='fnindexD[]' id='fnindexD$i' value='" . $r['fnindex'] . "' size=3></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftitem_codeD[]' id='ftitem_codeD$i' value='" . $r['ftitem_code'] . "'  size=16></td>";                   
                     echo "<td class='$class2'><input readonly type='text' name='ftwarehouse_codeD[]' id='ftwarehouse_codeD$i' value='" . $r['ftwarehouse_code'] . "'   size=10></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftlocation_codeD[]' id='ftlocation_codeD$i' value='" . $r['ftlocation_code'] . "'  size=10></td>";                  
                     echo "<td class='$class2'><input  readonly onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" type='text' name='fnqtyD[]' id='fnqtyD$i' value='" . $r['fnqty'] . "'   size=10></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftuom_codeD[]' id='ftuom_codeD$i' value='" . $r['ftuom_code'] . "'   size=10></td>";
                     echo "<td class='$class2'><input type='text' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  onChange=\"SalesInvoiceRecalQty();\" name='fcpriceD[]' id='fcpriceD$i' value='0'   size=15></td>";
                     echo "<td class='$class2'><input type='text' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  onChange=\"SalesInvoiceRecalQty();\"   name='ffdiscountD[]' id='ffdiscountD$i' value='0'   size=15></td>";
                     echo "<td class='$class2'><input readonly onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" type='text' name='fcdiscountD[]' id='fcdiscountD$i' value='0'  size=15></td>";
                     echo "<td class='$class2'><input readonly onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" type='text' name='fcamountD[]' id='fcamountD$i' value='0'></td>";
                     echo "</tr>";

                     $i++;
		 }
		echo "</table>";
		echo "<input id='TransactionDetailCount' name='TransactionDetailCount' value='$num_rows' type='hidden'>";
		break;
          
        case "03"://daftar invoice di AR
        
         $ssql="SELECT ftbranch_code,ftcustomer_code,ftsales_invoice_no,fdtrans_date,ftdo_no,
                        fcamount,fcpayment_amount,fcoutstanding_amount
                FROM 
                txsales_invoice_hdr
                WHERE (fnpayment_status=1 or fnpayment_status=2) AND fnstatus<>9 AND 
                        ftcustomer_code='{$b}'";
        

                $rs=mysql_query($ssql);
                   echo "<input type='hidden' id='fcamountxx'  name='fcamountxx'>" ;
                echo "<table class='ewTable' id='TransactionDetail1' name='TransactionDetail1' border='0' width='100%' cellspacing='0' celpadding='0'>
                    <tr class='ewTableHeader'>
                     <td  valign='top'>No</th>
                     <td  valign='top'>No. Invoice</th>                   
                     <td  valign='top'>Tgl. Invoice</th>
                     <td  valign='top'>No. DO</th>
                     <td  valign='top'>Jml. Total</th>
                     <td  valign='top'>Sisa Piutang</th>
                     <td  valign='top'>Jml. Pembayaran</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";
                    }
                    
                     echo "<tr class='$class1'>";
                     echo "<td class='$class2'><input readonly type='text' name='fnindexD1[]' id='fnindexD1$i' value='{$j}' size=3></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftsales_invoice_noD[]' id='ftsales_invoice_noD$i' value='" . $r['ftsales_invoice_no'] . "'  size=20></td>";                   
                     echo "<td class='$class2'><input readonly type='text' name='fdtrans_dateD[]' id='fdtrans_dateD$i' value='" . $r['fdtrans_date'] . "'   size=20></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftdo_noD[]' id='ftdo_noD$i' value='" . $r['ftdo_no'] . "'  size=20></td>";                  
                     echo "<td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  readonly type='text' name='fcamount1D[]' id='fcamount1D$i' value='" . $r['fcamount'] . "'   size=20></td>";
                     echo "<td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  readonly type='text' name='fcoutstanding_amountD[]' id='fcoutstanding_amountD$i' value='" . $r['fcoutstanding_amount'] . "'   size=20></td>";
                     echo "<td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  OnChange='PenerimaanPiutangRecalQty1()'; type='text' name='fcpayment_amountD[]' id='fcpayment_amountD$i' value='" . 0 . "'   size=20></td>";
                     echo "</tr>";

                     $i++;
		 }
		echo "</table>";
		echo "<input id='TransactionDetailCount1' name='TransactionDetailCount1' value='$num_rows' type='hidden'>";
		break;
                
        case "02": //Load data di POR
                $ssql="SELECT A1.ftpow_no,A1.ftstock_type_code,A1.ftitem_code,A1.ftitem_name,A1.ftcolor,
                                    A2.fnqty_on_hand AS fnqty_available,A1.fnqty_painting,A1.fnqty_neto,
                                    A1.fnqty_total_por,A1.fnqty_rekap,
                                    A1.fnqty_container,A1.fnqty_jakarta,
                                    A1.fnqty_total_order,A1.fnqty_result
                    FROM (
                            SELECT b.ftmpor_no,b.ftpow_no,b.ftstock_type_code,b.ftitem_code,c.ftitem_name,b.ftcolor,
                                    b.fnqty_available,b.fnqty_painting,b.fnqty_neto,
                                    b.fnqty_total_por,b.fnqty_rekap,
                                    b.fnqty_container,b.fnqty_jakarta,
                                    b.fnqty_total_order,b.fnqty_result
                            FROM txproduction_monitoring_por_hdr a ,txproduction_monitoring_por_det b,
                                    tlstock_hdr c
                            WHERE
                                    A.ftmpor_no=B.ftmpor_no AND a.fnstatus=0 AND 
                                    b.ftitem_code=c.ftitem_code 

                            UNION ALL 

                            SELECT '' AS ftmpor_no,b.ftpow_no,c.ftstock_type_code,b.ftitem_code,c.ftitem_name,c.ftcolor_code,
                                    0 AS fnqty_available,0 AS fnqty_painting,0 AS fnqty_neto,
                                    0 AS fnqty_total_por,0 AS fnqty_rekap,
                                    0 AS fnqty_container,0 AS fnqty_jakarta,
                                    0 AS fnqty_total_order,0 AS fnqty_result
                            FROM txproduction_outstanding_weekly_hdr A, txproduction_outstanding_weekly_det B,
                                    tlstock_hdr C
                            WHERE a.ftpow_no=b.ftpow_no AND 
                                    a.fnstatus<>9 AND 
                                    b.ftitem_code=c.ftitem_code AND
                                    NOT EXISTS (SELECT fnid FROM txproduction_monitoring_por_det AA 
                                                    WHERE B.ftpow_no=AA.ftpow_no AND
                                                            B.ftitem_code=AA.ftitem_code
                                                    )
                    ) A1	
                    INNER JOIN (	
                            SELECT ftitem_code,IFNULL(sum(fnqty_on_hand),0) as fnqty_on_hand,IFNULL(sum(fnqty_available),0) as fnqty_available
                            FROM tlstock_det 
                            GROUP BY ftitem_code
                    ) A2 ON
                    A1.ftitem_code=A2.ftitem_code";

                $rs=mysql_query($ssql);
             
                echo "<table class='ISTable' id='TransactionDetail' name='TransactionDetail' border='0' width='100%' cellspacing='0' celpadding='0'>
                        <tr class='ISTableTR'>
                        <th class='ISGridTH'>No</th>
                        <th class='ISGridTH'>No.POW</th>                   
                        <th class='ISGridTH'>Type Barang</th>
                        <th class='ISGridTH'>Kode Barang</th>
                        <th class='ISGridTH'>Nama Barang</th>
                        <th class='ISGridTH'>Warna</th>
                        <th class='ISGridTH'>Qty Avail</th>
                        <th class='ISGridTH'>SPK Painting</th>
                        <th class='ISGridTH'>Barang 1/2Jadi</th>
                        <th class='ISGridTH'>Total</th>
                        <th class='ISGridTH'>Rekap Mingguan Luar Kota</th>
                        <th class='ISGridTH'>OST Container</th>
                        <th class='ISGridTH'>OST Jakarta</th>
                        <th class='ISGridTH'>Total Order</th>
                        <th class='ISGridTH'>Hasil Akhir</th>
                        </tr>";
        
                $i=0;
		while($r = mysql_fetch_assoc($rs))
		 {
                    if ($i%2) {
                            $class1="ISGridTReven";
                            $class2="ISGridTDeven";
                    } else {						
                            $class1="ISGridTRodd";
                            $class2="ISGridTDodd";
                    }
                    $j=$i+1;
                    echo "<tr class='$class1'>
                    <td class='$class2'><input readonly type='text' name='fnindexD[]' id='fnindexD$i' value='" . $j . "' size=3></td>
                    <td class='$class2'><input readonly type='text' name='ftpow_noD[]' id='ftpow_noD$i' value='" . $r['ftpow_no'] . "'  size=16></td>                   
                    <td class='$class2'><input readonly type='text' name='ftstock_type_codeD[]' id='ftstock_type_codeD$i' value='" . $r['ftstock_type_code'] . "'   size=10></td>
                    <td class='$class2'><input readonly type='text' name='ftitem_codeD[]' id='ftitem_codeD$i' value='" . $r['ftitem_code'] . "'  size=10></td>       
                    <td class='$class2'><input readonly type='text' name='ftitem_nameD[]' id='ftitem_nameD$i' value='" . $r['ftitem_name'] . "'   size=10></td>
                    <td class='$class2'><input readonly type='text' name='ftcolorD[]' id='ftcolorD$i' value='" . $r['ftcolor'] . "'   size=10></td>
                    <td class='$class2'><input readonly type='text' name='fnqty_availableD[]' id='fnqty_availableD$i' value='" . $r['fnqty_available'] . "'   size=10></td>
                    <td class='$class2'><input type='text' name='fnqty_paintingD[]'  onChange=\"MonitoringPORRecalQty();\" id='fnqty_paintingD$i' value='" . $r['fnqty_painting'] . "'   size=10></td>
                   <td class='$class2'><input type='text' name='fnqty_netoD[]'   onChange=\"MonitoringPORRecalQty();\"  id='fnqty_netoD$i' value='" . $r['fnqty_neto'] . "'   size=10></td>
                   <td class='$class2'><input readonly type='text' name='fnqty_total_porD[]' id='fnqty_total_porD$i' value='" . $r['fnqty_total_por'] . "'   size=10></td>
                    <td class='$class2'><input type='text' name='fnqty_rekapD[]'  onChange=\"MonitoringPORRecalQty();\"  id='fnqty_rekapD$i' value='" . $r['fnqty_rekap'] . "'   size=10></td>
                    <td class='$class2'><input type='text' name='fnqty_containerD[]'  onChange=\"MonitoringPORRecalQty();\"  id='fnqty_containerD$i' value='" . $r['fnqty_container'] . "'   size=10></td>
                    <td class='$class2'><input type='text' name='fnqty_jakartaD[]'  onChange=\"MonitoringPORRecalQty();\"  id='fnqty_jakartaD$i' value='" . $r['fnqty_jakarta'] . "'   size=10></td>
                    <td class='$class2'><input readonly type='text' name='fnqty_total_orderD[]' id='fnqty_total_orderD$i' value='" . $r['fnqty_total_order'] . "'   size=10></td>
                   <td class='$class2'><input readonly type='text' name='fnqty_resultD[]' id='fnqty_resultD$i' value='" . $r['fnqty_result'] . "'   size=10></td>
                    </tr>";

                     $i++;
		 }
		echo "</table>";
		echo "<input id='TransactionDetailCount' name='TransactionDetailCount' value='$num_rows' type='hidden'>";
		break;
                
        case "04": //Credit Memo       
          
                   $objAxpDB->GridAllowAddNew(0,true);
                   $objAxpDB->GridAllowDelete(0,true);
                   $objAxpDB->Lookup("ftsales_invoice_no","SELECT ftsales_invoice_no,fdtrans_date FROM txsales_invoice_hdr WHERE fnstatus<>9 AND ftcustomer_code='{$_REQUEST['ftcustomer_code']}'","ftsales_invoice_no","fdtrans_date",0,true);
                   $objAxpDB->FormSQL("SELECT ftcm_no, ftcustomer_code, fdtrans_date, fntrans_type, ftnotes,  fcinvoice_amount, fcoutstanding_amount, fccredit_amount, fnstatus FROM txcredit_memo_hdr WHERE 1=0");
                   $objAxpDB->GridSQL(0, "SELECT fnindex, ftsales_invoice_no, fdsales_invoice_date, ftdescription, fcinvoice_amount, fcoutstanding_amount, fccredit_amount FROM txcredit_memo_det");
                   $objAxpDB->GridCaption(0, "No., No. Invoice, Tgl. Invoice, Keterangan, Jumlah Tagihan, Sisa Pembayaran, Credit Memo");   
                   $objAxpDB->Process();
                   ob_start();
                   $objAxpDB->setGrid1(0);
                   $html = ob_get_contents();
                   ob_end_clean();                  
                   ?>
			div = document.getElementById('txtHint');
                        var m='<?php echo js_esc($html); ?>';                       
			div.innerHTML = m.replace(/^\s*|\s*$/g,"");
                        document.getElementById('txtHint');                        
                        RowBuild0();

                   <?
                  
                
		break;
                
        case "05": // Rekap Bank Voucer
         $ssql="SELECT ftpp_no,ftpo_no,ftcv_no,ftreceipt_no,ftdue_date,
                        fcamount,fcpayment_amount,fcoutstanding_amount
                FROM 
                txpayment_projection_det
                WHERE (fnpayment_status=1 or fnpayment_status=2) AND fnstatus<>9 AND 
                        ftsupplier_code='{$b}'";
        

                $rs=mysql_query($ssql);
                   echo "<input type='hidden' id='fcamountxx'  name='fcamountxx'>" ;
                echo "<table class='ewTable' id='TransactionDetail1' name='TransactionDetail1' border='0' width='100%' cellspacing='0' celpadding='0'>
                    <tr class='ewTableHeader'>
                    <td valign='top'>No</th>
                    <td valign='top'>No. PP</th>                   
                    <td valign='top'>No. PO</th>
                    <td valign='top'>No. CV</th>
                    <td valign='top'>No. Td Terima</th>
                    <td valign='top'>Tgl. Jth Tempo</th>                 
                    <td valign='top'>Jml. Total</th>
                    <td valign='top'>Sisa Piutang</th>
                    <td valign='top'>Jml. Pembayaran</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";
                    }
                                                                                                            //                     $ssql="SELECT ftpp_no,ftpo_no,ftcv_no,ftreceipt_no,ftdue_date,
                                                                                                            //                        fcamount,fcpayment_amount,fcoutstanding_amount
                     echo "<tr class='$class1'>";
                     echo "<td class='$class2'><input readonly type='text' name='fnindexD1[]' id='fnindexD1$i' value='{$j}' size=3></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftpp_noD[]' id='ftpp_noD$i' value='" . $r['ftpp_no'] . "'  size=20></td>";                   
                     echo "<td class='$class2'><input readonly type='text' name='ftpo_noD[]' id='ftpo_noD$i' value='" . $r['ftpo_no'] . "'   size=20></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftcv_noD[]' id='ftcv_noD$i' value='" . $r['ftcv_no'] . "'  size=20></td>";    
                     echo "<td class='$class2'><input readonly type='text' name='ftreceipt_noD[]' id='ftreceipt_noD$i' value='" . $r['ftreceipt_no'] . "'  size=20></td>";                  
                     echo "<td class='$class2'><input readonly type='text' name='ftdue_dateD[]' id='ftdue_dateD$i' value='" . $r['ftdue_date'] . "'  size=20></td>";                  
                     echo "<td class='$class2'><input readonly  onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"   type='text' name='fcamount1D[]' id='fcamount1D$i' value='" . $r['fcamount'] . "'   size=20></td>";
                     echo "<td class='$class2'><input readonly  onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"   type='text' name='fcoutstanding_amountD[]' id='fcoutstanding_amountD$i' value='" . $r['fcoutstanding_amount'] . "'   size=20></td>";
                     echo "<td class='$class2'><input  onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"   OnChange='RekapBankVoucherRecalQty1()'; type='text' name='fcpayment_amountD[]' id='fcpayment_amountD$i' value='" . 0 . "'   size=20></td>";
                     echo "</tr>";

                     $i++;
		 }
		echo "</table>";
		echo "<input id='TransactionDetailCount1' name='TransactionDetailCount1' value='$num_rows' type='hidden'>";
		break;
        
        case "06": //debit memo
        $ssql="SELECT ftpp_no,ftpo_no,ftcv_no,ftreceipt_no,ftdue_date,
                        fcamount,fcpayment_amount,fcoutstanding_amount
                FROM 
                txpayment_projection_det
                WHERE (fnpayment_status=1 or fnpayment_status=2) AND fnstatus<>9 AND 
                        ftsupplier_code='{$b}'";
                $rs=mysql_query($ssql);
                   echo "<input type='hidden' id='fcamountxx'  name='fcamountxx'>" ;
                echo "<table class='ewTable' id='TransactionDetail1' name='TransactionDetail1' border='0' width='100%' cellspacing='0' celpadding='0'>
                    <tr class='ewTableHeader'>
                    <th  valign=top>No</th>
                    <th  valign=top>No. PP</th>                   
                    <th  valign=top>No. PO</th>
                    <th  valign=top>No. CV</th>
                    <th  valign=top>No. Td Terima</th>
                    <th  valign=top>Tgl. Jth Tempo</th>                 
                    <th  valign=top>Jml. Total</th>
                    <th  valign=top>Sisa Piutang</th>
                    <th  valign=top>Debit Memo</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";
                    }
                                                                                                            //                     $ssql="SELECT ftpp_no,ftpo_no,ftcv_no,ftreceipt_no,ftdue_date,
                                                                                                            //                        fcamount,fcpayment_amount,fcoutstanding_amount
                     echo "<tr class='$class1'>";
                     echo "<td class='$class2'><input readonly type='text' name='fnindexD[]' id='fnindexD1$i' value='{$j}' size=3></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftpp_noD[]' id='ftpp_noD$i' value='" . $r['ftpp_no'] . "'  size=16></td>";                   
                     echo "<td class='$class2'><input readonly type='text' name='ftpo_noD[]' id='ftpo_noD$i' value='" . $r['ftpo_no'] . "'   size=10></td>";
                     echo "<td class='$class2'><input readonly type='text' name='ftcv_noD[]' id='ftcv_noD$i' value='" . $r['ftcv_no'] . "'  size=10></td>";    
                     echo "<td class='$class2'><input readonly type='text' name='ftreceipt_noD[]' id='ftreceipt_noD$i' value='" . $r['ftreceipt_no'] . "'  size=10></td>";                  
                     echo "<td class='$class2'><input readonly type='text' name='ftdue_dateD[]' id='ftdue_dateD$i' value='" . $r['ftdue_date'] . "'  size=10></td>";                  
                     echo "<td class='$class2'><input readonly type='text' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  name='fcamount1D[]' id='fcamount1D$i' value='" . $r['fcamount'] . "'   size=10></td>";
                     echo "<td class='$class2'><input readonly type='text' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  name='fcoutstanding_amountD[]' id='fcoutstanding_amountD$i' value='" . $r['fcoutstanding_amount'] . "'   size=10></td>";
                     echo "<td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" OnChange='DebitMemoRecalQty()'; type='text' name='fcdebit_amountD[]' id='fcdebit_amountD$i' value='" . 0 . "'   size=10></td>";
                     echo "</tr>";

                     $i++;
		 }
		echo "</table>";
		echo "<input id='TransactionDetailCount1' name='TransactionDetailCount1' value='$num_rows' type='hidden'>";
		break;
	case "200":
		$sql="SELECT a.fnindex, a.ftitem_code, b.ftitem_name, a.ffqty-a.ffqty_in AS ffqty_po, 0 AS ffqty, a.ftuom_code, 0 AS fcprice FROM txpurchase_order_det a LEFT JOIN tlstock_hdr b ON a.ftitem_code = b.ftitem_code WHERE a.ftpo_no = '$b' AND a.ffqty <> a.ffqty_in";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);

		echo "<table class='ISTable' id='TransactionDetail' name='TransactionDetail' border='0' width='100%' cellspacing='0' celpadding='0'>
		<tr class='ISTableTR'>
		<th class='ISGridTH'>No</th>
		<th class='ISGridTH'>Kode Barang</th>
		<th class='ISGridTH'>Nama Barang</th>
		<th class='ISGridTH'>Qty PO (kg)</th>
		<th class='ISGridTH'>Qty (kg)</th>
		<th class='ISGridTH'>Satuan</th>
		<th class='ISGridTH'>HargaBrutto</th>
		</tr>";
		
		$i=0;
		while($row = mysql_fetch_array($result))
		 {
			if ($i%2) {
					$class1="ISGridTReven";
					$class2="ISGridTDeven";
				} else {						
					$class1="ISGridTRodd";
					$class2="ISGridTDodd";
				}

		 echo "<tr class='$class1'>";
		 echo "<td class='$class2'><input readonly type='text' name='fnindex[]' id='fnindex$i' value='" . $row['fnindex'] . "'></td>";
		 echo "<td class='$class2'><input readonly type='text' name='ftitem_code[]' id='ftitem_code$i' value='" . $row['ftitem_code'] . "'></td>";
		 echo "<td class='$class2'><input readonly type='text' name='ftitem_name[]' id='ftitem_name$i' value='" . $row['ftitem_name'] . "'></td>";
		 echo "<td class='$class2'><input readonly type='text' name='ffqty_po[]' id='ffqty_po$i' value='" . $row['ffqty_po'] . "'></td>";
		 echo "<td class='$class2'><input type='text' name='ffqty[]' id='ffqty$i' value='0' onChange=\"RecalculateGrid('ffqty', 'fftotal_qty');\"></td>";
		 echo "<td class='$class2'><input readonly type='text' name='ftuom_code[]' id='ftuom_code$i' value='" . $row['ftuom_code'] . "'></td>";
		 echo "<td class='$class2'><input type='text' name='fcNetto_Price[]' id='fcNetto_Price$i' value='0'></td>";
		 echo "</tr>";

		 $i++;
		 }
		echo "</table>";
		echo "<input id='TransactionDetailCount' name='TransactionDetailCount' value='$num_rows' type='hidden'>";
		break;
	case 201:
		$sql="SELECT a.fnindex, a.ftitem_code, b.ftitem_name, a.ffqty-IFNULL(c.ffqty_Return, 0) AS ffqty_PI, 0 AS ffqty, a.ftuom_code, a.fcprice, 0 AS fcamount FROM TXPurchase_Invoice_Det a LEFT JOIN tlstock_hdr b ON a.ftitem_code = b.ftitem_code LEFT JOIN ( SELECT b.ftPI_No, a.ftitem_code, SUM(a.ffqty) AS ffqty_Return FROM TXPurchase_Return_Det a LEFT JOIN TXPurchase_Return_Hdr b ON a.ftPR_No = b.ftPR_No	GROUP BY b.ftPI_No, a.ftitem_code ) c ON a.ftPI_No = c.ftPI_No AND a.ftitem_code = c.ftitem_code WHERE a.ftPI_No = '$b' AND a.ffqty <> IFNULL(c.ffqty_Return, 0)";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);

		echo "<table class='ISTable' id='TransactionDetail0' name='TransactionDetail0' border='0' width='100%' cellspacing='0' celpadding='0'>
		<tr class='ISTableTR'>
		<th class='ISGridTH'>No</th>
		<th class='ISGridTH'>Kode Barang</th>
		<th class='ISGridTH'>Nama Barang</th>
		<th class='ISGridTH'>Qty PI (kg)</th>
		<th class='ISGridTH'>Qty Retur (kg)</th>
		<th class='ISGridTH'>Harga Satuan</th>
		<th class='ISGridTH'>TotalHarga</th>
		</tr>";

		$i=0;
		while($row = mysql_fetch_array($result))
		{
			if ($i%2) {
				$class1="ISGridTReven";
				$class2="ISGridTDeven";
			} else {						
				$class1="ISGridTRodd";
				$class2="ISGridTDodd";
			}

			echo "<tr class='$class1'>";
			echo "<td><input readonly class='$class2' id='fnindexD$i' name='fnindexD[]' type='text' value='$i'></td>";
			echo "<td><input readonly class='$class2' id='ftitem_codeD$i' name='ftitem_codeD[]' value='" . $row["ftitem_code"] . "'></td>";
			echo "<td><input readonly class='$class2' id='ftitem_nameD$i' name='ftitem_nameD[]' value='" . $row["ftitem_name"] . "'></td>";
			echo "<td><input readonly class='$class2' id='ffqty_PID$i' name='ffqty_PID[]' type='text' value='" . $row["ffqty_PI"] . "'></td>";
			echo "<td><input class='$class2' id='ffqtyD$i' name='ffqtyD[]' type='text' value='" . $row["ffqty"] . "' onChange='SetAmount3();'></td>";
			echo "<td><input readonly class='$class2' id='fcpriceD$i' name='fcpriceD[]' type='text' value='" . $row["fcprice"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fcamountD$i' name='fcamountD[]' type='text' value='" . $row["fcamount"] . "'></td>";
			echo "</tr>";

			$i++;
		}
		echo "</table>";
		echo "<input id='TransactionDetailCount' name='TransactionDetailCount' value='$num_rows' type='hidden'>";
		break;
	case 202:
		$sql="SELECT a.fnindex, a.ftitem_code, b.ftitem_name, a.ffqty-IFNULL(c.ffqty_Return, 0) AS ffqty_SI, 0 AS ffqty, a.ftuom_code, a.fcprice, 0 AS fcamount FROM txsales_invoice_det a LEFT JOIN tlstock_hdr b ON a.ftitem_code = b.ftitem_code LEFT JOIN ( SELECT b.ftSI_No, a.ftitem_code, SUM(a.ffqty) AS ffqty_Return FROM TXSales_Return_Det a LEFT JOIN TXSales_Return_Hdr b ON a.ftSR_No = b.ftSR_No GROUP BY b.ftSI_No, a.ftitem_code ) c ON a.ftSI_No = c.ftSI_No AND a.ftitem_code = c.ftitem_code WHERE a.ftSI_No = '$b' AND a.ffqty <> IFNULL(c.ffqty_Return, 0)";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);

		echo "<table class='ISTable' id='TransactionDetail0' name='TransactionDetail0' border='0' width='100%' cellspacing='0' celpadding='0'>
		<tr class='ISTableTR'>
		<th class='ISGridTH'>No</th>
		<th class='ISGridTH'>Kode Barang</th>
		<th class='ISGridTH'>Nama Barang</th>
		<th class='ISGridTH'>Qty SI (kg)</th>
		<th class='ISGridTH'>Qty Retur (kg)</th>
		<th class='ISGridTH'>Satuan</th>
		<th class='ISGridTH'>Harga Satuan</th>
		<th class='ISGridTH'>TotalHarga</th>
		</tr>";

		$i=0;
		while($row = mysql_fetch_array($result))
		{
			if ($i%2) {
				$class1="ISGridTReven";
				$class2="ISGridTDeven";
			} else {						
				$class1="ISGridTRodd";
				$class2="ISGridTDodd";
			}

			echo "<tr class='$class1'>";
			echo "<td><input readonly class='$class2' id='fnindexD$i' name='fnindexD[]' type='text' value='$i'></td>";
			echo "<td><input readonly class='$class2' id='ftitem_codeD$i' name='ftitem_codeD[]' value='" . $row["ftitem_code"] . "'></td>";
			echo "<td><input readonly class='$class2' id='ftitem_nameD$i' name='ftitem_nameD[]' value='" . $row["ftitem_name"] . "'></td>";
			echo "<td><input readonly class='$class2' id='ffqty_SID$i' name='ffqty_SID[]' type='text' value='" . $row["ffqty_SI"] . "'></td>";
			echo "<td><input class='$class2' id='ffqtyD$i' name='ffqtyD[]' type='text' value='" . $row["ffqty"] . "' onChange='SetAmount3();'></td>";
			echo "<td><input readonly class='$class2' id='ftuom_codeD$i' name='ftuom_codeD[]' type='text' value='" . $row["ftuom_code"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fcpriceD$i' name='fcpriceD[]' type='text' value='" . $row["fcprice"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fcamountD$i' name='fcamountD[]' type='text' value='" . $row["fcamount"] . "'></td>";
			echo "</tr>";

			$i++;
		}
		echo "</table>";
		echo "<input id='TransactionDetailCount' name='TransactionDetailCount' value='$num_rows' type='hidden'>";
		break;
	case 203:
		$sql="SELECT ftPI_No, fdtrans_date AS fdPI_Date, fcamount, fcoutstanding_amount, fcpayment_amount FROM TXPurchase_Invoice_Hdr WHERE ftsupplier_code = '$b'";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);

		echo "<table class='ISTable' id='TransactionDetail0' name='TransactionDetail0' border='0' width='100%' cellspacing='0' celpadding='0'>
		<tr class='ISTableTR'>
		<th class='ISGridTH'>No</th>
		<th class='ISGridTH'>No. Faktur</th>
		<th class='ISGridTH'>Tgl. Faktur</th>
		<th class='ISGridTH'>Jumlah Tagihan</th>
		<th class='ISGridTH'>Sisa Pembayaran</th>
		<th class='ISGridTH'>Jumlah Pembayaran</th>
		</tr>";

		$i=0;
		while($row = mysql_fetch_array($result))
		{
			if ($i%2) {
				$class1="ISGridTReven";
				$class2="ISGridTDeven";
			} else {						
				$class1="ISGridTRodd";
				$class2="ISGridTDodd";
			}

			echo "<tr class='$class1'>";
			echo "<td><input readonly class='$class2' id='fnindexD$i' name='fnindexD[]' type='text' value='" . ($i+1) . "'></td>";
			echo "<td><input readonly class='$class2' id='ftPI_NoD$i' name='ftPI_NoD[]' value='" . $row["ftPI_No"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fdPI_DateD$i' name='fdPI_DateD[]' value='" . $row["fdPI_Date"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fcamountD$i' name='fcamountD[]' type='text' value='" . $row["fcamount"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fcoutstanding_amountD$i' name='fcoutstanding_amountD[]' type='text' value='" . $row["fcoutstanding_amount"] . "'></td>";
			echo "<td><input class='$class2' id='fcpayment_amountD$i' name='fcpayment_amountD[]' type='text' value='" . $row["fcpayment_amount"] . "' onChange='SetAmount9();'></td>";
			echo "</tr>";

			$i++;
		}
		echo "</table>";
		echo "<input id='TransactionDetailCount' name='TransactionDetailCount' value='$num_rows' type='hidden'>";
		break;
	case 204:
		$sql="SELECT ftSI_No, fdtrans_date AS fdSI_Date, fcamount, fcoutstanding_amount, fcpayment_amount FROM txsales_invoice_hdr WHERE ftcustomer_code = '$b'";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);

		echo "<table class='ISTable' id='TransactionDetail0' name='TransactionDetail0' border='0' width='100%' cellspacing='0' celpadding='0'>
		<tr class='ISTableTR'>
		<th class='ISGridTH'>No</th>
		<th class='ISGridTH'>No. Faktur</th>
		<th class='ISGridTH'>Tgl. Faktur</th>
		<th class='ISGridTH'>Jumlah Tagihan</th>
		<th class='ISGridTH'>Sisa Pembayaran</th>
		<th class='ISGridTH'>Jumlah Pembayaran</th>
		</tr>";

		$i=0;
		while($row = mysql_fetch_array($result))
		{
			if ($i%2) {
				$class1="ISGridTReven";
				$class2="ISGridTDeven";
			} else {						
				$class1="ISGridTRodd";
				$class2="ISGridTDodd";
			}

			echo "<tr class='$class1'>";
			echo "<td><input readonly class='$class2' id='fnindexD$i' name='fnindexD[]' type='text' value='" . ($i+1) . "'></td>";
			echo "<td><input readonly class='$class2' id='ftSI_NoD$i' name='ftSI_NoD[]' value='" . $row["ftSI_No"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fdSI_DateD$i' name='fdSI_DateD[]' value='" . $row["fdSI_Date"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fcamountD$i' name='fcamountD[]' type='text' value='" . $row["fcamount"] . "'></td>";
			echo "<td><input readonly class='$class2' id='fcoutstanding_amountD$i' name='fcoutstanding_amountD[]' type='text' value='" . $row["fcoutstanding_amount"] . "'></td>";
			echo "<td><input class='$class2' id='fcpayment_amountD$i' name='fcpayment_amountD[]' type='text' value='" . $row["fcpayment_amount"] . "' onChange='SetAmount9();'></td>";
			echo "</tr>";

			$i++;
		}
		echo "</table>";
		echo "<input id='TransactionDetailCount' name='TransactionDetailCount' value='$num_rows' type='hidden'>";
		break;
}