<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              $found=0;
              $methods=explode("___", $_REQUEST['method']);
              $nogiros=explode("___", $_REQUEST['nogiro']);
              for($i=0; $i < count($methods); $i++){
                if($methods[$i] == "0" || $methods[$i] == "1"){
                   $ssql="select fnid from txgiro2_hist
                   where ftdocument_no<>'".$_REQUEST['fttrans_no']."' and  fnstatus_giro<>9 and
                   ftgiro_no='".$nogiros[$i]."'";
                   $rs=mysql_query($ssql);
                   $r=mysql_fetch_assoc($rs);
                   if($r['fnid']) {
                   ?>
                      alert('No. Reff sudah pernah dipakai...');
                      document.getElementById("ftgiro_noDO<?php echo $i;?>").focus();
                   <?php
                      $found=1;
                      break;
                   }
                }
              }

              if($found == 0){
                  if(RetRstField("SELECT fnid FROM txrecap_bank_voucher_hdr WHERE ftcvs_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 {
                        ?>
                        if (RekapBankVoucherCheckCurrency()) {
                            submitbutton('Simpan','','','','');
                         }
                        <?php
                  }
              }
                   die("");
                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('fckurs').value='<?php echo $r["fcrate"]; ?>';

                  for (var idx=0; idx <  document.getElementsByName('fnindexD0[]').length; idx++)
                  {
                        if (document.getElementsByName('fnpayment_methodD0[]')[idx].value*1==9) {
                            document.getElementsByName('fnpayment_methodD0[]')[idx].value='';
                            ajax_do('query2.php?code=uangmukapembelian&obj1=&obj2=' + document.getElementById('ftsupplier_code').value + '&index=' + idx);
                            ajax_do('query2.php?code=8&obj1=&obj2=fnstatus_giroD0' + idx);

                            document.getElementsByName('fcamountUSDD0[]')[idx].value='0';
                        }
                  }

                  RekapBankVoucherRecalQtyImport0()
                <?php
                break;

            case "currency":
                // cek currency dari uang muka
                if ($_REQUEST["fnpayment_method"] == 9) {
                    $ssql="SELECT ftcurrency_code FROM txadvanced_payment WHERE fttrans_no='{$_REQUEST["ftgiro_no"]}'";
                    $mysql=mysql_query($ssql) or die ($ssql);
                    $r=mysql_fetch_assoc($mysql);

                    if ($_REQUEST["ftcurrency_code"] != $r["ftcurrency_code"]) {
                    ?>
                      document.getElementById('fnpayment_methodD0<?php echo $_REQUEST["index"]; ?>').value='';
                      ajax_do('query2.php?code=uangmukapembelian&obj1=&obj2=' + document.getElementById('ftsupplier_code').value + '&index=<?php echo $_REQUEST["index"]; ?>');
                      ajax_do('query2.php?code=8&obj1=&obj2=fnstatus_giroD0<?php echo $_REQUEST["index"]; ?>');


                      document.getElementById('fcamountUSDD0<?php echo $_REQUEST["index"]; ?>').value='0';
                      alert('Mata Uang pembayaran tidak boleh berbeda dengan Mata Uang dari Uang Muka Pembelian');

                      RekapBankVoucherRecalQtyImport0();
                    <?php
                    }
                }
                break;
        }

    }

