<?php

    Getsecurity("giro_mundur_piutang");

    $objAxpDB->ViewName("Daftar Giro Mundur Piutang");
    //$objAxpDB->ViewTable("vKUGiroMundurPiutang");
    $objAxpDB->ViewSQL("SELECT A.fnid, A.ftgiro_no, A.fdgiro_date AS fdtrans_date, A.fdgiro_cliring_date, A.fcamount, A.ftacc_no, D.ftcoa_name AS ftacc_desc,  A.ftdocument_no, C.ftcustomer_name AS ftcustomer_name,B.fttrans_status_name AS fnstatus_giro
    FROM txgiro_hist A INNER JOIN tstransaction_status B ON B.fntrans_group_code = 11 AND A.fnstatus_giro=fntrans_status_code
                        LEFT JOIN  tlcustomer C ON A.ftcustomer_code=C.ftcustomer_code
                        LEFT JOIN tlcoa D ON A.ftacc_no=d.ftcoa_code
                        LEFT JOIN tlcoa_subgroup E ON D.ftcoa_subgroup_code=E.ftcoa_subgroup_code
                        WHERE (('{$_SESSION['strbranch']}' <> 'PUSAT' AND a.ftbranch_code = '{$_SESSION['strbranch']}') OR '{$_SESSION['strbranch']}' = 'PUSAT')");

    $objAxpDB->ViewCaption("ID, No. Giro, Tgl. Giro, Tgl. Cair Giro, Jumlah, No. Perkiraan, Deskripsi Perkiraan , No. transaksi,  Nama Customer, Status ");
    $objAxpDB->ViewPeriod(TRUE);

    $objAxpDB->FormName("Giro Mundur Piutang");
    $objAxpDB->FormSQL("SELECT ftgiro_no, fdgiro_date, fdgiro_cliring_date, fcrate, fcamount, ftacc_no, ftdocument_no, ftcustomer_code, fnstatus_giro FROM txgiro_hist");
    $objAxpDB->FormCaption("No. Giro, Tgl. Giro, Tgl. Cair Giro, Kurs, Jumlah, No. Perkiraan, No. transaksi, Customer, Status");
    $objAxpDB->FormPosition("TL,TL, TL, TL, TL, TL, TL, TL, TL");

    $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", 1,true);
    $objAxpDB->Lookup("ftcustomer_code", "SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer", "ftcustomer_code", "ftcustomer_name", 0,false);

    $ssql="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";
    $objAxpDB->Lookup("ftacc_no", $ssql, "ftcoa_code", "ftcoa_name", -1,true);
    /*$ssql="SELECT ftcode as ftacc_no,ftdescription FROM tlmaster_bank";

    $objAxpDB->Lookup("ftacc_no", $ssql, "ftacc_no", "ftdescription", 1,true);*/

    $objAxpDB->SetStatus("id, fnstatus_giro");
    if ($objAxpDB->GetStatus("id") == "") {
            // $objAxpDB->ButtonShow("");
    } elseif ($objAxpDB->GetStatus("fnstatus_giro") == 0) {
            $objAxpDB->Lookup("fnstatus_giro", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_status_code<>9 /*AND fntrans_status_code<>2*/ AND fntrans_group_code = 11", "fntrans_status_code", "fttrans_status_name", 1,true);
            $objAxpDB->ButtonShow("simpan, tutup");
            $objAxpDB->FormLocked("1, 1, 0, 1, 1, 0, 1, 1, 0");
    } elseif ($objAxpDB->GetStatus("fnstatus_giro") != 9) {
      if ($objAxpDB->GetStatus("fnstatus_giro") != 0)
        $objAxpDB->ButtonShow("cetak, tutup");
      else
        $objAxpDB->ButtonShow("cetak,update,tutup");
        $objAxpDB->FormLocked("1, 1, 1, 1,1,1,  1, 1, 1");
    } elseif ($objAxpDB->GetStatus("fnstatus_giro") == 9) {
             $objAxpDB->FormLocked("1, 1, 1, 1,1,1,  1, 1, 1");
             $objAxpDB->ButtonShow("tutup");
    }
    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();