
<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_penjualan";
$SC = $_SERVER["SCRIPT_NAME"];

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


	
if (isset($_GET[idx])) {
	$iid = explode("-", $_GET[idx]);
	if ($iid[0] == "TRS"){
		$r = mysql_query("select * from tbl_pos_out where no_id = '".$_GET[idx]."'");
		$n = mysql_num_rows($r);
		if($n > 0) $d = mysql_fetch_object($r);
		mysql_free_result($r);
		if ($d->no_booking == NULL){
			$ket = "Individual";
		} else {
			$ket = "di Tangguhkan ke ".$d->no_booking ;
		}
		?>
		<div class="column">
		<div class="ui top attached info message">Data Customer</div>
		<div class="ui bottom attached segment">
		<table width="100%" border="1px" class="gridtable_keterangan">
			<tr>
				<td width="8%"><b>No.Trans</b></td>
				<td width="12%">: <?php echo $_GET[idx]; ?></td>
				
				<td width="8%"><b>No. Table</b></td>
				<td width="10%">: <?php echo $d->no_meja; ?></td>
				
				<td width="8%"><b>Date</b></td>
				<td width="12%">: <?php echo $d->tgl_trans; ?></td>
				
				<td width="8%"><b>Time</b></td>
				<td width="10%">: <?php echo $d->waktu; ?></td>
				
				<td width="10%"><b>Payment Status</b></td>
				<td width="14%">: <?php echo $ket; ?></td>
			</tr>
		</table> 
		<?php
	} else {
		include_once("keterangan.php");
	}
	
	
	$sql = "select * from tbl_referensi 
			where kd = 'POS' and id != '000' and keterangan2 like '%".$_GET[jns]."%' ";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	while ($row = mysql_fetch_array($r)) { ?>
		<div class="ui warning message">
			<?php echo $row[keterangan];?>
		</div>
	<table width="100%" class="rincian_laporan" border="1px">
		<tr>
			<th width="3%">No</th>
			<th width="5%">Date</th>
			<th width="5%">Time</th>
			<th>Items</th>
			<th width="10%">Price</th>
			<th width="5%">Qty</th>
			<th width="10%">Discount</th>
			<th width="10%">Amount</th>
			<th width="10%">User Entry</th>
			<th width="5%">Payment Stat</th>
			<th width="10%">No. Bill</th>
		</tr>	
	
	<?php 
	$sql1 = "select a.*, b.* from tbl_transaksi a 
			join tbl_layanan b on b.id = a.item_id
			where a.no_booking = '".$_GET[idx]."' and a.jns_trans = '".$row[keterangan2]."'";
	$r1 = mysql_query($sql1);
	$n1 = mysql_num_rows($r1);
	$no = 1;
	$jml = 0;
	while ($row1 = mysql_fetch_array($r1)) { ?>
		<tr>
			<td align="center"><?php echo $no++; ?></td>
			<td align="center"><?php echo $row1[tgl_trans]; ?></td>
			<td align="center"><?php echo $row1[wkt_entry]; ?></td>
			<td width=""><?php echo ucwords(strtolower($row1[nm_layanan])); ?></td>
			<td align="right"><?php echo number_format($row1[harga],2,",","."); ?></td>
			<td align="center"><?php echo $row1[qty]; ?></td>
			<td align="right"><?php echo number_format($row1[diskon],2,",","."); ?></td>
			<td align="right"><?php echo number_format($row1[jumlah],2,",","."); ?></td>
			<td><?php echo ucwords(strtolower($row1[user_entry])); ?></td>
			<td align="center"><?php echo $row1[status_bayar]; ?></td>
			<td align="center"><?php echo $row1[no_kwitansi]; ?></td>
		</tr>
	<?php $jml = $jml + $row1[jumlah]; } ?>
	<tr>
		<td align="right" colspan="7"><b>T O T A L</b></td>
		<td align="right"><b><?php echo number_format($jml,2,",","."); ?></b></td>
		<td>&nbsp;</td>
	</tr>
	</table>	
	<?php }
} else {
	
if (!isset($GLOBALS['print'])) {
	title_print("Point of Sales 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><b>Trans Type</b></td>
		<td><?php echo query_pointsale("jns",$_GET["jns"]); ?></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><input type="submit" value="Show"/></td>
	</tr>
</table>
</form>
<?php } else { 
if ($_GET[jns] == ""){
	$jn = "- All -";
} else {
	$jn = getFromTable("select keterangan from tbl_referensi where keterangan2 = '".$_GET[jns]."' ");
}
?>
<table class="gridtable_form" width="50%">
	<tr>
		<td><b>Report Name</b></td>
		<td> : Point of Sales 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>Trans Type</b></td>
		<td> : <?php echo $jn; ?></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/>
<h4 class="ui top attached block header">Residance</h4>
<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">Trans Type</td>
		<td class="gridtable_th" align="center">Date</td>
		<td class="gridtable_th" align="center">Time</td>
		<td class="gridtable_th" align="center">Room</td>
		<td class="gridtable_th" align="center">Guest ID</td>
		<td class="gridtable_th" align="center">Name</td>
		<td class="gridtable_th" align="center">Service</td>
		<td class="gridtable_th" align="center">Type</td>
		<td class="gridtable_th" align="center">Price</td>
		<td class="gridtable_th" align="center">Qty</td>
		<td class="gridtable_th" align="center">Disc</td>
		<td class="gridtable_th" align="center">Amount</td>
	</tr>
	<?php
	$sql = "select DISTINCT a.jns_trans, c.keterangan,a.tgl_trans, a.wkt_entry, a.no_booking, a.item_id,
			d.nm_layanan, d.category, e.keterangan as category_lay, a.harga, a.qty, a.diskon, a.jumlah, b.nm_lengkap, d.jenis
			from tbl_transaksi a 
			join tbl_booking b on b.id_booking = a.no_booking 
			join tbl_referensi c on c.keterangan2 = a.jns_trans 
			join tbl_layanan d on d.id = a.item_id
			left join tbl_referensi e on e.id = d.category and e.kd = 'KMN'
			WHERE a.jns_trans != 'ROOM' and a.jns_trans like '%".$_GET[jns]."%' and (CONCAT(a.tgl_trans,' ',a.wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."' )  ";
	
	
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;
	$jml = 0;
	while ($row = mysql_fetch_array($r)) {
		$r2 = 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 = '$row[no_booking]' ");
		$d2 = mysql_fetch_object($r2);
		$id_room = getFromTable("select item_id from tbl_transaksi where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$row[no_booking]."' ");
		$no_room = getFromTable("select no_room from tbl_room where id = $id_room ");
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<!--td class="gridtable_td">
			<a href="<?php echo "$SC?p=$PID&tgl1=$_GET[tgl1]&tgl2=$_GET[tgl2]&jns=$row[jns_trans]&idx=$row[no_booking]"; ?>"><img src="images/icon-mr.png" width="16" title="Lihat Rincian"></a>
		</td-->
		<td class="gridtable_td"><?php echo $row[keterangan]; ?></td>
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row[tgl_trans])); ?></td>
		<td class="gridtable_td" align="center"><?php echo $row[wkt_entry]; ?></td>
		<td class="gridtable_td"><?php echo $no_room." - ".ucwords(strtolower($d2->keterangan)); ?></td>
		<td class="gridtable_td" align="center"><?php echo $row[no_booking]; ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[nm_lengkap])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[nm_layanan])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[jenis])); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[harga],2,',','.'); ?></td>
		<td class="gridtable_td" align="center"><?php echo $row[qty]; ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[diskon],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[jumlah],2,',','.'); ?></td>
	</tr>
	<?php $jml = $jml + $row[jumlah]; } ?>
	<tr>
		<td class="gridtable_total" align="right" colspan="12">TOTAL</td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml,2,',','.'); ?></td>
	</tr>
