<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() {
		$( ".tanggal" ).datepicker({
		    dateFormat:'yy-mm-dd',
		    changeMonth :true,
		    changeYear :true
		});

		$( ".wkt" ).timepicker({
			timeFormat: 'HH:mm:ss',
			showSecond : true
		});
	});
</script>                
<?php 
   
$PID = "banquet";
$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' >  Banquet Reservation");
if(isset($_GET[act])){
	if($_GET[act] == "cancel"){
		include_once('keterangan.php');
	
	?>
	<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 Reason Cancel Reservation!</h4>
			<form action="actions/cancel_booking_insert.php" method="POST">
			<input type="hidden" name="p" value="<?php echo $PID;?>"/>
			<input type="hidden" name="idx" value="<?php echo $_GET["idx"];?>"/>
			<input type="hidden" name="down_paymen" value="<?php echo $downpay;?>"/>
			<table width="100%" class="gridtable_form" border="1px">						
				<tr>
					<td align="center"> <?php echo query_alasan("alasan", "001");?> </td>
				</tr>
				<tr>
					<td align="center"><input type="submit" value="Cancel Checkin" ></td>
				</tr>
			</table>
			</form>
		</div>
	</div>
	<div class="column"></div>
	<?php
	}elseif($_GET[act] == "edit"){
		include("keterangan.php");
		
		?>
	<div class="ui two column stackable grid">
	<div class="column">
	<?php
	if ($_SESSION["SELECT_PACK"]){
		$r = mysql_query("select * from tbl_layanan where id = '".$_SESSION["SELECT_PACK"]."' ");
	    $n = mysql_num_rows($r);
	    if($n > 0) $d = mysql_fetch_object($r);
	    mysql_free_result($r);
	    
	    $r1 = mysql_query("select * from tbl_referensi where id = '".$_SESSION["SELECT_ROOM"]."' and kd = 'BKT' ");
	    $n1 = mysql_num_rows($r1);
	    if($n1 > 0) $d1 = mysql_fetch_object($r1);
	    mysql_free_result($r1);
	    
	    $jns_room = $_SESSION["SELECT_ROOM"];
	    $id_lay = $_SESSION["SELECT_PACK"];
	} else {
		$id_trans = getFromTable("select id from tbl_transaksi where no_booking = '".$_GET[idx]."' and jns_trans = 'PAKET' and status_trans = 1");
		$id_lay = getFromTable("select item_id from tbl_transaksi where no_booking = '".$_GET[idx]."' and jns_trans = 'PAKET' and status_trans = 1");
		$r = mysql_query("select * from tbl_layanan where id = '".$id_lay."' ");
	    $n = mysql_num_rows($r);
	    if($n > 0) $d = mysql_fetch_object($r);
	    mysql_free_result($r);
	    
	    $jns_room = getFromTable("select jns_room from tbl_banquet where no_banquet = '".$_GET[idx]."'");
	    $r1 = mysql_query("select * from tbl_referensi where id = '".$jns_room."' and kd = 'BKT' ");
	    $n1 = mysql_num_rows($r1);
	    if($n1 > 0) $d1 = mysql_fetch_object($r1);
	    mysql_free_result($r1);
	    
	}
	
	    $r2 = mysql_query("select * from tbl_banquet where no_banquet = '".$_GET[idx]."'");
	    $n2 = mysql_num_rows($r2);
	    if($n2 > 0) $d2 = mysql_fetch_object($r2);
	    mysql_free_result($r2);
	?>
	<h4 class="ui top attached block header">Package Selected</h4>
	<div class="ui one cards">
		<div class="ui card">
		<div class="content">
			<div class="header"><?php echo $d1->keterangan; ?></div>
			<div class="description"><?php echo $d->nm_layanan;?></div>
		</div>
		<div class="extra content">
			<a class="friends"><font color="#3959c6"> Price : Rp. <?php echo number_format($d->hrg_layanan,2,',','.'); ?></font></a>
		</div>
		</div>
	</div>
	
	
</div>

<div class="column">
	
	<h4 class="ui top attached block header">Detail Reservation</h4>
	<form action="actions/banquet_update.php" method="POST">
	<input type="hidden" name="idx" value="<?php echo $_GET[idx];?>"/>		
	<input type="hidden" name="jns" value="<?php echo $jns_room;?>"/>		
	<input type="hidden" name="id_trans" value="<?php echo $id_trans;?>"/>		
	<input type="hidden" name="item_id" value="<?php echo $id_lay;?>"/>		
		<table width="100%" class="gridtable_form" border="1px">
			<tr>
				<td width="20%">Room Type</td>
				<td>: 
					<a href="javascript:cek_kamar();" ><img src="images/Service-icon.png" width="30px"/></a>
					
				</td>
			</tr>
			
			<tr>
				<td>Date</td>
				<td>: <input type="text" name="tgl_pakai" class="tanggal" value="<?php echo $d2->tgl_pakai ;?>" readonly="readonly"></td>
			</tr>
			<tr>
				<td>Time</td>
				<td>: <input type="text" name="wkt_pakai" class="wkt" value="<?php echo $d2->wkt_pakai ;?>" readonly="readonly"></td>
			</tr>
			<tr>
				<td>Order Name</td>
				<td>: <input type="text" name="nm_pemesan" value="<?php echo $d2->nm_pemesan ;?>" required="required"></td>
			</tr>
			<tr>
				<td>Adress</td>
				<td>: <input type="text" name="alamat" value="<?php echo $d2->alamat ;?>" required="required"></td>
			</tr>
			<tr>
				<td>City</td>
				<td>: <input type="text" name="kota" value="<?php echo $d2->kota ;?>" required="required"></td>
			</tr>
			<tr>
				<td>Phone Number</td>
				<td>: <input type="text" name="no_tlpn" value="<?php echo $d2->no_tlpn ;?>" required="required"></td>
			</tr>
			<tr>
				<td>Email</td>
				<td>: <input type="text" name="email" value="<?php echo $d2->email ;?>" required="required"></td>
			</tr>
			<tr>
				<td>Institution</td>
				<td>: <input type="text" name="instansi" value="<?php echo $d2->instansi ;?>" required="required"></td>
			</tr>
			<tr>
				<td>Description</td>
				<td>: <input type="text" name="keterangan" value="<?php echo $d2->keterangan ;?>" required="required"></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>: <input type="submit" value="Submit" class="blue ui mini button"></td>
			</tr>
			
		</table>
	</form>
	
</div>	
</div>	
		<?php
	}elseif($_GET[act] == "checkin"){
		mysql_query("update tbl_banquet set status = 'checkin' where no_banquet = '".$_GET[idx]."' ");
		echo "<script language='JavaScript'>document.location='index2.php?p=".$PID."'</script>";
		
	}elseif($_GET[act] == "add"){
	
		include_once('keterangan.php');
		$nm_kamar = getFromTable("select b.keterangan
						from tbl_room a
						join tbl_referensi b on b.id = a.kd_jenis and b.kd = 'ROM'
						where a.id = ".$_SESSION["SELECT_KAMAR_CEKIN"]);
		
		$kamar = $_SESSION["SELECT_NOMOR_CEKIN"]." - ".$nm_kamar;
		$key_kamar = getFromTable("select id_lock from tbl_room where id = ".$_SESSION["SELECT_KAMAR_CEKIN"]);
		$hrg_kamar = getFromTable("select b.harga
						from tbl_room a
						join tbl_referensi b on b.id = a.kd_jenis and b.kd = 'ROM'
						where a.id = ".$_SESSION["SELECT_KAMAR_CEKIN"]);
	?>
	<br/>
	<div class="ui three column stackable grid" align="center">
		<div class="column">
			<h4 class="ui top attached block header">Select Room</h4>
			<form action="actions/cekin_banquet_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="idx" value="<?php echo $_GET["idx"];?>"/>
			<input type="hidden" name="harga" value="<?php echo $hrg_kamar;?>"/>
			<table width="100%" class="gridtable_form" border="1px">						
				<tr>
					<td>Select Room</td>
					<td>: <input type="text" name="kamar" value="<?php echo $kamar; ?>" >
						<?php if ($no_room > 0) { ?>
						<?php } else { ?>
						&nbsp;<a href="javascript:cari_kamar('')"><img src="images/icon-view.png"></a>
						<?php }  ?>
					</td>
				</tr>
				<tr>
					<td>ID Key</td>
					<td>: <input type="text" name="key_id" value="<?php echo $key_kamar; ?>" readonly="readonly"></td>
				</tr>
				<tr>
					<td>Print Card</td>
					<td>: <br/> 	<?php
			
			if(isset($key_kamar)):
			//VARIABLE DIBAWAH INI AMBIL DARI KETERANGAN
		$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>:<br/> <input type="submit" value="Save" ></td>
				</tr>
			</table>
			</form>
			
		
			
			
		</div>
		
	</div>
	
	<?php
	} elseif ($_GET[act] == "new") {
		?>
<br/>
<div class="ui two column stackable grid">
	<div class="column">
	<?php
		if ($_SESSION["SELECT_PACK"]){
			$r = mysql_query("select * from tbl_layanan where id = '".$_SESSION["SELECT_PACK"]."' ");
		    $n = mysql_num_rows($r);
		    if($n > 0) $d = mysql_fetch_object($r);
		    mysql_free_result($r);
		    
		    $r1 = mysql_query("select * from tbl_referensi where id = '".$_SESSION["SELECT_ROOM"]."' and kd = 'BKT' ");
		    $n1 = mysql_num_rows($r1);
		    if($n1 > 0) $d1 = mysql_fetch_object($r1);
		    mysql_free_result($r1);
		?>
		<h4 class="ui top attached block header">Package Selected</h4>
		<div class="ui one cards">
			<div class="ui card">
			<div class="content">
				<div class="header"><?php echo $d1->keterangan; ?></div>
				<div class="description"><?php echo $d->nm_layanan;?></div>
			</div>
			<div class="extra content">
				<a class="friends"><font color="#3959c6"> Price : Rp. <?php echo number_format($d->hrg_layanan,2,',','.'); ?></font></a>
			</div>
			</div>
		</div>
		<?php
		}
		?>
		
	</div>

	<div class="column">
		
		<h4 class="ui top attached block header">Detail Reservation</h4>
		<form action="actions/banquet_insert.php" method="POST">
		<input type="hidden" name="jns" value="<?php echo $_SESSION["SELECT_ROOM"];?>"/>		
			<table width="100%" class="gridtable_form" border="1px">
				<tr>
					<td width="20%">Room Type</td>
					<td>: 
						<a href="javascript:cek_kamar();" ><img src="images/Service-icon.png" width="30px"/></a>
						
					</td>
				</tr>
				<?php
				if ($_SESSION["SELECT_ROOM"]){
					
				?>
				<tr>
					<td>Date</td>
					<td>: <input type="text" name="tgl_pakai" class="tanggal" value="" readonly="readonly"></td>
				</tr>
				<tr>
					<td>Time</td>
					<td>: <input type="text" name="wkt_pakai" class="wkt" value="" readonly="readonly"></td>
				</tr>
				<tr>
					<td>Order Name</td>
					<td>: <input type="text" name="nm_pemesan" value="" required="required"></td>
				</tr>
				<tr>
					<td>Adress</td>
					<td>: <input type="text" name="alamat" value="" required="required"></td>
				</tr>
				<tr>
					<td>City</td>
					<td>: <input type="text" name="kota" value="" required="required"></td>
				</tr>
				<tr>
					<td>Phone Number</td>
					<td>: <input type="text" name="no_tlpn" value="" required="required"></td>
				</tr>
				<tr>
					<td>Email</td>
					<td>: <input type="text" name="email" value="" required="required"></td>
				</tr>
				<tr>
					<td>Institution</td>
					<td>: <input type="text" name="instansi" value="" required="required"></td>
				</tr>
				<tr>
					<td>Description</td>
					<td>: <input type="text" name="keterangan" value="" required="required"></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>: <input type="submit" value="Submit" class="blue ui mini button"></td>
				</tr>
				<?php	
				}		
				?>
			</table>
		</form>
		
	</div>	
</div>	

<script language='JavaScript'>

</script>
<?php
	} else {
		
	}
} 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">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">Banquet ID</td>
			<td class="gridtable_th" align="center">Date</td>
			<td class="gridtable_th" align="center">Time Usage</td>
			<td class="gridtable_th" align="center">Name</td>
			<td class="gridtable_th" align="center">Address</td>
			<td class="gridtable_th" align="center">Hp & Email</td>
			<td class="gridtable_th" align="center">Status</td>
			<td class="gridtable_th" align="center">Package</td>
		</tr>
		<tr>
			<td class="gridtable_th" align="center"><a href="<?php echo "$SC?p=$PID&act=new"; ?>"><img src="images/icon-checklist.png"></a></td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center"><input type="text" name="no_book" size="10" value="<?php echo $_GET[no_book]; ?>"></td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center"><input type="text" name="nama" size="10" 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" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
			<td class="gridtable_th" align="center">&nbsp;</td>
		</tr>
	<?php
	$sql = "select * from tbl_banquet where status in ('booking','checkin')
	and upper(no_banquet) like '%". strtoupper($_GET[no_book]) ."%' 
	and upper(nm_pemesan) like '%". strtoupper($_GET[nama]) ."%' 
	and upper(alamat) like '%". strtoupper($_GET[alamat]) ."%'";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;
	while ($row = mysql_fetch_array($r)) { 
	$lay_id = getFromTable("select item_id from tbl_transaksi where no_booking = '".$row[no_banquet]."' and jns_trans = 'PAKET' ");
	$lay_nm = getFromTable("select nm_layanan from tbl_layanan where id = ".$lay_id." ");
	
	?>
		<tr>
			<td class="gridtable_td" align="center"><?php echo $no++; ?></td>
			<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&idx=".$row[no_banquet]."&act=checkin";?>"><img src="images/icon-ok.png" title="Check In"></a></td>
			<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&idx=".$row[no_banquet]."&act=edit";?>"><img src="images/icon-edit.png" title="Edit"></a></td>
			<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&idx=".$row[no_banquet]."&act=cancel";?>"><img src="images/icon-delete.png" title="Cancel"></a></td>
			<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&idx=".$row[no_banquet]."&act=add";?>" title="Add Room"><?php echo $row[no_banquet]; ?></a></td>
			<td class="gridtable_td" align="center"><?php echo $row[tgl_pakai]; ?></td>
			<td class="gridtable_td" align="center"><?php echo $row[wkt_pakai]; ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($row[nm_pemesan])); ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($row[alamat]." ".$row[kota])); ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($row[no_tlpn]." / ".$row[email])); ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($row[status])); ?></td>
			<td class="gridtable_td" align=""><?php echo ucwords(strtolower($lay_nm)); ?></td>
		</tr>
	<?php } ?>
	</table>
<?php }
//include 'footer.php';
?>
<script language='JavaScript'>
	$(function(){
		$('#copy').click(function(){
	    	var nm = $("#nm_pemesan").val();
	        $("#nm_lengkap").val(nm);
		         
		});
	});	
	function cek_kamar() {
		var tgl1 = $("#tgl1").val();
		var tgl2 = $("#tgl2").val();
	    sWin = window.open('includes/cek_banquet.php', 'xWin',
	 'top=0,left=0,width=750,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
	}

	function cari_kamar() {
	    sWin = window.open('includes/cari_kamar2.php?jns=003', '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>