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

<!--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">Senarai Temu Janji</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 collapsed" data-toggle="collapse" data-target="#collapseThree8">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Tapisan Tarikh Temu Janji</div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="collapseThree8" class="collapse" data-parent="#accordionExample8">
						<div class="card-body" style="padding-top:20px">
							<?php
								$klinik = 1;
								createDropDown($PDO, 'Klinik Vaterinar', 'i_vatklinik', 'filter_klinik_vat', $klinik, 'Pilih Klinik Vaterinar', 7, 3, 12, $readonly, 'nama_');
								createDateTB('Tarikh Dari', 'filter_tkh_from', 'Tarikh Dari', date('d-m-Y'), 3, $readonly, 7, 12);
								createDateTB('Tarikh Hingga', 'filter_tkh_to', 'Tarikh Dari', date('d-m-Y'), 3, $readonly, 7, 12);
							?>
							<hr>
							<div style="text-align:center;padding-bottom:20px">
								<button type="button" class="btn btn-primary" id="semakBtn">Semak</button>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--begin::Row-->
			<div class="row">
				<?php
					$tbColumn = array();
					$tbColumn[] = array('Bil', 5);
					$tbColumn[] = array('Tarikh', 20);
					$tbColumn[] = array('Masa', 20);
					$tbColumn[] = array('Nama Pemilik', 20);
					$tbColumn[] = array('No. KP Baru', 20);
					$tbColumn[] = array('Nama Haiwan Peliharaan', 20);
					$tbColumn[] = array('Remarks', 20);
					$tbColumn[] = array('No Resit', 20);
					$tbColumn[] = array('Status', 20);
					$tbColumn[] = array('Tindakan', 0);
					
					$userBtn = '';
					$userBtn = '<a class="btn btn-primary font-weight-bolder" onclick="loadTambah()"><span class="svg-icon svg-icon-md">'.$tambahBtnSvg.'</span>Tambah Temu Janji</a>';						
					
					createTable('indicator_table', $tbColumn, 'Pengurusan Temu Janji Klinik', 'Senarai Temu Janji', 0, $userBtn, 'ajax-modal', 12);
					//createTable('indicator_table', $tbColumn, 'Pengurusan Temu Janji Klinik', 'Senarai Temu Janji', 0, $userBtn, 'ajax-modal', 12);
				?>
				
			</div>
			<!--end::Row-->
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');
?>


<script>
var ajaxUrl = $('#script_base_name').val() + "-ajax.php";
var selectedKlinik = 0;
function getData()
{
	return {
		sqlOnly: 0,
		klinik_vat: $('#filter_klinik_vat').val(),
		tkh_from: $('#filter_tkh_from').val(),
		tkh_to: $('#filter_tkh_to').val(),
	};
}

function deleteFunction(id, desk)
{
	Swal.fire({
        title: "Pastikah Anda?",
        text: "Pastikah untuk selesaikan '" + desk + "' ?",
        icon: "warning",
        showCancelButton: true,
        confirmButtonText: "Ya",
		cancelButtonText: "Tidak",
    }).then(function(result) {
		if (result.value) {
			$.ajax({
			   type: "POST",
			   url: $('#script_base_name').val() + "-aktif.php",
			   data: 'id=' + id,
			   
			   success: function(res){
					swal.fire({
						text: "Berjaya selesaikan " + desk + ".",
						icon: "success",
						buttonsStyling: false,
						confirmButtonText: "OK!",
						customClass: {
							confirmButton: "btn font-weight-bold btn-light-primary"
						}
					}).then(function() {
						reloadTable();
					});
			   
			   }
		   });  //end ajax
		}
	});
}

function loadTambah()
{
	loadMyModal('pht_listjanji-tambah.php?klinik=' + selectedKlinik, '#ajax-modal');
}

function loadLink(is_popup, link)
{
	if(is_popup)
	{
		loadMyModal(link, '#ajax-modal');
	}
	else
	{
		// similar behavior as clicking on a link
		window.location.href = link;
	}
}

function reloadTable()
{
	$('#' + $('#table_name').val() + '_bigCardLabel').html('Pengurusan Temu Janji : ' + $('#filter_klinik_vat option:selected').text());
	$('#' + $('#table_name').val() + '_smallCardLabel').html('Senarai Temu Janji : ' + $('#filter_tkh_from').val() + (($('#filter_tkh_from').val() == $('#filter_tkh_to').val()) ? '':' to ' + $('#filter_tkh_to').val()));
	selectedKlinik = $('#filter_klinik_vat').val();
	reinitTable($('#table_name').val(), this.ajaxUrl, this.getData(), 1, 0);
}

$(document).ready(function(){  

	$('#ajax-modal').on('shown.bs.modal', function () {  // this is to clear modal cache each time modal load
	 $(this).removeData('bs.modal');
	}); 
	
	//initTable($('#table_name').val(), ajaxUrl, getData(), 1, 0);
	reloadTable();
	//print function
	$('#printPdf').click(function() {
		printFunc($('#table_name').val(), $(this).attr("value"), "normalPrint-landscape.php", $('#script_base_name').val(), $('#table_title').val(), $('#table_header').val());
	});
	
	$('#printExcel').click(function() {
		printFunc($('#table_name').val(), $(this).attr("value"), "sen_penternak-excel.php", $('#script_base_name').val(), $('#table_title').val(), $('#table_header').val());
	});
	
	$('#semakBtn').click(function(){
		reloadTable();
	});
});
</script>