<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 = "input_dp";
$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' >  Down Payment");
	include_once('keterangan.php');
	
	?>
	<br/>
	<div class="ui one column stackable grid" align="center">
		<div class="column">
			<h4 class="ui top attached block header">Payment</h4>
			<form action="actions/bayar_insert.php" method="POST" name="Form1">
			<input type="hidden" name="p" value="<?php echo $_GET[p];?>"/>
			<input type="hidden" name="idx" value="<?php echo $_GET[idx];?>"/>
			<input type="hidden" name="jenis" value="DEPOSIT"/>
			<input type="hidden" name="stat" value="001"/>
			<table width="100%" class="gridtable_form" border="1px">						
				<tr>
					<td>Payment Method</td>
					<td>: <?php echo query_carabayar("cab","001"," id='cab' class='cab'");?>
						<input type="text" name="no_kartu" value="" id="no_kartu" class="no_kartu" placeholder="No. Kartu" />
					</td>
					
					<td>Bill Amount</td>
					<td>: <input type="text" name="hrg1" id="hrg1" value="<?php echo $hrg_kamar;?>" class="auto" data-a-sep="," data-a-dec="."  >  </td>
					
					<td>Amount</td>
					<td>: <input type="text" name="bayar" id="bayar" value="<?php echo $hrg_kamar;?>" class="auto" data-a-sep="," data-a-dec="." style="background-color: #f1f876" >  </td>
					
				</tr>
				<tr>
					<td>Customer</td>
					<td>: <input type="text" name="nm_pembayar" id="nm_pembayar" size="25" value="<?php echo ucwords(strtolower($d->nm_lengkap)); ?>" ></td>
					
					<td>Materai (Rp.)</td>
					<td>: <input type="text" name="hrg_materai" id="hrg_materai" value="0,00" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" ></td>
					
					<td>Residue / Return</td>
					<td>: <input type="text" name="sisa" id="sisa" value="0" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" ></td>
				</tr>
				<tr>
					<td>Materai</td>
					<td>: <?php echo query_materai("materai","001"," OnChange=\"CekMaterai(this.value);\"");?></td>
					
					<td>Bill Total</td>
					<td>: <input type="text" name="hrg_tagihan" id="hrg_tagihan" value="<?php echo $hrg_kamar;?>" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" ></td>
					<input type="hidden" name="totag" id="totag" value="<?php echo $hrg_kamar;?>" />
					<input type="hidden" name="tax" value="0" />
					<input type="hidden" name="js_serv" value="0" />
					<input type="hidden" name="diskon" value="0" />
					
					<td>&nbsp;</td>
					<td>&nbsp; <input type="submit" value="Save" id="save"></td>
				</tr>
			</table>
			</form>
		</div>
	</div>
	<br/>
	<table width="90%" align="center" class="gridtable_form">
				<tr>
					<th>No</th>
					<th>&nbsp;</th>
					<th>Payment Date</th>
					<th>No. Check</th>
					<th>Total</th>
				</tr>
				<tr>
					<th colspan="5"><hr class="line_kw" /></th>
				</tr>
				<?php 
				$sql = "select * from tbl_pembayaran WHERE jns_bayar = 'DEPOSIT' and no_booking = '".$_GET[idx]."' ";
				$r = mysql_query($sql);
				$n = mysql_num_rows($r);
				
				$no = 1;

			while ($row = mysql_fetch_array($r)) {
				?>
				<tr>
					<td align="center"><?php echo $no++;?></td>
					<td align="center"><a href="javascript: cetakDP('<?php echo $_GET[idx];?>','<?php echo $row[no_kwitansi];?>')"><img src="images/print-icon1.png"></a></td>
					<td align="center"><?php echo $row[tgl_bayar];?></td>
					<td align="center"><?php echo $row[no_kwitansi];?></td>
					<td align="right"><?php echo number_format($row[jml_bayar],2,',','.');?></td>
				</tr>
				<?php } ?>
			</table>
