<?php
$PID = "change_room";
$SC = $_SERVER["SCRIPT_NAME"];

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

if(isset($_GET[idx])){
	title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Change Room");
	include_once('keterangan.php');
	
	$jns_kamar1 = getFromTable("select kd_jenis from tbl_room where id = ".$_SESSION["SELECT_KAMAR_CEKIN"]);
	$nm_kamar = getFromTable("select keterangan from tbl_referensi where kd = 'ROM' and id = $jns_kamar1");
	$kamar = $_SESSION["SELECT_NOMOR_CEKIN"]." - ".$nm_kamar;
	
	$id_kamar_lama = getFromTable("select item_id from tbl_transaksi where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$_GET[idx]."' ");
	
	$hrg_kamar = getFromTable("select harga from tbl_referensi where kd = 'ROM' and id = $jns_kamar1");
	$key_kamar = getFromTable("select id_lock from tbl_room where id = ".$_SESSION["SELECT_KAMAR_CEKIN"]);
	?>
	<br/>
	<div class="ui three column stackable grid" align="center">
		<div class="column"></div>
		<div class="column">
			<h4 class="ui top attached block header">Select Room</h4>
			<form action="actions/changeroom_insert.php" method="POST">
			<input type="hidden" name="p" value="<?php echo $PID;?>"/>
			<input type="hidden" name="id_kamar" value="<?php echo $_SESSION["SELECT_KAMAR_CEKIN"];?>"/>
			<input type="hidden" name="id_kamar_lama" value="<?php echo $id_kamar_lama;?>"/>
			<input type="hidden" name="idx" value="<?php echo $_GET["idx"];?>"/>
			<input type="hidden" name="harga" value="<?php echo $hrg_kamar;?>"/>
			<input type="hidden" name="jns_room" value="<?php echo $jns_kamar1;?>"/>
			<input type="hidden" name="tgl_trans" value="<?php echo $tgl_cekinroom;?>"/>
			<table width="100%" class="gridtable_form" border="1px">						
				<tr>
					<td>Select Room</td>
					<td>: <input type="text" name="kamar" value="<?php echo $kamar; ?>" >
						&nbsp;<a href="javascript:cari_kamar('<?php echo $jns_kamar; ?>')"><img src="images/icon-view.png"></a>
					</td>
				</tr>
				<tr>
					<td>ID Room</td>
					<td>: <input type="text" name="key_id" value="<?php echo $key_kamar; ?>" readonly="readonly"></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>
					<br/>
					<?php
			
			if(isset($kamar)):
						//VARIABLE DIBAWAH INI AMBIL DARI KETERANGAN
					//$key_kamar = getFromTable("select id_lock from tbl_room where id = $kamar ");
					$checkintime=explode(":",$checkin_time);
					//echo $checkin_date;
					$time= strtotime($checkin_date);
					$checkin= date('Ymd', strtotime( $checkin_date));
					$checkout= date('Ymd', strtotime( $checkin_date.'+1 day'));
					$co_time = $checkout."1210";
					$ci_time = $checkin.$checkintime[0].$checkintime[1];
					
					?>
					<a  href='javascript:cetakKunci("<?=$key_kamar;?>", "<?=$ci_time?>","<?=$co_time?>","<?=$guest_name?>","<?=$noktp?>","<?php echo $_GET[idx];?>");' style="border:1px solid #008000;border-radius:5px;font-size:12px;padding:5px;">Print Card Key</a>
					<?php endif;?>
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;&nbsp;<br/><input type="submit" value="Change Room" ></td>
				</tr>
			</table>
			</form>
		</div>
	</div>
	<div class="column"></div>
<script language='JavaScript'>
	function cari_kamar(tag) {
	    sWin = window.open('includes/cari_kamar2.php?jns='+tag, 'xWin',
	 	'top=0,left=0,width=1200,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
	}
	function cetakKunci(nomor_room, tanggal_checkin,tanggal_checkout,nama,idguest,booking_id) {
	    sWin = window.open('includes/cetak_card.php?nomor_room='+nomor_room+'&tanggal_ci='+tanggal_checkin+'&tanggal_co='+tanggal_checkout+'&nama='+nama+'&idguest='+idguest+'&booking_id='+booking_id, 'xWin',
	 	'top=0,left=0,width=550,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
	}
</script>
	<?php
} else {
	title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Change Room");
	
?>
<br/>
<form>
<input type="hidden" name="p" value="change_room"/>
<input type="submit" style="display: none;"/>
<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">Guest ID</td>
		<td class="gridtable_th" align="center">Check in<br/>Date</td>
		<td class="gridtable_th" align="center">Room</td>
		<td class="gridtable_th" align="center">Guest</td>
		<td class="gridtable_th" align="center">Address</td>
		<td class="gridtable_th" align="center">Hp & Email</td>
	</tr>
	<tr>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th" align="center"><input type="text" size="10" name="kd_book" value="<?php echo $_GET[kd_book];?>"></td>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th" align="center"><input type="text" name="nama" value="<?php echo $_GET[nama];?>"></td>
		<td class="gridtable_th" align="center"><input type="text" name="alamat" value="<?php echo $_GET[alamat];?>"></td>
		<td class="gridtable_th">&nbsp;</td>
	</tr>
	<?php
	$sql = "select DISTINCT a.*, b.keterangan as inisial, c.*, d.keterangan as negara, 
			(select min(z.tgl_trans) from tbl_transaksi z where z.no_booking = a.id_booking and z.jns_trans = 'ROOM')as tgl_trans, f.no_room
			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'
			join tbl_transaksi e on e.no_booking = a.id_booking
			join tbl_room f on f.id = e.item_id 
			where e.jns_trans = 'ROOM' and e.status_trans = 1 and 
			status_booking = 'cekin' and upper(id_booking) like '%".strtoupper($_GET[kd_book])."%' and
			upper(a.nm_lengkap) like '%".strtoupper($_GET[nama])."%' and (upper(a.alamat) like '%".strtoupper($_GET[alamat])."%'
			or upper(a.kota) like '%".strtoupper($_GET[alamat])."%' or upper(a.kd_pos) like '%".strtoupper($_GET[alamat])."%'
			or upper(d.keterangan) like '%".strtoupper($_GET[alamat])."%')  ";
	$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&idx=$row[id_booking]";?>"><?php echo $row[id_booking]; ?></a></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[tgl_trans])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[no_room]." - ".$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>
	</tr>
	<?php } ?>
</table>
</form>
<?php } ?>