<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM txloan_payment_hdr WHERE ftloan_payment_no='{$_REQUEST['fttrans_no']}'")) {
                  ?>

                   alert('No. transaksi sudah dipakai...\n System akan mengenerate No. transaksi kembali ...\n Silahkan ulangi proses penyimpanan...  ');
                  OnChangeDate_fdattendance_date();
            <?php
              }
              else {
                    ?>


                  submitbutton('Simpan','','','','');

            <?php
              }
			  die("");
            break;
        }
        
    }
     if(!$_REQUEST['id']) {
            $strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=hrd004&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftloan_payment_no&no_trans=ftloan_payment_no&table_name=txloan_payment_hdr');";

            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                           {$strAutoNumber1}


                                     }
                                     OnChangeDate_fdtrans_date();
                                var i=document.getElementsByName('fnindexD0[]').length;
                                 document.getElementById(\"TransactionDetail0\").deleteRow(2);
                                
                                ";

            $objAxpDB->FormJS($strAutoNumber0);
     }
 // Deklarasi UctVw
    $objAxpDB->ViewName("Daftar Pembayaran Pinjaman");
    $objAxpDB->ViewSQL("select a.fnid, a.ftloan_payment_no, a.ftemployee_code, a.ftemployee_name, a.fdtrans_date, a.fcloan_payment_amount, a.ftloan_payment_description, a.ftnotes, b.fttrans_status_name  from txloan_payment_hdr a LEFT JOIN tstransaction_status B ON a.fnstatus=b.fntrans_status_code AND B.fntrans_group_code=2 order by a.ftloan_payment_no desc,a.fdtrans_date desc");
    $objAxpDB->ViewCaption("ID, No. Transaksi, Kode Pegawai, Nama Pegawai, Tgl. Transaksi, Total, Keterangan, Catatan, Status");
	$objAxpDB->ViewPeriod(TRUE);

    // Deklarasi Header & Footer
    $objAxpDB->FormName("Pembayaran Pinjaman");
    $objAxpDB->FormSQL("select ftloan_payment_no, fdtrans_date, ftemployee_code, fcloan_payment_amount, ftloan_payment_description, ftnotes, fnstatus  from txloan_payment_hdr");
    $objAxpDB->FormCaption(" No. Transaksi,Tgl. Transaksi,  Kode Pegawai, Total, Keterangan, Catatan, Status");
    $objAxpDB->FormPosition("TL, TL, TL, BR, TL, BL, BR");
	
	if(!$_REQUEST['id']) {
		 $ajax1=" OnChange=\"ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&ftemployee_code='+ document.getElementById('ftemployee_code').value);\"";
		 $objAxpDB->FormScript(2, $ajax1); 		 
		 $ajax1=" OnChange=\"ValPembayaranPinjaman1();\"";
		 $objAxpDB->GridScript(0,6, $ajax1);
	}

	
    // Deklarasi Detail
    $objAxpDB->GridSQL(0, "select fnindex,  ftloan_no, fdloan_date,ftloan_type_code, fcloan_amount, fcloan_balance, fcloan_payment from txloan_payment_det");
    $objAxpDB->GridCaption(0, "No.,No. Peminjaman, Tgl. Peminjaman, Jenis Peminjaman, Jumlah Peminjaman, Sisa Peminjaman, Jumlah Pembayaran ");


    $objAxpDB->Lookup("ftloan_type_code", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 21", "fntrans_status_code", "fttrans_status_name", 0, True);
    $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("ftemployee_code", "SELECT ftemployee_code, ftemployee_name FROM tlemployee", "ftemployee_code", "ftemployee_name", -1, False);
     

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


    } elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
           
            $objAxpDB->ButtonShow("cetak,  batal, tutup");

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

	
	  if($_REQUEST['ajax']) {
           switch($_REQUEST['code']) {
           case "grid":
               ob_start();

                       $ssql="select b.fnindex ,a.ftloan_no, a.fdtrans_date as fdloan_date, 
								a.ftloan_type_code, a.fcloan_balance as fcloan_amount,
								a.fcloan_outstanding as fcloan_balance,a.fcloan_outstanding-a.fcloan_outstanding as fcloan_payment
								from txloan a left join txloan_payment_det b on 1=0
								where a.fnloan_payment_status<>3 and 
									a.fnstatus=1 and a.fnpayroll_slip=0 and 
                                        a.ftemployee_code='".$_REQUEST['ftemployee_code']."'
                                   #                           ";
                        $objAxpDB->GridSQL(0,$ssql);

               $objAxpDB->Process();
               $objAxpDB->setGrid2(0);
               $html = ob_get_contents();
               ob_end_clean();
                $ssql="select b.fnindex ,a.ftloan_no, a.fdtrans_date as fdloan_date,
								a.ftloan_type_code, a.fcloan_balance as fcloan_amount,
								a.fcloan_outstanding as fcloan_balance,a.fcloan_outstanding-a.fcloan_outstanding as fcloan_payment
								from txloan a left join txloan_payment_det b on 1=0
								where a.fnloan_payment_status<>3 and
									a.fnstatus=1 and a.fnpayroll_slip=0 and
                                        a.ftemployee_code='".$_REQUEST['ftemployee_code']."'
                                   #                               ";
               ?>

                    div = document.getElementById('txtHint0');
                    var m='<?php echo js_esc($html); ?>';
                    m= m.replace(/^\s*|\s*$/g,"");

                    div.innerHTML =m;
                  
                    RowIndex0();
                    reSize();


               <?

               break;

           }
           die("");
           exit;
    }
    
	
    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();


?>
