<?php
   if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
                if(RetRstField("SELECT fnid FROM txbankrcp_hdr WHERE ftbankrcp_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 "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_masuk');
    $objAxpDB->LookupMagicQuotes(True);
    $objAxpDB->ViewName("Daftar Bank Masuk");
    //$objAxpDB->ViewTable("vKUBankMasuk");
    // $objAxpDB->ViewSQL("SELECT A.fnid, A.ftbankrcp_no,  A.fdtrans_date, A.ftacc_no1,  e.ftcoa_name AS ftacc_desc,ff22_get_no_giro(A.ftbankrcp_no) AS ftgiro_no, A.ftreceive_name, A.ftreference, A.fccomparison_amount, A.ftremarks, A.fcamount, B.fttrans_status_name
    $objAxpDB->ViewSQL("SELECT A.fnid, A.ftbankrcp_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 txbankrcp_hdr  A INNER 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.ftbankrcp_no DESC,  A.fdtrans_date DESC");
    $objAxpDB->ViewPeriod(TRUE);
    $objAxpDB->ViewCaption("ID, No. transaksi, Tgl. transaksi, Kode Bank, Nama Bank, Diterima Dari, No Referensi, Jumlah Total, Keterangan, Total, Status");
    
    $objAxpDB->FormName("Bank Masuk");
    $objAxpDB->FormSQL("SELECT ftbankrcp_no, ftacc_no1, ftreceive_name, fdtrans_date, ftcurrency_code, fcrate, ftreference, fccomparison_amount, ftremarks,  fcamount, fnstatus FROM txbankrcp_hdr");
    $objAxpDB->FormCaption("No. transaksi, Bank, Diterima Dari, 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");
    $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=TN009&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftbankrcp_no&no_trans=ftbankrcp_no&table_name=txbankrcp_hdr&ftbranch_code={$_SESSION['strbranch']}');";
            
            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                           {$strAutoNumber1}
                                }
                                 OnChangeDate_fdtrans_date();
                                 document.getElementById('ftcurrency_code').value='IDR';
                                 {$ajaxKurs}
                                ";

            $objAxpDB->FormJS($strAutoNumber0);
          
    }

    if(!$_REQUEST['id']) {
        $mm=" '' AS fnstatus_giro ";
    }
    else {
        $mm=" fnstatus_giro ";
    }

    $objAxpDB->Lookup("ftcurrency_code", "SELECT  ftsimbol, ftdescription  FROM tlcurrency_hdr ORDER BY ftsimbol", "ftsimbol", "ftdescription", 0, 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);
    $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);

    $ftbankrcp_no=RetRstField("select ftbankrcp_no from txbankrcp_hdr where fnid='".$_REQUEST['id']."'");

    /*$objAxpDB->GridSQL(0, "SELECT a.fnindex, a.ftcoa_code, a.fnpayment_method, a.ftgiro_no, a.fdgiro_date, a.fdgiro_cliring_date,
							a.ftdescription, a.fcamount, b.fttrans_status_name as fnstatus_giro
							FROM txbankrcp_det a ,
							tstransaction_status b,
							tlcoa c
							WHERE b.fntrans_group_code = 11 and a.fnstatus_giro=b.fntrans_status_code and
							a.ftcoa_code=c.ftcoa_code and a.ftbankrcp_no='$ftbankrcp_no' #");
    */
    $objAxpDB->GridSQL(0, "SELECT fnindex, ftcoa_code, fnpayment_method, ftgiro_no, fdgiro_date, fdgiro_cliring_date,
							ftdescription, fcamount, fnstatus_giro FROM txbankrcp_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=\"BankMasukRecalQty();\"");
    $objAxpDB->GridDelJS(0,"BankMasukRecalQty();");
    //$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->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, 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');
        $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
        $objAxpDB->ButtonShow("baru, tutup");
    }
    
    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();
    
?>    