<?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 txgiro_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 txar_hdr WHERE ftar_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 {
                    ?>
                      document.frmMain.mode.value = "simpan";
                      
                      if (PenerimaanPiutangCheckCurrency()) {
//                            document.frmMain.submit(); 
                            submitbutton('Simpan','','','','');
                      }
                      //submitbutton('Simpan','','','','');
                    <?php
                    }
                }
                die("");
                break;
                
            case "transno2":
                ?>
                document.frmMain.mode.value = "final_bank";
                document.frmMain.submit();
                <?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('fcrate').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=uangmukapenjualan&obj1=&obj2=' + document.getElementById('ftcustomer_code').value + '&index=' + idx);
                            ajax_do('query2.php?code=8&obj1=&obj2=fnstatus_giroD0' + idx);

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

                  PenerimaanPiutangRecalQty0();
                <?php
                break;

            case "currency":
                // cek currency dari uang muka
                if ($_REQUEST["fnpayment_method"] == 9) {
                    $ssql="SELECT ftcurrency_code FROM txadvanced_receive 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=uangmukapenjualan&obj1=&obj2=' + document.getElementById('ftcustomer_code').value + '&index=<?php echo $_REQUEST["index"]; ?>');
                      ajax_do('query2.php?code=8&obj1=&obj2=fnstatus_giroD0<?php echo $_REQUEST["index"]; ?>');


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

                      PenerimaanPiutangRecalQty0();
                    <?php
                    }
                }
                break;

        }

    }

