<?php 
$id = explode("-",$_GET[idx]);

if ($id[0] == "BO"){
	
$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);

$guest_type = $d->guest_type;
$jns_kamar = $d->jns_room;
$nm_kamar = $d->keterangan;
$lama_inap = $d->lama_inap ;
$hrg_kamar = ($d->harga * $lama_inap);
/*
if ($guest_type == "001"){
	$hrg_kamar = $d->harga;
} else {
	$hrg_kamar = 0;
}
*/



$tgl_cekinroom = getFromTable("select tgl_trans from tbl_transaksi where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$_GET[idx]."' ");
$tgl_cekinroom2 = getFromTable("select tgl_entry from tbl_transaksi where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$_GET[idx]."' order by id desc");
$jam_cekinroom = getFromTable("select wkt_entry from tbl_transaksi where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$_GET[idx]."' ");
$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 ");
$key_kamar = getFromTable("select id_lock from tbl_room where id = $id_room ");
$retur = getFromTable("select sum(jml_bayar + diskon) from tbl_pembayaran where no_booking = '".$_GET[idx]."' and jns_bayar = 'RETUR'");
$downpay1 = getFromTable("select sum(jml_bayar) from tbl_pembayaran where no_booking = '".$_GET[idx]."' and jns_bayar = 'DEPOSIT'");
$downpay = $downpay1 - $retur;

$sisa_tagihan = $hrg_kamar - $downpay;
?>
<div class="column">
	
	<table class="ui top attached info message" width="100%">
		<tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;Data Customer</td>
			<td align="right"><a href="index2.php?p=<?php echo $_GET[p];?>"><img src="images/icon-back_asli.png"/></a>&nbsp;&nbsp;&nbsp;&nbsp;</td>
		</tr>
	</table>
	<div class="ui bottom attached segment">
		<table width="100%" border="1px" class="gridtable_keterangan">
			<tr>
				<td width="10%"><b>No. Reservation</b></td>
				<td width="17%">: <?php echo $d->id_booking; ?></td>
				
				<td width="10%"><b>Guest</b></td>
				<td width="%">: <?php echo ucwords(strtolower($d->nm_lengkap)); ?></td>
				
				<td width="10%"><b>No. Room</b></td>
				<td width="17%">: <?php echo $no_room; ?></td>
			</tr>
			<tr>
				<td><b>Reservation Date</b></td>
				<td>: <?php echo $d->tgl_booking; ?></td>
				
				<td><b>Address</b></td>
				<td>: <?php echo ucwords(strtolower($d->alamat." ".$d->kota." ".$d->negara)); ?></td>
				
				<td><b>Room Type</b></td>
				<td>: <?php echo ucwords(strtolower($d->keterangan)); ?></td>
			</tr>
			<tr>
				<td><b>Checkin Date</b></td>
				<td>: <?php echo $d->tgl_cekin; ?></td>
				<?php
					$checkin_date =  $tgl_cekinroom2;
					$checkin_time =  $jam_cekinroom;
					$noktp =  $d->no_ktp;
					$guest_name = ucwords(strtolower($d->nm_lengkap));
				?>
				<td><b>Hp & Email</b></td>
				<td>: <?php echo $d->no_hp." / ".$d->email; ?></td>
				
				<td><b>Down Payment</b></td>
				<td>: Rp. <?php echo number_format($downpay,2,",","."); ?></td>
			</tr>
		</table>
	</div>
</div>
<?php } else { 
$r = mysql_query("select a.*, a.nm_pemesan as nm_lengkap, b.keterangan as ket1, c.item_id, c.harga 
				from tbl_banquet a
				join tbl_referensi b on b.id = a.jns_room and b.kd = 'BKT'
				join tbl_transaksi c on c.no_booking = a.no_banquet and c.jns_trans = 'PAKET'
				 where a.no_banquet = '".$_GET[idx]."' ");
$n = mysql_num_rows($r);
if($n > 0) $d = mysql_fetch_object($r);
mysql_free_result($r);
$hrg_kamar = $d->harga;

$tgl_cekinroom = getFromTable("select tgl_trans from tbl_transaksi where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$_GET[idx]."' ");
$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 ");
$key_kamar = getFromTable("select id_lock from tbl_room where id = $id_room ");
$lay = getFromTable("select nm_layanan from tbl_layanan where id = ".$d->item_id);
$retur = getFromTable("select sum(jml_bayar + diskon) from tbl_pembayaran where no_booking = '".$_GET[idx]."' and jns_bayar = 'RETUR'");
$tagihan = getFromTable("select sum(jumlah) from tbl_transaksi where no_booking = '".$_GET[idx]."' and status_trans = 1");
$byr_pos = getFromTable("select sum(jml_bayar) from tbl_pembayaran where no_booking = '".$_GET[idx]."' and jns_bayar = 'BAYAR'");
$downpay1 = getFromTable("select sum(jml_bayar) from tbl_pembayaran where no_booking = '".$_GET[idx]."' and jns_bayar = 'DEPOSIT'");
$downpay = $downpay1 - $retur;
?>
<div class="column">
	
	<table class="ui top attached info message" width="100%">
		<tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;Customer Data</td>
			<td align="right"><a href="index2.php?p=<?php echo $_GET[p];?>"><img src="images/icon-back_asli.png"/></a>&nbsp;&nbsp;&nbsp;&nbsp;</td>
		</tr>
	</table>
	<div class="ui bottom attached segment">
		<table width="100%" border="1px" class="gridtable_keterangan">
			<tr>
				<td width="10%"><b>Trans ID</b></td>
				<td width="17%">: <?php echo $d->no_banquet; ?></td>
				
				<td width="10%"><b>Guest Name</b></td>
				<td width="%">: <?php echo ucwords(strtolower($d->nm_lengkap)); ?></td>
				
				<td width="10%"><b>Banquet Type</b></td>
				<td width="17%">: <?php echo ucwords(strtolower($lay)); ?></td>
			</tr>
			<tr>
				<td><b>Booking Date</b></td>
				<td>: <?php echo $d->tgl_booking; ?></td>
				
				<td><b>Address</b></td>
				<td>: <?php echo ucwords(strtolower($d->alamat." ".$d->kota)); ?></td>
				
				<td><b>Price</b></td>
				<td>: <?php echo number_format($d->harga,2,",","."); ?></td>
			</tr>
			<tr>
				<td><b>Use Date</b></td>
				<td>: <?php echo $d->tgl_pakai; ?></td>
				<?php 
				//untuk keycard banquet
				$checkin_date= $d->tgl_pakai;
				$noktp =  $d->no_ktp;
				$guest_name = ucwords(strtolower($d->nm_lengkap));
				?>
				
				<td><b>Hp & Email</b></td>
				<td>: <?php echo $d->no_tlpn." / ".$d->email; ?></td>
				
				<td><b>Downpayment</b></td>
				<td>: Rp. <?php echo number_format($downpay,2,",","."); ?></td>
			</tr>
		</table>
	</div>
</div>
<?php } ?>
