<?php

   if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
                  if(RetRstField("SELECT fnid FROM txbankpym_hdr WHERE ftbankpym_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 "transno2":
                    ?>
                      submitbutton('Final','','','','');

                    <?php
            break;
            case "transno3":
                    ?>
                    submitbutton('Simpan','','','','');
                    <?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); ?>';
                <?php
            break;
            // Status Giro
            case "statusgiro":
                if (($_REQUEST['status'] == '0') || ($_REQUEST['status'] == '1')) {
                    $statusgiro = "0";
                } else {
                    $statusgiro = "1";
                }  
                ?>
                  document.getElementById('fnstatus_giroD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $statusgiro; ?>';
                <?php 
                break;
             
        }
        die("");
    }

    Getsecurity('bank_keluar');
    $objAxpDB->LookupMagicQuotes(True);
    $objAxpDB->ViewName("Daftar Bank Keluar");
    //$objAxpDB->ViewTable("vKUBankKeluar");
    // $objAxpDB->ViewSQL("SELECT A.fnid, A.ftbankpym_no, A.fdtrans_date, A.ftacc_no1, e.ftcoa_name AS ftacc_desc, ff20_get_no_giro(a.ftbankpym_no) AS ftgiro, A.ftreceive_name,  A.fccomparison_amount, A.ftremarks,
    $objAxpDB->ViewSQL("SELECT A.fnid, A.ftbankpym_no, A.fdtrans_date, A.ftacc_no1, e.ftcoa_name AS ftacc_desc, A.ftreceive_name, A.ftreference, A.fccomparison_amount, A.ftremarks,
                                A.fcamount, B.fttrans_status_name
                        FROM txbankpym_hdr  A LEFT JOIN tstransaction_status B ON a.fnstatus=b.fntrans_status_code AND fntrans_group_code=2
                                LEFT JOIN tlmaster_cast d ON A.ftacc_no1=d.ftcode
                                LEFT JOIN tlcoa e ON A.ftacc_no1=e.ftcoa_code
                        ORDER BY  A.ftbankpym_no DESC, A.fdtrans_date DESC");
    $objAxpDB->ViewCaption("ID, No. transaksi,Tgl. transaksi,Kode Bank, Nama Bank, Dibayar Kepada, No Referensi, Jumlah Total, Keterangan, Total, Status");
    
    $objAxpDB->FormName("Bank Keluar");
    $objAxpDB->FormSQL("SELECT ftbankpym_no, ftacc_no1, ftreceive_name, fdtrans_date, ftcurrency_code, fcrate, ftreference, fccomparison_amount, ftremarks,  fcamount, fnstatus FROM txbankpym_hdr");
    $objAxpDB->FormCaption("No. transaksi, Bank, Dibayar Kepada, Tgl. transaksi, Mata Uang, Kurs, No. Referensi, Jumlah Total, Keterangan,  Total,  Status");
    $objAxpDB->FormPosition("TL, TL, TL, TR, TR, TR, TL, TR, BL, BR, BR");
    $objAxpDB->ViewPeriod(TRUE);

    $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']) {
            $strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=TN010&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftbankpym_no&no_trans=ftbankpym_no&table_name=txbankpym_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}
                            ";

            $objAxpDB->FormJS($strAutoNumber0);
     }

    if(!$_REQUEST['id']) {
        $mm=" '' AS fnstatus_giro ";
        $ftft_no_cost=" SELECT b.ftbankpym_no ";
        $ftft_no_cost.=" FROM txbankpym_hdr a ";
        $ftft_no_cost.=" INNER JOIN txbankpym_det b  ON a.ftbankpym_no=b.ftbankpym_no ";
        $ftft_no_cost.=" WHERE IFNULL(b.fttf_no,'')<>'' AND a.fnstatus<>9 AND a.fnstatus<>3 ORDER BY IFNULL(b.fttf_no,'') DESC";
        $ftft_no_cost=" SELECT ftpf_no AS fttf_no ,ftdocument_no FROM txgiro2_hist WHERE fnstatus_giro<>9 AND IFNULL(ftpf_no,'')<>'' ORDER BY  ftpf_no DESC";
    }
    else {
        $mm=" fnstatus_giro ";
        $ftft_no_cost=" SELECT b.ftbankpym_no ";
        $ftft_no_cost.=" FROM txbankpym_hdr a ";
        $ftft_no_cost.=" INNER JOIN txbankpym_det b  ON a.ftbankpym_no=b.ftbankpym_no ";
        $ftft_no_cost.=" WHERE IFNULL(b.fttf_no,'')<>'' AND a.fnstatus<>9 AND a.fnstatus<>3 ORDER BY IFNULL(b.fttf_no,'') DESC ";
        $ftft_no_cost=" SELECT ftpf_no AS fttf_no ,ftdocument_no FROM txgiro2_hist WHERE fnstatus_giro<>9 AND IFNULL(ftpf_no,'')<>'' ORDER BY  ftpf_no DESC";
    }

    $objAxpDB->Lookup("ftcurrency_code", "SELECT  ftsimbol, ftdescription  FROM tlcurrency_hdr ORDER BY ftsimbol", "ftsimbol", "ftdescription", 0, 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("ftacc_no1", "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 AND RIGHT(a.ftcoa_code, 5) <> '.0000'", "ftcoa_code", "ftcoa_name", -1,true);

    $ftbankpym_no=RetRstField("select ftbankpym_no from txbankpym_hdr where fnid='".$_REQUEST['id']."'");
    $objAxpDB->GridSQL(0, "SELECT fnindex, ftcoa_code, fnpayment_method, ftgiro_no, fdgiro_date, fdgiro_cliring_date,
                                ftdescription, fcamount, fnstatus_giro FROM txbankpym_det");
    $objAxpDB->GridCaption(0, "No., No. Perkiraan, Metode Pembayaran, No. Giro, Tgl. Giro, Tgl. Cair, Keterangan, Jumlah Total, Status Giro");

    $objAxpDB->FormScript(4, "OnChange=\"{$ajaxKurs}\"");
    
    // Trigger Script utk Kolom di Grid
    $objAxpDB->GridScript(0, 7, " onChange=\"BankKeluarRecalQty();\"");
    $objAxpDB->GridDelJS(0,"BankKeluarRecalQty();");
    //$ajaxStatusGiro=" onChange=\"ajax_do('query2.php?code=8&obj1=' + this.value + '&obj2=fnstatus_giroD0_N_');\"";
    $ajaxStatusGiro=" onChange=\"ajax_do('keuangan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=statusgiro&status=' + this.value + '&index=_N_');\"";
    $objAxpDB->GridScript(0, 2, $ajaxStatusGiro);
    //$objAxpDB->GridScript(0, 3, " onChange=\"ajax_do('query2.php?code=tglgiro&obj1=' + this.value + '&obj2=fdgiro_cliring_dateD0_N_');\"");
    //$ajaxDateGiro="ajax_do('keuangan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&code=tglgiro&ajax=1&tgl=' + this.value + '&index=_N_');";
    //$objAxpDB->GridScript(0,4, "onChange=\"{$ajaxDateGiro}\"");

    $objAxpDB->Lookup("ftcoa_code", "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=17 AND*/ RIGHT(a.ftcoa_code, 5) <> '.0000'", "ftcoa_code", "ftcoa_name", -1, false);
    $objAxpDB->Lookup("ftacc_no", "SELECT ftcode as  ftcoa_code,ftdescription  as ftcoa_name FROM tlmaster_cast UNION ALL SELECT ftcode as  ftcoa_code,ftdescription  as ftcoa_name FROM tlmaster_bank  ", "ftcoa_code", "ftcoa_name", -1,true);
    $objAxpDB->Lookup("fnpayment_method", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 8 AND ( (fntrans_status_code<=4) or fntrans_status_code=7)", "fntrans_status_code", "fttrans_status_name", -1,true);
    $objAxpDB->Lookup("fnstatus_giro", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 11", "fntrans_status_code", "fttrans_status_name", 0, true);
    
    $objAxpDB->SetStatus("id, fnstatus");
    if ($objAxpDB->GetStatus("id") == "")
        $objAxpDB->ButtonShow("baru");
    elseif ($objAxpDB->GetStatus("id") == 0) {
        $objAxpDB->GridAllowAddNew(0,true);
        $objAxpDB->GridAllowDelete(0,true);
        $objAxpDB->GridLocked(0,'1,0,0,0,0,0,0,0,1');
        $objAxpDB->ButtonShow("reset, simpan, tutup");
        $objAxpDB->FormLocked("1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1");
        
        // $ajaxGridxxx="document.getElementById('ftremarks').value=document.getElementById('ftdescriptionD0_N_').value;";
        // $objAxpDB->GridScript(0,6, "onChange=\"{$ajaxGridxxx}\"");
    }

    elseif ($objAxpDB->GetStatus("fnstatus") == 0) {
        $objAxpDB->GridAllowAddNew(0,true);
        $objAxpDB->GridAllowDelete(0,true);
        $objAxpDB->GridLocked(0,'1,0,0,0,0,0,0,0,1');
        $objAxpDB->ButtonShow("reset, simpan, tutup");
        $objAxpDB->FormLocked("1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1");
        // $ajaxGridxxx="document.getElementById('ftremarks').value=document.getElementById('ftdescriptionD0_N_').value;";
        // $objAxpDB->GridScript(0,6, "onChange=\"{$ajaxGridxxx}\"");
       
    } elseif (($objAxpDB->GetStatus("fnstatus") == 1) || ($objAxpDB->GetStatus("fnstatus") == 2)) {
           if(isset($_REQUEST['revisi'])) {
                $objAxpDB->ButtonShow("simpan_revisi, tutup");
                $objAxpDB->FormLocked("1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1");
                $objAxpDB->GridLocked(0,'0,0,0,0,0,0,0,0,1,1,1');
                $objAxpDB->GridAllowAddNew(0,true);
                $objAxpDB->GridAllowDelete(0,true);

           } else {
                $objAxpDB->ButtonShow("baru, cetak, revisi, batal, tutup");
                $objAxpDB->FormLocked("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');
           }
    } elseif ($objAxpDB->GetStatus("fnstatus") == 3) {
             $objAxpDB->GridLocked(0,'1,1,1,1,1,1,1,1,1,1,1');
             $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
             $objAxpDB->ButtonShow("baru, tutup");
             
    } elseif ($objAxpDB->GetStatus("fnstatus") == 9) {
        $objAxpDB->GridLocked(0,'1,1,1,1,1,1,1,1,1,1,1,1');
        $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
        $objAxpDB->ButtonShow("baru, tutup");
        //$objAxpDB->Lookup("fnstatus_giro", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 11 AND (fntrans_status_code<=4 OR fntrans_status_code=6)", "fntrans_status_code", "fttrans_status_name", 0,true);

    }
    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();
    
?>    