function GetInvoice() {
    $x="";

    if($_REQUEST['ftcustomer_code']=="") {
        $code=" 1=0 ";

    } else {
        $ssql="select ifnull(ftparent_code,'') as ftparent_code
                 from tlcustomer
                 where ftcustomer_code='".$_REQUEST['ftcustomer_code']."'";

        $ftcustomer_codex= RetRstField($ssql)  ;

        if($ftcustomer_codex) {
            $ssql="select ftcustomer_code
                    from tlcustomer
                    where ftparent_code='". $ftcustomer_codex."'";
            $rs=mysql_query($ssql);
            $code=" ( ftcustomer_code='{$ftcustomer_codex}'";

            while($r=mysql_fetch_assoc($rs)) {
                $code.=" or ftcustomer_code='{$r['ftcustomer_code']}' ";
            }

            $code.=" )";


        } else {

            $ssql="select ftcustomer_code
                    from tlcustomer
                    where ftparent_code='".$_REQUEST['ftcustomer_code']."'";
            $rs=mysql_query($ssql);
            $code=" ( ftcustomer_code='{$_REQUEST['ftcustomer_code']}'";

            while($r=mysql_fetch_assoc($rs)) {
                $code.=" or ftcustomer_code='{$r['ftcustomer_code']}' ";
            }

            $code.=" )";
        }

    }

    if(isset($_REQUEST['revisi'])) {
        $ssql=" SELECT * FROM (
                    -- piutang awal
                    SELECT NULL AS fnindex,a.ftsales_invoice_no,a.fdtrans_date,a.ftdo_no,a.ftcurrency_code,
                            a.fcrate AS fcrate_invoice, a.fcamount, a.fcoutstanding_amount,
                            '0' AS fcpayment_amount, IFNULL(a.fcamount,0) * a.fcrate AS fcamount_base, '0' AS fcpayment_amount_base,
                            'PIUTANG AWAL' AS ftsales_type, 0 AS fnorder
                    FROM  txsales_invoice_hdr a
                    WHERE  a.fnstatus=1 AND (a.fcamount - IFNULL(a.fcpayment_amount,'')) != 0 AND fnsaldo_awal = 1 AND {$code}
                            AND a.ftsales_invoice_no NOT IN (SELECT ftsales_invoice_no FROM txar_det WHERE ftar_no = '{$_REQUEST['ftar_no']}')
                               
                    -- invoice        
                    UNION ALL 
                    SELECT b.fnindex,a.ftsales_invoice_no,a.fdtrans_date,a.ftdo_no,a.ftcurrency_code,
                            a.fcrate AS fcrate_invoice, a.fcamount, a.fcoutstanding_amount,
                            '0' AS fcpayment_amount, IFNULL(a.fcamount,0) * a.fcrate AS fcamount_base, '0' AS fcpayment_amount_base,
                            'FAKTUR' AS ftsales_type, 1 AS fnorder
                    FROM  txsales_invoice_hdr a
                    LEFT JOIN txsales_invoice_det b ON 1=0
                    WHERE  a.fnstatus=1 AND fnsaldo_awal = 0 AND {$code}
                            AND a.fcoutstanding_amount > 0
                            -- AND (a.fcamount - IFNULL(a.fcpayment_amount,'')) != 0 
                            AND a.ftsales_invoice_no NOT IN (SELECT ftsales_invoice_no FROM txar_det WHERE ftar_no = '{$_REQUEST['ftar_no']}')
                            AND a.fdtrans_date >= '{$_SESSION['fdstart_period']}'    
                    
                    -- adjustment
                    UNION ALL 
                    SELECT NULL AS fnindex,a.ftsales_invoice_no,a.fdtrans_date,a.ftdo_no,a.ftcurrency_code,
                            a.fcrate AS fcrate_invoice, a.fcamount, a.fcoutstanding_amount,
                            '0' AS fcpayment_amount, IFNULL(a.fcamount,0) * a.fcrate AS fcamount_base, '0' AS fcpayment_amount_base,
                            'ADJUSTMENT' AS ftsales_type, 2 AS fnorder
                    FROM  txsales_invoice_adjustment_hdr a
                    WHERE  a.fnstatus=1 AND (a.fcamount - IFNULL(a.fcpayment_amount,'')) != 0 AND {$code}
                            AND a.ftsales_invoice_no NOT IN (SELECT ftsales_invoice_no FROM txar_det WHERE ftar_no = '{$_REQUEST['ftar_no']}')
                            AND a.fdtrans_date >= '{$_SESSION['fdstart_period']}'
                                
                    -- sales retur (Tidak dipakai)
                    /* UNION ALL 
                    SELECT NULL AS fnindex,a.ftsales_return_no AS ftsales_invoice_no,a.fdtrans_date,'' AS ftdo_no,'IDR' AS ftcurrency_code,
                            1 AS fcrate_invoice, (a.fcamount * -1) AS fcamount, (IFNULL(a.fcoutstanding_amount,a.fcamount) * -1) AS fcoutstanding_amount,
                            '0' AS fcpayment_amount, (IFNULL(a.fcamount,0) * -1) AS fcamount_base, '0' AS fcpayment_amount_base,
                            'RETUR' AS ftsales_type, 3 AS fnorder
                    FROM  txsales_return_hdr a
                    WHERE  a.fnstatus=1 AND (a.fcamount - IFNULL(a.fcpayment_amount,'')) != 0 AND {$code}        
                            AND a.ftsales_return_no NOT IN (SELECT ftsales_invoice_no FROM txar_det WHERE ftar_no = '{$_REQUEST['ftar_no']}')
                            AND a.fdtrans_date >= '{$_SESSION['fdstart_period']}' */
                                
                    -- existing sales invoice in ar        
                    UNION ALL
                    SELECT fnindex, ftsales_invoice_no, fdinvoice_date as fdtrans_date, ftdo_no, ftcurrency_code,
                            IFNULL(fcrate_invoice,1) as fcrate_invoice, fcamount, fcoutstanding_amount,
                            fcpayment_amount, fcamount * IFNULL(fcrate_invoice,1) as fcamount_base, fcpayment_amount_base,
                            ftsales_type, 0 AS fnorder 
                    FROM txar_det
                    WHERE  ftar_no = '{$_REQUEST['ftar_no']}' 
                ) x 
                ORDER BY fnorder, fdtrans_date, ftsales_invoice_no ";

    } else {
        
        $ssql="SELECT * FROM (
                    -- piutang awal
                    SELECT NULL AS fnindex,a.ftsales_invoice_no,a.fdtrans_date,a.ftdo_no,a.ftcurrency_code,
                            a.fcrate AS fcrate_invoice, a.fcamount, a.fcoutstanding_amount,
                            '0' AS fcpayment_amount, IFNULL(a.fcamount,0) * a.fcrate AS fcamount_base, '0' AS fcpayment_amount_base,
                            'PIUTANG AWAL' AS ftsales_type, 0 AS fnorder
                    FROM  txsales_invoice_hdr a
                    WHERE  a.fnstatus=1 AND (a.fcamount - IFNULL(a.fcpayment_amount,'')) != 0 AND fnsaldo_awal = 1 AND {$code}
                                
                    -- invoice
                    UNION ALL
                    SELECT b.fnindex,a.ftsales_invoice_no,a.fdtrans_date,a.ftdo_no,a.ftcurrency_code,
                            a.fcrate AS fcrate_invoice, a.fcamount, a.fcoutstanding_amount,
                            '0' AS fcpayment_amount, IFNULL(a.fcamount,0) * a.fcrate AS fcamount_base, '0' AS fcpayment_amount_base,
                            'FAKTUR' AS ftsales_type, 1 AS fnorder
                    FROM  txsales_invoice_hdr a
                    LEFT JOIN txsales_invoice_det b ON 1=0
                    WHERE  a.fnstatus=1 AND fnsaldo_awal = 0 AND {$code}
                            AND a.fcoutstanding_amount > 0
                            -- AND (a.fcamount - IFNULL(a.fcpayment_amount,'')) != 0 
                            AND a.fdtrans_date >= '{$_SESSION['fdstart_period']}'
                                
                    -- adjustment
                    UNION ALL 
                    SELECT NULL AS fnindex,a.ftsales_invoice_no,a.fdtrans_date,a.ftdo_no,a.ftcurrency_code,
                            a.fcrate AS fcrate_invoice, a.fcamount, a.fcoutstanding_amount,
                            '0' AS fcpayment_amount, IFNULL(a.fcamount,0) * a.fcrate AS fcamount_base, '0' AS fcpayment_amount_base,
                            'ADJUSTMENT' AS ftsales_type, 2 AS fnorder
                    FROM  txsales_invoice_adjustment_hdr a
                    WHERE  a.fnstatus=1 AND (a.fcamount - IFNULL(a.fcpayment_amount,'')) != 0 AND {$code}
                            AND a.fdtrans_date >= '{$_SESSION['fdstart_period']}'
                                
                    -- sales retur (tidak dipakai lagi)
                    /* UNION ALL 
                    SELECT NULL AS fnindex,a.ftsales_return_no AS ftsales_invoice_no,a.fdtrans_date,'' AS ftdo_no,'IDR' AS ftcurrency_code,
                            1 AS fcrate_invoice, (a.fcamount * -1) AS fcamount, (IFNULL(a.fcoutstanding_amount,a.fcamount) * -1) AS fcoutstanding_amount,
                            '0' AS fcpayment_amount, (IFNULL(a.fcamount,0) * -1) AS fcamount_base, '0' AS fcpayment_amount_base,
                            'RETUR' AS ftsales_type, 3 AS fnorder
                    FROM  txsales_return_hdr a
                    WHERE  a.fnstatus=1 AND (a.fcamount - IFNULL(a.fcpayment_amount,'')) != 0 AND {$code} 
                            AND a.fdtrans_date >= '{$_SESSION['fdstart_period']}' */
                    
            )  X ";
            // ORDER BY fnorder, fdtrans_date DESC, ftsales_invoice_no DESC LIMIT 220"; 
                            
            if(RetRstField("SELECT fnid FROM tlcustomer WHERE ftcustomer_type_code = 'DST' AND ftcustomer_code = '{$_REQUEST['ftcustomer_code']}' ")) {
                $ssql = $ssql . " ORDER BY fdtrans_date, fnorder, ftsales_invoice_no  ";
            } else {    
                $ssql = $ssql . " ORDER BY fdtrans_date DESC, fnorder DESC, ftsales_invoice_no DESC  ";
            }    
            // limit 220 karena kalau lebih simpan jadi tidak jalan. harus DICEK segera !!!!
    } 

    $rs=mysql_query($ssql);
    $r['ftcurrency_code']=$_REQUEST['ftcurrency_code'];
    
    $x="";
    $x.= "<BR><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</th>
             <td  valign='top'>Tipe Invoice</td>
             <td  valign='top'>No. Invoice</td>
             <td  valign='top'>No. DO</td>
             <td  valign='top'>Tgl. Invoice</td>
             <td  valign='top'>Jml. Total</td>
             <td  valign='top'>Sisa Piutang</td>
             <td  valign='top'>Jml. Pembayaran</td>
             <td  valign='top'>Mata Uang</td>
             <td  valign='top'>Kurs Invoice</td>
             <td  valign='top'>Jml. Pembayaran (IDR)</td>
             <td  valign='top'>#</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";
        }

        $x.= "<tr class='$class1'>
                 <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='fnindexD1[]' id='fnindexD1$i' value='{$j}' size=4></td>
                 <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='ftsales_typeD1[]' id='ftsales_typeD1$i' value='" . $r['ftsales_type'] . "'  size=10></td>
                 <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='ftsales_invoice_noD1[]' id='ftsales_invoice_noD1$i' value='" . $r['ftsales_invoice_no'] . "'  size=15></td>
                 <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='ftdo_noD1[]' id='ftdo_noD1$i' value='" . $r['ftdo_no'] . "'  size=15></td>
                 <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='fdtrans_dateD1[]' id='fdtrans_dateD1$i' value='" . $r['fdtrans_date'] . "'   size=10></td>
                 <td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right; background-color: #E0E0E0\"  readonly type='text' name='fcamountD1[]' id='fcamountD1$i' value='" . $r['fcamount'] . "'   size=15></td>
                 <td class='$class2'><input readonly style=\"text-align: right; background-color: #E0E0E0 \" onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\"    type='text' name='fcoutstanding_amountD1[]' id='fcoutstanding_amountD1$i' value='" . $r['fcoutstanding_amount'] . "'   size=15></td>
                 <td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\"  OnChange='PenerimaanPiutangRecalQty0()'; type='text' name='fcpayment_amountD1[]' id='fcpayment_amountD1$i' value='" .  $r['fcpayment_amount'] . "'   size=15></td>
                 <td class='$class2'><input readonly style='background-color: #E0E0E0' type='text' name='ftcurrency_codeD1[]' id='ftcurrency_codeD1$i' value='" .  $r['ftcurrency_code']  . "'   size=5></td>
                 <td class='$class2'><input readonly style='background-color: #E0E0E0;text-align: right;' type='text' name='fcrate_invoiceD1[]' id='fcrate_invoiceD1$i' value='" . $r['fcrate_invoice']  . "'   size=10></td>
                 <td class='$class2'><input readonly style='background-color: #E0E0E0;text-align: right;' onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" type='text' name='fcpayment_amount_baseD1[]' id='fcpayment_amount_baseD1$i' value='" . $r['fcpayment_amount_base'] . "'   size=15></td>
                 <td class='$class2'><input type=checkbox onclick=\"if(this.checked) { document.getElementById('fcpayment_amountD1$i').value='" . $r['fcoutstanding_amount']  . "';document.getElementById('fcpayment_amount_baseD1$i').value='" . $r['fcoutstanding_amount_base']  . "';} PenerimaanPiutangRecalQty0();\"></td>
              </tr>";

        $i++;
    }

    $x.= "</table>
         <input id='TransactionDetailCount1' name='TransactionDetailCount1' value='$num_rows' type='hidden'>";

    
    return $x;

}

