<?php
    Getsecurity("sales_invoice");

    if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
                // Validasi gudang dan lokasi untuk settingan SI Auto DO
                If($_SESSION["SIAutoDO"]) {               
                    ?>
                    var i=document.getElementsByName('fnindexD0[]').length;
                    for (var j=1;j < i;j++) {      
                        if ((document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1 > 0) && (document.getElementsByName('ftwarehouse_codeD0[]')[j].value == '')) {
                            alert('Gudang harus diisi.');
                            document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
                            process.exit();
                        }
                         
                        if ((document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1 > 0) && (document.getElementsByName('ftlocation_codeD0[]')[j].value == '')) {
                            alert('Lokasi harus diisi.');
                            document.getElementsByName('ftlocation_codeD0[]')[j].focus();
                            process.exit();
                        } 
                    }
                    <?php
                    
                }    
                // alert('Qty tidak boleh lebih dari qty tersedia. ');
                            
                   
                // Validasi tidak boleh qty minus
                if (!$_SESSION["QtyMinus"]) {
                    ?>
                    var i=document.getElementsByName('fnindexD0[]').length;
                    for (var j=1;j < i;j++) {      
                        if ((document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1 > document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1) && (document.getElementsByName('ftstock_category_codeD0[]')[j].value != 'srv')) {
                            alert('Qty tidak boleh lebih dari qty tersedia.');
                            document.getElementsByName('fnqtyD0[]')[j].focus();
                            process.exit();
                         }
                    }
                    <?php
                }
                  
                if(RetRstField("SELECT fnid FROM txsales_invoice_hdr WHERE ftsales_invoice_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
                }
                break;
            case "tgl":
                if ($_REQUEST['termpayment'] == '') {$_REQUEST['termpayment'] = 0; }
                $ssql="select date_add('".CDate($_REQUEST['tgl'])."',INTERVAL ".intval($_REQUEST['ftterm_payment'])." DAY)";
                $date=RetRstField($ssql);
                ?>
                document.getElementById('fddue_date').value='<?php echo CDateRev($date); ?>';
                <?php
                break;
            case "tgltempo":
                if ($_REQUEST['termpayment'] == '') {$_REQUEST['termpayment'] = 0; }
                $ssql="select date_add('".CDate($_REQUEST['fdtrans_date'])."',INTERVAL {$_REQUEST['ftterm_payment']} DAY)";
                $date=RetRstField($ssql);
                ?>
                document.getElementById('fddue_date').value='<?php echo CDateRev($date); ?>';
                <?php
                break;
            case "salesorder":        
                $ssql ="SELECT a.ftterm_payment, a.fntax_code, a.ftreff_no, a.ffdiscount, 
                            a.fcother_cost, a.ffvat, a.ftcurrency_code, a.fcrate, a.fcamount,
                            a.ftcustomer_code,b.ftcustomer_name,b.fttax_code, IFNULL(b.ftaddress,'') AS ftaddress,
                            IFNULL(b.ftcity,'') AS ftcity, IFNULL(b.ftzip_code,'') AS ftzip_code,
                            IFNULL(b.ftstate,'') AS ftstate, IFNULL(b.ftcountry,'') AS ftcountry ,a.ftsales_code
                        FROM txsales_order_hdr a INNER JOIN tlcustomer b ON a.ftcustomer_code = b.ftcustomer_code 
                        WHERE a.ftso_no='{$_REQUEST['ftso_no']}' ";

                $rs=mysql_query($ssql) ;
                $r=mysql_fetch_assoc($rs);

                $str=(!empty($r['ftaddress']))? $r['ftaddress']: "";
                if(!empty($r['ftcity'])){
                    if(!empty($str)) $str.=" - ";
                    $str.=$r['ftcity'];
                }
   
                ?>
                    document.getElementById('ftcustomer_code').value='<?php echo $r['ftcustomer_code']; ?>';
                    document.getElementById('hidden_ftcustomer_code').value='<?php echo $r['ftcustomer_code']; ?>';
                    document.getElementById('span_ftcustomer_code').innerHTML='<?php echo $r['ftcustomer_name']; ?>';    
                    document.getElementById('ftship_address').value='<?php echo js_esc($str);?>';
                    document.getElementById('ftreff_no').value='<?php echo $r['ftreff_no']; ?>';
                    document.getElementById('ftterm_payment').value='<?php echo $r['ftterm_payment']; ?>';
                    document.getElementById('fntax_code').value='<?php echo $r['fntax_code']; ?>';
                    document.getElementById('ffdiscount').value='<?php echo $r['ffdiscount']; ?>';
                    document.getElementById('fcother_cost').value='<?php echo number_format($r['fcother_cost'], 2); ?>';
                    document.getElementById('ftcurrency_code').value='<?php echo $r['ftcurrency_code']; ?>';
                    document.getElementById('fcrate').value='<?php echo number_format($r['fcrate'], 2); ?>';
                    document.getElementById('ffvat').value='<?php echo number_format($r['ffvat'], 2); ?>';
                    document.getElementById('ftsales_code').value='<?php echo $r['ftsales_code']; ?>';
                <?php
                
                //$strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=pu004&ftstock_type_code=' + document.getElementById(\"ftstock_type_code\").value + '&ftcategory_code=' + document.getElementById(\"ftcategory_code\").value + '&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftstock_in_no&no_trans=ftstock_in_no&table_name=txstock_in_hdr&ftbranch_code={$_SESSION['strbranch']}');" ;
                //echo $strAutoNumber1;
                $ajax_due="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&code=tgltempo&ajax=1&fdtrans_date=' + document.getElementById('fdtrans_date').value + '&ftterm_payment=' + document.getElementById('ftterm_payment').value + '&fddue_date=fddue_date');";
                echo $ajax_due;
                
                break;      
            case "invoice":               
                $ssql="SELECT  IFNULL(ftcustomer_code,'') AS ftcustomer_code  ,IFNULL(ftship_address,'') AS ftship_address
                          FROM `txdelivery_order_hdr`
                          WHERE ftdo_no='{$_REQUEST['ftdo_no']}'";

                $rs=mysql_query($ssql) ;
                $r=mysql_fetch_assoc($rs);

                $rs1=mysql_query("SELECT ftcustomer_code,ftcustomer_name,fttax_code,
                                    IFNULL(ftaddress,'') AS ftaddress,IFNULL(ftcity,'') AS ftcity,
                                    IFNULL(ftzip_code,'') AS ftzip_code,IFNULL(ftstate,'') AS ftstate,
                                    IFNULL(ftcountry,'') AS ftcountry FROM tlcustomer WHERE
                                    ftcustomer_code='{$r['ftcustomer_code']}'");

                $r1=mysql_fetch_assoc($rs1);
                $str=(!empty($r1['ftaddress']))? $r1['ftaddress']: "";

                if(!empty($r1['ftcity'])){
                    if(!empty($str)) $str.=" - ";
                        $str.=$r1['ftcity'];
                }

                ?>
                    document.getElementById("DivCtl_ftcustomer_code").innerHTML='<input type=hidden name=ftcustomer_code value=\'<?php echo $r['ftcustomer_code']; ?>\'><input readonly  style="background-color: #E0E0E0" size="30" type=text value=\'<?php echo "{$r['ftcustomer_code']}"; ?>\'>&nbsp;<font color="red" SIZE="2">-</font>&nbsp;&nbsp;<span id="span_ftcustomer_code" name="span_ftcustomer_code"> <?php echo $r1['ftcustomer_name']; ?></span><input type="hidden" id="hidden_ftcustomer_code" name="hidden_ftcustomer_code" size="100"  value="<?php echo $r1['ftcustomer_name']; ?>" readonly style="background-color: #E0E0E0" >';
                    document.getElementById('ftship_address').value='<?php echo js_esc($str);?>';
                    SetValueSelected('<?php echo $r1['fttax_code']; ?>',document.getElementById('fntax_code'));
                <?php

                $ssql="SELECT b.fddue_date, b.ftterm_payment, b.fntax_code, b.ftreff_no, b.ffdiscount,
                          b.fcdiscount, b.fcother_cost, b.ffvat, b.ftcurrency_code, b.fcrate,
                          b.fcvat, b.fcamount, a.fdtrans_date
                          FROM txdelivery_order_hdr a INNER JOIN txsales_order_hdr b
                          ON a.ftso_no=b.ftso_no
                          WHERE a.ftdo_no='{$_REQUEST['ftdo_no']}'
                          GROUP BY b.ftso_no";

                $rs=mysql_query($ssql) ;
                $r=mysql_fetch_assoc($rs);

                ?>
                    document.getElementById('fdtrans_date').value='<?php echo CDateRev($r['fdtrans_date']); ?>';
                    document.getElementById('fdvat_date').value='<?php echo CDateRev($r['fdtrans_date']); ?>';
                    document.getElementById('fddue_date').value='<?php echo CDateRev($r['fddue_date']); ?>';
                    
                    document.getElementById('ftreff_no').value='<?php echo $r['ftreff_no']; ?>';
                    document.getElementById('ftterm_payment').value='<?php echo $r['ftterm_payment']; ?>';
                    document.getElementById('fntax_code').value='<?php echo $r['fntax_code']; ?>';
                    document.getElementById('ffdiscount').value='<?php echo number_format($r['ffdiscount'], 2); ?>';
                    document.getElementById('fcdiscount').value='<?php echo number_format($r['fcdiscount'], 2); ?>';
                    document.getElementById('fcother_cost').value='<?php echo number_format($r['fcother_cost'], 2); ?>';
                    document.getElementById('ftcurrency_code').value='<?php echo $r['ftcurrency_code']; ?>';
                    document.getElementById('fcrate').value='<?php echo number_format($r['fcrate'], 2); ?>';
                    document.getElementById('ffvat').value='<?php echo number_format($r['ffvat'], 2); ?>';
                    document.getElementById('fcvat').value='<?php echo number_format($r['fcvat'], 2); ?>';
                    document.getElementById('fcamount').value='<?php echo number_format($r['fcamount'], 2); ?>';
                <?php

                $html = GetInvoice();

                ?>
                    div = document.getElementById('txtHint0');
                    var m='<?php echo js_esc($html); ?>';
                    m= m.replace(/^\s*|\s*$/g,"");
                    div.innerHTML =m;
                    <!--reSize();-->
                    ElementCurrencyALL();

                    SalesInvoiceRecalQty0();
                    OnChangeDate_fdtrans_date();
                <?php

                $ajax_due="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&code=tgltempo&ajax=1&fdtrans_date=' + document.getElementById('fdtrans_date').value + '&ftterm_payment=' + document.getElementById('ftterm_payment').value + '&fddue_date=fddue_date');";
                echo $ajax_due;


                break;

               case "tipeinvoice":
                   $do=$_REQUEST['do_no'];
                   $do_1=substr($do,0,3);
                   if($do_1=='DOB')
                   {
                       ?>
                        document.getElementById('ftitem_type').value=0;
                        <?php
                   }
                   else
                   {
                       ?>
                        document.getElementById('ftitem_type').value=1;
                        <?php
                   }
                break;
             case "idr":
                $ssql="SELECT fcrate FROM tlcurrency_hdr WHERE ftsimbol='{$_REQUEST["ftcurrency_code"]}'";
                $mysql=mysql_query($ssql) or die ($ssql);
                $r=mysql_fetch_assoc($mysql);
                ?>
                  document.getElementById('fcrate').value='<?php echo number_format($r["fcrate"], 2); ?>';
                  ElementCurrencyALL();
                <?php
                break;

            case "formula":
                $ssql="SELECT IFNULL(SUM(ffformula),1) as ffformula
                        FROM tlstock_multi_det
                        WHERE ftitem_code='{$_REQUEST['ftitem_code']}'
                        and ftuom_code_multi='{$_REQUEST['ftuom_code']}'
                        ";
                $ffformula=RetRstField($ssql);
                $ffQtyMulti=(double)$ffformula*(double)CCur($_REQUEST['fnqty']);
                ?>
                        document.getElementById('ffformulaD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ffformula; ?>';
                        document.getElementById('fnqty_baseD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ffQtyMulti; ?>';
                <?php

                die("");
                break;
            
            case "gudang":
                $ssql="SELECT ftlocation_code,ftlocation_name FROM tllocation WHERE ftwarehouse_code='{$_REQUEST['ftwarehouse_code']}' and fnstatus = 1 ";
                $rs=mysql_query($ssql);
                ?>  
                        var ObjSelect=document.getElementById('<?php echo $_REQUEST['ObjLokasi']; ?>');
                        var len = ObjSelect.length;
                                for (var idx=0; idx < len; idx++)
                                {
                                        if (ObjSelect.options[ObjSelect.length-1].value!='') {
                                                  ObjSelect.remove(ObjSelect.length-1);
                                        }
                                }
                <?php
                $i=0;
                while($r=mysql_fetch_assoc($rs)) {
                        $i++;
                        echo " try {
                                    ObjSelect.add(new Option('{$r['ftlocation_code']}--{$r['ftlocation_name']}','{$r['ftlocation_code']}'),null,null);
                                   }
                               catch(ex) {
                                    ObjSelect.add(new Option('{$r['ftlocation_code']}--{$r['ftlocation_name']}','{$r['ftlocation_code']}'), $i, $i);
                               } ";
                }
                
                echo " try {
                            ObjSelect.selectedIndex=0;
                       } catch(ex) {

                       } ";
                die("");
                break;
                
            case "lokasi":
                ?>
                if (<?php echo $_REQUEST['index']; ?> != 1) {
                    // make sure variable index - 1 is exists , effect from delete row 
                    var i;
                    for (i = <?php echo $_REQUEST['index']; ?> - 1; i >= 0 ; i--) {
                        if (document.getElementById('ftwarehouse_codeD0' + i) !== null) { break; }         
                    }
       
                    //opsi untuk harus gudang yg sama 
                    //if (document.getElementById('ftwarehouse_codeD0' + i).value != '<?php echo $ftwarehouse_code; ?>') {
                    //    alert('Tidak bisa memilih dari Gudang yang berbeda.');
                    //    document.getElementById('ftlocation_codeD0<?php echo $_REQUEST['index']; ?>').value='';
                    //    document.getElementById('ftwarehouse_codeD0<?php echo $_REQUEST['index']; ?>').value='';
                    //} else {
                        ajax_do('query2.php?code=qty_onhand&ftwarehouse_code=<?php echo $_REQUEST['ftwarehouse_code']; ?>&ftlocation_code=<?php echo $_REQUEST['ftlocation_code']; ?>&ftitem_code=' + document.getElementById('ftitem_codeD0<?php echo $_REQUEST['index']; ?>').value+ '&objQty=fnqty_availableD0<?php echo $_REQUEST['index']; ?>');                
                    //}
                } else {    
                    ajax_do('query2.php?code=qty_onhand&ftwarehouse_code=<?php echo $_REQUEST['ftwarehouse_code']; ?>&ftlocation_code=<?php echo $_REQUEST['ftlocation_code']; ?>&ftitem_code=' + document.getElementById('ftitem_codeD0<?php echo $_REQUEST['index']; ?>').value+ '&objQty=fnqty_availableD0<?php echo $_REQUEST['index']; ?>');                
                }    
                <?php 
                
                die("");
                break;
           } 
           
    }

    /* tidak digunakan lagi 
    function GetInvoice() {
        $x="";
        $ssql="SELECT a.fnindex as fnindex,a.ftitem_code,a.ftitem_name,a.ftprint_name,a.ftuom_code,a.ftstock_category_code,a.ftwarehouse_code,a.ftlocation_code,a.fnqty,
                0 as fcprice,0 as fcDisc,0 as fcamount,a.fnqty_base,a.ffformula
                FROM txdelivery_order_det a
                WHERE a.ftdo_no='{$_REQUEST['ftdo_no']}' ";

        $rs=mysql_query($ssql);
        
        $x.= "<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'>Qty</th>
                <td  valign='top'>Satuan</th>
                <td  valign='top'>Kategori</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>";

            $ssql="select ftcustomer_code
                  from  txdelivery_order_hdr
                  where ftdo_no='{$_REQUEST['ftdo_no']}'";
            $ftcustomer_code=RetRstField($ssql);

            $ssql="select ftso_no
                  from  txdelivery_order_hdr
                  where ftdo_no='{$_REQUEST['ftdo_no']}'";
            $ftso_no=RetRstField($ssql);

            $ssql=" select ftcustomer_type_code
                    from tlcustomer
                    where ftcustomer_code='{$ftcustomer_code}'";
            $ftcustomer_type_code=RetRstField($ssql);

            $ssql=" select ftharga_potong_pajak
                    from tlcustomer
                    where ftcustomer_code='{$ftcustomer_code}'";
            $ftharga_potong_pajak=RetRstField($ssql);

            if(!RetRstField("select fnid from tlcustomer where ftfiktif='1' and   ftcustomer_code='{$ftcustomer_code}'")) {
                $mmm="0";
            }
            else {
                $mmm="1";
            }


        $i=0;
        while($r = mysql_fetch_assoc($rs))
         {
            if($mmm=="1") {
                $ftitem_name=$r['ftprint_name'];
                $ftprint_name=$r['ftprint_name'];
            }
            else {
                 $ftitem_name=$r['ftitem_name'];
                 $ftprint_name=$r['ftprint_name'];
            }

            if ($i%2) {
                    $class1="ewTableRow";
                    $class2="ISGridTDeven";
            } else {
                    $class1="ewTableRow";
                    $class2="ISGridTDodd";
            }

            /*$ssql="select fcselling_price
                   from tlselling_price
                   where ftitem_code='{$r[ftitem_code]}'
                   and ftcustomer_type_code='{$ftcustomer_type_code}'";

            $fcselling_price=RetRstField($ssql);
            if( $ftharga_potong_pajak=="1") {
                 #$fcselling_price=$fcselling_price- $fcselling_price*0.1;
                 $fcselling_price=round($fcselling_price/(1.1),2);
            }
            else {
                 $fcselling_price=$fcselling_price;
            }

            $ssql="select ffselling_discount
                   from tlselling_price
                   where ftitem_code='{$r[ftitem_code]}'
                   and ftcustomer_type_code='{$ftcustomer_type_code}'";

            $ffselling_discount=RetRstField($ssql);*/