function GetCV() {
    $x="";
    if(isset($_REQUEST['revisi'])) {
        
        $ssql="SELECT * FROM (
                    -- hutang awal
                    SELECT NULL AS fnindex,a.ftpurchase_invoice_no AS ftpi_no,a.fdtrans_date AS ftdue_date,a.ftpo_no,a.ftcurrency_code,
                            a.fcrate as fckurs, a.fcamount as fcamountUSD , a.fcoutstanding_amount AS fcoutstanding_amountUSD,
                            '0' AS fcpayment_amountUSD, IFNULL(a.fcamount,0) * a.fcrate AS fcamount,
                            IFNULL(a.fcoutstanding_amount,0) * a.fcrate AS fcoutstanding_amount,
                            'HUTANG AWAL' AS ftpi_type, 0 AS fnorder, '' AS ftreference
                    FROM txpurchase_invoice_hdr a
                    WHERE a.fnstatus=1 AND fnsaldo_awal = 1 AND a.fnpo_type='1'
                            AND a.fcoutstanding_amount > 0
                            AND a.ftsupplier_code='".$_REQUEST['ftsupplier_code']."'
                            AND a.ftpurchase_invoice_no NOT IN (SELECT ftpi_no FROM txrecap_bank_voucher_det WHERE ftcvs_no = '{$_REQUEST['ftcvs_no']}')
                    -- invoice            
                    UNION ALL
                    SELECT b.fnindex,a.ftpurchase_invoice_no AS ftpi_no,a.fdtrans_date AS ftdue_date,a.ftpo_no,a.ftcurrency_code,
                            a.fcrate as fckurs, a.fcamount as fcamountUSD , a.fcoutstanding_amount AS fcoutstanding_amountUSD,
                            '0' AS fcpayment_amountUSD, IFNULL(a.fcamount,0) * a.fcrate AS fcamount,
                            IFNULL(a.fcoutstanding_amount,0) * a.fcrate AS fcoutstanding_amount,
                            'FAKTUR' AS ftpi_type, 1 AS fnorder, c.ftreference
                    FROM txpurchase_invoice_hdr a
                    LEFT JOIN txpurchase_invoice_det b ON 1=0
                    LEFT JOIN txpurchase_order_hdr c ON a.ftpo_no = c.ftpo_no
                    WHERE a.fnstatus=1 AND a.fnpo_type='1'
                            AND a.fcoutstanding_amount > 0
                            AND a.ftsupplier_code='".$_REQUEST['ftsupplier_code']."' 
                            AND a.ftpurchase_invoice_no NOT IN (SELECT ftpi_no FROM txrecap_bank_voucher_det WHERE ftcvs_no = '{$_REQUEST['ftcvs_no']}')
                            AND a.fdtrans_date >= '{$_SESSION['fdstart_period']}'        
                    -- existing purchase invoice in ap    
                    SELECT a.fnindex, a.ftpi_no, a.ftdue_date, a.ftpo_no, a.ftcurrency_code,
                            IFNULL(b.fcrate,1) as fckurs, a.fcamountUSD, a.fcoutstanding_amountUSD,
                            a.fcpayment_amountUSD, a.fcamount, a.fcoutstanding_amount 
                            ftpi_type, 0 AS fnorder, '' AS ftreference 
                    FROM txrecap_bank_voucher_det a
                    INNER JOIN txpurchase_invoice_hdr b ON a.ftpi_no = b.ftpurchase_invoice_no
                    LEFT JOIN txpurchase_order_hdr c ON b.ftpo_no = c.ftpo_no
                    WHERE  ftcvs_no = '{$_REQUEST['ftcvs_no']}'  
               ) x 
               ORDER BY fnorder, fdtrans_date, ftpi_no ";

    } else {
        
        $ssql="SELECT * FROM (
                -- hutang awal
                SELECT NULL AS fnindex,a.ftpurchase_invoice_no AS ftpi_no,a.fdtrans_date AS ftdue_date,a.ftpo_no,a.ftcurrency_code,
                        a.fcrate as fckurs, a.fcamount as fcamountUSD , a.fcoutstanding_amount AS fcoutstanding_amountUSD,
                        '0' AS fcpayment_amountUSD, IFNULL(a.fcamount,0) * a.fcrate AS fcamount, 
                        IFNULL(a.fcoutstanding_amount,0) * a.fcrate AS fcoutstanding_amount,                         
                        'HUTANG AWAL' AS ftpi_type, 0 AS fnorder, '' AS ftreference
                FROM txpurchase_invoice_hdr a
                WHERE  a.fnstatus=1 AND a.fnpo_type='1' AND fnsaldo_awal = 1 AND A.ftsupplier_code='{$_REQUEST['ftsupplier_code']}'
                        AND a.fcoutstanding_amount > 0
         
                UNION ALL 
                -- invoice
                SELECT b.fnindex,a.ftpurchase_invoice_no AS ftpi_no,a.fdtrans_date AS ftdue_date,a.ftpo_no,a.ftcurrency_code,
                        a.fcrate as fckurs, a.fcamount as fcamountUSD , a.fcoutstanding_amount AS fcoutstanding_amountUSD,
                        '0' AS fcpayment_amountUSD, IFNULL(a.fcamount,0) * a.fcrate AS fcamount, 
                        IFNULL(a.fcoutstanding_amount,0) * a.fcrate AS fcoutstanding_amount,                         
                        'FAKTUR' AS ftpi_type, 1 AS fnorder, c.ftreference
                FROM txpurchase_invoice_hdr a
                LEFT JOIN txpurchase_invoice_det b ON 1=0
                LEFT JOIN txpurchase_order_hdr c ON a.ftpo_no = c.ftpo_no
                WHERE  a.fnstatus=1 AND a.fnpo_type='1' AND a.ftsupplier_code='{$_REQUEST['ftsupplier_code']}'
                        AND a.fcoutstanding_amount > 0
                        AND a.fdtrans_date >= '{$_SESSION['fdstart_period']}'    
        )  X 
        ORDER BY fnorder, ftdue_date DESC, ftpi_no DESC "; 
    }

        $rs=mysql_query($ssql);

        $r['ftcurrency_code']=$_REQUEST['ftcurrency_code'];
        $x.= "<input type='hidden' id='fcamountxx'  name='fcamountxx'>
        <table class='ewTable' id='TransactionDetail1' name='TransactionDetail1' border='0' width='100%' cellspacing='0' celpadding='0'>
            <tr class='ewTableHeader'>
            <td valign='top'>No</td>
            <td valign='top'>Tipe Invoice</td>
            <td valign='top'>No. PI</td>
            <td valign='top'>No. PO</td>
            <td valign='top'>Tgl. Jth Tempo</td>
            <td valign='top'>Jml. Total </td>
            <td valign='top'>Sisa Hutang </td>
            <td valign='top'>Jml. Pembayaran </td>
            <td valign='top'>Mata Uang </td>
            <td valign='top'>Kurs </td>
            <td valign='top'>Jml. Pembayaran IDR</td>
            <td valign='top'>#</td>
            </tr>";

        $i=0;
        $j=0;
        while($r = mysql_fetch_assoc($rs))
         {
            $j = $i + 1;                                                                          

            if ($i%2) {
                    $class1="ewTableRow";
                    $class2="ISGridTDeven";
            } else {
                    $class1="ewTableRow";
                    $class2="ISGridTDodd";
            }
            
            if ($r['ftreference']!='') {
                    $ftreference="<br><font size='1'>Ref : " . $r['ftreference'] . "</font>";
            }  
            
             $x.= "<tr class='$class1'>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0'  type='text' name='fnindexD1[]' id='fnindexD1$i' value='{$j}' size=3></td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0'  type='text' name='ftpi_typeD1[]' id='ftpi_typeD1$i' value='" . $r['ftpi_type'] . "'  size=10></td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0'  type='text' name='ftpi_noD1[]' id='ftpi_noD1$i' value='" . $r['ftpi_no'] . "'  size=20></td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0'  type='text' name='ftpo_noD1[]' id='ftpo_noD1$i' value='" . $r['ftpo_no'] . "'  size=20>" . $ftreference . "</td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0'  type='text' name='ftdue_dateD1[]' id='ftdue_dateD1$i' value='" . CDateRev($r['ftdue_date']) . "'  size=20></td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0;text-align: right;' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\"   type='text' name='fcamountUSDD1[]' id='fcamountUSDD1$i' value='" . $r['fcamountUSD']   . "'   size=20></td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0;text-align: right;'  onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\"   type='text' name='fcoutstanding_amountUSDD1[]' id='fcoutstanding_amountUSDD1$i' value='" . $r['fcoutstanding_amountUSD']  . "'   size=20></td>
             <td class='$class2' valign='top'><input  onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" OnChange='RekapBankVoucherRecalQtyImport1();' type='text' name='fcpayment_amountUSDD1[]' id='fcpayment_amountUSDD1$i' value='" . $r['fcpayment_amountUSD']  . "' size=20></td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0' type='text' name='ftcurrency_codeD1[]' id='ftcurrency_codeD1$i' value='" .  $r['ftcurrency_code']  . "'   size=20></td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0;text-align: right;' type='text' name='fckursD1[]' id='fckursD1$i' value='" . $r['fckurs']  . "'   size=15></td>
             <td class='$class2' valign='top'><input readonly style='background-color: #E0E0E0;text-align: right;' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\"   type='hidden' name='fcamountD1[]' id='fcamountD1$i' value='" . $r['fcamount']  . "'   size=20>
                                 <input readonly style='background-color: #E0E0E0;text-align: right;' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\"   type='hidden' name='fcoutstanding_amountD1[]' id='fcoutstanding_amountD1$i' value='" . $r['fcoutstanding_amount'] . "'   size=20>
                                 <input readonly style='background-color: #E0E0E0;text-align: right;' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" type='text' name='fcpayment_amountD1[]' id='fcpayment_amountD1$i' value='" . $r['fcpayment_amount']  . "'   size=20></td>
             <td class='$class2' valign='top'><input type=checkbox onclick=\"if(this.checked) { document.getElementById('fcpayment_amountUSDD1$i').value='" . $r['fcoutstanding_amountUSD'] . "';document.getElementById('fcpayment_amountD1$i').value='" . $r['fcoutstanding_amount']  . "'; } RekapBankVoucherRecalQtyImport1();\"></td>
             </tr>";
             
             $i++;
            
         }
        $x.=  "</table>
        <input id='TransactionDetailCount1' name='TransactionDetailCount1' value='$num_rows' type='hidden'>";

        return $x;
}

