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

$program_sc = fetch_postget_val('program_sc',$_POST, $_GET);
$daerah_sc = fetch_postget_val('daerah_sc',$_POST, $_GET);
$dun_sc = fetch_postget_val('dun_sc',$_POST, $_GET);
$tahun_sc_year = fetch_postget_val('tahun_sc_year',$_POST, $_GET);

$PDO_stmt = $PDO->prepare("SELECT * FROM i_program WHERE id_program = ?");
$PDO_stmt->bindValue(1, $program_sc, PDO::PARAM_INT);
$PDO_stmt->execute();
$program_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$PDO_stmt = $PDO->prepare("SELECT * FROM i_daerah WHERE id_daerah = ?");
$PDO_stmt->bindValue(1, $daerah_sc, PDO::PARAM_INT);
$PDO_stmt->execute();
$daerah_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$PDO_stmt = $PDO->prepare("SELECT * FROM i_dun WHERE id_dun = ?");
$PDO_stmt->bindValue(1, $dun_sc, PDO::PARAM_INT);
$PDO_stmt->execute();
$dun_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
?>
<div class="modal-header">
	<h5 class="modal-title">Modal Cetak Baucer</h5>
	<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="baucer_closeBtn" name="baucer_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('Program', 'baucer_program', $program_List['desk_program'], '', 3, 7, 1, 12);
					createLabels('Daerah', 'baucer_daerah', $daerah_List['desk_daerah'], '', 3, 7, 1, 12);
					createLabels('DUN', 'baucer_dun', $dun_List['desk_dun'], '', 3, 7, 1, 12);
					createDateTB('Tarikh Majlis Dari', 'baucer_tkh', 'Tarikh Majlis Dari', '', 3, $readonly, 7, 12);
					createDateTB('Tarikh Majlis Hingga', 'baucer_tkh_hingga', 'Tarikh Majlis Hingga', '', 3, $readonly, 7, 12);
					createTimeTB('Masa Dari', 'baucer_from', 'Masa Dari', '', 3, $readonly, 7, 12);
					createTimeTB('Masa Hingga', 'baucer_to', 'Masa Hingga', '', 3, $readonly, 7, 12);
					$myArray = [];
					$myArray[] = array(1, 'Di Pejabat');
					$myArray[] = array(2, 'Di Bank');
					createDropDown_Array('Tempat', $myArray, 'baucer_tempat', '', 'Sila Pilih Tempat', 7, 3, 12, $readonly);
					
					$myQuery = "
						SELECT id_tempattunai AS id, alamat_tempattunai as name
						FROM i_tempattunai
						WHERE aktif = 1
						AND id_daerah = $daerah_sc
						ORDER BY susunan
					";
					createDropDown_sql($PDO, 'Alamat Pejabat', $myQuery, 'baucer_alamat', 0, 'Sila Pilih Alamat Pejabat', 7, 3, 12, $readonly);
					
					//createTextArea('Alamat', 'baucer_alamat', 'Alamat Pejabat', '', $readonly, 3, 7, 12, '', 10);		
					createLabels('Alamat Bank', 'baucer_alamatbank', $dun_List['alamat_bank'], '', 3, 7, 1, 12);	
				?>
			</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">Cetak Baucer</button>';
	?>
</div>

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

	$('.select2').select2({ width: '100%' });
	
	$('.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>'
		}
	});
	
	$('.myTimePicker').timepicker({
		minuteStep: 1,
		defaultTime: '',
		showSeconds: false,
		showMeridian: true,
		snapToStep: true
	});
	
	$('#baucer_tempat').change(function(){
		if($('#baucer_tempat').val() == 1)
		{
			$('#baucer_alamat_div').show();
			$('#baucer_alamatbank_div').hide();
		}
		else if($('#baucer_tempat').val() == 2)
		{
			$('#baucer_alamat_div').hide();
			$('#baucer_alamatbank_div').show();
		}
		else
		{
			$('#baucer_alamat_div').hide();
			$('#baucer_alamatbank_div').hide();
		}
	});
	$('#baucer_tempat').trigger('change');
	
	$('#indicator_simpanBtn').click(function() {
		var indicator_list = [[]];
		indicator_list.push(['baucer_tkh', 'Tarikh Majlis Dari', 'tb']);
		indicator_list.push(['baucer_tkh_hingga', 'Tarikh Majlis Hingga', 'tb']);
		indicator_list.push(['baucer_from', 'Masa Dari', 'tb']);
		indicator_list.push(['baucer_to', 'Masa Hingga', 'tb']);
		indicator_list.push(['baucer_tempat', 'Tempat', 'dd']);
		if($('#baucer_tempat').val() == 1)
		{
			indicator_list.push(['baucer_alamat', 'Alamat', 'dd']);
		}
		
		if (checkInput(indicator_list))
		{
			var dataOption = [];
			dataOption.program_sc = "<?=$program_sc?>";
			dataOption.daerah_sc = "<?=$daerah_sc?>";
			dataOption.dun_sc = "<?=$dun_sc?>";
			dataOption.tahun_sc_year = "<?=$tahun_sc_year?>";
			dataOption.baucer_tkh = $('#baucer_tkh').val();
			dataOption.baucer_tkh_hingga = $('#baucer_tkh_hingga').val();
			dataOption.baucer_from = $('#baucer_from').val();
			dataOption.baucer_to = $('#baucer_to').val();
			dataOption.baucer_tempat = $('#baucer_tempat').val();
			if($('#baucer_tempat').val() == 1)
			{
				dataOption.baucer_alamat = $("#baucer_alamat option:selected").text();
			}
			else
			{
				dataOption.baucer_alamat = $('#baucer_alamatbank').html();
			}
			console.log(dataOption);
			post('general-pemohon_list_template2.php', dataOption);
		}
	});		
});		
</script>
