<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 = "global_report";
$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' >  Global Report");
if (!isset($GLOBALS['print'])) {
	title_print("Global 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>
	<tr>
		<td><b>View Detail</b></td>
		<td><a href="<?php echo "$SC?p=grobal_report_detail&tgl1=".$_GET[tgl1]."&tgl2=".$_GET[tgl2];?>"><img src="images/report-icon.png" width="30"></a></td>
	</tr>
</table>
</form>
<?php } else { ?>
<table class="gridtable_form" width="50%">
	<tr>
		<td><b>Report Name</b></td>
		<td> : Global 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/>
<div class="ui warning message"><b>POINT OF SALES</b></div>
<table width="100%" id='mytable' class="gridtable">
	<tr>
		<th class="gridtable_th" rowspan="2">NO</th>
		<th class="gridtable_th" rowspan="2">ITEMS</th>
		<th class="gridtable_th" rowspan="2">QTY</th>
		<th class="gridtable_th" colspan="4">SERVICE ITEMS</th>
		<th class="gridtable_th" colspan="2">TRANSACTIONS</th>
		<th class="gridtable_th" rowspan="2">TOTAL</th>
	</tr>
	<tr>
		<th class="gridtable_th">BREAKFAST</th>
		<th class="gridtable_th">FOOD</th>
		<th class="gridtable_th">Beverage</th>
		<th class="gridtable_th">OTHER</th>
		
		<th class="gridtable_th">TOT. SEVICE</th>		
		<th class="gridtable_th">DISC</th>
	</tr>
<?php

$sql = "select * from tbl_referensi where kd = 'POS' and id != '000' order by ID";
$r = mysql_query($sql);
$n = mysql_num_rows($r);

$no = 1;
$jumlah1 = 0;
$jumlah2 = 0;
$jumlah3 = 0;
$jumlah4 = 0;
$jumlah5 = 0;
$jumlah6 = 0;
$jumlah7 = 0;
$jumlah8 = 0;

while ($row = mysql_fetch_array($r)) { 
$qty = getFromTable("select sum(qty) from tbl_transaksi where jns_trans = '".$row[keterangan2]."' and status_trans = 1 and (CONCAT(tgl_trans,' ',wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."')");
$jml = getFromTable("select sum(jumlah) from tbl_transaksi where jns_trans = '".$row[keterangan2]."' and status_trans = 1 and (CONCAT(tgl_trans,' ',wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."')");
$ds = getFromTable("select sum(diskon) from tbl_transaksi where jns_trans = '".$row[keterangan2]."' and status_trans = 1 and (CONCAT(tgl_trans,' ',wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."')");
$sv = getFromTable("select sum(diskon + jumlah) from tbl_transaksi where jns_trans = '".$row[keterangan2]."' and status_trans = 1 and (CONCAT(tgl_trans,' ',wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."')");


$ket = $row[keterangan];
if ($row[keterangan2] == "ROOM"){
	$bf = getFromTable("select (breakfast * $qty) as bf from tbl_referensi where kd = 'ROM' and id != '000' group by bf ");
	$fd = 0;
	$bv = 0;
	$ot = $jml - $bf;
} else {
	if ($row[keterangan2] == 'RESTO' || $row[keterangan2] == 'BAR' || $row[keterangan2] == 'LOUNGE' ){
		$bf = 0;
		$fd = getFromTable("select sum(a.jumlah) from tbl_transaksi a, tbl_layanan b
							where a.item_id = b.id and b.jenis = 'Food' and a.jns_trans = '".$row[keterangan2]."' 
							and a.status_trans = 1 and (CONCAT(tgl_trans,' ',wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') ");
		$bv = getFromTable("select sum(a.jumlah) from tbl_transaksi a, tbl_layanan b
							where a.item_id = b.id and b.jenis = 'Beverage' and a.jns_trans = '".$row[keterangan2]."' 
							and a.status_trans = 1 and (CONCAT(tgl_trans,' ',wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') ");
		$ot = getFromTable("select sum(a.jumlah) from tbl_transaksi a, tbl_layanan b
							where a.item_id = b.id and b.jenis not in ('Beverage','Food') and a.jns_trans = '".$row[keterangan2]."' 
							and a.status_trans = 1 and (CONCAT(tgl_trans,' ',wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') ");
	} else {
		$bf = 0;
		$fd = 0;
		$bv = 0;
		$ot = getFromTable("select sum(a.jumlah) from tbl_transaksi a, tbl_layanan b
							where a.item_id = b.id and a.jns_trans = '".$row[keterangan2]."' 
							and a.status_trans = 1 and (CONCAT(tgl_trans,' ',wkt_entry) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') ");
	}
	
}

?>
	<tr>
		<td class="gridtable_td" align="center"><?php echo $no++;?></td>
		<td class="gridtable_td" align="left"><?php echo strtoupper($ket);?></td>
		<td class="gridtable_td" align="center"><?php echo $qty;?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($bf,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($fd,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($bv,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($ot,2,",",".");?></td>
		
		<td class="gridtable_td" align="right"><?php echo number_format($sv,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($ds,2,",",".");?></td>
		
		<td class="gridtable_td" align="right"><?php echo number_format($jml,2,",",".");?></td>
	</tr>
	
	
<?php  
$jumlah1 = $jumlah1 + $bf; 
$jumlah2 = $jumlah2 + $fd; 
$jumlah3 = $jumlah3 + $bv; 
$jumlah4 = $jumlah4 + $ot; 
$jumlah5 = $jumlah5 + $sv; 
$jumlah6 = $jumlah6 + $ds; 
$jumlah7 = $jumlah7 + $jml; 
} ?>
<tr>
	<td class="gridtable_total" colspan="3" align="right">TOTAL</td>
	<td class="gridtable_total" align="right"><?php echo number_format($jumlah1,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($jumlah2,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($jumlah3,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($jumlah4,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($jumlah5,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($jumlah6,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($jumlah7,2,",",".");?></td>
</tr>
</table>
<div class="ui warning message"><b>GUEST PAYMENT</b></div>
<table width="100%" id='mytable' class="gridtable">
	<tr>
		<th class="gridtable_th" rowspan="2">NO</th>
		<th class="gridtable_th" rowspan="2">PAYMENT TYPE</th>
		<th class="gridtable_th" colspan="4">SERVICE</th>
		<th class="gridtable_th" colspan="2">PAYMENT</th>
		<th class="gridtable_th" rowspan="2">TOTAL</th>
	</tr>
	<tr>
		<th class="gridtable_th">TAX</th>
		<th class="gridtable_th">SERVICE</th>
		<th class="gridtable_th">DISCOUNT</th>
		<th class="gridtable_th">MATERAI</th>
		<th class="gridtable_th">AMOUNT</th>
		<th class="gridtable_th">RETURN</th>
	</tr>
	<?php
	$sql1 = "select distinct jns_bayar, status_bayar from tbl_pembayaran where jns_bayar != 'BATAL' ";
	$r1 = mysql_query($sql1);
	$n1 = mysql_num_rows($r1);
	
	$tot1 = 0; 
	$tot2 = 0; 
	$tot3 = 0; 
	$tot4 = 0; 
	$tot5 = 0; 
	$tot6 = 0; 
	$tot7 = 0; 

	$noo = 1;
	
	while ($row1 = mysql_fetch_array($r1)) { 
	
	if ($row1[jns_bayar] == "RETUR"){
		$jml = 0;
		$tax = getFromTable("select sum(tax_ppn) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' ");
		$serv = getFromTable("select sum(servis) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' ");
		$disc = getFromTable("select sum(diskon) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' ");
		$mat = getFromTable("select sum(materai) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' ");
		$ret = getFromTable("select sum(jml_bayar) * -1 from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = 'RETUR' ");
	} elseif ($row1[jns_bayar] == "DEPOSIT"){
		$jml = getFromTable("select sum(jml_bayar) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$tax = getFromTable("select sum(tax_ppn) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$serv = getFromTable("select sum(servis) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$disc = getFromTable("select sum(diskon) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$mat = getFromTable("select sum(materai) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$ret = 0;
	} else {
		$jml = getFromTable("select sum(jml_bayar) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$tax = getFromTable("select sum(tax_ppn) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$serv = getFromTable("select sum(servis) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$disc = getFromTable("select sum(diskon) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$mat = getFromTable("select sum(materai) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
		$ret = getFromTable("select sum(sisa) from tbl_pembayaran where (CONCAT(tgl_bayar,' ',wkt_bayar) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and jns_bayar = '".$row1[jns_bayar]."' and status_bayar = '".$row1[status_bayar]."'");
	}
	
	$total = $jml + $ret;
	
	if ($row1[jns_bayar] == "DEPOSIT"){
		$keterangan = "DOWN PAYMENT";
	} elseif ($row1[jns_bayar] == "RETUR"){
		$keterangan = "CHECKOUT (RETUR) PAYMENT";	
	} else {
		if ($row1[status_bayar] == "001"){
			$keterangan = "POINT OF SALES PAYMENT";
		} else {
			$keterangan = "CHECKOUT PAYMENT";
		}
		
	}
?>
	<tr>
		<td class="gridtable_td" align="center"><?php echo $noo++;?></td>
		<td class="gridtable_td" align="left"><?php echo $keterangan;?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($tax,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($serv,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($disc,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($mat,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($jml,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($ret,2,",",".");?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($total,2,",",".");?></td>
	</tr>
	
	
<?php
$tot1 = $tot1 + $tax; 
$tot2 = $tot2 + $serv; 
$tot3 = $tot3 + $disc; 
$tot4 = $tot4 + $mat; 
$tot5 = $tot5 + $jml; 
$tot6 = $tot6 + $ret; 
$tot7 = $tot7 + $total; 
} ?>
<tr>
	<td class="gridtable_total" colspan="2" align="right">TOTAL</td>
	<td class="gridtable_total" align="right"><?php echo number_format($tot1,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($tot2,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($tot3,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($tot4,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($tot5,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($tot6,2,",",".");?></td>
	<td class="gridtable_total" align="right"><?php echo number_format($tot7,2,",",".");?></td>
</tr>

</table>
<div class="ui warning message"><b>OTHER INCOME / EXPENCE</b></div>
<table width="50%" id='mytable' class="gridtable">
	<tr>
		<th class="gridtable_th">NO</th>
		<th class="gridtable_th">DESCRIPTION</th>
		<th class="gridtable_th">AMOUNT</th>
	</tr>
<?php
$sql3 = "select distinct d_k from tbl_other_jurnal ";
$r3 = mysql_query($sql3);
$n3 = mysql_num_rows($r3);
while ($row3 = mysql_fetch_array($r3)) { 
if ($row3[d_k] == "C"){
	$kett = "EXPENCE";
} else {
	$kett = "INCOME";
}
?>
<tr>
	<td class="gridtable_td_yellow" colspan="3"><?php echo $kett;?></td>
</tr>

<?php
	$sql4 = "select a.*, b.layanan from tbl_other_jurnal a, tbl_mjurnal b where a.id_jurnal = b.id and (a.tgl_trans between '".$_GET[tgl1]."' and '".$_GET[tgl2]."') and d_k = '".$row3[d_k]."' order by a.id_jurnal ";
	$r4 = mysql_query($sql4);
	$n4 = mysql_num_rows($r4);
	$nnoo = 1;
	
	$toot = 0;
	while ($row4 = mysql_fetch_array($r4)) { ?>
	<tr>
		<td class="gridtable_td" align="center"><?php echo $nnoo++;?></td>
		<td class="gridtable_td" align="left"><?php echo strtoupper($row4[layanan]);?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row4[jumlah],2,",",".");?></td>
	</tr>			
	<?php $toot = $toot + $row4[jumlah]; } ?>
	<tr>
		<td class="gridtable_total" colspan="2" align="right">TOTAL</td>
		<td class="gridtable_total" align="right"><?php echo number_format($toot,2,",",".");?></td>
	</tr>
	<?php }
?>
</table>