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

$indicator_Query = "SELECT A.*
				  FROM i_kawalan A
				  WHERE A.id_program = 2";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $id_program, PDO::PARAM_INT);
$PDO_stmt->execute();
$kawalan_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$kawalanyear = $kawalan_List['tahun_bayaran_tunai'];
?>	

<style>
.select2-container--default .select2-results__option[aria-disabled=true] {
    display: none;
}
</style>
<link href="//www.amcharts.com/lib/3/plugins/export/export.css" rel="stylesheet" type="text/css" />
<!--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">LAPORAN PENERIMA & PERUNTUKAN BAYARAN TAHUN <?=$kawalanyear?></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="" data-target="#collapseThree8">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Tapisan</div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="collapseThree8" class="" data-parent="#accordionExample8">
						<div class="card-body"><br>
							<form id="tapisan_form">
							<?php
								$Query = "SELECT id_program AS id, desk_program as name
											FROM i_program
											WHERE aktif = 1
											AND id_program IN (1,2,3,4,5,7)
											ORDER BY susunan";
								createCheckBox_sql($PDO, 'Program', $Query, 'bayaran_program', '1,2,3,4,7', '', 6, 'desk_', 2, 12, $readonly, true);
								
								$my_array = [];
								$my_array[] = array(1, 'Dokumen Peruntukan Bayaran');
								$my_array[] = array(2, 'Dokumen Jumlah Peruntukan');
								$my_array[] = array(3, 'Dokumen Jumlah Penerima Ikut Tahun');
								createDropDown_Array('Dokumen', $my_array, 'bayaran_dokumen', 1, 'Pilih Jenis Dokumen', 6, 2, 12, $readonly);
								
								createThn('Tahun', 'bayaran_dari', $kawalanyear, 2, 12, 2, 1, 1, 0);
								//createThn('Tahun Hingga', 'bayaran_hingga', date('Y'), 2, 12, 2, $readonly, 20, 0);
							?>
							</form>
							<div style="text-align:center">
								<input type="hidden" id="cetakInput">
								<input type="hidden" id="cetakInputValue">
								<button type="button" class="btn btn-primary mr-5" id="showBtn">Jana Statistik Peruntukan Bayaran</button>
								<button type="button" class="btn btn-primary mr-5" id="janaBtn">Jana Dokumen</button>
							</div>
						</div>
					</div>
				</div>
			</div>
			
			<div class="card">
				<div class="col-md-12">
					<div id="maklumat_div" style="overflow-x:auto;"></div>
				</div>
			</div>
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');
?>

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

	$('#daerah_sc').change(function(){
		$('.all_daerah').attr('disabled', 'disabled');
		$('.daerah_' + $('#daerah_sc').val()).removeAttr('disabled');
	});

	$('#ajax-modal').on('shown.bs.modal', function () {  // this is to clear modal cache each time modal load
	 $(this).removeData('bs.modal');
	}); 
	
	$('#bayaran_program_check_uncheck').change(function(){
		$('.bayaran_program_myCheckBox').prop('checked', this.checked);
	});
	$('#bayaran_program_check_uncheck').trigger('change');
	
	//print function
	$('#printExcel, #printPdf').click(function() {
		printFunc($('#table_name').val(), $(this).attr("value"), "normalPrint.php", $('#script_base_name').val(), $('#table_title').val(), $('#table_header').val());
	});
	/*
	$('#bayaran_dokumen').change(function(){
		if($('#bayaran_dokumen').val() == 3)
		{
			$('#bayaran_dari_div').show();
			//$('#bayaran_hingga_div').show();
		}
		else
		{
			$('#bayaran_dari_div').hide();
			//$('#bayaran_hingga_div').hide();
		}
	});
	*/
	$('#bayaran_dokumen').trigger('change');
	
	$('#janaBtn').click(function() {
		var indicator_list = [[]];
		indicator_list.push(['bayaran_dokumen', 'Jenis Dokumen', 'dd']);
		
		if (checkInput(indicator_list))
		{
			var allCheck = $('#tapisan_form input:checkbox').serialize();
			allCheck = allCheck.replace(/bayaran\_program\_check\_uncheck=0\&/g, "");
			allCheck = allCheck.replace(/bayaran\_program\_check\_uncheck=1\&/g, "");
			allCheck = allCheck.replace(/\&/g, ",");
			allCheck = allCheck.replace(/bayaran\_program=/g, "");
			
			var dataObject = [];
			dataObject['program'] = allCheck;
			dataObject['bayaran_dari'] = $('#bayaran_dari_year').val();
			
			if($('#bayaran_dokumen').val() == 1)
			{
				post('la_bayaran-cetak_jumlah.php', dataObject);
			}
			else if($('#bayaran_dokumen').val() == 2)
			{
				post('la_bayaran-cetak_peruntukan.php', dataObject);
			} 
			else if($('#bayaran_dokumen').val() == 3)
			{
				post('la_bayaran-cetak_penerima.php', dataObject);
			} 
		}
	});
	
	$('#showBtn').click(function() {
		var allCheck = $('#tapisan_form input:checkbox').serialize();
		allCheck = allCheck.replace(/bayaran\_program\_check\_uncheck=0\&/g, "");
		allCheck = allCheck.replace(/bayaran\_program\_check\_uncheck=1\&/g, "");
		allCheck = allCheck.replace(/\&/g, ",");
		allCheck = allCheck.replace(/bayaran\_program=/g, "");
		
		var param = 'program=' + allCheck;
		param += '&bayaran_dari=' + $('#bayaran_dari_year').val();
		
		$('#showBtn').html("LOADING...");
		$('#showBtn').addClass('disabled');
		$('#maklumat_div').html("<h6>Sedang Jana Maklumat Peruntukan Bayaran ...</h6>");
		$.ajax({
		   type: "POST",
		   url: "la_bayaran-show_jumlah.php",
		   data: param,		   
		   success: function(res){
			   $('#maklumat_div').html(res);
				$('#showBtn').html("Jana Statistik Peruntukan Bayaran");
				$('#showBtn').removeClass('disabled');
		   }
		});
	});
	
	$('#janaBtn_peruntukan').click(function() {
		var allCheck = $('#tapisan_form input:checkbox').serialize();
		allCheck = allCheck.replace(/bayaran\_program\_check\_uncheck=0\&/g, "");
		allCheck = allCheck.replace(/bayaran\_program\_check\_uncheck=1\&/g, "");
		allCheck = allCheck.replace(/\&/g, ",");
		allCheck = allCheck.replace(/bayaran\_program=/g, "");
		console.log(allCheck);
		
		var dataObject = [];
		dataObject['program'] = allCheck;
		console.log(dataObject);
		post('la_bayaran-cetak_peruntukan.php', dataObject);
	});
	
});
</script>