<?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 if(RetRstField("SELECT fnid FROM txbankrcp_hdr WHERE ftbankrcp_no='{$_REQUEST['ftbankrcp_no']}'")) {
                          ?>
                          alert('No. RV sudah dipakai...\n System akan mengenerate No. RV kembali ...\n Silahkan ulangi proses penyimpanan...  ');
                          OnChangeDate_fdtrans_date();
                    <?php
                      }
                      else if(RetRstField("SELECT * FROM txbankrcp_hdr WHERE ftjournal_no='{$_REQUEST['ftjournal_no']}'")) {
                          ?>
                          alert('No. Jurnal sudah dipakai...\n System akan mengenerate No. jurnal kembali ...\n Silahkan ulangi proses penyimpanan...  ');
                          OnChangeDate_fdtrans_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');";
            $strAutoNumber2="ajax_do('query2.php?code=2&ftmodule_code=TN009&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftbankrcp_no&no_trans=ftbankrcp_no&table_name=txbankrcp_hdr');";
            $strAutoNumber3="ajax_do('query2.php?code=2&ftmodule_code=TN013&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftjournal_no&no_trans=ftjournal_no&table_name=txbankrcp_hdr');";

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

                                     }
                                       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();
                                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->ViewTable("vHRPembayaranPinjaman");
    $objAxpDB->FormSQL("select ftloan_payment_no, fdtrans_date, ftemployee_code, fcloan_payment_amount, ftloan_payment_description, ftnotes, fnstatus
                                 ,ftbankrcp_no,
                                             ftjournal_no,
                                             ftacc_no,
                                             fnpayment_method,
                                             ftgiro_no,
                                             fdgiro_date,
                                             fdgiro_cliring_date,
                                             fnstatus_giro
                            from txloan_payment_hdr");
    $objAxpDB->FormCaption(" No. Transaksi,Tgl. Transaksi,  Kode Pegawai, Total, Keterangan, Catatan, Status
                        ,
                                             No. Bank Masuk,
                                             No. Jurnal,
                                             Bank,
                                             Metode Pembayaran,
                                             No. Giro,
                                             Tgl. Giro,
                                             Tgl. Cair Giro,
                                             Status Giro");
    $objAxpDB->FormPosition("TL, TL, TL, BR, TL, BL, BR, TR,TR,TR,TR,TR,TR,TR,TR");
	 $objAxpDB->FormScript(10, "onChange=\"Changefnpayment_method();\"");
	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->GridAutoAdd(0, 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("ftemployee_code", "SELECT ftemployee_code, ftemployee_name FROM tlemployee", "ftemployee_code", "ftemployee_name", -1, False);
       $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->SetStatus("id, fnstatus");
    if ($objAxpDB->GetStatus("id") == "") {
            $objAxpDB->ButtonShow("baru, cetak_daftar, export_excel ,  tutup");
    } elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->ButtonShow("reset, simpan, tutup");
            $objAxpDB->FormLocked("0, 0, 0, 1, 0, 0,1,0,0,0,0,0,0,0,1");
            $objAxpDB->GridLocked(0, "1, 1, 1, 1,1,1,0");

    } elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
            $objAxpDB->ButtonShow("cetak, final,  batal, tutup");
             $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1,1,1,1,1,1,1,1,1,1");
            $objAxpDB->GridLocked(0, "1, 1, 1, 1,1,1,0");
   } 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");
           $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,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();
                    $_REQUEST['id']=0.5;
                       $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=2 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();


?>
