<?php
if($_REQUEST['ajax']) {
  switch($_REQUEST['code']) {
    case "transno":
      if(RetRstField("SELECT fnid FROM txpurchase_invoice_hdr WHERE ftpurchase_invoice_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("");
  exit;
}

Getsecurity('saldoawal_hutang');
$objAxpDB->ViewSQL("SELECT A.fnid, A.ftpurchase_invoice_no,  A.ftsupplier_code, d.ftsupplier_name, A.fdtrans_date,  A.fddue_date, A.fcamount,A.fcpayment_amount, A.fcoutstanding_amount, C.fttrans_status_name AS fnpayment_status,  B.fttrans_status_name
                    FROM txpurchase_invoice_hdr  A INNER JOIN tstransaction_status B ON a.fnstatus=b.fntrans_status_code AND B.fntrans_group_code=2
                    INNER JOIN tstransaction_status C ON a.fnpayment_status=C.fntrans_status_code AND C.fntrans_group_code=1
                    left join tlsupplier d on a.ftsupplier_code=d.ftsupplier_code
                    WHERE A.fnsaldo_awal=1
                    ORDER BY A.ftpurchase_invoice_no DESC, A.fdtrans_date DESC");
$objAxpDB->ViewCaption("ID, No. Transaksi, No. Supplier, Supplier, Tgl. Transaksi, Tgl. Jatuh Tempo, Jumlah Piutang, Jumlah Terbayar, Sisa Pembayaran, Status Pembayaran, Status");

//$ajaxinvoice="ajax_do('penjualan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=invoice&ftdo_no='+ document.getElementById('ftdo_no').value);";

if(!$_REQUEST['id']) {
  $strAutoNumber1=" ajax_do('query2.php?code=2&ftmodule_code=TN124&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftpurchase_invoice_no&no_trans=ftpurchase_invoice_no&table_name=txpurchase_invoice_hdr');";
  $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                      {$strAutoNumber1}
                    }

  OnChangeDate_fdtrans_date();
  $ajaxinvoice";

  $objAxpDB->FormJS($strAutoNumber0);
  $objAxpDB->Lookup("ftdo_no", "SELECT ftdo_no,fdtrans_date FROM txpurchase_invoice_hdr WHERE fnstatus=1 ORDER BY ftdo_no DESC,fdtrans_date  DESC", "ftdo_no", "fdtrans_date", -1,true);
}

$objAxpDB->FormName("Saldo Awal Hutang");
 $objAxpDB->FormSQL("SELECT ftpurchase_invoice_no, fdtrans_date,   fddue_date,ftsupplier_code, fcamount, fcpayment_amount, fcoutstanding_amount, fnpayment_status, fnstatus,fnsaldo_awal FROM txpurchase_invoice_hdr");
    $objAxpDB->FormCaption("No. Transaksi, Tgl. Transaksi, Tgl. Jatuh Tempo, Supplier, Jumlah Hutang , Jumlah Terbayar, Sisa Pembayaran,  Status Pembayaran, Status, fnsaldo_awal");
    $objAxpDB->FormPosition("TL, TL, TL, TL, TL, TL, TL, TL,TR ,HD");

    $objAxpDB->FormScript(4, "onChange=ValSaldoAwalHutang1()");


    $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("fnpayment_status", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 1", "fntrans_status_code", "fttrans_status_name", 1,true);
    $objAxpDB->Lookup("ftsupplier_code", "SELECT ftsupplier_code, ftsupplier_name FROM tlsupplier", "ftsupplier_code", "ftsupplier_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,0,0,1,1,1,1");
    } elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
            $objAxpDB->ButtonShow(" batal, tutup");
               $objAxpDB->FormLocked("1,1,1,1,1,1,1,1,1");
           #$objAxpDB->Lookup("ftsupplier_code", "SELECT ftsupplier_code, ftsupplier_name FROM tlsupplier", "ftsupplier_code", "ftsupplier_name", 1,true);
    } elseif ($objAxpDB->GetStatus("fnstatus") == 9) {
              $objAxpDB->FormLocked("1,1,1,1,1,1,1,1,1");
            $objAxpDB->ButtonShow("baru, tutup");
    }

    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();