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

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


if (!isset($GLOBALS['print'])) {
	title_print("Cashier Report");
	

?>
<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>Type</b></td>
		<td><?php echo query_jnsbayar("jns",$_GET["jns"]); ?></td>
	</tr>
	<tr>
		<td><b>Payment Method</b></td>
		<td><?php echo query_carabayar2("cab",$_GET["cab"]); ?></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]."' ");
}
if ($_GET[cab] == ""){
	$cb = "- All Method -";
} else {
	$cb = getFromTable("select keterangan from tbl_referensi where kd = 'CAB'and id = '".$_GET[cab]."' ");
}
?>
<table class="gridtable_form" width="50%">
	<tr>
		<td><b>Report Name</b></td>
		<td> : Cashier 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>Payment Method</b></td>
		<td> : <?php echo $cb; ?></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">Payment<br/>type</td>
		<td class="gridtable_th" align="center">Guest<br/>ID</td>
		<td class="gridtable_th" align="center">Name</td>
		<td class="gridtable_th" align="center">Room</td>
		<td class="gridtable_th" align="center">Date</td>
		<td class="gridtable_th" align="center">Time</td>
		<td class="gridtable_th" align="center">Payment<br/>Method</td>
		<td class="gridtable_th" align="center">Disc</td>
		<td class="gridtable_th" align="center">Materai</td>
		<td class="gridtable_th" align="center">Tax</td>
		<td class="gridtable_th" align="center">Service</td>
		<td class="gridtable_th" align="center">Amount</td>
		<td class="gridtable_th" align="center">Return</td>
		<td class="gridtable_th" align="center">Total</td>
		<td class="gridtable_th" align="center">User</td>
	</tr>
	<?php
	$sql = "select a.*, b.*, c.keterangan as cab, d.keterangan2,
			case when a.jns_bayar = 'DEPOSIT' then 0 else sisa end as sisa1 		
			from tbl_pembayaran a 
			join tbl_booking b on b.id_booking = a.no_booking
			join tbl_referensi c on c.id = a.cara_bayar and c.kd = 'CAB'
			join tbl_referensi d on d.keterangan2 = a.jns_bayar and d.kd = 'JBY'
			where a.jml_bayar != 0 and (CONCAT(a.tgl_bayar,' ',a.wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and
			a.jns_bayar like '%".$_GET[jns]."%' and a.cara_bayar like '%".$_GET[cab]."%'
			";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;
	$jml = 0; $jml1 = 0; $jml2 = 0; $jml3 = 0; $jml4 = 0; $jml5 = 0; $jml6 = 0; $jml7 = 0;
	while ($row = mysql_fetch_array($r)) {
	$r2 = mysql_query("select a.item_id, a.jns_trans, a.no_booking, b.kd_jenis, b.no_room, c.keterangan
						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'
						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);
	
	if ($row[keterangan2] == "BAYAR" and $row[jml_bayar] < 0){
		$ket = "REVISION";
	} else {
		$ket = $row[keterangan2];
	}
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<td class="gridtable_td"><?php echo $ket; ?></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 $d2->no_room." ".ucwords(strtolower($d2->keterangan)); ?></td>
		<td class="gridtable_td" align="center"><?php echo $row[tgl_bayar]; ?></td>
		<td class="gridtable_td" align="center"><?php echo $row[wkt_bayar]; ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[cab])); ?></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[materai],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[tax_ppn],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[servis],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[jml_bayar],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[sisa1],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[jml_bayar] + $row[sisa1],2,',','.'); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[user_entry])); ?></td>
	</tr>
	<?php 
	$jml1 = $jml1 + $row[jml_bayar]; 
	$jml2 = $jml2 + $row[materai]; 
	$jml3 = $jml3 + $row[diskon]; 
	$jml4 = $jml4 + $row[tax_ppn]; 
	$jml5 = $jml5 + $row[servis]; 
	$jml6 = $jml6 + $row[sisa1]; 
	} 
	
	$sql2 = "select a.*, b.*, c.keterangan as cab, d.keterangan2, case when a.jns_bayar = 'DEPOSIT' then 0 else sisa end as sisa1 
			from tbl_pembayaran a 
			join tbl_pos_out b on b.no_id = a.no_booking 
			join tbl_referensi c on c.id = a.cara_bayar and c.kd = 'CAB' 
			join tbl_referensi d on d.keterangan2 = a.jns_bayar and d.kd = 'JBY' 
			where a.jml_bayar != 0 and (CONCAT(a.tgl_bayar,' ',a.wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and
			a.jns_bayar like '%".$_GET[jns]."%' and a.cara_bayar like '%".$_GET[cab]."%'
			";
	$r2 = mysql_query($sql2);
	$n2 = mysql_num_rows($r2);
	
	//$no = 1;
	while ($row2 = mysql_fetch_array($r2)) {
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<td class="gridtable_td">POS PAYMENT</td>
		<td class="gridtable_td" align="center"><?php echo $row2[no_id]; ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row2[nm_pembayar])); ?></td>
		<td class="gridtable_td">&nbsp;</td>
		<td class="gridtable_td" align="center"><?php echo $row2[tgl_bayar]; ?></td>
		<td class="gridtable_td" align="center"><?php echo $row2[wkt_bayar]; ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row2[cab])); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row2[diskon],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row2[materai],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row2[tax_ppn],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row2[servis],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row2[jml_bayar],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row2[sisa1],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row2[jml_bayar] + $row2[sisa1],2,',','.'); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row2[user_input])); ?></td>
	</tr>
	<?php
	$jml1 = $jml1 + $row2[jml_bayar]; 
	$jml2 = $jml2 + $row2[materai]; 
	$jml3 = $jml3 + $row2[diskon]; 
	$jml4 = $jml4 + $row2[tax_ppn]; 
	$jml5 = $jml5 + $row2[servis]; 
	$jml6 = $jml6 + $row2[sisa1]; 	
	}
	
	
	$sql3 = "select a.*, b.*, c.keterangan as cab, d.keterangan2, case when a.jns_bayar = 'DEPOSIT' then 0 else sisa end as sisa1 
			from tbl_pembayaran a 
			join tbl_banquet b on b.no_banquet = a.no_booking 
			join tbl_referensi c on c.id = a.cara_bayar and c.kd = 'CAB' 
			join tbl_referensi d on d.keterangan2 = a.jns_bayar and d.kd = 'JBY' 
			where a.jml_bayar != 0 and (CONCAT(a.tgl_bayar,' ',a.wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and
			a.jns_bayar like '%".$_GET[jns]."%' and a.cara_bayar like '%".$_GET[cab]."%'
			";
	$r3 = mysql_query($sql3);
	$n3 = mysql_num_rows($r3);
	
	//$no = 1;
	while ($row3 = mysql_fetch_array($r3)) {
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<td class="gridtable_td">BANQUET PAYMENT</td>
		<td class="gridtable_td" align="center"><?php echo $row3[no_banquet]; ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row3[nm_pembayar])); ?></td>
		<td class="gridtable_td">&nbsp;</td>
		<td class="gridtable_td" align="center"><?php echo $row3[tgl_bayar]; ?></td>
		<td class="gridtable_td" align="center"><?php echo $row3[wkt_bayar]; ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row3[cab])); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row3[diskon],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row3[materai],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row3[tax_ppn],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row3[servis],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row3[jml_bayar],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row3[sisa1],2,',','.'); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row3[jml_bayar] + $row3[sisa1],2,',','.'); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row3[user_input])); ?></td>
	</tr>
	<?php
	$jml1 = $jml1 + $row3[jml_bayar]; 
	$jml2 = $jml2 + $row3[materai]; 
	$jml3 = $jml3 + $row3[diskon]; 
	$jml4 = $jml4 + $row3[tax_ppn]; 
	$jml5 = $jml5 + $row3[servis]; 
	$jml6 = $jml6 + $row3[sisa1]; 	
	}
	?>
	<tr>
		<td class="gridtable_total" align="right" colspan="8">TOTAL</td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml3,2,',','.'); ?></td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml2,2,',','.'); ?></td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml4,2,',','.'); ?></td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml5,2,',','.'); ?></td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml1,2,',','.'); ?></td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml6,2,',','.'); ?></td>
		<td class="gridtable_total" align="right"><?php echo number_format($jml1 + $jml6,2,',','.'); ?></td>
		<td class="gridtable_total" align="right">&nbsp;</td>
	</tr>
</table>