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

$script_base = 'pht_listjanji';
$myID = fetch_postget_val('appointment',$_POST, $_GET);

$indicator_Query = "SELECT desk_ubat, quantity, ubat_remarks, price_ubat
				  FROM m_appointment_ubat
				  LEFT JOIN i_ubat ON m_appointment_ubat.id_ubat = i_ubat.id_ubat
				  WHERE id_vatklinik_appointment = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();
$ubat_List = [];
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$ubat_List[] = $result;
}

?>
<div class="modal-header">
	<h5 class="modal-title">Medicine List</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
					include_once ("general-appointment_detail.php");
				?>
				<div class="col-md-12">
					<h4><u>Doctor Check Result</u></h4>
					<?php echo ($appointment_List['check_result']==''?'Tiada':$appointment_List['check_result']); ?>
					<br>
					<br>
					<h4><u>Resit : <?=$appointment_List['resit_number'].' ('.$appointment_List['tkh_resit'].')'?></u></h4>
					<table class="table table-sm thead-dark table-hover">
						<tr style="background-color:lightgray">
							<th style="width:10%;text-align:center">#</th>
							<th style="width:30%">Nama Ubat</th>
							<th style="width:30%">Remarks</th>
							<th style="width:10%;text-align:center">Quantity</th>
							<th style="width:10%;text-align:right">Price</th>
							<th style="width:10%;text-align:right">Total</th>
						</tr>
						<?php
							if(count($ubat_List) > 0)
							{
								for($num = 0; $num < count($ubat_List); $num++)
								{
									echo '<tr>';
										echo '<td style="text-align:center">'.($num+1).'</td>';
										echo '<td>'.$ubat_List[$num]['desk_ubat'].'</td>';
										echo '<td>'.$ubat_List[$num]['ubat_remarks'].'</td>';
										echo '<td style="text-align:center">'.$ubat_List[$num]['quantity'].'</td>';
										echo '<td style="text-align:right">'.number_format($ubat_List[$num]['price_ubat'], 2).'</td>';
										echo '<td style="text-align:right">'.number_format($ubat_List[$num]['quantity'] * $ubat_List[$num]['price_ubat'], 2).'</td>';
									echo '</tr>';
								}
							}
							else
							{
								echo '<tr>';
									echo '<td colspan=4 style="text-align:center">Tiada Ubat Diperlukan</td>';
								echo '</tr>';
							}
							echo '<tr>';
								echo '<td></td>';
								echo '<td>Charge Rawatan</td>';
								echo '<td></td>';
								echo '<td></td>';
								echo '<td></td>';
								echo '<td style="text-align:right">'.number_format($appointment_List['rawatan_fee'], 2).'</td>';
							echo '</tr>';
							echo '<tr>';
								echo '<td colspan="5" style="text-align:right;">Jumlah</td>';
								echo '<td style="text-align:right;">'.number_format($appointment_List['total_resit'], 2).'</td>';
							echo '</tr>';
						?>
					</table>
				</div>
				<div class="col-md-12" style="text-align:center">
					<button type="button" class="btn btn-primary" id="resitBtn">Cetak Resit</button>
				</div>
			</div>
			
		</div>
	</form>
</div>
<div class="modal-footer">
	<?php
		//echo '<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>';
		if($readonly == 0)
		{
			//echo '<button type="button" class="btn btn-primary" id="appointment_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;
	});
	
	$('#resitBtn').click(function() {
		
		var dataObject = [];
		dataObject['appointment'] = "<?=$myID?>";
		post('pht_listjanji-ubat_list_resit.php', dataObject);
	});		
	
	
});		
</script>