/*
function GetMemo($ftar_no="") {
 
    if($ftar_no != ""){
        $ssql=" SELECT ftbranch_code, ftcm_no,
                    fccm_amount, fccm_payment, fccm_outstanding
                FROM txar_cm
                WHERE ftar_no='{$ftar_no}'
                ORDER BY fnindex ASC";
        $readonly="readonly";
    } else {
        $ssql=" SELECT ftbranch_code, ftcm_no,
                    fcinvoice_amount AS fccm_amount, 0 AS fccm_payment,
                    fcoutstanding_amount AS fccm_outstanding
                FROM txcredit_memo_hdr
                WHERE
                    fnstatus=1 AND
                    ftcustomer_code='{$_REQUEST["ftcustomer_code"]}' AND
                    fcoutstanding_amount>0";
    }
  
  $x="";
  $rs=mysql_query($ssql);
  $x.= "<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. Credit Memo</th>
          <td  valign='top'>Jml. Credit Memo</th>
          <td  valign='top'>Sisa Credit Memo</th>
          <td  valign='top'>Pemakaian Credit 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";
    }

    $fccm_outstanding=$r['fccm_outstanding'];
    $fccm_payment=$r['fccm_payment'];

    $x.= "<tr class='$class1'>
           <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='fnindexD2[]' id='fnindexD2$i' value='{$j}' size=3></td>
           <td class='$class2'><input readonly style='background-color: #E0E0E0'  type='text' name='ftcm_noD2[]' id='ftcm_noD2$i' value='" . $r['ftcm_no'] . "'  size=25></td>
           <td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right; background-color: #E0E0E0\"  readonly type='text' name='fccm_amountD2[]' id='fccm_amountD2$i' value='" . $r['fccm_amount'] . "'   size=20></td>
           <td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right; background-color: #E0E0E0\"  readonly type='text' name='fccm_outstandingD2[]' id='fccm_outstandingD2$i' value='" . $fccm_outstanding . "'   size=20></td>
           <td class='$class2'><input onblur=\"ElementCurrencyOnBlur(this);\" onfocus=\"ElementCurrencyOnBlur(this); this.select();\" style=\"text-align: right;\" $readonly type='text' name='fccm_paymentD2[]' id='fccm_paymentD2$i' value='" . $fccm_payment . "' onchange=\"PenerimaanPiutangRecalQty0();\"  size=20></td>
        </tr>";
    
    $i++;
  }
  
  $x.= "</table>
        <input id='TransactionDetailCount2' name='TransactionDetailCount2' value='$num_rows' type='hidden'>";

  return $x;
}
*/

