
<link rel="stylesheet" type="text/css" href="../css/semantic.css">
<link rel="stylesheet" type="text/css" href="../css/default.css">
<SCRIPT type="text/javascript" language="JavaScript" src="../js/jquery.js"></SCRIPT>
<script type='text/javascript' language="JavaScript" src='../js/jquery.ui.datepicker.js'></script>
<SCRIPT type='text/javascript' language="JavaScript" src='../js/jquery-ui.js'></SCRIPT>
<link rel="stylesheet" type="text/css" href="../css/jquery-ui2.css" />
<style>
.harga{
	text-align: right;
}
</style>
<script>
	$(function() {
        $( ".tanggal" ).datepicker({
            dateFormat:'yy-mm-dd',
            changeMonth :true,
            changeYear :true
        });
    });
</script>
<?php
@session_start();
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' >  Choose Room Type");

if (isset($_GET["update"])) {
    mysql_query("update tbl_transaksi set diskon = ".$_GET[diskon].", jumlah = ".$_GET[jumlah]." where id = ".$_GET[pid]);
    
    ?>
    <SCRIPT language="JavaScript">
        window.opener.location = window.opener.location;
        window.close();
    </SCRIPT>
    <?php
    exit;
}

if (isset($_GET["add"])) {
    $id = getFromTable("select count(id) + 1 from tbl_transaksi ");
	echo $max = getFromTable("select max(id) from tbl_transaksi  where no_booking = '".$_GET[idx]."' and jns_trans = 'ROOM' and status_trans = 1 ");
	
	$r = mysql_query("select * from tbl_transaksi
					 where id = $max ");
	$n = mysql_num_rows($r);
	if($n > 0) $d = mysql_fetch_object($r);
	mysql_free_result($r);
	
	mysql_query("insert into tbl_transaksi (id, jns_trans, tgl_trans, tgl_entry,
				wkt_entry, no_booking, item_id, qty, harga, 
				diskon, jumlah, user_entry) values 
	            ('$id', 'ROOM', '".$_GET[date]."', CURRENT_DATE, 
	        	CURRENT_TIME, '".$_GET[idx]."', '".$d->item_id."', 1, '".$d->harga."',
	        	'".$d->diskon."', '".$d->jumlah."', '".$_SESSION[nama_usr]."')");
    //die();
    ?>
    <SCRIPT language="JavaScript">
        window.opener.location = window.opener.location;
        window.close();
    </SCRIPT>
    <?php
    exit;
}

require_once("../includes/keterangan.php");

if($_GET[act] == "add") {
	?>
	<form>
		<input type="hidden" name="p" value="<?php echo $PID;?>"/>
		<input type="hidden" name="add" value="add"/>
		<input type="hidden" name="idx" value="<?php echo $_GET[idx];?>"/>
		<div class="ui three column stackable grid" align="center">
			<div class="column"></div>
			<div class="column">
				<table width="100%" class="gridtable_form" border="1px">
					<tr>
						<td><b>Date</b></td>
						<td> : <input type="text" name="date" class="tanggal" value="<?php echo $d->tgl_trans;?>" readonly="readonly"/>	</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;&nbsp;<input type="submit" value="Update"/></td>
					</tr>
				</table>
			</div>
			<div class="column"></div>
		</div>
	</form>
	<?php
} elseif($_GET[act] == "edt") {
	$r = mysql_query("select * from tbl_transaksi
					 where id = '".$_GET[pid]."' ");
	$n = mysql_num_rows($r);
	if($n > 0) $d = mysql_fetch_object($r);
	mysql_free_result($r);
?>
<!--h4 class="ui top attached block header">Kamar Tersedia</h4-->
<form>
	<input type="hidden" name="p" value="<?php echo $PID;?>"/>
	<input type="hidden" name="update" value="edt"/>
	<input type="hidden" name="pid" value="<?php echo $_GET[pid];?>"/>
	<div class="ui three column stackable grid" align="center">
		<div class="column"></div>
		<div class="column">
			<table width="100%" class="gridtable_form" border="1px">
				<tr>
					<td><b>Date</b></td>
					<td> : <input type="text" name="date" value="<?php echo $d->tgl_trans;?>" readonly="readonly"/>	</td>
				</tr>
				<tr>
					<td><b>Price</b></td>
					<td> : <input type="text" name="harga" id="harga" class="harga" value="<?php echo $d->harga;?>" readonly="readonly"/>	</td>
				</tr>
				<tr>
					<td><b>Discount (%)</b></td>
					<td> : <input type="text" name="persen" id="persen" class="harga" value="0" />	</td>
				</tr>
				<tr>
					<td><b>Discount (IDR)</b></td>
					<td> : <input type="text" name="diskon" id="diskon" class="harga" value="<?php echo $d->diskon;?>" readonly="readonly"/>	</td>
				</tr>
				<tr>
					<td><b>Price</b></td>
					<td> : <input type="text" name="jumlah" id="jumlah" class="harga" value="<?php echo $d->jumlah;?>" readonly="readonly"/>	</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;&nbsp;<input type="submit" value="Update"/></td>
				</tr>
			</table>
		</div>
		<div class="column"></div>
	</div>
</form>
<script type="text/javascript">
	$(function(){
		$('#persen').keyup(function(){
    		var harga = parseInt($("#harga").val());
    		var per = parseInt($("#persen").val());
    		
    		dis = (harga * per) / 100;
    		tot = harga - dis;
    		
    		$("#diskon").val(dis);
    		$("#jumlah").val(tot);
    	});
	});
</script>
<?php } ?>
<div style="clear: both; display: block;"></div>
