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

              if(RetRstField("SELECT fnid FROM tlasset_category WHERE ftcategory_code='{$_REQUEST['ftcategory_code']}'")) {
                ?>
                  alert('Kode Asset sudah dipakai...');
                <?php
              }
              else {
                ?>
                  submitbutton('Simpan','','','','');
                <?php
              }
            break;

            case "penyusutan":
                if(RetRstField("SELECT fntrans_status_code FROM tstransaction_status WHERE fntrans_status_code='{$_REQUEST['fntype']}'") == 2) {
                    ?>
                    document.getElementById('ffpercentage').value='<?php echo "50.00"; ?>';
                    <?php
                }else{
                    ?>
                    document.getElementById('ffpercentage').value='0.00';
                    <?php

                }

            break;

        }
        die("");
    }

    Getsecurity('category_asset');

    $objAxpDB->ViewName("Daftar Kategori Asset");

    $sql = "SELECT a.fnid,
                   a.ftcategory_code,
                   a.ftcategory_name,
                   b.fttrans_status_name,
                   a.ffpercentage,
                   a.fndepriciation_year FROM tlasset_category A
                   INNER JOIN tstransaction_status B ON a.fntype=b.fntrans_status_code
                   WHERE fntrans_group_code = 78 AND fnactive_status = 1";

    $objAxpDB->ViewSQL($sql);
    $objAxpDB->ViewCaption("ID, Kode Kategori, Nama Kategori, Jenis Penyusutan, Percentage (%) ,Masa Tahun Penyusutan");
    $objAxpDB->ViewPeriod(FALSE);

    $objAxpDB->FormName("Kategori Asset");

    $objAxpDB->FormSQL("SELECT ftcategory_code, ftcategory_name, fntype, fndepriciation_year,ffpercentage FROM tlasset_category");
    $objAxpDB->FormCaption("Kode Kategori, Nama Kategori,Jenis Penyusutan, Masa Tahun Penyusutan, Penyusutan Menurun ( % )");
    $objAxpDB->FormPosition("TL, TL, TL,TL,TL");

    $objAxpDB->Lookup("fntype", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 78 AND fnactive_status = 1 ", "fntrans_status_code", "fttrans_status_name", -1,true);

    $ajaxpenyusutan="ajax_do('akunting.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=penyusutan&fntype='+ document.getElementById('fntype').value);";
    $objAxpDB->FormScript(2, "onChange=\"{$ajaxpenyusutan}\"");

    $objAxpDB->SetStatus("id");
    if ($objAxpDB->GetStatus("id") == "")
            $objAxpDB->ButtonShow("baru");

    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");
    }


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