<?php

    if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
                if(RetRstField("SELECT fnid FROM txgeneral_journal_hdr WHERE ftjournal_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;
        }
        die("");
    }

    Getsecurity('jurnal_umum');

    $objAxpDB->ViewName("Daftar Jurnal Umum");
    $objAxpDB->ViewSQL("SELECT b.fnid, b.fdtrans_date, b.ftjournal_no, b.ftdocument_no, b.fcdebit AS fcamount, b.ftnotes, c.fttrans_status_name FROM txgeneral_journal_hdr b LEFT JOIN tstransaction_status c ON b.fnStatus = c.fnTrans_Status_Code AND c.fnTrans_Group_Code = 2  WHERE fntype = 1 GROUP BY b.ftJournal_No ORDER BY b.fdTrans_Date DESC, b.ftjournal_no DESC");
    $objAxpDB->ViewCaption("ID, Tgl. Jurnal, No. Jurnal, No. Referensi, Jumlah Total, Catatan, Status");
    $objAxpDB->ViewPeriod(TRUE);
    
     if(!$_REQUEST['id']) {
            $strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=acc002&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftjournal_no&no_trans=ftjournal_no&table_name=txgeneral_journal_hdr&ftbranch_code={$_SESSION['strbranch']}');";
            $ajaxTransDate="ajax_do('akunting.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=tgl&tgl=' + document.getElementById(\"fdtrans_date\").value + '');";
            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                           {$strAutoNumber1}
                                           {$ajaxTransDate}
                                     }

                              OnChangeDate_fdtrans_date();
                                         
                              document.getElementById(\"fntype\").value='1';
                              document.getElementById(\"ftsource\").value='Jurnal Umum';";
            $objAxpDB->FormJS($strAutoNumber0);
     }

    $objAxpDB->FormName("Jurnal Umum");
    $objAxpDB->FormSQL("SELECT ftjournal_no, fdtrans_date, ftdocument_no, fcdebit, fccredit, ftnotes, fntype, ftsource, fnstatus FROM txgeneral_journal_hdr");
    $objAxpDB->FormCaption("No. Jurnal, Tgl. Jurnal, No. Referensi, Total Debit, Total Kredit, Catatan, Tipe Jurnal, Sumber Jurnal, Status");
    $objAxpDB->FormPosition("TL, TL, TR, BR, BR, BL, HD, HD, BR");
    $objAxpDB->FormScript(1,"onChange=\"OnChangeDate_fdtrans_date()\"");
    
    $objAxpDB->GridSQL(0, "SELECT fnindex, ftcoa_code, ftdescription, fcdebit, fccredit FROM txgeneral_journal_det");
    $objAxpDB->GridCaption(0, "No, No. Perkiraan, Keterangan, Debit, Kredit");
    $objAxpDB->GridScript(0, 3, "onChange='JurnalUmumRecalGrid();'");
    $objAxpDB->GridScript(0, 4, "onChange='JurnalUmumRecalGrid();'");

    $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("ftcoa_code", "SELECT ftCOA_Code, ftCOA_Name FROM tlcoa WHERE fnstatus=1 AND RIGHT(ftcoa_code,4) != '0000' ", "ftCOA_Code", "ftCOA_Name", -1, False);

    $objAxpDB->SetStatus("id, fnstatus");
    if ($objAxpDB->GetStatus("id") == "") {
            $objAxpDB->ButtonShow("baru");
    } elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->ButtonShow("reset, simpan, tutup");
            $objAxpDB->FormLocked("1, 0, 0, 1, 1, 0, 1, 1, 1");
            $objAxpDB->GridLocked(0, "1, 0, 0, 0, 0");
            $objAxpDB->GridAllowAddNew(0, TRUE);
            $objAxpDB->GridAllowDelete(0, TRUE);
            $objAxpDB->GridDelJS(0,"JurnalUmumRecalGrid();");
    } elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
            if(isset($_REQUEST['revisi'])) {
                $objAxpDB->ButtonShow("simpan_revisi, tutup");
                $objAxpDB->FormLocked("1, 0, 0, 1, 1, 0, 1, 1, 1");
                $objAxpDB->GridLocked(0, "1, 0, 0, 0, 0");
                $objAxpDB->GridAllowAddNew(0,true);
                $objAxpDB->GridAllowDelete(0,true);
                $objAxpDB->GridDelJS(0,"JurnalUmumRecalGrid();");
           } else {
                $objAxpDB->ButtonShow("baru, cetak, revisi, batal, tutup");
                $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1");
                $objAxpDB->GridLocked(0, "1, 1, 1, 1, 1");
           }

    } elseif (($objAxpDB->GetStatus("fnstatus") == 3) || ($objAxpDB->GetStatus("fnstatus") == 9)) {
            $objAxpDB->ButtonShow("tutup");
            $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1");
            $objAxpDB->GridLocked(0, "1, 1, 1, 1, 1");
    }
    
    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();