/*
            $ssql="select fcprice, ffdiscount, fcdiscount
                   from txsales_order_det
                   where ftso_no='{$ftso_no}'
                   AND ftitem_code='{$r[ftitem_code]}'";
            $mysql2=mysql_query($ssql);
            $r2=mysql_fetch_assoc($mysql2);
            $fcselling_price=$r2["fcprice"];
            $ffselling_discount=$r2["ffdiscount"];
            $fcselling_discount=(($r['fnqty'] * $fcselling_price) * $ffselling_discount) / 100;

             $x.= "<tr class='$class1'>
             <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='fnindexD[]' id='fnindexD$i' value='" . $r['fnindex'] . "' size=3></td>
             <td class='$class2'><input  type='hidden' name='ftlocation_codeD[]' id='ftlocation_codeD$i' value='" . $r['ftlocation_code'] . "'>
                                <input   type='hidden' name='ftwarehouse_codeD[]' id='ftwarehouse_codeD$i' value='" . $r['ftwarehouse_code'] . "' >
                                <input readonly style='background-color: #E0E0E0'  type='text'  size='25'  name='ftitem_codeD[]' id='ftitem_codeD$i' value='" . $r['ftitem_code'] . "'  size=16>
                                <input  type='hidden' name='ftprint_nameD[]' id='ftprint_nameD$i' value='" .$ftprint_name . "'>
                                <input  type='hidden' name='ftitem_nameD[]' id='ftitem_nameD$i' value='" .$ftitem_name . "'>{$ftitem_name}</td>
             <td class='$class2'><input readonly style='background-color: #E0E0E0'  onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" type='text' name='fnqtyD[]' id='fnqtyD$i' value='" . $r['fnqty'] . "'   size=10>
                                <input type='hidden' name='fnqty_baseD[]' id='fnqty_baseD' value='" . $r['fnqty_base'] . "'   size=10>
                                <input type='hidden' name='ffformulaD[]' id='ffformulaD' value='" . $r['ffformula'] . "'   size=10></td>
             <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='ftuom_codeD[]' id='ftuom_codeD$i' value='" . $r['ftuom_code'] . "'   size=3></td>
             <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='ftstock_category_codeD[]' id='ftstock_category_codeD$i' value='" . $r['ftstock_category_code'] . "'   size=10></td>
             <td class='$class2'><input type='text' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  onChange=\"SalesInvoiceRecalPrice();\" name='fcpriceD[]' id='fcpriceD$i' value='" . $fcselling_price . "'  size=15><input type=hidden name='fcpriceListD[]'  id='fcpriceListD$i' value='{$fcselling_price}'>  </td>
             <td class='$class2'><input type='text' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  onChange=\"SalesInvoiceRecalDiscDetailPercent($i);\"   name='ffdiscountD[]' id='ffdiscountD$i' value='" . $ffselling_discount . "' size=15></td>
             <td class='$class2'><input readonly  onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" type='text'  onChange=\"SalesInvoiceRecalDiscDetailRp($i);\"  name='fcdiscountD[]' id='fcdiscountD$i' value='". $fcselling_discount ."'  size=15></td>
             <td class='$class2'><input type='text' readonly style='background-color: #E0E0E0;text-align: right;' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\"  name='fcamountD[]' id='fcamountD$i' value='0'></td>
             </tr>";

             $i++;
         }
        $x.= "</table>
        <input id='TransactionDetailCount' name='TransactionDetailCount' value='$num_rows' type='hidden'>
       ";
        return $x;
    } */

    // filter only sales transaction if login by user
    $ftsales_code = RetRstField("Select ifnull(ftsales_code,'') FROM tluser WHERE ftusername = '{$_SESSION['username']}' ");
    if ($ftsales_code != "") { $sql_sales = " AND a.ftsales_code = '{$ftsales_code}' "; } 
    
    // filter warehouse code based on login user
    $ftwarehouse_code = RetRstField("Select ifnull(ftwarehouse_code,'') FROM tluser WHERE ftusername = '{$_SESSION['username']}' ");
    if ($ftwarehouse_code != "") { 
        $str_warehouse = explode(",", $ftwarehouse_code);
        $sql_where = "''";

        foreach($str_warehouse as $item) {
            $sql_where = $sql_where . ",'{$item}'";
        }
        $sql_where = " AND e.ftwarehouse_code IN ({$sql_where})";
    }
    
    $objAxpDB->ViewName("Daftar Sales Invoice");
    //$objAxpDB->ViewTable("vSASalesInvoice");
    $objAxpDB->ViewSQL("SELECT DISTINCT A.fnid, A.fdtrans_date, A.ftsales_invoice_no, A.ftso_no, CONCAT(A.ftcustomer_code,' - ',d.ftcustomer_name) as ftcustomer_name, 
                            A.fddue_date,  A.fcamount, A.fcoutstanding_amount, C.fttrans_status_name AS fnpayment_status, B.fttrans_status_name
                        FROM txsales_invoice_hdr  A 
                        INNER JOIN tstransaction_status B ON a.fnstatus=b.fntrans_status_code AND B.fntrans_group_code=2
                        INNER JOIN tstransaction_status C ON a.fnpayment_status=C.fntrans_status_code AND C.fntrans_group_code=1
                        INNER JOIN tlcustomer d ON a.ftcustomer_code = d.ftcustomer_code
                        WHERE A.fnsaldo_awal=0 {$sql_sales} {$sql_where}  
                        AND (('{$_SESSION['strbranch']}' <> 'PUSAT' AND a.ftbranch_code = '{$_SESSION['strbranch']}') OR '{$_SESSION['strbranch']}' = 'PUSAT')
                        ORDER BY  A.fdtrans_date DESC,ftsales_invoice_no DESC");
    $objAxpDB->ViewCaption("ID, Tgl. Invoice, No. Invoice, No. Sales Order, Nama Customer, Tgl. Jatuh Tempo, Total Invoice, Sisa Pembayaran, Status Pembayaran, Gudang, Status");
    $objAxpDB->ViewPeriod(TRUE);

    $ajaxKurs="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=idr&ftcurrency_code='+ document.getElementById('ftcurrency_code').value);";

    if($_REQUEST['id']=="") {
        // Form Daftar -- no script yet
    } else if(!$_REQUEST['id']){
            $strAutoNumber1=" ajax_do('query2.php?code=2&ftdo_no=' + document.getElementById(\"ftdo_no\").value + '&ftmodule_code=TN006&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftsales_invoice_no&no_trans=ftsales_invoice_no&table_name=txsales_invoice_hdr&ftbranch_code={$_SESSION['strbranch']}');";
            $strAutoNumber2=" ajax_do('query2.php?code=2&ftdo_no=' + document.getElementById(\"ftdo_no\").value + '&ftmodule_code=TN021&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftsales_invoice_no&no_trans=ftsales_invoice_no&table_name=txsales_invoice_hdr&ftbranch_code={$_SESSION['strbranch']}');";
            $strAutoNumber3=" ajax_do('query2.php?code=2&ftdo_no=' + document.getElementById(\"ftdo_no\").value + '&ftmodule_code=TN022&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftsales_invoice_no&no_trans=ftsales_invoice_no&table_name=txsales_invoice_hdr&ftbranch_code={$_SESSION['strbranch']}');";

            // $ajaxTransDate="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=tgl&tgl=' + document.getElementById(\"fdtrans_date\").value + '&ftterm_payment=+ document.getElementById(\"ftterm_payment\").value +');";
            $ajax_tipe="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=tipeinvoice&do_no=' + document.getElementById(\"ftdo_no\").value + '');";
            $ajax_due="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&code=tgltempo&ajax=1&fdtrans_date=' + document.getElementById('fdtrans_date').value + '&ftterm_payment=' + document.getElementById('ftterm_payment').value + '&fddue_date=fddue_date');";
            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                     if(document.getElementById(\"fntax_code\").value==0) {
                                           {$strAutoNumber1}
                                     }
                                     else if(document.getElementById(\"fntax_code\").value==1) {
                                           {$strAutoNumber2}
                                     }
                                     else if(document.getElementById(\"fntax_code\").value==2) {
                                           {$strAutoNumber3}
                                     }
                                    
                                     document.getElementById(\"fdvat_date\").value=document.getElementById(\"fdtrans_date\").value;
                                     ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=tgl&tgl=' + document.getElementById('fdtrans_date').value + '&ftterm_payment=' + document.getElementById('ftterm_payment').value);

                                     {$ajaxTransDate}{$ajax_tipe}
                                     
                                }
                                 OnChangeDate_fdtrans_date();
                                 document.getElementById('ftcurrency_code').value='IDR';
                                 {$ajaxKurs}";
            $objAxpDB->FormJS($strAutoNumber0);
            
            // System Setting
            if($_SESSION["SOAutoDOPrint"] || $_SESSION["SOAutoDOSave"]) { 
                // Tidak perlu lookup untuk SO dan DO
                $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0");
            } else if ($_SESSION["SIAutoDO"]) { // Tampilkan lookup no SO
                $objAxpDB->Lookup("ftso_no", "SELECT ftso_no, CONCAT(DATE_FORMAT(fdtrans_date,'%d/%m/%Y'),' (',ftcustomer_code,')') AS ftreference FROM txsales_order_hdr WHERE fnstatus!=3 AND fnstatus!=5 AND fnstatus!=9 AND fnreceive_status != 3 ORDER BY ftso_no", "ftso_no", "ftreference", -1,true);    
                $objAxpDB->FormLocked("1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0");
            } else if ($_SESSION["SOManual"]) { // Tampilkan lookup no DO
                $objAxpDB->Lookup("ftdo_no", "SELECT ftdo_no,ftreference FROM txdelivery_order_hdr WHERE fnstatus=1", "ftdo_no", "ftreference", -1,true);    
                $objAxpDB->FormLocked("1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0");
            }  

    } else {
            $objAxpDB->FormJS("ElementCurrencyALL();");
    }

    $objAxpDB->FormName("Sales Invoice");
    $objAxpDB->FormSQL("SELECT ftsales_invoice_no, ftso_no, ftdo_no, ftcustomer_code, ftship_address, ftitem_type, fdtrans_date,  ftterm_payment, fddue_date, ftcurrency_code, fcrate, fntax_code,ftreff_no, fnpayment_status, fdvat_date, ftvat_no,ftnotes, fcpayment_amount, fcoutstanding_amount, fcsub_amount, ffdiscount, fcdiscount, fcother_cost, ffvat, fcvat, fcamount, fnstatus, fcreturn_amount,fntotal_qty,ftsales_code FROM txsales_invoice_hdr");
    $objAxpDB->FormCaption("No. Invoice,  No. SO, No. DO, Customer, Alamat, Tipe Invoice, Tgl. Invoice,  Syarat Pembayaran, Tgl. Jatuh Tempo, Mata Uang, Kurs, Kode Pajak, Referensi, Status Pembayaran,Tgl. Faktur Pajak, No. Faktur Pajak, Catatan, Jumlah Terbayar, Sisa Pembayaran,   Sub Total, Discount (%), Discount(Rp), Biaya Lain-lain, Pajak (%), Pajak (Rp), Grand Total, Status, Jumlah Retur, Total Qty, Salesman");
    $objAxpDB->FormPosition("TL, TL, TL, TL, TL, HD, TR, TR, TR, TR, TR, TR, TL, TR, TR, TR, BL, BL, BL, BR, BR, BR, BR, BR, BR, BR, BR, BL, HD, TL");
    
    $ajaxFormula="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=formula&index=_N_&index=_N_&ftitem_code='+ document.getElementById('ftitem_codeD0_N_').value+'&ftuom_code='+ document.getElementById('ftuom_codeD0_N_').value+'&fnqty='+ document.getElementById('fnqtyD0_N_').value);";
    
    $ajaxSO="ajax_do_grid0('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=salesorder&ftso_no='+ document.getElementById('ftso_no').value);";
    $objAxpDB->FormScript(1, "onChange=\"{$ajaxSO}\"");
    
    // setting do create invoice belum dibuat coding nya
    //$ajaxinvoice="ajax_do_grid0('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=invoice&ftdo_no='+ document.getElementById('ftdo_no').value);";
    //$objAxpDB->FormScript(2, "onChange=\"{$ajaxinvoice}\"");
    
    $objAxpDB->FormScript(6, "onChange=\"{$ajax_due}\"");
    $objAxpDB->FormScript(7, "onChange=\"{$ajax_due}\"");    
    $objAxpDB->FormScript(9, "OnChange=\"{$ajaxKurs}\"");
    $objAxpDB->FormScript(11, "onChange=\"OnChangeDate_fdtrans_date();\"");
    $objAxpDB->FormScript(20, "onChange=\"SalesInvoiceRecalDiscPercent();\"");
    $objAxpDB->FormScript(21, "onChange=\"SalesInvoiceRecalDiscRp();\"");
    $objAxpDB->FormScript(22, "onChange=\"SalesInvoiceRecalQty0();\"");
    $objAxpDB->FormScript(23, "onChange=\"SalesInvoiceRecalQty0();\"");
    
    $ssql= "SELECT fnindex, ftitem_code,ftdescription, ftstock_category_code, ftwarehouse_code, ftlocation_code,
                    fnqty_so, fnqty_so_base, fnqty_so_outstanding, fnqty_so_outstanding_base, fnqty_available, 
                    fnqty, fnqty_base, ftuom_code,  fcprice, ffdiscount, fcdiscount, fcamount, ffformula, fnindex_so 
            FROM txsales_invoice_det";
    
    $objAxpDB->GridSQL(0, $ssql);
    $objAxpDB->GridCaption(0, "No., Kode Barang, Keterangan, Kategori Stock, Gudang, Lokasi, Qty SO, Qty SO Base, Qty Sisa SO, Qty Sisa SO Base, Qty Available, Qty, Qty Base, Satuan, Harga, Discount(%), Discount, Jumlah, Formula, Index SO");
    $objAxpDB->GridDelJS(0, "SalesInvoiceRecalQty0();SalesInvoiceRecalDiscDetailPercent();");
    $objAxpDB->GridSize(0, '3,5,5,5,5,5,5,5,5,5,5,5,5,5,10,5,10,10,5,5');

    $objAxpDB->Lookup("ftcurrency_code", "SELECT  ftsimbol, ftdescription  FROM tlcurrency_hdr ORDER BY ftsimbol", "ftsimbol", "ftdescription", 0, True);
    $objAxpDB->Lookup("ftpayment_method", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 8", "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("fntax_code", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 15", "fntrans_status_code", "fttrans_status_name", 1,true);
    $objAxpDB->Lookup("fnpayment_status", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 1", "fntrans_status_code", "fttrans_status_name", 1,true);
    $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr", "ftitem_code", "ftitem_name", -1,false);
    $objAxpDB->Lookup("ftitem_type","SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fttrans_group_name='tipe barang invoice'","fntrans_status_code","fttrans_status_name",1,true);
    $objAxpDB->Lookup("ftcustomer_code","SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer","ftcustomer_code","ftcustomer_name", -1,false);
    $objAxpDB->Lookup("ftterm_payment", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 75 and fnactive_status=1 ORDER BY fntrans_status_code ", "fntrans_status_code", "fttrans_status_name", 1,true);
    $objAxpDB->Lookup("ftsales_code", "SELECT  ftsales_code, ftsales_name  FROM tlsales WHERE fnstatus=1 ORDER BY ftsales_code", "ftsales_code", "ftsales_name", -1, true);
     
    $objAxpDB->SetStatus("id, fnstatus");
    if ($objAxpDB->GetStatus("id") == "") {
            // Tombol baru dimunculkan apabila bukan setting auto DO 
            if ($_SESSION["SOAutoDOPrint"] || $_SESSION["SOAutoDOSave"]) {} else { $objAxpDB->ButtonShow("baru"); } 
    } elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->GridLocked(0, '1,1,0,1,0,0,1,1,1,1,1,0,1,1,0,0,0,1,1,1');
            $objAxpDB->GridHidden(0, '0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,1,1');
            $objAxpDB->GridAutoAdd(0,false);
            $objAxpDB->GridAllowAddNew(0,false);
            $objAxpDB->GridAllowDelete(0,false);
            $objAxpDB->ButtonShow("reset, simpan, tutup");
    } elseif ($objAxpDB->GetStatus("fnstatus") == 0) {
            $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
            $objAxpDB->GridLocked(0, '1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1');
            $objAxpDB->GridHidden(0, '0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,1,1');
            $objAxpDB->Lookup("ftcustomer_code", "SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer", "ftcustomer_code", "ftcustomer_name", 1,false);
            $objAxpDB->ButtonShow("update, batal, tutup"); 
    } elseif (($objAxpDB->GetStatus("fnstatus") == 1) OR ($objAxpDB->GetStatus("fnstatus") == 2)) {
            
            $ajaxInquiry="window.open('penjualan.php?form=history_bayar&mode=".$_REQUEST['mode']."&id=".$_REQUEST['id']."','win_inquiry','height='+250+',width='+700+',top='+100+',left='+200+',scrollbars=0,resizable=1,menubar=0,status=0,fullscreen=1');";

            $button_pembayaran = "<input type='button' value='History Bayar' OnClick=\"{$ajaxInquiry}\">";
            $objAxpDB->FormLayout(18, $button_pembayaran);

            $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
            $objAxpDB->GridLocked(0, '1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1');
            $objAxpDB->GridHidden(0, '0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,1,1');
            $objAxpDB->Lookup("ftcustomer_code", "SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer", "ftcustomer_code", "ftcustomer_name", 1,false);
            if ($_SESSION["SOAutoDOPrint"] || $_SESSION["SOAutoDOSave"]) {  // Tombol baru dimunculkan apabila bukan setting auto DO 
                $objAxpDB->ButtonShow("cetak, batal, tutup");
            } else { $objAxpDB->ButtonShow("baru, cetak, batal, tutup"); }
    } elseif (($objAxpDB->GetStatus("fnstatus") == 3) OR ($objAxpDB->GetStatus("fnstatus") == 9)) {
            $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1, 1");
            $objAxpDB->GridLocked(0, '1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1');
            $objAxpDB->GridHidden(0, '0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,1,1');
            if ($_SESSION["SOAutoDOPrint"] || $_SESSION["SOAutoDOSave"]) {  // Tombol baru dimunculkan apabila bukan setting auto DO 
                $objAxpDB->ButtonShow("baru, tutup");
            } else { $objAxpDB->ButtonShow("baru, tutup"); }
    } 
    
    if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            // Tarik data dari Sales Order
            case "salesorder":
                ob_start();
                $_REQUEST['id']=0.5;
                
                $ftcurrency_code=RetRstField("SELECT ftcurrency_code FROM txsales_order_hdr WHERE ftso_no='{$_REQUEST['ftso_no']}'");
                $fcrate=RetRstField("SELECT fcrate FROM txsales_order_hdr WHERE ftso_no='{$_REQUEST['ftso_no']}'");
                
                $ssql= "SELECT a.fnindex, a.ftitem_code,a.ftdescription, b.ftstock_category_code, '' AS ftwarehouse_code, '' AS ftlocation_code,
                            a.fnqty AS fnqty_so,a.fnqty_base AS fnqty_so_base,
                            round(a.fnqty-IFNULL(a.fnqty_accept,0),2) AS fnqty_so_outstanding,round(a.fnqty_base-IFNULL(a.fnqty_accept_base,0),2) AS fnqty_so_outstanding_base, 
                            (a.fnqty_base-a.fnqty_base) AS fnqty_available,(a.fnqty_base-a.fnqty_base) AS fnqty, (a.fnqty_base-a.fnqty_base) AS fnqty_base, a.ftuom_code,
                            a.fcprice AS fcprice, a.ffdiscount, (a.fcdiscount-a.fcdiscount) AS fcdiscount, (a.fcamount-a.fcamount) as fcamount, 
                            a.ffformula AS ffformula,a.fnindex AS fnindex_so 
                        FROM txsales_order_det a
                        INNER JOIN txsales_order_hdr d on a.ftso_no = d.ftso_no 
                        LEFT JOIN tlstock_hdr{$tablename} b ON a.ftitem_code=b.ftitem_code
                        LEFT JOIN tlstock_group{$tablename} c ON b.ftstock_group_code=c.ftstock_group_code
                        WHERE a.ftso_no='".$_REQUEST['ftso_no']."' AND b.fnstatus = 1
                                AND (a.fnqty_base-IFNULL(a.fnqty_accept_base,0)>0)
                        ORDER BY a.fnindex
                        #";
                     
                $objAxpDB->GridSQL(0,$ssql);
                $objAxpDB->GridCaption(0, "No., Kode Barang, Keterangan, Kategori Stock, Gudang, Lokasi, Qty SO, Qty SO Base, Qty Sisa SO, Qty Sisa SO Base, Qty Available, Qty, Qty Base, Satuan, Harga, Discount(%), Discount, Jumlah, Formula, Index SO");
                $objAxpDB->GridLocked(0, '1,1,0,1,0,0,1,1,1,1,1,0,1,1,0,0,0,1,1,1');
                $objAxpDB->GridHidden(0, '0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,1,1');
                $objAxpDB->GridSize(0, '3,5,5,5,5,5,5,5,5,5,5,5,5,5,10,5,10,10,5,5');

                $ajaxGudang="OnChange=\"ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=gudang&ftwarehouse_code='+this.value+'&ObjLokasi=ftlocation_codeD0_N_');\"";
                $ajaxLokasi="OnChange=\"ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=lokasi&index=_N_&ftlocation_code='+this.value+'&ftwarehouse_code='+document.getElementById('ftwarehouse_codeD0_N_').value);\"";
    
                $objAxpDB->GridScript(0,4, $ajaxGudang);
                $objAxpDB->GridScript(0,5, $ajaxLokasi);
                $objAxpDB->GridScript(0,11, "onChange=\"{$ajaxFormula}SalesInvoiceRecalDiscDetailPercent(_N_);SalesInvoiceRecalDiscPercent();\"");
                $objAxpDB->GridScript(0,14, "onChange=\"SalesInvoiceRecalDiscDetailPercent(_N_);SalesInvoiceRecalDiscPercent();\"");
                $objAxpDB->GridScript(0,15, "onChange=\"SalesInvoiceRecalDiscDetailPercent(_N_);SalesInvoiceRecalDiscPercent();\"");
                $objAxpDB->GridScript(0,16, "onChange=\"SalesInvoiceRecalDiscDetailRp(_N_);SalesInvoiceRecalDiscPercent();\"");
                
                $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr{$tablename} $m", "ftitem_code", "ftitem_name",-1,false);
                $objAxpDB->Lookup("ftwarehouse_code", "SELECT ftwarehouse_code, ftwarehouse_name FROM tlwarehouse where fnstatus = 1 ", "ftwarehouse_code", "ftwarehouse_name",-1,true);
                $objAxpDB->Lookup("ftlocation_code", "SELECT ftlocation_code, ftlocation_name FROM tllocation where fnstatus = 1 ", "ftlocation_code", "ftlocation_name", -1,true,"' AND ftwarehouse_code=\''+ document.getElementById('ftwarehouse_code').value + '\''");
                //$objAxpDB->LookupGrid(0,"ftuom_code", "SELECT ftuom_code, ftuom_name FROM tluom ", "ftuom_code", "ftuom_name", -1,true);
                
                $objAxpDB->GridAllowAddNew(0,false);
                $objAxpDB->GridAllowDelete(0,false);
            
                $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();
                SalesInvoiceRecalQty0();
                
                document.getElementById('ftcurrency_code').value='<?php echo $ftcurrency_code; ?>';
                document.getElementById('fcrate').value='<?php echo $fcrate; ?>';
                ElementCurrencyALL();
                <?php

                break;
            }
        die("");
        exit;
    }
    

    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();