</table>


<h4 class="ui top attached block header">Non Residance</h4>
<table id='mytable' class="gridtable tableWithFloatingHeader" width="100%" border="0px">
	<tr>
		<td class="gridtable_th" align="center">No</td>
		<td class="gridtable_th" align="center">Trans Date</td>
		<td class="gridtable_th" align="center">Time</td>
		<td class="gridtable_th" align="center">Trans ID</td>
		<td class="gridtable_th" align="center">Status</td>
		<td class="gridtable_th" align="center">Guest ID</td>
		<td class="gridtable_th" align="center">Name</td>
		<td class="gridtable_th" align="center">Service</td>
		<td class="gridtable_th" align="center">Type</td>
		<td class="gridtable_th" align="center">Price</td>
		<td class="gridtable_th" align="center">Qty</td>
		<td class="gridtable_th" align="center">Disc</td>
		<td class="gridtable_th" align="center">Amount</td>
	</tr>
	<?php
	$sql = "select DISTINCT b.*, a.jns_trans, c.keterangan, c.keterangan2, a.item_id, d.nm_layanan, a.harga, a.qty, a.diskon, a.jumlah, d.jenis 
			from tbl_transaksi a 
			join tbl_pos_out b on b.no_id = a.no_booking 
			join tbl_referensi c on c.keterangan2 = a.jns_trans 
			join tbl_layanan d on d.id = a.item_id
			WHERE a.jns_trans like '%".$_GET[jns]."%' and (CONCAT(b.tgl_trans,' ',b.waktu) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."' )  ";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;
	$jml = 0;
	while ($row = mysql_fetch_array($r)) {
	
	
	$tagihan = getFromTable("select sum(jumlah) from tbl_transaksi where no_booking = '".$row[no_id]."' 
							 and jns_trans = '".$row[jns_trans]."' ");
	if ($row[no_booking] == NULL || $row[no_booking] == ''){
		$status = "Individual";
		$room = "";
		$nama = "";
	} else {
		$status = "Di Tagihkan";
		$r2 = mysql_query("select a.item_id, a.jns_trans, a.no_booking, b.kd_jenis, b.no_room, c.keterangan, d.*
						from tbl_transaksi a
						join tbl_room b on b.id = a.item_id
						join tbl_referensi c on c.id = b.kd_jenis and c.kd = 'ROM'
						join tbl_booking d on d.id_booking = a.no_booking
						where a.jns_trans = 'ROOM' and a.status_trans = 1 and 
						no_booking = '".$row[no_booking]."' ");
		$n2 = mysql_num_rows($r2);
		if($n2 > 0) $d2 = mysql_fetch_object($r2);
		mysql_free_result($r2);
		$room = $d2->no_room." ".ucwords(strtolower($d2->keterangan));
		$nama = $d2->nm_lengkap;
	}
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<!--td class="gridtable_td">
			<a href="<?php echo "$SC?p=$PID&tgl1=$_GET[tgl1]&tgl2=$_GET[tgl2]&jns=$row[jns_trans]&idx=$row[no_id]"; ?>"><img src="images/icon-mr.png" width="16" title="Lihat Rincian"></a>
		</td-->
		<td class="gridtable_td" align="center"><?php echo $row[tgl_trans]; ?></td>
		<td class="gridtable_td" align="center"><?php echo $row[waktu]; ?></td>
		<td class="gridtable_td" align="center"><?php echo $row[no_id]; ?></td>
		<td class="gridtable_td"><?php echo $status; ?></td>
		<td class="gridtable_td"><?php echo $row[no_booking]; ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($nama)); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[nm_layanan])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[jenis])); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[harga],2,',','.'); ?></td>
		<td class="gridtable_td" align="center"><?php echo $row[qty]; ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[diskon],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[jumlah],2,',','.'); ?></td>
	</tr>
	<?php $jml = $jml + $row[jumlah]; } ?>
	<tr>
		<td class="gridtable_total" align="right" colspan="12">TOTAL</td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml,2,',','.'); ?></td>
	</tr>
</table>
<?php
}
?>
