<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM txloan WHERE ftloan_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
              }
            break;
			case "employee":
				$ssql="select ifnull(sum(a.fcloan_outstanding),0) as fcloan_outstanding
						from txloan a
						where a.fnstatus=2 and
							a.fnloan_payment_status<>3
							and ftemployee_code='{$_REQUEST['ftemployee_code']}'";
				$fcloan_outstanding=RetRstField($ssql);
				$ssql="select ifnull(fcmaximum_loan,0) as fcmaximum_loan from tlemployee where ftemployee_code='{$_REQUEST['ftemployee_code']}'";
				$fcmaximum_loan=RetRstField($ssql);
				?>

					document.getElementById('fcloan_amount').value='<?php echo $fcloan_outstanding; ?>';
					document.getElementById('fcloan_max').value='<?php echo $fcmaximum_loan; ?>';
				<?php
			break;
        }
        die("");
    }
     if(!$_REQUEST['id']) {
            $strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=hrd003&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftloan_no&no_trans=ftloan_no&table_name=txloan');
                             ajax_do('query2.php?code=2&ftmodule_code=TN010&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftbankpym_no&no_trans=ftbankpym_no&table_name=txbankpym_hdr');
                              ajax_do('query2.php?code=2&ftmodule_code=TN014&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftjournal_no&no_trans=ftjournal_no&table_name=txbankpym_hdr');

                            ";

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


                                     }
                                     function Changefnpayment_method() {
                                            if(document.getElementById('fnpayment_method').value==0) {
                                                document.getElementById('fnstatus_giro').selectedIndex=1;
                                            }
                                            else if(document.getElementById('fnpayment_method').value==1) {
                                                document.getElementById('fnstatus_giro').selectedIndex=1;
                                            }
                                            else if(document.getElementById('fnpayment_method').value==2) {
                                                document.getElementById('fnstatus_giro').selectedIndex=2;
                                            }
                                            else if(document.getElementById('fnpayment_method').value==3) {
                                                 document.getElementById('fnstatus_giro').selectedIndex=2;
                                            }
                                            else if(document.getElementById('fnpayment_method').value==4) {
                                                 document.getElementById('fnstatus_giro').selectedIndex=2;
                                            }
                                     }
                                     OnChangeDate_fdtrans_date();

                                ";

            $objAxpDB->FormJS($strAutoNumber0);
     }
  // Deklarasi UctVw
    $objAxpDB->ViewName("Daftar Pinjaman");
    $objAxpDB->ViewSQL("select a.fnid, a.ftloan_no,  a.fdtrans_date,a.ftemployee_code, d.ftemployee_name,  a.fcloan_balance, C.fttrans_status_name AS fnpayment_status,  B.fttrans_status_name
				from txloan   A INNER JOIN tstransaction_status B ON a.fnstatus=b.fntrans_status_code AND B.fntrans_group_code=2
                                left join tlemployee d on a.ftemployee_code=d.ftemployee_code
                       INNER JOIN tstransaction_status C ON a.fnloan_payment_status=C.fntrans_status_code AND C.fntrans_group_code=1
                        order by  a.ftloan_no desc, a.fdtrans_date desc");
    $objAxpDB->ViewCaption("ID, No. Transaksi,  Tgl. Transkasi,Kode Pegawai,Nama Pegawai, Hutang, Status Bayar, Status");
	$objAxpDB->ViewPeriod(TRUE);

    // Deklarasi Header & Footer
    $objAxpDB->FormName("Pinjaman 1");
    $objAxpDB->FormSQL("select ftloan_no, ftemployee_code, fdtrans_date,
                                ftloan_type_code, fnpayroll_slip,fdloan_period_from, fdloan_period_to,
                                     fcloan_max, fcloan_amount, fcloan_balance,
                                        fcloan_payment, fcloan_outstanding,
                                             ftnotes, fnloan_payment_status, fnstatus,
                                             ftbankpym_no,
                                             ftjournal_no,
                                             ftacc_no,
                                             fnpayment_method,
                                             ftgiro_no,
                                             fdgiro_date,
                                             fdgiro_cliring_date,
                                             fnstatus_giro
                                             from txloan");
    $objAxpDB->FormCaption(" No. Transaksi, Kode Pegawai, Tgl. Transkasi,
                                Jenis Pinjaman,Potong di pengajian, Periode 1, Periode 2,
                                    Max Pinjaman, Total Hutang, Jumlah Pinjaman,
                                        Total Terbayar, Sisa Hutang, Keterangan,
                                             Status Bayar, Status,
                                             No. Bank Keluar,
                                             No. Jurnal,
                                             Bank,
                                             Metode Pembayaran,
                                             No. Giro,
                                             Tgl. Giro,
                                             Tgl. Cair Giro,
                                             Status Giro");

	$objAxpDB->FormPosition("TL, TL, TL, TL, TL, TL, TL, TL, TL, TL ,TL, TL, TL, TL,TL,
                            TR,TR,TR,TR,TR,TR,TR,TR");
	$objAxpDB->Lookup("ftemployee_code", "SELECT ftemployee_code, ftemployee_name FROM tlemployee", "ftemployee_code", "ftemployee_name", -1, False);
	$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("fnloan_payment_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("fnpayroll_slip", "select fntrans_status_code, fttrans_status_name from tstransaction_status where fntrans_group_code = 28", "fntrans_status_code", "fttrans_status_name", 0, True);
    $objAxpDB->Lookup( "ftacc_no", "SELECT ftcode as  ftcoa_code,ftdescription  as ftcoa_name FROM tlmaster_cast UNION ALL SELECT ftcode as  ftcoa_code,ftdescription  as ftcoa_name FROM tlmaster_bank  ", "ftcoa_code", "ftcoa_name", -1,true);
    $objAxpDB->Lookup("fnpayment_method", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 8 AND ( (fntrans_status_code<=4) or fntrans_status_code=7)", "fntrans_status_code", "fttrans_status_name", -1,true);
    $objAxpDB->Lookup("fnstatus_giro", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 11 AND (fntrans_status_code<=4 OR fntrans_status_code=6)", "fntrans_status_code", "fttrans_status_name", 0,true);


     $objAxpDB->FormScript(18, "onChange=\"Changefnpayment_method();\"");
	if(!$_REQUEST['id']) {
		$ajax1="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=employee&ftemployee_code='+ document.getElementById('ftemployee_code').value);";
		$objAxpDB->FormScript(1, "onChange=\"{$ajax1}\"");
		$objAxpDB->FormScript(9, "onChange=\"document.getElementById('fcloan_outstanding').value=document.getElementById('fcloan_balance').value;\"");
	}

    $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, 0, 0, 0, 0, 1, 1, 0, 1, 1,0,1,1,0,0,0,0,0,0,0,1");

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

     } elseif ($objAxpDB->GetStatus("fnstatus") == 2) {
			 $objAxpDB->ButtonShow("cetak, batal, tutup");
            $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,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, 1, 1, 1,1,1,1,1,1,1,1,1,1,1,1,1");

    }

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


?>
