<script type="text/javascript" src="js/autoNumeric.js"></script>
<script type="text/javascript" src="js/numeral.js"></script>
<script type="text/javascript">
	jQuery(function($) {
	    $('.auto').autoNumeric('init');
	});
	
	
</script>
<style>
	.auto {
		text-align:right;
	}
</style>
<?php
$PID = "casher_retur";
$SC = $_SERVER["SCRIPT_NAME"];

require_once("lib/dbconn.php");
require_once("lib/form.php");
require_once("lib/functions.php");



if(isset($_GET[idx])){
	title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  retur downpayment");
	include_once('keterangan.php');
	
	?>
	<br/>
	<div class="ui one column stackable grid" align="center">
		<div class="column">
			<h4 class="ui top attached block header">Retur Downpayment</h4>
			<form action="actions/retur_insert.php" method="POST">
			<input type="hidden" name="idx" value="<?php echo $_GET[idx];?>"/>
			<input type="hidden" name="jenis" value="RETUR"/>
			<table width="100%" class="gridtable_form" border="1px">						
				<tr>
					<td>Payment Method</td>
					<td>: <?php echo query_carabayar("cab","001");?></td>
					
					<td>Downpayment Amount</td>
					<td>: <input type="text" name="downpay" id="downpay" value="<?php echo $downpay;?>" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" >  </td>
							
					<td>Residue / Return</td>
					<td>: <input type="text" name="bayar" id="bayar" value="<?php echo $downpay;?>" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" ></td>
				</tr>
				<tr>
					<td>Receiver Name</td>
					<td>: <input type="text" name="nm_pembayar" id="nm_pembayar" size="25" value="<?php echo ucwords(strtolower($d->nm_lengkap)); ?>" ></td>
					
					<td>Discount / TAX (% / Rp.)</td>
					<td>: <input type="text" name="persen" id="persen" maxlength="3" size="3" value="0" data-a-sep="," data-a-dec="." class="auto" > / 
						<input type="text" name="diskon" id="diskon" value="0" class="auto" data-a-sep="," data-a-dec="." size="12" >
					</td>
					
					<td>&nbsp;</td>
					<td>&nbsp; 
					<?php if($downpay > 0) { ?>
					<input type="submit" value="Retur">
					<?php } ?>
					</td>
				</tr>
				<tr>
					<td colspan="8" class="ui warning message">
						<i><b>Note: Downpayment = Total Downpayment - (Return + Materai)</b></i>
					</td>
				</tr>
			</table>
			</form>
		</div>
	</div>
<script language='JavaScript'>
	
	$(function(){
            
    $('#persen').keyup(function(){
    	var persen = $("#persen").val();
    	var downpay = $("#downpay").val();
		var downpay1 = downpay.replace(",","");
		var downpay2 = downpay1.replace(",","");
		var downpay3 = parseInt(downpay2.replace(".",","));
         
         if (persen > 100 || persen < 0){
		 	alert('Persen diskon tidak boleh melebihi 100%!');
		 	$("#persen").val(0.00);
		 	$("#diskon").val(0.00);
		 	$("#bayar").val(downpay3);
		 } else {
		 	dis = (downpay3 * persen) / 100;
		 	bayar = downpay3 - dis;
		 	$("#diskon").val(dis);
		 	$("#bayar").val(bayar);		 	
		 }
         
    });

});
</script>
	<?php
} else {
	title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  List Booking");
	
?>
<br/>
<form>
<input type="hidden" name="p" value="casher_retur"/>
<input type="submit" style="display: none;"/>
<table id='mytable' class="gridtable tableWithFloatingHeader" width="100%" border="1px">
	<tr>
		<td class="gridtable_th" align="center">No</td>
		<td class="gridtable_th" align="center">No. Booking</td>
		<td class="gridtable_th" align="center">Tgl. Booking</td>
		<td class="gridtable_th" align="center">Tgl. Cek-In</td>
		<td class="gridtable_th" align="center">Nama</td>
		<td class="gridtable_th" align="center">Alamat</td>
		<td class="gridtable_th" align="center">No.Hp & Email</td>
		<td class="gridtable_th" align="center">Jenis Kamar</td>
		<td class="gridtable_th" align="center">Uang Muka</td>
	</tr>
	<tr>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th" align="center"><input type="text" size="10" name="kd_book" value="<?php echo $_GET[kd_book];?>"></td>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th" align="center"><input type="text" name="nama" value="<?php echo $_GET[nama];?>"></td>
		<td class="gridtable_th" align="center"><input type="text" name="alamat" value="<?php echo $_GET[alamat];?>"></td>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th">&nbsp;</td>
	</tr>
	<?php
	$sql = "select a.*, b.keterangan as inisial, c.*, d.keterangan as negara
			from tbl_booking a 
			JOIN tbl_referensi b ON b.id = a.kd_inisial and b.kd = 'INS'
			JOIN tbl_referensi c ON c.id = a.jns_room and c.kd = 'ROM'
			join tbl_referensi d on d.id = a.kd_negara and d.kd = 'NGR'
			where status_booking = 'booking' and upper(id_booking) like '%".strtoupper($_GET[kd_book])."%' and
			upper(a.nm_lengkap) like '%".strtoupper($row[nm_lengkap])."%' and (upper(a.alamat) like '%".strtoupper($row[alamat])."%'
			or upper(a.kota) like '%".strtoupper($row[kota])."%' or upper(a.kd_pos) like '%".strtoupper($row[kd_pos])."%'
			or upper(d.keterangan) like '%".strtoupper($row[negara])."%')  ";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;

while ($row = mysql_fetch_array($r)) {
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&idx=$row[id_booking]";?>"><?php echo $row[id_booking]; ?></a></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[tgl_booking])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[tgl_cekin])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[inisial]." ".$row[nm_lengkap])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[alamat]." ".$row[kota]." ".$row[kd_pos]." ".$row[negara])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[no_hp]." / ".$row[email])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[keterangan])); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[down_paymen],2,",","."); ?></td>
	</tr>
	<?php } ?>
</table>
</form>
<?php } ?>