<?php 
require('includes/header.php'); 
?>	

<style>
.select2-container--default .select2-results__option[aria-disabled=true] {
    display: none;
}
</style>
<!--begin::Content-->
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
	<!--begin::Subheader-->
	<div class="subheader py-2 py-lg-4 subheader-solid" id="kt_subheader">
		<div class="container-fluid d-flex align-items-center justify-content-between flex-wrap flex-sm-nowrap">
			<!--begin::Info-->
			<div class="d-flex align-items-center flex-wrap mr-2">
				<!--begin::Page Title-->
				<h5 class="text-dark font-weight-bold mt-2 mb-2 mr-5">Kemasukan Rekod Bayaran Tunai</h5>
				<!--end::Page Title-->
				<!--begin::Actions-->
				<div class="subheader-separator subheader-separator-ver mt-2 mb-2 mr-4 bg-gray-200"></div>
			</div>
			<!--end::Info-->
		</div>
	</div>
	<!--end::Subheader-->
	<!--begin::Entry-->
	<div class="d-flex flex-column-fluid">
		<!--begin::Container-->
		<div class="container">
			<div class="accordion accordion-solid accordion-panel accordion-svg-toggle" id="accordionExample8">
				<div class="card">
					<div class="card-header" id="headingThree8">
						<div class="card-title" data-toggle="collapse" data-target="#collapseThree8">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Kemasukan Rekod Bayaran Tunai</div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="collapseThree8" class="" data-parent="#accordionExample8">
						<div class="card-body" style="padding-top:10px">
							<form id="tapisan_form">
								<?php
									$myQuery = "
										SELECT i_program.id_program AS id, i_program.desk_program as name, i_kawalan.tahun_bayaran_tunai AS cTag1, i_bayaranfasa.desk_bayaranfasa AS cTag2, i_kawalan.tkh_cutoff_tunai AS cTag3
										FROM i_program
										LEFT JOIN i_kawalan ON i_kawalan.id_program = i_program.id_program
										LEFT JOIN i_bayaranfasa ON i_kawalan.id_bayaranfasa_tunai = i_bayaranfasa.id_bayaranfasa
										WHERE i_program.aktif = 1
										AND i_program.flag_eft = 1
										ORDER BY i_program.susunan
									";
									//createDropDown_sql($PDO, 'Program', $myQuery, 'tunai_program', 0, 'Sila Pilih Program', 6, 2, 12, $readonly);
									$myQuery_cmd = $PDO->prepare($myQuery);
									$myQuery_cmd->execute();
									$selectArray = [];
									while($result = $myQuery_cmd->fetch(PDO::FETCH_ASSOC)) {
										$temp = array($result['id'], $result['name']);
										//case for customtag
										for($num2 = 1; $num2 <= 3; $num2++)
										{
											if($result['cTag'.$num2] != ''){$temp[] = $result['cTag'.$num2];}
										}
										
										$selectArray[] = $temp;
									}
									createDropDown_Array('Program', $selectArray, 'tunai_program', 0, 'Sila Pilih Program', 6, 2, 12, $readonly);
									createLabels('Tahun Bayaran', 'tunai_tahun', '', '', 2, 6, 1, 12);
									createLabels('Fasa Bayaran', 'tunai_fasa', '', '', 2, 6, 1, 12);
									createLabels('Tarikh Cut Off', 'tunai_cutoff', '', '', 2, 6, 1, 12);
									
									if($my_details->user_level == 1 || $my_details->user_level == 3 || $my_details->user_daerah == 0)
									{
										createDropDown($PDO, 'Daerah', 'i_daerah', 'tunai_daerah', 0, 'Semua Daerah', 6, 2, 12, $readonly);
									}
									else
									{			
										$mydaerah = $my_details->user_daerah;
										
										$mySQL = "SELECT id_daerah AS id, desk_daerah AS name
												FROM i_daerah
												WHERE id_daerah = $mydaerah
												ORDER BY susunan";									
										createDropDown_sql($PDO, 'Daerah', $mySQL, 'tunai_daerah', $my_details->user_daerah, 'Sila Pilih Daerah', 6, 2, 12, $readonly);										
									}
								
									$Query = "SELECT id_dun AS id, desk_dun as name, id_daerah
												FROM i_dun
												WHERE aktif = 1
												ORDER BY susunan";
									$PDO_stmt = $PDO->prepare($Query);
									$PDO_stmt->execute();
									$dunArray = [];
									while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
									{
										$temp = array($result['id'], $result['name'], ' class="all_daerah daerah_'.$result['id_daerah'].'"');		
										$dunArray[] = $temp;
									}
									createDropDown_Array_Special('DUN', $dunArray, 'tunai_dun', 0, 'Semua DUN', 6, 2, 12, $readonly);
								?>
							</form>
							<div style="text-align:center;padding-top:20px">
								<button type="button" class="btn btn-primary" id="janaBtn">Mula Pembayaran</button>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--begin::Row-->
			<br>
			<div class="row" id="maklumatDiv" style="display:none">
				<div class="col-md-12">
					<div class="card">
						<div class="card-header" style="padding-bottom:0px">
							<div class="card-title">
								<h3 class="card-label">Maklumat Pembayaran</h3>
							</div>
						</div>
						<div class="card-body">
							<input type="hidden" id="bayaran_program_id">
							<input type="hidden" id="bayaran_daerah_id">
							<input type="hidden" id="bayaran_dun_id">
							<?php
								createLabels('Program', 'bayaran_program', '', '', 2, 6, 1, 12);
								createLabels('Tahun Bayaran', 'bayaran_tahun', '', '', 2, 6, 1, 12);
								createLabels('Fasa Bayaran', 'bayaran_fasa', '', '', 2, 6, 1, 12);
								createLabels('Tarikh Cut Off', 'bayaran_cutoff', '', '', 2, 6, 1, 12);
								createLabels('Daerah', 'bayaran_daerah', '', '', 2, 6, 1, 12);
								createLabels('DUN', 'bayaran_dun', '', '', 2, 6, 1, 12);
								
								$divSize = 12;
								$tbSize = 6;
								$labelsize = 2;
								$name = 'bayaran_kp';
								$label = 'No Kad Pengenalan';
								$placeholder = 'No Kad Pengenalan';
								echo '<div class="form-group row col-md-'.$divSize.'" id="'.$name.'_div">';
									echo '<label class="col-md-'.$labelsize.' col-form-label" id="'.$name.'_label">'.$label.'</label>';
									echo '<div class="col-md-'.$tbSize.'">';
									/*
										echo '<input type="text" class="form-control m-input" placeholder="'.$placeholder.'" id="'.$name.'" name="'.$name.'" value="'.$value.'"/>';
									echo '</div>';
									echo '<div class="col-md-2">';
										echo '<button type="button" class="btn btn-success" id="semakBtn">Semak</button>';
									echo '</div>';
									*/
									
										echo '<div class="input-group">';
											echo '<input type="text" style="margin-left:0px" class="form-control m-input numonly" placeholder="'.$placeholder.'" id="'.$name.'" name="'.$name.'" value="'.$value.'"/>';
											echo '<div class="input-group-append">';
												echo '<button type="button" class="btn btn-success" id="semakBtn">Semak</button>';
											echo '</div>';
										echo '</div>';
									
									echo '</div>';
								echo '</div>';
							?>
						</div>
					</div>
				</div>
			</div>
			<!--end::Row-->
			<?php
				createModal();
			?>
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');
?>

