<?php    
$PID = "revised_room";
$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' >  Discount Room");

if ($_GET[act] == "act"){
	include_once("keterangan.php");
	$sql = "select * from tbl_transaksi
			where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$_GET[idx]."'
			order by tgl_trans ";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;
	?>
	<a href="javascript:addRoom('<?php echo $_GET[idx]; ?>')"><img src="images/icon-checklist.png" title="Add Room" /></a>
	<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">Edit</td>
		<td class="gridtable_th" align="center">Del</td>
		<td class="gridtable_th" align="center">Date</td>
		<td class="gridtable_th" align="center">Price</td>
		<td class="gridtable_th" align="center">Qty</td>
		<td class="gridtable_th" align="center">Discount</td>
		<td class="gridtable_th" align="center">Amount</td>
	</tr>
	<?php while ($row = mysql_fetch_array($r)) { ?>
		<tr>
			<td class="gridtable_td" align="center"><?php echo $no++;?></td>
			
			<td class="gridtable_td" align="center">			
				<a href="javascript:edtRoom('<?php echo $_GET[idx]; ?>','<?php echo $row[id]; ?>')"><img src="images/icon-edit.png" title="Edit Discount" /></a>
			</td>
			<td class="gridtable_td" align="center">			
				<a href="<?php echo "$SC?p=$PID&act=del&idx=".$_GET[idx]."&pid=".$row[id]; ?>"><img src="images/icon-delete.png" title="Delete Room" /></a>
			</td>
			<td class="gridtable_td" align="center"><?php echo $row[tgl_trans];?></td>
			<td class="gridtable_td" align="right"><?php echo $row[harga];?></td>
			<td class="gridtable_td" align="center"><?php echo $row[qty];?></td>
			<td class="gridtable_td" align="right"><?php echo $row[diskon];?></td>
			<td class="gridtable_td" align="right"><?php echo $row[jumlah];?></td>
		</tr>
	<?php } ?>
	</table>
	<script language='JavaScript'>
	function edtRoom(tag,tag1) {
	    sWin = window.open('includes/edit_room.php?idx='+tag+'&act=edt&pid='+tag1, 'xWin',
	 'top=0,left=0,width=1200,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
	}
	
	function addRoom(tag) {
	    sWin = window.open('includes/edit_room.php?idx='+tag+'&act=add', 'xWin',
	 'top=0,left=0,width=1200,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
	}
	</script>
	
<?php
	
} elseif($_GET[act] == "del") {
	mysql_query("update tbl_transaksi set status_trans = 0 where id = '".$_GET[pid]."'");
	echo "<script language='JavaScript'>document.location='index2.php?p=".$PID."&act=act&idx=".$_GET[idx]."'</script>";
} else {
	
?>
<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">No. Reg</td>
		<td class="gridtable_th" align="center">Date<br/>Check in</td>
		<td class="gridtable_th" align="center">No.<br/>Room</td>
		<td class="gridtable_th" align="center">Room Type</td>
		<td class="gridtable_th" align="center">Guest</td>
	</tr>
	<?php
	$sql = "select DISTINCT 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 a.status_booking = 'cekin' and b.status_trans = 1
			 ";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;

while ($row = mysql_fetch_array($r)) {
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&act=act&idx=".$row[id_booking]; ?>"><?php echo $row[id_booking]; ?></a></td>
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row[tgl_cekin])); ?></td>
		<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>		
	</tr>
	<?php } ?>
</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>
<?php } ?>