<?php 
include_once ("includes/setup.inc.php");

$script_base = 'general-byr_ae';
$myID = fetch_postget_val('id',$_POST, $_GET);
$readonly = fetch_postget_val('readonly',$_POST, $_GET);
$temp = ($my_details->usr_id).'_'.time();

$indicator_Query = "SELECT A.*, B.desk_bayaranjenis, C.desk_carabayar, D.desk_bank, E.desk_bayaranfasa, F.no_sirianakemas, F.nama_anakemas, F.kpbaru_anakemas, F.nama_akaunanakemas
				  FROM m_bayaran_AE A
				  LEFT JOIN i_bayaranjenis B ON B.id_bayaranjenis = A.id_bayaranjenis
				  LEFT JOIN i_carabayar C ON C.id_carabayar = A.id_carabayar
				  LEFT JOIN i_bank D ON D.id_bank = A.id_bank
				  LEFT JOIN i_bayaranfasa E ON E.id_bayaranfasa = A.id_bayaranfasa
				  LEFT JOIN m_anakemas F ON F.id_anakemas = A.id_anakemas
				  WHERE A.id_anakemas = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

?>
<div class="modal-header">
	<h5 class="modal-title">Kemaskini Maklumat Pembayaran Program Anak Emas</h5>
	<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="closeBtn" name="closeBtn" ></button>
</div>
<div class="modal-body">
	<form action="javascript:;" class="form-horizontal" name="indicator_form" id="indicator_form">
		<div class="form-body">
			<div class="row">
				<?php
					createLabels('No. Siri', 'siri', $indicator_List['no_sirianakemas'], '', 3, 7, 0, 12);
					createLabels('Nama Anak Emas', 'nama', $indicator_List['nama_anakemas'], '', 3, 7, 0, 12);
					createLabels('No. MyKid', 'kp', $indicator_List['kpbaru_anakemas'], '', 3, 7, 0, 12);
					createLabels('Cara Bayar', 'cara', $indicator_List['desk_carabayar'], '', 3, 7, 0, 12);
					createLabels('Jumlah Bayaran', 'jum', 'RM '.$indicator_List['jum_bayaran'], '', 3, 7, 0, 12);
					createLabels('Tahun Bayaran', 'thn', $indicator_List['tahun_bayar'], '', 3, 7, 0, 12);
					createLabels('Pemilik Akaun', 'milik', $indicator_List['nama_akaunanakemas'], '', 3, 7, 0, 12);
					
					createDropDown($PDO, 'Bank', 'i_bank', 'id_bank', $indicator_List['id_bank'], 'Sila Pilih Bank', 7, 3, 12);
					createTextBox('No. Akaun', 'no_akaun', 'No. Akaun', $indicator_List['no_akaun'], 3, 0, 7, 12, '', 'numonly');
					createDropDown($PDO, 'Cara Bayar', 'i_carabayar', 'id_carabayar', $indicator_List['id_carabayar'], 'Sila Pilih Cara Bayar', 7, 3, 12);
					createDropDown($PDO, 'Kategori Bayaran', 'i_bayarankat', 'id_bayarankat', $indicator_List['id_bayarankat'], 'Sila Pilih Kategori Bayaran', 7, 3, 12);
					createDropDown($PDO, 'Fasa Bayaran', 'i_bayaranfasa', 'id_bayaranfasa', $indicator_List['id_bayaranfasa'], 'Sila Pilih Fasa Bayaran', 7, 3, 12);
					createDateTB('Tarikh Bayaran', 'tkh_bayar', 'Tarikh Bayaran',formatDate($indicator_List['tkh_bayar'], 'd M Y'), 3, 4, 0, 12);	
					createTextArea('Catatan', 'catatan', 'Catatan', $indicator_List['catatan'], 0, 3, 7, 12, 'text', 5);		
				?>
			</div>
		</div>
	</form>
</div>
<div class="modal-footer">
	<?php
		echo '<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>';
		echo '<button type="button" class="btn btn-primary" id="indicator_simpanBtn">Simpan</button>';
	?>
</div>

<script>
$(document).ready(function(){  

	$('.select2').select2({ width: '100%' }); 
	
	$('.numonly').keypress(function(evt){
		evt = (evt) ? evt : window.event;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if ((charCode >= 48 && charCode <= 57)) {
			return true;
		}
		return false;
	});	

	$('.myDatePicker').datepicker({
		autoclose: true,
		clearBtn: true,
		format: "dd M yyyy",
		todayHighlight: true,
		orientation: "bottom left",
		templates: {
			leftArrow: '<i class="la la-angle-left"></i>',
			rightArrow: '<i class="la la-angle-right"></i>'
		}
	});
	
	$('#indicator_simpanBtn').click(function() {
		var indicator_list = [[]];
		indicator_list.push(['id_bank', 'Bank', 'dd']);
		indicator_list.push(['no_akaun', 'No. Akaun', 'tb']);
		indicator_list.push(['id_bayaranfasa', 'Fasa Bayaran', 'dd']);
		indicator_list.push(['tkh_bayar', 'Tarikh Bayaran', 'tb']);
		indicator_list.push(['catatan', 'Catatan', 'tb']);
		
		if (checkInput(indicator_list))
		{
			$(this).prop("disabled",true);
			var param = $('#indicator_form').serialize();
			$.ajax({
				type: "POST", 
				url: "<?=$script_base?>_insert.php", 
				data: param+ '&id=' + "<?=$myID?>",

				success: function(res){
					if(res > 0)
					{
						swal.fire({
							text: "Berjaya Kemaskini Maklumat",
							icon: "success",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							//window.parent.reloadTable();
							window.location.reload();
							$("#closeBtn").click();
						});
					}
					else
					{
						swal.fire({
							text: "Error. " + res,
							icon: "error",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							$(this).prop("disabled",false);										
						});
					}
					
				} 
			});  //end ajax
		}
	});		
});		
</script>