<script>
var digit = 12;
$('#bayaran_kp').keyup(function(){
	if(this.value.length == digit){
		$('#semakBtn').click();
	}
});

$(document).ready(function(){  

	/*$('#ajax-modal').on('shown.bs.modal', function () {  // this is to clear modal cache each time modal load
	 $(this).removeData('bs.modal');
	}); */
	
	$('#tunai_daerah').change(function(){
		$('.all_daerah').attr('disabled', 'disabled');
		$('.daerah_' + $('#tunai_daerah').val()).removeAttr('disabled');
		$('#tunai_dun').val(0);
		$('#tunai_dun').trigger("change");
	});
	$('#tunai_daerah').trigger('change');
	
	$('#tunai_program').change(function(){
		if($('#tunai_program').val() > 0)
		{
			var element = $(this).find('option:selected'); 
			var cTag1 = element.attr("cTag1"); 
			var cTag2 = element.attr("cTag2"); 
			var cTag3 = element.attr("cTag3"); 

			$('#tunai_tahun').html(cTag1); 
			$('#tunai_fasa').html(cTag2);
			$('#tunai_cutoff').html(cTag3);
		}
	});
	
	$('#janaBtn').click(function() {
		var check_List = [[]];
		check_List.push(['tunai_program', 'Program', 'dd']);
		check_List.push(['tunai_daerah', 'Daerah', 'dd']);
		//check_List.push(['tunai_dun', 'DUN', 'dd']);
		
		if (checkInput(check_List))
		{
			$('#maklumatDiv').show();
			$('#bayaran_program_id').val($("#tunai_program").val());			
			$('#bayaran_daerah_id').val($("#tunai_daerah").val());			
			$('#bayaran_dun_id').val($("#tunai_dun").val());	
			
			$('#bayaran_program').html($("#tunai_program option:selected").text());			
			$('#bayaran_tahun').html($("#tunai_tahun").html());			
			$('#bayaran_fasa').html($("#tunai_fasa").html());			
			$('#bayaran_cutoff').html($("#tunai_cutoff").html());			
			$('#bayaran_daerah').html($("#tunai_daerah option:selected").text());			
			$('#bayaran_dun').html($("#tunai_dun option:selected").text());
		}
		else
		{
			$('#maklumatDiv').hide();
		}
	});
	
	$('#semakBtn').click(function() {
		var check_List = [[]];
		check_List.push(['bayaran_kp', 'No Kad Pengenalan', 'tb']);
		
		if (checkInput(check_List))
		{
			loadMyModal('tu_senarai-semak.php?kp=' + $('#bayaran_kp').val() + '&tahun=' + $('#bayaran_tahun').html() + '&program=' + $('#bayaran_program_id').val() + '&daerah=' + $('#bayaran_daerah_id').val() + '&dun=' + $('#bayaran_dun_id').val(), '#ajax-modal');
		}
	});
	
});
</script>