Getsecurity("recap_bank_voucher_import");

$objAxpDB->ViewName("Daftar Pembayaran Hutang Import");
$objAxpDB->ViewSQL("SELECT a.fnid, a.ftcvs_no, a.fdtrans_date, c.ftsupplier_name,ff08_get_giro_no(a.ftcvs_no) as ftgiro,ff07_get_po_no(a.ftcvs_no) as ftpo_no,ftremarks, a.fcsub_amount, B.fttrans_status_name 
                    FROM txrecap_bank_voucher_hdr a
                    INNER JOIN tstransaction_status b ON a.fnstatus=b.fntrans_status_code AND b.fntrans_group_code=2
                    INNER JOIN tlsupplier c on a.ftsupplier_code=c.ftsupplier_code
                    WHERE a.fntype=1
                    AND (('{$_SESSION['strbranch']}' <> 'PUSAT' AND a.ftbranch_code = '{$_SESSION['strbranch']}') OR '{$_SESSION['strbranch']}' = 'PUSAT')
                    ORDER BY a.ftcvs_no DESC, a.fdtrans_date DESC");

$objAxpDB->ViewCaption("ID, No. transaksi, Tgl. transaksi, Supplier,No. Giro/Tgl. Giro, No. PO,Catatan, Total Pembayaran, Status");
$objAxpDB->ViewPeriod(TRUE);

$objAxpDB->FormName("Pembayaran Hutang Import");
$objAxpDB->FormSQL("SELECT ftcvs_no, ftsupplier_code, ftRef_No, fdtrans_date, ftcurrency_code, fckurs, fcdebit_memo, ftremarks,
                   fcinvoice_amountUSD, ftother_coa_code AS ftother2_coa_code, fcother_costUSD, fcsub_amountUSD, fcamountUSD,
                   fcinvoice_amount, fcother_cost, fcsub_amount, fcamount, fcrate_adjustment, fnstatus
                   FROM txrecap_bank_voucher_hdr");

$objAxpDB->FormCaption("No. transaksi, Supplier, No Ref, Tgl. transaksi, Mata Uang , Kurs , Sisa Debit Memo IDR, Catatan,
                        Sub Total Hutang, No. Perkiraan Biaya, Biaya, Total Hutang, Total Pembayaran,
                        Sub Total Hutang IDR , Biaya IDR, Total Hutang IDR,  Total Pembayaran IDR, Selisih Kurs, Status");
$objAxpDB->FormPosition("TL, TL, TL, TR, TR, TR, HD, BL, HD, HD, BR, BR, BR, HD, HD, BR, BR, BR, TL");

$ftcvs_no=RetRstField("select ftcvs_no from txrecap_bank_voucher_hdr where fnid='".$_REQUEST['id']."'");
//$ajaxGrid="document.getElementById('ftremarks').value='Terima dr '+document.getElementById('hidden_ftsupplier_code').value;";
$ajaxGrid=$ajaxGrid . "ajax_do('keuangan.php?ftcvs_no=".$ftcvs_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=cv&ftcurrency_code='+ document.getElementById('ftcurrency_code').value + '&ftsupplier_code='+ document.getElementById('ftsupplier_code').value);";
$objAxpDB->FormScript(1, "onChange=\"{$ajaxGrid}\"");

$ajaxKurs="ajax_do('keuangan.php?ftcvs_no=".$ftcvs_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=idr&ftcurrency_code='+ document.getElementById('ftcurrency_code').value);";
$objAxpDB->FormScript(3, "OnChange=\"{$ajaxKurs}RekapBankVoucherRecalQtyImport0();\"");

$js_form_currency_code="RekapBankVoucherRecalQtyImport0();";
$objAxpDB->FormScript(4, "OnChange=\"{$js_form_currency_code}\"");
$objAxpDB->FormScript(5, "OnChange=\"{$js_form_currency_code}\"");
$objAxpDB->FormScript(9, "onChange=\"RekapBankVoucherRecalQtyImport0();\"");

$objAxpDB->GridSQL(0, "SELECT a.fnindex, a.fnpayment_method, a.ftacc_no,
                            a.ftgiro_no ,a.fcamountUSD, a.fdgiro_date, a.fdgiro_cliring_date ,
                            a.ftother_coa_code, a.fcother_costUSD, a.fctotalUSD,
                            a.fcamount, a.fcother_cost, a.fctotal ,
                            b.fttrans_status_name as fnstatus_giro
                        FROM txrecap_bank_voucher_det1 a , tstransaction_status b
                        WHERE b.fntrans_group_code = 11 and a.fnstatus_giro=b.fntrans_status_code
                            and a.ftcvs_no='{$ftcvs_no}' #");

$objAxpDB->GridCaption(0, "No., Metode Pembayaran, Kas/Bank,
                         No. Giro/Cheque, Jumlah, Tgl. Giro, Tgl. Cair,
                         No. Perkiraan, Biaya, Total,
                         Jumlah IDR, Biaya IDR, Total IDR, Status Giro");
$objAxpDB->GridHidden(0,"0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1");
$objAxpDB->GridSize(0, "1,,,10,12,5,5,,,,,,12,");
$objAxpDB->GridDelJS(0,"RekapBankVoucherRecalQtyImport0();");

$ajaxUangMuka="ajax_do('query2.php?code=uangmukapembelian&obj1=' + this.value + '&obj2=' + document.getElementById('ftsupplier_code').value + '&index=_N_');";
$ajaxStatusGiro="ajax_do('query2.php?code=8&obj1=' + this.value + '&obj2=fnstatus_giroD0_N_');";
$objAxpDB->GridScript(0,1, "onChange=\"{$ajaxUangMuka}{$ajaxStatusGiro}\"");

// $ajaxCurrency="ajax_do('keuangan.php?ftcvs_no=".$ftcvs_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=currency&index=_N_&ftcurrency_code=' + document.getElementById('ftcurrency_code').value + '&ftgiro_no=' + document.getElementById('ftgiro_noD0[]')[_N_].value  + '&fnpayment_method=' + document.getElementById('fnpayment_methodD0_N_').value);";
$ajaxCurrency = "ajax_do('keuangan.php?ftcvs_no=".$ftcvs_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=currency&index=_N_&ftcurrency_code=' + document.getElementById('ftcurrency_code').value + '&ftgiro_no=' + document.getElementsByName('ftgiro_noD0[]')[_N_].value + '&fnpayment_method=' + document.getElementById('fnpayment_methodD0_N_').value);";

$js_grid0_fcamountUSD="onChange=\"{$ajaxCurrency}RekapBankVoucherRecalQty0();\"";
$objAxpDB->GridScript(0, 4, $js_grid0_fcamountUSD);

$js_grid0_fcother_costUSD="onChange=\"RekapBankVoucherRecalQty0();\"";
$objAxpDB->GridScript(0, 8, $js_grid0_fcother_costUSD);

$objAxpDB->GridSQL(1, "SELECT fnindex, ftpi_type, ftpi_no, ftpo_no, ftdue_date,
                              fcamountUSD, fcoutstanding_amountUSD, fcpayment_amountUSD,
                              ftcurrency_code as ftcurrency_code2, fcamount, fcoutstanding_amount,
                              fcpayment_amount
                       FROM txrecap_bank_voucher_det");
$objAxpDB->GridCaption(1, "No., Tipe Invoice, No. PI, No. PO, Tgl. Jth Tempo, Jml. Total, Sisa Hutang, Jml. Pembayaran, Mata Uang, Jml. Total IDR, Sisa Hutang IDR, Jml. Pembayaran IDR");
$objAxpDB->GridHidden(1,"0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1");
$objAxpDB->GridSize(1, "1,10,15,15,10,10,15,15,15,10,5,15");

$js_grid0_fcpayment_amountUSD="onChange=\"RekapBankVoucherRecalQtyImport0();\"";
$objAxpDB->GridScript(1,6, $js_grid0_fcpayment_amountUSD);

$objAxpDB->GridSQL(2, "SELECT fnindex, ftcoa_code, ftdescription, fcamount
                       FROM txrecap_bank_voucher_cost");
$objAxpDB->GridCaption(2, "No., No Perkiraan, Keterangan, Jumlah");
$objAxpDB->GridHidden(2,"0, 0, 1, 0");

$ajaxothercost="onChange=\"RekapBankVoucherRecalQty0();\"";
$objAxpDB->GridScript(2, 3, $ajaxothercost);

$ajaxCost="ajax_do('keuangan.php?ftcvs_no=".$ftcvs_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=othercost&fcother_costUSD=' + document.getElementById('fcother_costUSD').value);";

if(!$_REQUEST['id']) {
    $ssql="SELECT a.ftcoa_code, a.ftcoa_name FROM tlcoa a INNER JOIN tlcoa_subgroup b ON a.ftcoa_subgroup_code=b.ftcoa_subgroup_code WHERE (a.ftcoa_subgroup_code=16 OR a.ftcoa_subgroup_code=17) AND RIGHT(a.ftcoa_code, 5)<>'.0000' ORDER BY ftcoa_code ASC";
    $objAxpDB->Lookup("ftacc_no", $ssql, "ftcoa_code", "ftcoa_name", -1,true);
    $where_coa3 = "WHERE fnstatus = 1 AND RIGHT(ftcoa_code, 5)<>'.0000' ORDER BY ftcoa_code ";
}   
else {
    $ssql="SELECT DISTINCT a.ftcoa_code, a.ftcoa_name FROM tlcoa a INNER JOIN txrecap_bank_voucher_det1 b ON a.ftcoa_code=b.ftacc_no ORDER BY ftcoa_code ASC";
    $objAxpDB->Lookup("ftacc_no", $ssql, "ftcoa_code", "ftcoa_name", -1,true);
    $where_coa3 = "WHERE fnstatus = 1 AND RIGHT(ftcoa_code, 5)<>'.0000' ORDER BY ftcoa_code ";
}

$objAxpDB->LookupMagicQuotes(True);
$objAxpDB->Lookup("ftcurrency_code", "SELECT  ftsimbol, ftdescription  FROM tlcurrency_hdr ORDER BY ftsimbol", "ftsimbol", "ftdescription", 0, True);
$objAxpDB->Lookup("ftsupplier_code", "SELECT ftsupplier_code, ftsupplier_name FROM tlsupplier WHERE fnsupplier_type IN (1, 2) ORDER BY ftsupplier_code", "ftsupplier_code", "ftsupplier_name", -1,false);
$objAxpDB->Lookup("fnpayment_method", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 8 AND fntrans_status_code IN (0,1, 2, 3, 4, 5, 9)", "fntrans_status_code", "fttrans_status_name", -1,true);
$objAxpDB->Lookup("ftcoa_code", "SELECT ftcoa_code, ftcoa_name FROM TLCOA", "ftcoa_code", "ftcoa_name", -1,true);
$objAxpDB->Lookup("ftacc_no", $ssql, "ftcoa_code", "ftcoa_name", -1,true);
$objAxpDB->Lookup("ftother_coa_code", "SELECT ftcoa_code, ftcoa_name FROM tlcoa WHERE RIGHT(ftcoa_code, 5)<>'.0000' ORDER BY ftcoa_code ASC", "ftcoa_code", "ftcoa_name", -1,true);
$objAxpDB->Lookup("ftother2_coa_code", "SELECT ftcoa_code, ftcoa_name FROM tlcoa WHERE RIGHT(ftcoa_code, 5)<>'.0000' ORDER BY ftcoa_code ASC", "ftcoa_code", "ftcoa_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->LookupGrid(2,"ftcoa_code", "SELECT ftcoa_code, ftcoa_name FROM tlcoa $where_coa3", "ftcoa_code", "ftcoa_name", -1,false);

$objAxpDB->SetStatus("id, fnstatus");
if($_REQUEST['id']) {
    if(isset($_REQUEST['revisi'])) {
        $ajaxGrid="ajax_do('keuangan.php?ftcvs_no=".$ftcvs_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&revisi=1&code=cv&ftcurrency_code='+ document.getElementById('ftcurrency_code').value + '&ftsupplier_code='+ document.getElementById('ftsupplier_code').value);";
        $strAutoNumber0="  {$ajaxGrid}
                           {$ajaxCost}
                        ";

        $objAxpDB->FormJS($strAutoNumber0);
    } else {
        $objAxpDB->FormJS($ajaxCost);
    }
}else {
    $strAutoNumber1 = " ajax_do('query2.php?code=2&ftmodule_code=tn119&fntype=1&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftcvs_no&no_trans=ftcvs_no&table_name=txrecap_bank_voucher_hdr&ftbranch_code={$_SESSION['strbranch']}');";
    $strAutoNumber0 = " function OnChangeDate_fdtrans_date() {
                            {$strAutoNumber1}
                            for (var j=0; j < document.getElementsByName('fnindexD0[]').length; j++) {   
                                document.getElementsByName('fdgiro_dateD0[]')[j].value=document.getElementById('fdtrans_date').value;
                                document.getElementsByName('fdgiro_cliring_dateD0[]')[j].value=document.getElementById('fdtrans_date').value;
                            }       
                        }

                        OnChangeDate_fdtrans_date();
                        document.getElementById('ftcurrency_code').value='IDR';
                        {$ajaxKurs}
                        {$ajaxCost} ";

  $objAxpDB->FormJS($strAutoNumber0);
}

if ($objAxpDB->GetStatus("id") == "")
    $objAxpDB->ButtonShow("baru");
elseif ($objAxpDB->GetStatus("id") == 0) {
    $objAxpDB->FormLocked("1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1");
    $objAxpDB->GridAllowAddNew(0,true);
    $objAxpDB->GridAllowDelete(0,true);
    $objAxpDB->GridAllowAddNew(2,true);
    $objAxpDB->GridAllowDelete(2,true);
    $objAxpDB->GridLocked(0, "1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1");
    $objAxpDB->GridLocked(1, "1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
    $objAxpDB->GridLocked(2, "1, 0, 0, 0");
    $objAxpDB->ButtonShow("reset, simpan, tutup");
    $objAxpDB->GridLayout(1, 9, "&nbsp;<input type='hidden' id='hd_includeD1_N_' name='hd_includeD1[]' value='0'> <input type='checkbox'  id='chk_includeD1_N_' name='chk_includeD1[]' onclick='RekapBankVoucherRecalQty2(_N_);'>");
} elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
    if(isset($_REQUEST['revisi'])) {
        $objAxpDB->FormLocked("1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1");
        //$objAxpDB->GridAllowAddNew(0,true);
        //$objAxpDB->GridAllowDelete(0,true);
        $objAxpDB->GridAllowAddNew(2,true);
        $objAxpDB->GridAllowDelete(2,true);
        $objAxpDB->GridLocked(0, "1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1");
        $objAxpDB->GridLocked(1, "1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
        $objAxpDB->GridLocked(2, "1, 0, 0, 0");
        $objAxpDB->ButtonShow("simpan_revisi, tutup");
        $objAxpDB->GridLayout(1, 9, "&nbsp;<input type='hidden' id='hd_includeD1_N_' name='hd_includeD1[]' value='0'> <input type='checkbox'  id='chk_includeD1_N_' name='chk_includeD1[]' onclick='RekapBankVoucherRecalQty2(_N_);'>");
    } else {
        $objAxpDB->FormLocked("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");
        $objAxpDB->GridLocked(1, "1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
        $objAxpDB->GridLocked(2, "1, 1, 1, 1");

        $fnstatusgiro = RetRstField("SELECT COUNT(fnid) FROM txrecap_bank_voucher_det1 WHERE fnstatus_giro <> 0 AND (fnpayment_method = 0 OR fnpayment_method = 1) AND ftcvs_no = '{$_REQUEST['$ftcvs_no']}'");

        if ($fnstatusgiro == 0) {
            $objAxpDB->ButtonShow("baru, cetak, revisi, batal, tutup");
        } else {
            $objAxpDB->ButtonShow("baru, cetak, batal, tutup");
        }

    }
  
} elseif ($objAxpDB->GetStatus("fnstatus") == 2) {
    $objAxpDB->FormLocked("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");
    $objAxpDB->GridLocked(1, "1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
    $objAxpDB->GridLocked(2, "1, 1, 1, 1");
    $objAxpDB->ButtonShow("cetak,tutup");
} elseif (($objAxpDB->GetStatus("fnstatus") == 3) || ($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");
    $objAxpDB->GridLocked(0, "1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
    $objAxpDB->GridLocked(1, "1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
    $objAxpDB->GridLocked(2, "1, 1, 1, 1");
    $objAxpDB->ButtonShow("tutup");
}

if($_REQUEST['ajax']) {
  switch($_REQUEST['code']) {
    case "cv":
        $html = GetCV();
        ?>
        div = document.getElementById('txtHint1');
        var m='<?php echo js_esc($html); ?>';
        m= m.replace(/^\s*|\s*$/g,"");
        div.innerHTML =m;
        <!--reSize();-->
        RekapBankVoucherRecalQtyImport1();
        <?

        $ssql="SELECT IFNULL(SUM(fcoutstanding_amount),0) AS fcoutstanding_amount
                 FROM txdebit_memo_hdr
                 WHERE fnstatus<>9 AND ftsupplier_code='{$_REQUEST['ftsupplier_code']}'";

        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $str= $r['fcoutstanding_amount'] ;
        ?>
        document.getElementById('fcdebit_memo').value='<?php echo $str; ?>';
        <?php
    break;

    case "othercost":

        $html = "<table border=0 cellpadding=0 cellspacing=0 class='is_edit_table'>
                 <tr><td align='left'><input readonly style=\"text-align: right;background-color: #E0E0E0\"  type='text' name='fcother_costUSD' id='fcother_costUSD' value='" . $_REQUEST['fcother_costUSD'] . "'  size=18>
                                      <input type='button' id='cmd_other_cost' name = 'cmd_other_cost' value='SHOW DETAIL' onClick=\"ShowCost();\"></td></tr>
                 <tr><td><div id='divOtherCost' name='divOtherCost'></td></tr></table> ";

        ?>
        function ShowCost() {
            if (document.getElementById('cmd_other_cost').value == 'SHOW DETAIL') {
                  document.getElementById('divOtherCost').style.display = 'block';
                  document.getElementById('cmd_other_cost').value='HIDE DETAIL';
                  document.getElementById('TransactionDetail2').style.width = '50vw';
                  document.getElementById('DivCtl_fcother_cost').style.width = '50vw';
                  document.getElementById('divOtherCost').style.width = '50vw';
            } else {
                  document.getElementById('divOtherCost').style.display = 'none';
                  document.getElementById('cmd_other_cost').value='SHOW DETAIL';
            }
        }

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

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

        ElementCurrencyALL();
        <?php

    break;
  }

  die("");
  exit;
}

  $objAxpDB->Process();
  $objAxpDB->WriteHtmlTable();