<link rel="stylesheet" type="text/css" href="../css/cetak.css">
<?php
@session_start();
require_once("../lib/dbconn.php");
require_once("../lib/form.php");
require_once("../lib/functions.php");

$r2 = mysql_query("select *
				from tbl_pnpm");
$n2 = mysql_num_rows($r2);
if($n2 > 0) $d2 = mysql_fetch_object($r2);
mysql_free_result($r2);

$r = mysql_query("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 a.id_booking = '".$_GET[idx]."' ");
$n = mysql_num_rows($r);
if($n > 0) $d = mysql_fetch_object($r);
mysql_free_result($r);

$id_room = getFromTable("select item_id from tbl_transaksi where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$_GET[idx]."' ");
$no_room = getFromTable("select no_room from tbl_room where id = $id_room ");


?>

<table width="100%">
 <tr>
		<td class="judul_kw"><?php echo $d2->nm_hotel; ?></td>
	</tr>
	<tr>
		<td class="judul1_kw"><?php echo $d2->alamat1; ?></td>
	</tr>
	<tr>
		<td class="judul1_kw"><?php echo $d2->alamat2; ?></td>
	</tr>
	<!--tr>
		<td class="judul_kw">Official Receipt</td>
	</tr-->
</table>
<hr class="line_kw"/>

<?php
If(isset($_GET[kw])){
	$r3 = mysql_query("select * from tbl_pembayaran
					where no_kwitansi = '".$_GET[kw]."' ");
	$n3 = mysql_num_rows($r3);
	if($n3 > 0) $d3 = mysql_fetch_object($r3);
	mysql_free_result($r3);
	
	//echo "select keterangan from tbl_referensi where kd = 'CAB' and id = '".$d3->cara_bayar."'";
	$cab = getFromTable("select keterangan from tbl_referensi where kd = 'CAB' and id = '".$d3->cara_bayar."'");
	?>
	<table width="100%" class="tbl_kw" border="0px">
		<tr>
			<th width="20%">No.</th>
			<td width="40%">: <?php echo $_GET[kw]; ?></td>
			<td width="5%">&nbsp;</td>
			<td width="5%">&nbsp;</td>
			<th width="10%"><?php echo ucwords(strtolower($d2->kota)); ?>,</th>
			<td width="20%"><?php echo date("d-m-Y"); ?></td>
		</tr>
		<tr>
			<th >Customer</th>
			<td >: <?php echo $d->inisial." ".$d3->nm_pembayar; ?></td>
			<td >&nbsp;</td>
			<td >&nbsp;</td>
			<th >&nbsp;</th>
			<td >&nbsp;</td>
		</tr>
		<?php 
		$id = explode("-",$_GET[idx]);
		
		if ($id[0] == "BQ"){
			$qty = 1;
			$harga = getFromTable("select a.hrg_layanan from tbl_layanan a
						join tbl_transaksi b on b.item_id = a.id and b.jns_trans = 'PAKET'
						where b.no_booking = '".$_GET[idx]."'");
			
		} else {
			$qty = getFromTable("select lama_inap from tbl_booking where id_booking = '".$_GET[idx]."'");
			$harga = $d->harga;
		}
		$paket = getFromTable("select a.nm_layanan from tbl_layanan a
		join tbl_transaksi b on b.item_id = a.id and b.jns_trans = 'PAKET'
		where b.no_booking = '".$_GET[idx]."'");
		
		if ($id[0] == "BQ"){ 
		$no_room = $paket;
		?>
		<tr>
			<th >Package</th>
			<td >: <?php echo $paket; ?></td>
			<td >&nbsp;</td>
			<td >&nbsp;</td>
			<th >&nbsp;</th>
			<td >&nbsp;</td>
		</tr>
		<?php } else { ?>
		<tr>
			<th >Room Type</th>
			<td >: <?php echo $no_room." - ".$d->keterangan; ?></td>
			<td >&nbsp;</td>
			<td >&nbsp;</td>
			<th >&nbsp;</th>
			<td >&nbsp;</td>
		</tr>
		<?php } ?>
		<tr>
			<th >Date</th>
			<td >: <?php echo $d3->tgl_bayar; ?></td>
			<td >&nbsp;</td>
			<td >&nbsp;</td>
			<th >&nbsp;</th>
			<td >&nbsp;</td>
		</tr>
		<tr>
			<th >Payment Method</th>
			<td >: <?php echo $cab." ".$d3->no_kartu; ?></td>
			<td >&nbsp;</td>
			<td >&nbsp;</td>
			<th >&nbsp;</th>
			<td >&nbsp;</td>
		</tr>
	</table>
	<br/>

	<table width="100%" class="rincian" >
		<tr>
			<th class="rincian_th" width="5%">No</th>
			<th class="rincian_th" colspan="2">Item</th>
			<th class="rincian_th" width="5%">Qty</th>
			<th class="rincian_th">Amount</th>
		</tr>
		
		<tr>
			<td class="rincian_td" align="center">1.</td>
			<td class="rincian_td" colspan="2">Down Payment <?php echo $no_room." - ".$d->keterangan; ?> @<?php echo number_format($harga,0,",","."); ?></td>
			<td class="rincian_td" align="center"> <?php echo $qty; ?> </td>
			<td class="rincian_td" align="right"><?php echo number_format($harga * $qty,0,",","."); ?></td>
		</tr>
		
		<tr>
			<td align="right" class="rincian_total" colspan="4"><b>Total</b></td>
			<td align="right" class="rincian_total"><b><?php echo number_format($harga * $qty,0,",","."); ?></b></td>
		</tr>
		<tr>
			<td class="rincian_total" colspan="2"><b><i>Your satisfaction is our happiness</i></b></td>
			<td align="right" class="rincian_total" colspan="2"><b>Materai</b></td>
			<td align="right" class="rincian_total"><b><?php echo number_format($d3->materai,0,",","."); ?></b></td>
		</tr>
		<tr>
			<td class="rincian_total" colspan="2"><b>Thank you.</b></td>
			<td align="right" class="rincian_total" colspan="2"><b>Payment Amount</b></td>
			<td align="right" class="rincian_total"><b><?php echo number_format($d3->jml_bayar,0,",","."); ?></b></td>
		</tr>
		<?php
		$cek = getFromTable("");
		$sisa = ($harga * $qty) - $d3->jml_bayar;
		if ($sisa > 0){
		
		?>
		<tr>
			<td align="right" class="rincian_total" colspan="4"><b>Remaining Payment</b></td>
			<td align="right" class="rincian_total"><b><?php echo number_format($sisa,0,",","."); ?></b></td>
		</tr>
		<?php } ?>
	</table>
	<table width="100%">
		<tr>
			<td align="center" class="judul1_kw"><!--Customer--></td>
			<td align="center" class="judul1_kw">Cashier</td>
		</tr>
		<tr>
			<td align="center" class="judul1_kw">&nbsp;<br><br><br></td>
			<td align="center" class="judul1_kw">&nbsp;</td>
		</tr>
		<tr>
			<td align="center" class="judul1_kw"><b><!--<?php echo ucwords(strtolower($d3->nm_pembayar)); ?>--></b></td>
			<td align="center" class="judul1_kw"><b><?php echo ucwords(strtolower($_SESSION[nama_usr])); ?></b></td>
		</tr>
	</table>
	<SCRIPT LANGUAGE="JavaScript">
	
	function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
	}
		
	printWindow();
	</script>
<?php } else { ?>
	<table width="80%" align="center" class="tbl_list">
		<tr>
			<th colspan="5">Select Payment</th>
		</tr>
		<tr>
			<th>No</th>
			<th>&nbsp;</th>
			<th>Date</th>
			<th>No.</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="cetak_dp.php?idx=<?php echo $_GET[idx];?>&kw=<?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 $row[jml_bayar];?></td>
		</tr>
		<?php } ?>
	</table>
<?php } ?>