<script type="text/javascript" src="js/autoNumeric.js"></script>
<script type="text/javascript" src="js/numeral.js"></script>
<script type="text/javascript">
	jQuery(function($) {
	    $('.auto').autoNumeric('init');
	});
	
	
</script>
<style>
	.auto {
		text-align:right;
	}
</style>
<?php
$PID = "cek_in";
$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' >  Room Check In");
	include_once('keterangan.php');
	
	$kamar = $_SESSION["SELECT_NOMOR_CEKIN"]." - ".$nm_kamar;
	$key_kamar = getFromTable("select id_lock from tbl_room where id = ".$_SESSION["SELECT_KAMAR_CEKIN"]);
	
	$r = mysql_query("select *
					from tbl_booking
					where id_booking = '".$_GET[idx]."' ");
	$n = mysql_num_rows($r);
	if($n > 0) $d = mysql_fetch_object($r);
	mysql_free_result($r);

	?>
	<br/>
	<form action="actions/bayar_insert.php" method="POST" name="Form1">
	<input type="hidden" name="p" value="<?php echo $_GET[p];?>"/>
	<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;?>"/>
	<input type="hidden" name="jenis" value="DEPOSIT"/>
	<input type="hidden" name="stat" value="001"/>
	
	<div class="ui three column stackable grid" align="center">
		<div class="column">
			<h4 class="ui top attached block header">Select No Room</h4>
			<!--form action="actions/cekin_insert.php" method="POST"-->
			
			
			<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('<?php echo $jns_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>No.ID (KTP/SIM/PASSPORT)</td>
					<td>: <input type="text" name="no_ktp" value="<?php echo $d->no_ktp; ?>" required="required"></td>
				</tr>
				<tr>
					<td>Date of Birth</td>
					<td>: <input type="text" name="tgl_lahir" value="<?php echo $d->tgl_lahir; ?>" class="tanggal" readonly="readonly"></td>
				</tr>
				<tr>
					<td>Guest Type</td>
					<td>: <?php echo query_jnsguest("guest_type",$d->guest_type,"","") ;?>	</td>
				</tr>
			</table>
			<!--/form-->
		</div>
		<div class="column">
		<?php
			
			if(isset($no_room)):
			//VARIABLE DIBAWAH INI AMBIL DARI KETERANGAN
		$key_kamar = getFromTable("select id_lock from tbl_room where id = $id_room ");
		$checkintime=explode(":",$checkin_time);
		//echo $checkin_date;
		$time= strtotime($checkin_date);
		$checkin= date('Ymd', strtotime( $checkin_date));
		$checkout= date('Ymd', strtotime( $checkin_date.'+'.$lama_inap.' 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:0px solid #008000;border-radius:5px;font-size:12px;padding:5px;"></a>
		<?php endif;?>
		</div>
		<div class="column">
			<table width="100%" align="center" class="gridtable_form">
				<tr>
					<th>No</th>
					<th>&nbsp;</th>
					<th>Payment Date</th>
					<th>No. Check</th>
					<th>Total</th>
				</tr>
				<tr>
					<th colspan="5"><hr class="line_kw" /></th>
				</tr>
				<?php 
				$sql = "select * from tbl_pembayaran WHERE jns_bayar = 'DEPOSIT' and no_booking = '".$_GET[idx]."' ";
				$r = mysql_query($sql);
				$n = mysql_num_rows($r);
				
				$no = 1;

			while ($row = mysql_fetch_array($r)) {
				?>
				<tr>
					<td align="center"><?php echo $no++;?></td>
					<td align="center"><a href="javascript: cetakDP('<?php echo $_GET[idx];?>','<?php echo $row[no_kwitansi];?>');"><img src="images/print-icon1.png"></a></td>
					<td align="center"><?php echo $row[tgl_bayar];?></td>
					<td align="center"><?php echo $row[no_kwitansi];?></td>
					<td align="right"><?php echo $row[jml_bayar];?></td>
				</tr>
				<?php } ?>
			</table>
		</div>
	</div>

	<div class="ui one column stackable grid" align="center">
		<div class="column">
			<h4 class="ui top attached block header">Payment</h4>
			<!--form action="actions/bayar_insert.php" method="POST" name="Form1"-->			
			<table width="100%" class="gridtable_form" border="1px">						
				<tr>
					<td>Payment Advanced</td>
					<td>: <?php echo query_carabayar("cab","001"," id='cab' class='cab'");?>
						<input type="text" name="no_kartu" value="" id="no_kartu" class="no_kartu" placeholder="No. Kartu" />
					</td>
					
					<td>Bill Amount</td>
					<td>: <input type="text" name="hrg1" id="hrg1" value="<?php echo $sisa_tagihan;?>" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" >  </td>
					
					<td>Payment Amount</td>
					<td>: <input type="text" name="bayar" id="bayar" value="<?php echo $sisa_tagihan;?>" class="auto" data-a-sep="," data-a-dec="." style="background-color: #f1f876" >  </td>
					
				</tr>
				<tr>
					<td>Order Name</td>
					<td>: <input type="text" name="nm_pembayar" id="nm_pembayar" size="25" value="<?php echo ucwords(strtolower($d->nm_lengkap)); ?>" ></td>
					
					<td>Materai ($.)</td>
					<td>: <input type="text" name="hrg_materai" id="hrg_materai" value="0,00" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" ></td>
					
					<td>Residue / Return</td>
					<td>: <input type="text" name="sisa" id="sisa" value="0" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" ></td>
				</tr>
				<tr>
					<td>Materai</td>
					<td>: <?php echo query_materai("materai","001"," OnChange=\"CekMaterai(this.value);\"");?></td>
					
					<td>Bill Total</td>
					<td>: <input type="text" name="hrg_tagihan" id="hrg_tagihan" value="<?php echo $sisa_tagihan;?>" class="auto" data-a-sep="," data-a-dec="." readonly="readonly" ></td>
					<input type="hidden" name="totag" id="totag" value="<?php echo $sisa_tagihan;?>" />
					<input type="hidden" name="tax" value="0" />
					<input type="hidden" name="js_serv" value="0" />
					<input type="hidden" name="diskon" value="0" />
					
					<td>&nbsp;</td>
					
					<td>&nbsp; 
					<?php if(isset($_SESSION["SELECT_KAMAR_CEKIN"])) { ?>
					<input type="submit" value="Save">
					<?php } ?>
					</td>
				</tr>
			</table>
			
		</div>
	</div>
	</form>
<script language='JavaScript'>
	function CekMaterai(tag){
		var harga = $("#hrg1").val();
		var harga1 = harga.replace(",","");
		var harga2 = harga1.replace(",","");
		var harga3 = parseInt(harga2.replace(".",","));
		//alert(harga1);
		if(tag == "002"){
			tagihan = numeral(harga3 + 3).format('0,0.00');			
			$("#hrg_materai").val('3.00');
			$("#hrg_tagihan").val(tagihan);
			$("#bayar").val(tagihan);
			$("#totag").val(harga3 + 3);
		} else if (tag == "003"){
			tagihan = numeral(harga3 + 6).format('0,0.00');
			$("#hrg_materai").val('6.00');
			$("#hrg_tagihan").val(tagihan);
			$("#bayar").val(tagihan);
			$("#totag").val(harga3 + 6);
		} else {
			tagihan = numeral(harga3).format('0,0.00');
			$("#hrg_materai").val('0.00');
			$("#hrg_tagihan").val(tagihan);
			$("#bayar").val(tagihan);
			$("#totag").val(harga3);
		}
	}
	
	$(function(){
            
    $('#bayar').keyup(function(){
    	var totag = parseInt($("#totag").val());
    	var harga = $("#bayar").val();
		var harga1 = harga.replace(",","");
		var harga2 = harga1.replace(",","");
		var harga3 = parseInt(harga2.replace(".",","));
         
         jml = totag - harga3;
         $("#sisa").val(jml);
    });
    
    $('#cab').change(function(){
    	var cab = $("#cab").val();
    		
		if(cab == "001"){
			$("#no_kartu").attr('readonly','readonly');
			$("#no_kartu").val('');
		} else {
			//$("#no_kartu").attr('readonly','');
		}
         
         
    });
    
});
</script>
	
<script language='JavaScript'>
	function cari_kamar(tag) {
	    sWin = window.open('includes/cari_kamar.php?jns='+tag, 'xWin',
	 	'top=0,left=0,width=1200,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
	}
	
	function cetakDP(tag, tag1) {
	    sWin = window.open('includes/cetak_dp.php?idx='+tag+'&kw='+tag1, '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 {
	



if($_GET[act] == "add"){ 

title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Check In");
?>
	
	<div class="ui three column stackable grid">
  <div class="column">
		
		<table width="100%" class="gridtable_form" border="1px">						
			<tr>
				<td>Select Room Type</td>
				<td><input type="button" value="Check" onclick="javascript:cek_kamar();" class="blue ui mini button" ></td>
			</tr>
		</table>
	</div>	
	<div class="column">
	
	<?php
		if ($_SESSION["SELECT_KAMAR"]){
			$r = mysql_query("select * from tbl_referensi where id = '".$_SESSION["SELECT_KAMAR"]."' and kd = 'ROM'");
		    $n = mysql_num_rows($r);
		    if($n > 0) $d = mysql_fetch_object($r);
		    mysql_free_result($r);
		?>
		<h4 class="ui top attached block header">Room Type</h4>
		<div class="ui one cards">
			<div class="ui card">
				<div class="image dimmable">
					
				<img src="images/<?php echo $d->gambar;?>" >
				</div>
			<div class="content">
				<div class="header"><?php echo $d->keterangan; ?></div>
				<div class="description"><?php echo $d->keterangan2;?></div>
			</div>
			<div class="extra content">
				<a class="friends"><font color="#3959c6"> Price /Night : Rp. <?php echo number_format($d->harga,2,',','.'); ?></font></a>
			</div>
			</div>
		</div>
		<?php
		}
		?>
	</div>
	<div class="column">
		<?php
		if ($_SESSION["SELECT_KAMAR"]){
			$lama_inap = getFromtable("select date('".$_SESSION[SELECT_TGL2]."') - date('".$_SESSION[SELECT_TGL1]."') ");
		?>
		<h4 class="ui top attached block header">Detail Check-in</h4>
		<form action="actions/booking_insert.php" method="POST">
		<input type="hidden" name="jns" value="<?php echo $_SESSION["SELECT_KAMAR"];?>"/>
		<input type="hidden" name="p" value="<?php echo $PID;?>"/>
		<input type="hidden" name="cek" value="ceking"/>	
		<input type="hidden" name="nm_pemesan" value="">	
			<table width="100%" class="gridtable_form" border="1px">
				<tr>
					<td>No.REG</td>
					<td>: <input type="text" value="-Otomatis-" disabled="disabled"></td>
				</tr>
				
				<tr>
					<td>ID (KTP/SIM/PASPORT)</td>
					<td>: <input type="text" name="no_ktp" value="-" required="required"></td>
				</tr>
				<tr>
					<td>Initial</td>
					<td>: <?php echo query_inisial("ins","001"); ?></td>
				</tr>
				<tr>
					<td>Guest Name</td>
					<td>: <input type="text" name="nm_pelanggan" id="nm_lengkap" value="" required="required"></td>
				</tr>
				<tr>
					<td>Date of Birth</td>
					<td>: <input type="text" name="tgl_lahir" class="tanggal" value="-" required="required"></td>
				</tr>
				<input type="hidden" name="nm_panggilan" value="">
				<tr>
					<td>Address</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>
				<input type="hidden" name="kd_pos" value="00000" >
				<!--tr>
					<td>Kode Pos</td>
					<td>: <input type="text" name="kd_pos" value="" ></td>
				</tr-->
				<tr>
					<td>Country</td>
					<td>: <?php echo query_negara("negara","064"); ?></td>
				</tr>
				<tr>
					<td>No.Hp</td>
					<td>: <input type="text" name="no_hp" value="" required="required"></td>
				</tr>
				<tr>
					<td>Email</td>
					<td>: <input type="text" name="email" value="-" required="required"></td>
				</tr>
				<tr>
					<td>Company</td>
					<td>: <input type="text" name="instansi" value="-" required="required"></td>
				</tr>
				<tr>
					<td>Rate /Night</td>
					<td>: <input type="text" name="harga1" align="right" value="<?php echo number_format($d->harga,2,',','.'); ?>" readonly="readonly"></td>
					
				</tr>
				<input type="hidden" name="harga" id="harga" value="<?php echo $d->harga; ?>" />
				<tr>
					<td>Length Of Stay</td>
					<td>: <input type="text" name="lama_inap" value="1" id="lama_inap"></td>
				</tr>
				<tr>
					<td>Total</td>
					<td>: <input type="text" name="total_tagihan" id="total_tagihan" value="<?php echo number_format($d->harga,2,',','.');?>" readonly="readonly" ></td>
				</tr>
				<tr>
					<td>Guest Type</td>
					<td>: <?php echo query_jnsguest("guest_type",$d->guest_type,"","") ;?> </td>
				</tr>
				<?php
				$pax = "<select name='pax'>\n";
				for ($i = 1; $i <= 10; $i++){
					$pax .= "<option value = $i>$i</option>";
				}
				$pax .= "</select>\n";
				?>
				<tr>
					<td>Person</td>
					<td>: <?php echo $pax;?> </td>
				</tr>
				<input type="hidden" name="down_paymen" value="0" >
				<tr>
					<td>&nbsp;</td>
					<td>: <input type="submit" value="Submit" class="blue ui mini button"></td>
				</tr>
			</table>
		</form>
		<?php	
		}		
		?>
	</div>	
</div>	

<script language='JavaScript'>
	$(function(){
		$('#copy').click(function(){
	    	var nm = $("#nm_pemesan").val();
	        $("#nm_lengkap").val(nm);
	         
    	});
    	
    	$('#lama_inap').keyup(function(){
	    	var harga = parseInt($("#harga").val());
	        var lm = parseInt($("#lama_inap").val());
	        
	         tag = harga * lm;
	         $("#total_tagihan").val(tag);
    	});
    });
function cek_kamar() {
	var tgl1 = $("#tgl1").val();
	var tgl2 = $("#tgl2").val();
    sWin = window.open('includes/cek_kamar.php?tgl1='+tgl1+'&tgl2='+tgl2, 'xWin',
 'top=0,left=0,width=750,height=550,menubar=no,scrollbars=yes');
    sWin.focus();
}
</script>
<?php
} else {
	title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Reservation List");
	
?>
<br/>
<form>
<input type="hidden" name="p" value="cek_in"/>
<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">No. Reserv.</td>
		<td class="gridtable_th" align="center">Reserv.<br/>Date</td>
		<td class="gridtable_th" align="center">Checkin.<br/>Date</td>
		<td class="gridtable_th" align="center">Guest 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">Room Type</td>
		<td class="gridtable_th" align="center">Down Payment</td>
	</tr>
	<tr>
		<td class="gridtable_th">
			<a href="<?php echo "$SC?p=$PID&act=add";?>"><img src="images/icon-checklist.png"/></a>
		</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>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th">&nbsp;</td>
	</tr>
	<?php
	$sql = "select a.*, b.keterangan as inisial, c.*, d.keterangan as negara
			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'
			where status_booking = 'booking' and upper(id_booking) like '%".strtoupper($_GET[kd_book])."%' and
			upper(a.nm_lengkap) like '%".strtoupper($row[nm_lengkap])."%' and (upper(a.alamat) like '%".strtoupper($row[alamat])."%'
			or upper(a.kota) like '%".strtoupper($row[kota])."%' or upper(a.kd_pos) like '%".strtoupper($row[kd_pos])."%'
			or upper(d.keterangan) like '%".strtoupper($row[negara])."%')  ";
	$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_booking])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[tgl_cekin])); ?></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>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[keterangan])); ?></td>
		<td class="gridtable_td" align="right"><?php echo number_format($row[down_paymen],2,",","."); ?></td>
	</tr>
	<?php } ?>
</table>
</form>
<?php } } ?>