<link rel="stylesheet" type="text/css" href="../css/cetak.css">
<?php    
$PID = "guestfolio";
$SC = $_SERVER["SCRIPT_NAME"];

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


//title("Guest Folio");

$r = mysql_query("select a.*, b.keterangan as inisial, c.*, d.keterangan as negara, e.keterangan as guest_tipe, 
				CURRENT_DATE as tgl
				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'
				join tbl_referensi e on e.id = a.guest_type and e.kd = 'JPG'
				where a.id_booking = '".$_GET[idx]."' ");
$n = mysql_num_rows($r);
if($n > 0) $d = mysql_fetch_object($r);
mysql_free_result($r);

$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 ");
?>
<br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/>
<br/><br/>

<!--hr class="line_kw"/-->
<table width="100%" border="0px" class="tbl_kw">
	<tr>
		<td width="14%"><b>&nbsp;&nbsp;Guest Name</b></td>
		<td width="%">: <?php echo ucwords(strtolower($d->nm_lengkap)); ?></td>
		
		<td width="12%"><b>No.Booking</b></td>
		<td width="17%">: <?php echo $d->id_booking; ?></td>				
		
		<td width="12%"><b>No. Room</b></td>
		<td width="20%">: <?php echo $no_room; ?></td>

	</tr>
	<tr>
		<td><b>&nbsp;&nbsp;Address</b></td>
		<td>: <?php echo ucwords(strtolower($d->alamat." ".$d->kota." ".$d->negara)); ?></td>
		
		<td><b>Checkin Date</b></td>
		<td>: <?php echo $d->tgl_cekin; ?></td>
		
		<td><b>Room Type</b></td>
		<td>: <?php echo ucwords(strtolower($d->keterangan)); ?></td>
	</tr>
	<tr>		
		<td><b>&nbsp;&nbsp;Hp & Email</b></td>
		<td>: <?php echo $d->no_hp." / ".$d->email; ?></td>
		
		<td><b>Current Date</b></td>
		<td>: <?php echo $d->tgl; ?></td>		
		
		<td><b>Guest Status</b></td>
		<td>: <?php echo $d->guest_tipe; ?></td>
	</tr>
	<tr>		
		<td><b>&nbsp;&nbsp;</b></td>
		<td>&nbsp;</td>
		
		<td><b>Pax</b></td>
		<td>: <?php echo $d->pax; ?></td>	
		
		<td><b>Company</b></td>
		<td>: <?php echo $d->instansi; ?></td>
	</tr>
</table>
<!--hr class="line_kw"/-->
<br/><br/><br/><br/><br/>
<table width="100%" class="rincian" border="0px">
	<!--tr>
		<th class="rincian_th">DATE</th>
		<th class="rincian_th">TIME</th>
		<th class="rincian_th">DESCRIPTION</th>
		<th class="rincian_th">DEBET</th>
		<th class="rincian_th">CREDIT</th>
		<th class="rincian_th">BALANCE</th>
	</tr-->
<?php
$sql1 = "select a.jns_trans, a.tgl_trans, a.diskon, a.wkt_entry, a.jumlah, 0 as sisa
		from tbl_transaksi a
		where a.no_booking = '".$_GET[idx]."' and a.status_trans = 1
		union 
		select b.jns_bayar as jns_trans, b.tgl_bayar as tgl_trans, b.diskon, b.wkt_bayar as wkt_entry, (b.jml_bayar - b.tax_ppn - b.servis) as jumlah, b.sisa
		from tbl_pembayaran b
		where b.no_booking = '".$_GET[idx]."' and jns_bayar != 'BATAL'
		order by tgl_trans, wkt_entry";
$r1 = mysql_query($sql1);
$n1 = mysql_num_rows($r1);

$balance = 0;
while ($row = mysql_fetch_array($r1)) {
		if ($row[jns_trans] == "DEPOSIT" || $row[jns_trans] == "BAYAR" ){
			if ($row[jns_trans] == "BAYAR" && $row[sisa] < 0){
				$credit = $row[jumlah] + $row[sisa];
			} else {
				$credit = $row[jumlah];
			}
			
			$debet = 0;			
		} else {
			$credit = 0;
			$debet = $row[jumlah];
		}
		$balance = $balance + $debet - $credit;
		
		if ($row[jns_trans] == "BAYAR"){
			$ket = "Payment";
		} else {
			$ket = $row[jns_trans];
		}
		?>
	<tr>
		<td class="rincian_td" align="center"><?php echo $row[tgl_trans]; ?></td>
		<td class="rincian_td" align="center"><?php echo $row[wkt_entry]; ?></td>
		<td class="rincian_td" align=""><?php echo ucwords(strtolower($ket)); ?></td>
		<td class="rincian_td" align="right"><?php echo number_format($debet,2,",","."); ?></td>
		<td class="rincian_td" align="right"><?php echo number_format($credit,2,",","."); ?></td>
		<td class="rincian_td" align="right"><?php echo number_format($balance,2,",","."); ?></td>
	</tr>
	<?php
	}
?>
<tr>
	<td align="right" class="rincian_total" colspan="4"><b>Total</b></td>
	<td align="right" class="rincian_total" colspan="2"><b><?php echo number_format($balance,2,",","."); ?></b></td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
	
	function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
	}
		
	printWindow();
	</script>