function GetArDet($ftar_no) {
    $x="";
    $ssql="SELECT A.fnindex,A.ftsales_invoice_no,B.ftdo_no, A.fdinvoice_date,
                    A.fdtrans_date,A.fcamount,A.fcoutstanding_amount,
                    A.fcpayment_amount
                FROM
                txar_hdr AA INNER JOIN
                txar_det A ON AA.ftar_no=A.ftar_no
                INNER JOIN txsales_invoice_hdr B ON A.ftsales_invoice_no=B.ftsales_invoice_no
                WHERE AA.ftar_no='{$ftar_no}'";

                $rs=mysql_query($ssql);
                $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</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";
                    }

                     $x.= "<tr class='$class1'>
                      <td class='$class2'><input readonly  style='background-color: #E0E0E0'   type='text' name='fnindexD1[]' id='fnindexD1$i' value='{$j}' size=3></td>
                      <td class='$class2'><input readonly  style='background-color: #E0E0E0'   type='text' name='ftsales_invoice_noD1[]' id='ftsales_invoice_noD1$i' value='" . $r['ftsales_invoice_no'] . "'  size=20></td>
                      <td class='$class2'><input readonly  style='background-color: #E0E0E0'  type='text' name='fdtrans_dateD1[]' id='fdtrans_dateD1$i' value='" . $r['fdtrans_date'] . "'   size=20></td>
                      <td class='$class2'><input readonly  style='background-color: #E0E0E0'   type='text' name='ftdo_noD1[]' id='ftdo_noD1$i' value='" . $r['ftdo_no'] . "'  size=20></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='fcamountD1[]' id='fcamountD1$i' value='" .  $r['fcamount']  . "'   size=20></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='fcoutstanding_amountD1[]' id='fcoutstanding_amountD1$i' value='" . $r['fcoutstanding_amount']  . "'   size=20></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='fcpayment_amountD1[]' id='fcpayment_amountD1$i' value='" . $r['fcpayment_amount']  . "'   size=20></td>
                      </tr>";

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

                return $x;
}

Getsecurity('penerimaan_piutang');

