<?php
    if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "kodeasset":


              list($dt, $mn, $yr)=split("/", $_REQUEST['fdpurchase_date']);
              $periode_input = $yr . "-" . $mn;

              if(RetRstField("SELECT fnid FROM tlasset WHERE ftasset_code='{$_REQUEST['ftasset_code']}'")) {
                ?>
                  alert('Kode Asset sudah dipakai...');
                <?php

              } else if ($tanggal = RetRstField("SELECT fdTrans_Date AS fdtrans_date FROM txdepriciation_hdr WHERE fnstatus = 1 AND  LEFT(fdtrans_date, 7)='{$periode_input}' AND  fnstatus = 1  ORDER BY fdtrans_date DESC LIMIT 1")){
                ?>
                  alert('Sudah Ada Transaksi Penyusutan Pada Bulan <?php echo tgl_indo($tanggal); ?> ');
                <?php
              }else{
                ?>
                  submitbutton('Simpan','','','','');
                <?php
              }
            break;

        }
        die("");
    }

    Getsecurity('asset');

    // $date_now = date('Y-m');
    // $bulan = tgl_indo(date('Y-m'));

    $objAxpDB->ViewName("Daftar Asset");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.ftasset_code, a.ftasset_name, b.ftcategory_name, c.fttrans_status_name FROM tlasset a LEFT JOIN tlasset_category b ON a.ftcategory_code=b.ftcategory_code
                        LEFT JOIN tstransaction_status c on a.fnstatus = c.fntrans_status_code and c.fnTrans_Group_Code = 9 ");
    $objAxpDB->ViewCaption("ID, Kode Asset, Nama Asset, Kategori Asset, Status");
    $objAxpDB->ViewPeriod(FALSE);

    $objAxpDB->FormName("Asset");
    $objAxpDB->FormSQL("SELECT ftasset_code, ftasset_name, fdpurchase_date, fcacquistion_price, ftcategory_code, fnstatus, fnselling_status, fdselling_date FROM tlasset");
    $objAxpDB->FormCaption("Kode Asset, Nama Asset, Tgl. Pembelian, Harga Perolehan, Kode Kategori, Status, Status Jual, Tgl. Penjualan");
    $objAxpDB->FormPosition("TL, TL, TL, TL, TL, TL, TR, TR");

    $objAxpDB->Lookup("ftcategory_code", "SELECT ftcategory_code, ftcategory_name FROM tlasset_category", "ftcategory_code", "ftcategory_name", -1, True);
    $objAxpDB->Lookup("fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 9", "fntrans_status_code", "fttrans_status_name", 1, True);
    $objAxpDB->Lookup("fnselling_status", "SELECT 0 AS fntrans_status_code, 'TIDAK TERJUAL' AS fttrans_status_name UNION ALL SELECT 1 AS fntrans_status_code, 'SUDAH TERJUAL' AS fttrans_status_name", "fntrans_status_code", "fttrans_status_name", 0, True);

    $objAxpDB->SetStatus("id");
    if ($objAxpDB->GetStatus("id") == "")
            $objAxpDB->ButtonShow("baru, tutup");
    elseif ($objAxpDB->GetStatus("id") == 0)
            $objAxpDB->ButtonShow("reset, simpan, tutup");
    elseif ($objAxpDB->GetStatus("id") != 0) {
            $objAxpDB->ButtonShow("update, hapus, tutup");
            $objAxpDB->FormLocked("1, 0, 0, 0, 0");
    }

    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();
?>