<script language='JavaScript'>
	function cetakDP(tag, tag1) {
	    sWin = window.open('includes/cetak_dp.php?idx='+tag+'&kw='+tag1, 'xWin',
	 	'top=0,left=0,width=1200,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
	}
	
	function CekMaterai(tag){
		var harga = $("#hrg1").val();
		var harga1 = harga.replace(",","");
		var harga2 = harga1.replace(",","");
		var harga3 = parseInt(harga2.replace(".",","));
		//alert(harga1);
		if(tag == "002"){
			tagihan = numeral(harga3 + 3000).format('0,0.00');			
			$("#hrg_materai").val('3,000.00');
			$("#hrg_tagihan").val(tagihan);
			$("#bayar").val(tagihan);
			$("#totag").val(harga3 + 3000);
		} else if (tag == "003"){
			tagihan = numeral(harga3 + 6000).format('0,0.00');
			$("#hrg_materai").val('6,000.00');
			$("#hrg_tagihan").val(tagihan);
			$("#bayar").val(tagihan);
			$("#totag").val(harga3 + 6000);
		} else {
			tagihan = numeral(harga3).format('0,0.00');
			$("#hrg_materai").val('0.00');
			$("#hrg_tagihan").val(tagihan);
			$("#bayar").val(tagihan);
			$("#totag").val(harga3);
		}
	}
	
	$(function(){
            
    $('#bayar').keyup(function(){
    	var totag = parseInt($("#totag").val());
    	var harga = $("#bayar").val();
		var harga1 = harga.replace(",","");
		var harga2 = harga1.replace(",","");
		var harga3 = parseInt(harga2.replace(".",","));
         jml = totag - harga3;
         $("#sisa").val(jml);
         if(totag>=harga3){
		 	jml = totag - harga3;
        	 $("#sisa").val(jml);
        	 $("#save").show();
        }else{
        	 $("#sisa").val(jml);
			 $("#save").hide();
		}
         
    });
    
    $('#cab').change(function(){
    	var cab = $("#cab").val();
    		
		if(cab == "001"){
			$("#no_kartu").attr('readonly','readonly');
			$("#no_kartu").val('');
		} else {
			//$("#no_kartu").attr('readonly','');
		}
         
         
    });
    
});
</script>
	<?php
} else {
	title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Guest List");
	
?>
<br/>
<form>
<input type="hidden" name="p" value="input_dp"/>
<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. Guest</td>
		<td class="gridtable_th" align="center">Date Check in</td>
		<td class="gridtable_th" align="center">Status Guest</td>
		<td class="gridtable_th" align="center">Room</td>
		<td class="gridtable_th" align="center">Guest</td>
		<td class="gridtable_th" align="center">Address</td>
		<td class="gridtable_th" align="center">No.Hp & Email</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">&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>
	</tr>
	<?php
	$sql = "select distinct 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'
			left join tbl_transaksi e on e.no_booking = a.id_booking
			left join tbl_room f on f.id = e.item_id and e.jns_trans = 'ROOM' and e.status_trans = 1
			where  
			status_booking != 'cekout' and upper(id_booking) like '%".strtoupper($_GET[kd_book])."%' and
			upper(a.nm_lengkap) like '%".strtoupper($_GET[nama])."%' and (upper(a.alamat) like '%".strtoupper($_GET[alamat])."%'
			or upper(a.kota) like '%".strtoupper($_GET[alamat])."%' or upper(a.kd_pos) like '%".strtoupper($_GET[alamat])."%'
			or upper(d.keterangan) like '%".strtoupper($_GET[alamat])."%')  ";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;

while ($row = mysql_fetch_array($r)) {
	$tgl_cekin = getFromTable("select tgl_trans from tbl_transaksi where no_booking = '".$row[id_booking]."' and jns_trans = 'ROOM' and status_trans = 1 ");
	if ($tgl_cekin != NULL){ $ket = "Check In"; } else { $ket = "Booking"; }
	?>
	<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($tgl_cekin)); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($ket)); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[no_room]." - ".$row[keterangan])); ?></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>
	</tr>
	<?php } ?>
</table>
</form>
<br/>
<?php
title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Guest Banquet List");
?>
<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">Banquet ID</td>
			<td class="gridtable_th" align="center">Date</td>
			<td class="gridtable_th" align="center">Time Usage</td>
			<td class="gridtable_th" align="center">Name</td>
			<td class="gridtable_th" align="center">Address</td>
			<td class="gridtable_th" align="center">Hp & Email</td>
			<td class="gridtable_th" align="center">Status</td>
			<td class="gridtable_th" align="center">Package</td>
		</tr>
		<tr>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center"><input type="text" name="no_book" size="10" value="<?php echo $_GET[no_book]; ?>"></td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center"><input type="text" name="nama" size="10" 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" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
		</tr>
	<?php
	$sql = "select * from tbl_banquet where status in ('booking','checkin')
	and upper(no_banquet) like '%". strtoupper($_GET[no_book]) ."%' 
	and upper(nm_pemesan) like '%". strtoupper($_GET[nama]) ."%' 
	and upper(alamat) like '%". strtoupper($_GET[alamat]) ."%'";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;
	while ($row = mysql_fetch_array($r)) { 
	$lay_id = getFromTable("select item_id from tbl_transaksi where no_booking = '".$row[no_banquet]."' and jns_trans = 'PAKET' ");
	$lay_nm = getFromTable("select nm_layanan from tbl_layanan where id = ".$lay_id." ");
	
	?>
		<tr>
			<td class="gridtable_td" align="center"><?php echo $no++; ?></td>
			<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&idx=".$row[no_banquet];?>" title="Add Room"><?php echo $row[no_banquet]; ?></a></td>
			<td class="gridtable_td" align="center"><?php echo $row[tgl_pakai]; ?></td>
			<td class="gridtable_td" align="center"><?php echo $row[wkt_pakai]; ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($row[nm_pemesan])); ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($row[alamat]." ".$row[kota])); ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($row[no_tlpn]." / ".$row[email])); ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($row[status])); ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($lay_nm)); ?></td>
		</tr>
	<?php } ?>
	</table>
<?php } ?>