
<SCRIPT type='text/javascript' language="JavaScript" src='js/jquery-ui-timepicker-addon.js'></SCRIPT>
<link rel="stylesheet" type="text/css" href='js/jquery-ui-timepicker-addon.css'/>
        
<script>
	$(function() {
		var startDateTextBox  = $('.wkt1');
		var endDateTextBox = $('.wkt2');

		$.timepicker.datetimeRange(
			startDateTextBox,
			endDateTextBox,
			{
				minInterval: (1000*60*60), // 1hr
				dateFormat: 'yy-mm-dd', 
				timeFormat: 'HH:mm:ss',
				start: {}, // start picker options
				end: {} // end picker options					
			}
		);
	});
</script>
<?php 
   
$PID = "lap_cekout_guest";
$SC = $_SERVER["SCRIPT_NAME"];

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


//title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Chekout Guest Report");
if (!isset($GLOBALS['print'])) {
	title_print("Chekout Guest Report");	
	$tgl = date("d-m-Y");
	$jam = date("H:i:s");


?>
<form>
<input type="hidden" name="p" value="<?php echo $PID;?>"/>

<table class="gridtable_form" width="40%">
	<tr>
		<td><b>Date From</b></td>
		<td><input type="text" name="tgl1" class="wkt1" value="<?php echo $_GET["tgl1"]; ?>" ></td>
	</tr>
	<tr>
		<td><b>To</b></td>
		<td><input type="text" name="tgl2" class="wkt2" value="<?php echo $_GET["tgl2"]; ?>" ></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><input type="submit" value="Show"/></td>
	</tr>
</table>
</form>
<?php } else { ?>
<table class="gridtable_form" width="50%">
	<tr>
		<td><b>Report Name</b></td>
		<td> : Chekout Guest Report </td>
	</tr>
	<tr>
		<td><b>Date From</b></td>
		<td> : <?php echo $_GET["tgl1"]; ?> <b>to</b> <?php echo $_GET["tgl2"]; ?></td>
	</tr>
	<tr>
		<td><b>Date Print</b></td>
		<td> : <?php echo $tgl; ?> &nbsp; <?php echo $jam; ?></td>
	</tr>
	<tr>
		<td><b>User Print</b></td>
		<td> : <?php echo $_SESSION[nama_usr];?>  </td>
	</tr>
</table>
<?php } ?>
<br/>
<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">Cekout Date</td>
		<td class="gridtable_th" align="center">Guest ID</td>
		<td class="gridtable_th" align="center">Room No</td>
		<td class="gridtable_th" align="center">Room Type</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">TOTAL PRICE</td>
		<td class="gridtable_th" align="center">TOTAL DISCOUNT</td>
		<td class="gridtable_th" align="center">TOTAL AMOUNT</td>
	</tr>
	<?php
	$sql = "select a.*, c.keterangan as inisial, d.*, d.keterangan as negara, f.no_room
			from tbl_booking a 
			join tbl_transaksi b on b.no_booking = a.id_booking
			join tbl_referensi c ON c.id = a.kd_inisial and c.kd = 'INS'
			join tbl_referensi d ON d.id = a.jns_room and d.kd = 'ROM'
			join tbl_referensi e on e.id = a.kd_negara and e.kd = 'NGR'
			join tbl_room f on f.id = b.item_id
			where b.jns_trans = 'ROOM' and b.status_trans = 1 and (CONCAT(b.tgl_trans,' ',b.wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."' )
			 and b.id = (select max(z.id) from tbl_transaksi z where z.no_booking = a.id_booking and z.jns_trans = b.jns_trans and z.status_trans = 1)
			and a.status_booking = 'cekout'
			";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;
	$tot = 0;
	while ($row = mysql_fetch_array($r)) {
		$harga = getFromTable("select sum(harga) from tbl_transaksi where no_booking = '".$row[id_booking]."' and status_trans = 1 ");
		$diskon = getFromTable("select sum(diskon) from tbl_transaksi where no_booking = '".$row[id_booking]."' and status_trans = 1 ");
		$qty = getFromTable("select sum(qty) from tbl_transaksi where no_booking = '".$row[id_booking]."' and status_trans = 1 ");
		$jumlah = getFromTable("select sum(jumlah) from tbl_transaksi where no_booking = '".$row[id_booking]."' and status_trans = 1 ");
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row[tgl_cekout])); ?></td>
		<?php if (!isset($GLOBALS['print'])) { ?>
		<td class="gridtable_td" align="center"><a href="javascript:GuestFolio('<?php echo $row[id_booking]; ?>')"><?php echo $row[id_booking]; ?></a></td>
		<?php } else { ?>
		<td class="gridtable_td" align="center"><?php echo $row[id_booking]; ?></td>
		<?php } ?>
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row[no_room])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($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>
		<td class="gridtable_td" align="right"><?php echo number_format($harga, 2, ',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($diskon, 2, ',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($jumlah, 2, ',','.'); ?></td>
	</tr>
	<?php 
	$tot = $tot + $jumlah;
	} ?>
	<tr>
		<td class="gridtable_total" align="right" colspan="10">TOTAL</td>
		<td class="gridtable_total" align="right"><?php echo number_format($tot, 2, ',','.'); ?></td>
	</tr>
</table>

<script language='JavaScript'>
function GuestFolio(tag) {
    sWin = window.open('includes/guestfolio.php?idx='+tag, 'xWin',
 'top=0,left=0,width=1200,height=550,menubar=no,scrollbars=yes');
    sWin.focus();
}
</script>
