<?php

    GetSecurity('kas_masuk');

      if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
                if(RetRstField("SELECT fnid FROM txcashrcp_hdr WHERE ftcashrcp_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 $r["fcrate"]; ?>';
                <?php
                break;
            
        }       
        die("");
    }

    $objAxpDB->LookupMagicQuotes(True);
    $objAxpDB->ViewName("Daftar Kas Masuk");
    //$objAxpDB->ViewTable("vKUKasMasuk");
    $objAxpDB->ViewSQL("SELECT A.fnid, A.ftcashrcp_no,A.fdtrans_date, A.ftacc_no1, C.ftcoa_name  as  ftacc_desc,  A.ftreceive_name, A.ftdoc_no, A.fccomparison_amount, A.ftremarks,  A.fcamount,  B.fttrans_status_name
                       FROM txcashrcp_hdr  A
                       INNER JOIN tstransaction_status B ON a.fnstatus=b.fntrans_status_code AND fntrans_group_code=2
                       LEFT JOIN tlcoa C ON A.ftacc_no1=C.ftcoa_code
                       WHERE (('{$_SESSION['strbranch']}' <> 'PUSAT' AND a.ftbranch_code = '{$_SESSION['strbranch']}') OR '{$_SESSION['strbranch']}' = 'PUSAT')
                        ORDER BY A.ftcashrcp_no DESC, A.fdtrans_date DESC");
    
    $objAxpDB->ViewCaption("ID, No. transaksi,Tgl. transaksi,  Kode Kas, Nama Kas, Diterima Dari, No Referensi, Jumlah Total, Keterangan,  Total, Status");
    $objAxpDB->ViewPeriod(TRUE);
	
    $objAxpDB->FormName("Kas Masuk");
    $objAxpDB->FormSQL("SELECT ftcashrcp_no, ftacc_no1, ftreceive_name, fdtrans_date, ftcurrency_code, fcrate, fccomparison_amount, ftremarks,  fcamount, fnstatus, ftdoc_no FROM txcashrcp_hdr");
    $objAxpDB->FormCaption("No. transaksi, Kas, Diterima Dari, Tgl. transaksi, Mata Uang, Kurs, Jumlah Total, Keterangan, Total, Status, No Referensi");
    $objAxpDB->FormPosition("TL, TL, TL, TR, TR, TR, TR, BL, BR, BR, TL");
    $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=TN007&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftcashrcp_no&no_trans=ftcashrcp_no&table_name=txcashrcp_hdr&ftbranch_code={$_SESSION['strbranch']}');";
            //$strAutoNumber2="ajax_do('query2.php?code=2&ftmodule_code=TN011&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftjournal_no&no_trans=ftjournal_no&table_name=txcashrcp_hdr');";
           
            $strAutoNumber0="   function OnChangeDate_fdtrans_date() {                                                    
                                           {$strAutoNumber1} 
                                } 
                                
                                OnChangeDate_fdtrans_date();
                                document.getElementById('ftcurrency_code').value='IDR';
                                {$ajaxKurs}
                                ";   
        
            $objAxpDB->FormJS($strAutoNumber0);
     }

    $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=15 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);	

//    $objAxpDB->GridSQL(0, "SELECT fnindex, ftacc_no, ftdescription, fcamount FROM TXCashRcp_Det");
//    $objAxpDB->GridCaption(0, "No., No. Perkiraan,  Keterangan, Jumlah Total");  
//    $objAxpDB->GridScript(0,3, "onChange=\"KasMasukRecalQty();\"");
//    $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->FormScript(4, "OnChange=\"{$ajaxKurs}\"");
    $objAxpDB->GridSQL(0, "SELECT fnindex, ftcoa_code, ftdescription, fcamount FROM TXCashRcp_Det");
    $objAxpDB->GridCaption(0, "No.,  No. Perkiraan, Keterangan, Jumlah Total");
    
    // Trigger Script utk Kolom di Grid
    $objAxpDB->GridScript(0,3, "onChange=\"KasMasukRecalQty();\"");
    $objAxpDB->GridDelJS(0,"KasMasukRecalQty();");
    $objAxpDB->Lookup("ftcoa_code", "SELECT ftcoa_code, ftcoa_name FROM tlcoa WHERE SUBSTR(ftcoa_code, 5) <> '.0000'", "ftcoa_code", "ftcoa_name", -1,false);
    
    $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');
            $objAxpDB->ButtonShow("reset, simpan, tutup");
            $objAxpDB->FormLocked("1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0");
             
            // $ajaxGrid="document.getElementById('ftremarks').value=document.getElementById('ftdescriptionD0_N_').value;";
            // $objAxpDB->GridScript(0,2, "onChange=\"{$ajaxGrid}\"");
    }
    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, 1, 1, 0");
                $objAxpDB->GridLocked(0,'0,0,0,0');
                $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');   
           }

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

    $objAxpDB->WriteHtmlTable();
    
?>    