$objAxpDB->ViewName("Daftar Penerimaan Piutang");
$objAxpDB->ViewSQL("SELECT a.fnid,  a.ftar_no, a.fdtrans_date,c.ftcustomer_code,  c.ftcustomer_name, a.ftdescription, a.fcamount, B.fttrans_status_name
                    FROM txar_hdr A INNER JOIN tstransaction_status B ON a.fnstatus=b.fntrans_status_code AND b.fntrans_group_code=2
                    INNER JOIN tlcustomer C ON A.ftcustomer_code=c.ftcustomer_code
                    WHERE (('{$_SESSION['strbranch']}' <> 'PUSAT' AND a.ftbranch_code = '{$_SESSION['strbranch']}') OR '{$_SESSION['strbranch']}' = 'PUSAT')
                    ORDER BY a.ftar_no DESC,  a.fdtrans_date DESC");

$objAxpDB->ViewCaption("ID, No. transaksi, Tgl. transaksi,Kode Customer, Customer, Keterangan, Total Penerimaan,  Status Transaksi");
$objAxpDB->ViewPeriod(TRUE);

$objAxpDB->FormName("Penerimaan Piutang");
$objAxpDB->FormSQL("SELECT ftar_no, fdtrans_date, ftcurrency_code, fcrate, ftcustomer_code, ftRef_No ,
                        ftremarks,fcinvoice_amount,
                        fcother_cost, fcsub_amount,fcamount, fcsub_amount * fcrate as fcsub_amount_base, fcamount * fcrate as fcamount_base,
                        fcrate_adjustment, fnstatus,  fccredit_memo, fnstatus2 FROM txar_hdr");

$objAxpDB->FormCaption("No. transaksi, Tgl. transaksi, Mata Uang, Kurs, Kode Customer, No Ref, Catatan,  Sub Total Piutang, Biaya, Total Piutang, Total Penerimaan, Total Piutang IDR,  Total Penerimaan IDR, Selisih Kurs, Status, No Ref, Sisa Kredit Memo, Status Giro");
$objAxpDB->FormPosition("TL, TR, TR, TR, TL, TL, BL, HD, BR, BR, BR, BR, BR, BR, TL, HD");

$ftar_no=RetRstField("select ftar_no from txar_hdr where fnid='".$_REQUEST['id']."'");
$objAxpDB->GridSQL(0, "SELECT a.fnindex, a.fnpayment_method, a.ftacc_no, a.ftgiro_no, a.fcamount,
                            a.fdgiro_date, a.fdgiro_cliring_date, a.ftother_coa_code, a.fcother_cost, a.fctotal,
                            a.fctotal * c.fcrate as fctotal_base ,b.fttrans_status_name as fnstatus_giro
                        FROM txar_det1 a , tstransaction_status b, txar_hdr c
                        WHERE b.fntrans_group_code = 11 and a.fnstatus_giro=b.fntrans_status_code and a.ftar_no = c.ftar_no and 
                            a.ftar_no='$ftar_no' #");

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

$ajaxUangMuka="ajax_do('query2.php?code=uangmukapenjualan&obj1=' + this.value + '&obj2=' + document.getElementById('ftcustomer_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?ftar_no=".$ftar_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);";
$objAxpDB->GridScript(0,4, "onChange=\"{$ajaxCurrency}PenerimaanPiutangRecalQty0();\"");
$objAxpDB->GridScript(0,8, "onChange=\"PenerimaanPiutangRecalQty0();\"");
$objAxpDB->GridDelJS(0,"PenerimaanPiutangRecalQty0();");

$objAxpDB->GridSQL(1, "SELECT fnindex, ftsales_type, ftsales_invoice_no, ftdo_no, fdinvoice_date, fcamount, fcoutstanding_amount, fcpayment_amount, ftcurrency_code, fcrate_invoice, fcpayment_amount_base FROM txar_det");
$objAxpDB->GridCaption(1, "No., Tipe Invoice, No. Invoice, No. DO, Tgl. Invoice, Jml Total, Sisa Piutang, Jml Pembayaran, Mata Uang, Kurs Invoice, Jml Pembayaran (IDR)");
$objAxpDB->GridScript(1,5, "onChange=\"PenerimaanPiutangRecalQty0();\"");
$objAxpDB->GridSize(1, "1,15,15,15,10,15,15,15,10,5,15");

// Tidak dipakai lagi 
$objAxpDB->GridSQL(2, "SELECT fnindex, ftcm_no, fccm_amount, fccm_outstanding, fccm_payment FROM txar_cm");
$objAxpDB->GridCaption(2, "No.,No. Credit Memo, Jml. Credit Memo, Sisa Credit Memo,Pemakaian Credit Memo");
$objAxpDB->GridHidden(2, "1,1,1,1,1");
// $objAxpDB->GridScript(2,4, "onChange=\"Hitungcm();\"");

// Grid3 - Other Cost
$objAxpDB->GridSQL(3, "SELECT fnindex, ftcoa_code, ftdescription, fcamount FROM txar_cost");
$objAxpDB->GridCaption(3, "No., No Perkiraan, Keterangan, Jumlah");
$objAxpDB->GridHidden(3,"0,0,0,0");
$objAxpDB->GridSize(3, "1,15,10,10");

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

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

$objAxpDB->SetStatus("id, fnstatus, fnstatus2");

if(!$_REQUEST['id']) {
    $mm=" '' AS fnstatus_giro ";
    //$objAxpDB->Lookup("ftcustomer_code", "SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer WHERE ifnull(ftparent_code,\'\')=\'\'", "ftcustomer_code", "ftcustomer_name", -1,false);
    $objAxpDB->Lookup("ftcustomer_code", "SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer WHERE ifnull(ftparent_code,'')=''", "ftcustomer_code", "ftcustomer_name", -1,false);
    
    $ssql_coa="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=15 OR a.ftcoa_subgroup_code=16) AND RIGHT(a.ftcoa_code, 5)<>'.0000' AND fnstatus = 1 ORDER BY ftcoa_code ASC";
    $where_coa3 = "WHERE fnstatus = 1 AND RIGHT(ftcoa_code, 5)<>'.0000' ORDER BY ftcoa_code ";

}
else {
    $mm=" '' AS fnstatus_giro ";
    $objAxpDB->Lookup("ftcustomer_code", "SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer", "ftcustomer_code", "ftcustomer_name", -1,false);

    $ssql_coa="SELECT DISTINCT a.ftcoa_code, a.ftcoa_name FROM tlcoa a INNER JOIN txar_det1 b ON a.ftcoa_code=b.ftacc_no ORDER BY ftcoa_code ASC";
    $where_coa3 = "WHERE RIGHT(ftcoa_code, 5)<>'.0000' ORDER BY ftcoa_code ";
}

$objAxpDB->LookupMagicQuotes(True);
$objAxpDB->Lookup("ftacc_no", $ssql_coa, "ftcoa_code", "ftcoa_name", -1,true);
$objAxpDB->LookupGrid(3,"ftcoa_code", "SELECT ftcoa_code, ftcoa_name FROM tlcoa $where_coa3", "ftcoa_code", "ftcoa_name", -1,false);
$objAxpDB->Lookup("ftcurrency_code", "SELECT  ftsimbol, ftdescription  FROM tlcurrency_hdr ORDER BY ftsimbol", "ftsimbol", "ftdescription", 0, True);
$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, 6, 9)", "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("fnstatus2", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 2", "fntrans_status_code", "fttrans_status_name", 0,true);

$ssql="SELECT ftcoa_code, ftcoa_name FROM tlcoa WHERE RIGHT(ftcoa_code, 5)<>'.0000' AND (ftcoa_name LIKE 'biaya%' OR ftcoa_name LIKE 'aktiva%' OR ftcoa_name LIKE 'piutang%') ORDER BY ftcoa_code ASC";
$objAxpDB->Lookup("ftother_coa_code", $ssql, "ftcoa_code", "ftcoa_name", -1,true);

$ssql="SELECT ftcoa_code, ftcoa_name FROM tlcoa WHERE ftcoa_name LIKE 'biaya%' AND RIGHT(ftcoa_code, 5)<>'.0000'";
$objAxpDB->Lookup("ftother2_coa_code", $ssql, "ftcoa_code", "ftcoa_name", -1,true);

 /*
 if ($objAxpDB->GetStatus("fnstatus") == 2) {
	if ($objAxpDB->GetStatus("fnstatus2") == 0) {
		//$ajaxGrid="ajax_do_grid1('keuangan.php?ftar_no=".$ftar_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=invoice&ftcustomer_code='+ document.getElementById('ftcustomer_code').value);";

		if(GetsecurityByname("penerimaan_piutang_simpan_penerimaan")||GetsecurityByname("penerimaan_piutang_final_penerimaan")) {
			$objAxpDB->GridSQL(1, "SELECT fnindex, ftsales_invoice_no, fdinvoice_date, ftdo_no, fcamount as fcamount1, fcoutstanding_amount, fcpayment_amount FROM txar_det");
			$objAxpDB->GridCaption(1, "No., No. Invoice, Tgl. Invoice, No. DO, Jml Total, Sisa Piutang, Jml Pembayaran");
                        $objAxpDB->GridSQL(2, "SELECT fnindex, ftcm_no, fccm_amount, fccm_outstanding, fccm_payment FROM txar_cm");
			$objAxpDB->GridCaption(2, "No.,No. Credit Memo, Jml. Credit Memo, Sisa Credit Memo,Pemakaian Credit Memo");

		}
	}
	elseif ($objAxpDB->GetStatus("fnstatus2") == 1) {
		//$ajaxGrid="ajax_do_grid1('keuangan.php?ftar_no=".$ftar_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=invoice&ftcustomer_code='+ document.getElementById('ftcustomer_code').value);";

		if(GetsecurityByname("penerimaan_piutang_simpan_penerimaan")||GetsecurityByname("penerimaan_piutang_final_penerimaan")) {
			$objAxpDB->GridSQL(1, "SELECT fnindex, ftsales_invoice_no, fdinvoice_date, fcamount as fcamount1, fcoutstanding_amount, fcpayment_amount FROM txar_det");
			$objAxpDB->GridCaption(1, "No., No. Invoice, Tgl. Invoice, Jml Total, Sisa Piutang, Jml Pembayaran");
                        $objAxpDB->GridSQL(2, "SELECT fnindex, ftcm_no, fccm_amount, fccm_outstanding, fccm_payment FROM txar_cm");
			$objAxpDB->GridCaption(2, "No.,No. Credit Memo, Jml. Credit Memo, Sisa Credit Memo,Pemakaian Credit Memo");

		}
	}
	elseif ($objAxpDB->GetStatus("fnstatus2") == 2) {

		if(GetsecurityByname("penerimaan_piutang_simpan_penerimaan")||GetsecurityByname("penerimaan_piutang_final_penerimaan")) {
			$objAxpDB->GridSQL(1, "SELECT fnindex, ftsales_invoice_no, fdinvoice_date, fcamount as fcamount1, fcoutstanding_amount, fcpayment_amount FROM txar_det");
			$objAxpDB->GridCaption(1, "No., No. Invoice, Tgl. Invoice, Jml Total, Sisa Piutang, Jml Pembayaran");
                        $objAxpDB->GridSQL(2, "SELECT fnindex, ftcm_no, fccm_amount, fccm_outstanding, fccm_payment FROM txar_cm");
			$objAxpDB->GridCaption(2, "No.,No. Credit Memo, Jml. Credit Memo, Sisa Credit Memo,Pemakaian Credit Memo");

		}
	} 
}
elseif ($objAxpDB->GetStatus("fnstatus") == 9) {
    $objAxpDB->GridSQL(1, "SELECT fnindex, ftsales_invoice_no, fdinvoice_date, fcamount as fcamount1, fcoutstanding_amount, fcpayment_amount FROM txar_det");
    $objAxpDB->GridCaption(1, "No., No. Invoice, Tgl. Invoice, Jml Total, Sisa Piutang, Jml Pembayaran");
    $objAxpDB->GridSQL(2, "SELECT fnindex, ftcm_no, fccm_amount, fccm_outstanding, fccm_payment FROM txar_cm");
    $objAxpDB->GridCaption(2, "No.,No. Credit Memo, Jml. Credit Memo, Sisa Credit Memo,Pemakaian Credit Memo");
}
elseif ($objAxpDB->GetStatus("fnstatus") == 0 || $objAxpDB->GetStatus("fnstatus") == 1) {
    $objAxpDB->GridSQL(1, "SELECT fnindex, ftsales_invoice_no, fdinvoice_date, fcamount as fcamount1, fcoutstanding_amount, fcpayment_amount FROM txar_det");
    $objAxpDB->GridCaption(1, "No., No. Invoice, Tgl. Invoice, Jml Total, Sisa Piutang, Jml Pembayaran");
    $objAxpDB->GridSQL(2, "SELECT fnindex, ftcm_no, fccm_amount, fccm_outstanding, fccm_payment FROM txar_cm");
    $objAxpDB->GridCaption(2, "No.,No. Credit Memo, Jml. Credit Memo, Sisa Credit Memo,Pemakaian Credit Memo");
}
*/
$obj_customer=" function OnChangecustomer() {
                        var m=document.getElementById('ftcustomer_code').value;
                        var result='';

                        return \"select ftcm_no,fdtrans_date from txcredit_memo_hdr where fcoutstanding_amount>0 and ftcustomer_code='\"+m+\"'\";
                  }";
 
// $ajax_cm="ajax_do('keuangan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=cm_grid&index=_N_&ftcm_no='+ document.getElementById('ftcm_noD2_N_').value);";
$ajaxKurs="ajax_do('keuangan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=idr&ftcurrency_code='+ document.getElementById('ftcurrency_code').value);";

if($_REQUEST['id']) {
    
    if(isset($_REQUEST['revisi'])) {
        $ajaxGrid2="ajax_do('keuangan.php?ftar_no=".$ftar_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&revisi=1&code=invoice&ftcustomer_code='+ document.getElementById('ftcustomer_code').value);";
        $strAutoNumber0="  {$ajaxGrid2}
                           {$ajaxCost}
                        ";

        $objAxpDB->FormJS($strAutoNumber0);
    } else {
        $objAxpDB->FormJS($ajaxCost);
    }

} else {
    $strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=TN016&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftar_no&no_trans=ftar_no&table_name=txar_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();
                        $obj_customer
                        document.getElementById('ftcurrency_code').value='IDR';
                        {$ajaxKurs}
                        {$ajaxCost}
                      ";

      $objAxpDB->FormJS($strAutoNumber0);
      // $ajaxGrid="document.getElementById('ftremarks').value='Terima dr '+document.getElementById('hidden_ftcustomer_code').value;";
      $ajaxGrid2="ajax_do('keuangan.php?ftar_no=".$ftar_no."&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=invoice&ftcustomer_code='+ document.getElementById('ftcustomer_code').value);";
}

$objAxpDB->FormScript(2, "OnChange=\"{$ajaxKurs}\"");
$objAxpDB->FormScript(3, "OnChange=\"PenerimaanPiutangRecalQty0();\"");
$objAxpDB->FormScript(4, "onChange=\"{$ajaxGrid}{$ajaxGrid2}PenerimaanPiutangRecalQty0();\"");
$objAxpDB->FormScript(10, "onChange=\"PenerimaanPiutangRecalQty0();\"");

if ($objAxpDB->GetStatus("id") == "")
        $objAxpDB->ButtonShow("baru");

elseif ($objAxpDB->GetStatus("id") == 0) {
        $objAxpDB->GridAllowAddNew(0,true);
        $objAxpDB->GridAllowDelete(0,true);
        $objAxpDB->GridAllowAddNew(3,true);
        $objAxpDB->GridAllowDelete(3,true);
        $objAxpDB->GridLocked(0, "1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1");
        $objAxpDB->ButtonShow("reset, simpan, tutup");
        $objAxpDB->FormLocked("1, 0, 0, 0, 0, 0, 0, 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");
        // $objAxpDB->GridLocked(2, "1, 1, 1, 1, 1");
        $objAxpDB->GridLocked(3, "1, 0, 0, 0");
        // $objAxpDB->GridScript(2,1, "onChange=\"{$ajaxGrid}\"");

/*
} elseif ($objAxpDB->GetStatus("fnstatus") == 0) {
        $objAxpDB->GridAllowAddNew(0,true);
        $objAxpDB->GridAllowDelete(0,true);
        $objAxpDB->ButtonShow("final_bank, batal, tutup");
        $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
        $objAxpDB->GridLocked(0, "1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1");
        $objAxpDB->GridLocked(1, "1, 1, 1, 1, 1, 1, 1");
        // $objAxpDB->GridLocked(2, "1, 1, 1, 1, 1");
        $objAxpDB->GridLocked(3, "1, 1, 1, 1");
   
 } elseif ($objAxpDB->GetStatus("fnstatus") == 2) {
        if ($objAxpDB->GetStatus("fnstatus2") == 0) {
                 
                 //$objAxpDB->ButtonShow("cetak_bank,  batal, tutup");
                 $objAxpDB->ButtonShow("cetak,  batal, tutup");
                 $objAxpDB->FormLocked("1, 1, 1, 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");
                 // $objAxpDB->GridLocked(2, "1, 1, 1, 1, 1");
                 // $objAxpDB->GridScript(2,1, "onChange=\"{$ajax_cm}\"");
                 $objAxpDB->GridLocked(3, "1, 1, 1, 1");
                 //$objAxpDB->Lookup("ftcm_no", "select ftcm_no,fdtrans_date from txcredit_memo_hdr", "ftcm_no", "fdtrans_date", -1,false);

        }
        elseif ($objAxpDB->GetStatus("fnstatus2") == 1) {
                //$objAxpDB->ButtonShow("cetak_bank,final_penerimaan, batal, baru, tutup");
                $objAxpDB->ButtonShow("cetak,final_penerimaan, batal, baru, tutup");
                $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,1, 1,1,1,1,1");
                $objAxpDB->GridAllowAddNew(2,true);
                $objAxpDB->GridAllowDelete(2,true);
                // $objAxpDB->GridLocked(2, "1, 0, 1, 1, 0");
                // $objAxpDB->GridScript(2,1, "onChange=\"{$ajax_cm}\"");
                $objAxpDB->GridLocked(3, "1, 1, 1, 1");
                //$objAxpDB->Lookup("ftcm_no", "select ftcm_no,fdtrans_date from txcredit_memo_hdr", "ftcm_no", "fdtrans_date", -1,false);

        }
        elseif ($objAxpDB->GetStatus("fnstatus2") == 2) {
                //$objAxpDB->ButtonShow("cetak_bank,cetak_penerimaan, batal, tutup");
                $objAxpDB->ButtonShow("cetak,cetak_penerimaan, batal, tutup");
                $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1,1,1, 1,1, 1, 1, 1, 1,1,1,1,1");
                // $objAxpDB->GridLocked(2, "1, 1, 1, 1, 1");
                $objAxpDB->GridLocked(3, "1, 1, 1, 1");
                //$objAxpDB->Lookup("ftcm_no", "select ftcm_no,fdtrans_date from txcredit_memo_hdr",  "ftcm_no", "fdtrans_date", -1,false);
        }

        $objAxpDB->GridLocked(0, "1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
*/

} elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
        if(isset($_REQUEST['revisi'])) {
            $objAxpDB->GridAllowAddNew(0,true);
            $objAxpDB->GridAllowDelete(0,true);
            $objAxpDB->GridAllowAddNew(3,true);
            $objAxpDB->GridAllowDelete(3,true);
            $objAxpDB->GridLocked(0, "1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1");
            $objAxpDB->ButtonShow("simpan_revisi, tutup");
            $objAxpDB->FormLocked("1, 1, 0, 0, 1, 0, 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, 1, 1, 1");
            $objAxpDB->GridLocked(3, "1, 0, 0, 0");
            // $objAxpDB->GridScript(2,1, "onChange=\"{$ajaxGrid}\"");

        } else {
            $objAxpDB->GridLocked(0, "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, 1");
            $objAxpDB->GridLocked(3, "1, 1, 1, 1");
            $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1,1,1,1,1");

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

            if ($fnstatusgiro == 0) {
                $objAxpDB->ButtonShow("baru, cetak, revisi, batal, tutup");
            } else {
                $objAxpDB->ButtonShow("baru, cetak, batal, tutup");
            }
        }
        
} elseif (($objAxpDB->GetStatus("fnstatus") == 3) || ($objAxpDB->GetStatus("fnstatus") == 9)) {
        $objAxpDB->GridLocked(0, "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, 1");
        $objAxpDB->GridLocked(3, "1, 1, 1, 1");
        $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1");
        $objAxpDB->ButtonShow("tutup");
}

if($_REQUEST['ajax']) {
   switch($_REQUEST['code']) {
        case "invoice":
           $html = GetInvoice();
           // $html2 = GetMemo();
            ?>  
                div = document.getElementById('txtHint1');
                div2 = document.getElementById('txtHint2');
                var m='<?php echo js_esc($html); ?>';
                var m2='<?php echo js_esc($html2); ?>';
                m= m.replace(/^\s*|\s*$/g,"");
                m2= m2.replace(/^\s*|\s*$/g,"");
                div.innerHTML =m;
                div2.innerHTML = '';
                <!--reSize();-->
                RowIndex1();
            <?
            $ssql=" SELECT IFNULL(SUM(fcoutstanding_amount),0) AS fcoutstanding_amount
                    FROM txcredit_memo_hdr
                    WHERE fnstatus<>9 AND ftcustomer_code='{$_REQUEST['ftcustomer_code']}'";

            $rs=mysql_query($ssql);
            $r=mysql_fetch_assoc($rs);
            $str=$r['fcoutstanding_amount'] ;

            ?> 
            document.getElementById('fccredit_memo').value='<?php echo $str; ?>';
            ElementCurrencyALL();
            <?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\" onblur='ElementCurrencyOnBlur(this);' onfocus='ElementCurrencyOnBlur(this); this.select();' type='text' name='fcother_cost' id='fcother_cost' value='" . $_REQUEST['fcother_cost'] . "'  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('TransactionDetail3').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_cost');
            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('txtHint3').innerHTML;
            document.getElementById('txtHint3').innerHTML = '';
            RowIndex1();
            <!--reSize();-->
            document.getElementById('divOtherCost').style.display = 'none';

            ElementCurrencyALL();
            <?php

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

$objAxpDB->Process();

$objAxpDB->WriteHtmlTable();