
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
   $('#load_latest_scores').load('dashboard.php');
}, 100000); // refresh every 10000 milliseconds
</script>
<html>
<head>

	<link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
	<link href="assets/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" />
	<link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
	<link href="assets/css/style.css" rel="stylesheet" />
	<link href="assets/css/style_responsive.css" rel="stylesheet" />
	<link href="assets/css/style_default.css" rel="stylesheet" id="style_color" />
	<link href="#" rel="stylesheet" id="style_metro" />
	<link href="assets/fancybox/source/jquery.fancybox.css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" href="assets/gritter/css/jquery.gritter.css" />
	<link rel="stylesheet" type="text/css" href="assets/uniform/css/uniform.default.css" />
	<link rel="stylesheet" type="text/css" href="assets/bootstrap-daterangepicker/daterangepicker.css" />
	<link href="assets/fullcalendar/fullcalendar/bootstrap-fullcalendar.css" rel="stylesheet" />
	<link href="assets/jqvmap/jqvmap/jqvmap.css" media="screen" rel="stylesheet" type="text/css" />
</head>

<?php
@session_start();
require_once("lib/dbconn.php");

$tot_rom = getFromTable("select count(id) from tbl_room");
$bln = date("Y-m");
$tot_booking = getFromTable("select count(id_booking) from tbl_booking where status_booking = 'booking' and tgl_booking = CURRENT_DATE ");
$tot_booking2 = getFromTable("select count(id_booking) from tbl_booking where tgl_booking like '%".$bln."%'");
$tot_book1 = getFromTable("select count(id_booking) from tbl_booking where jns_room = '001' and tgl_booking like '%".$bln."%'");
$tot_book2 = getFromTable("select count(id_booking) from tbl_booking where jns_room = '002' and tgl_booking like '%".$bln."%'");
$tot_book3 = getFromTable("select count(id_booking) from tbl_booking where jns_room = '003' and tgl_booking like '%".$bln."%'");
$tot_book4 = getFromTable("select count(id_booking) from tbl_booking where jns_room = '004' and tgl_booking like '%".$bln."%'");
$tot_book5 = getFromTable("select count(id_booking) from tbl_booking where jns_room = '005' and tgl_booking like '%".$bln."%'");

$tot_ceking = getFromTable("select count(id_booking) from tbl_booking where status_booking = 'cekin' and tgl_cekin = CURRENT_DATE ");
$tot_ceking2 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekin','cekout') and tgl_cekin like '%".$bln."%'");
$tot_cekin1 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekin','cekout') and jns_room = '001' and tgl_cekin like '%".$bln."%'");
$tot_cekin2 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekin','cekout') and jns_room = '002' and tgl_cekin like '%".$bln."%'");
$tot_cekin3 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekin','cekout') and jns_room = '003' and tgl_cekin like '%".$bln."%'");
$tot_cekin4 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekin','cekout') and jns_room = '004' and tgl_cekin like '%".$bln."%'");
$tot_cekin5 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekin','cekout') and jns_room = '005' and tgl_cekin like '%".$bln."%'");

$tot_cancel = getFromTable("select count(no_booking) from tbl_batal_booking where tgl_trans = CURRENT_DATE ");
$tot_cancel2 = getFromTable("select count(no_booking) from tbl_batal_booking where tgl_trans like '%".$bln."%'");
$tot_alasan1 = getFromTable("select count(no_booking) from tbl_batal_booking where alasan = '001' and tgl_trans like '%".$bln."%'");
$tot_alasan2 = getFromTable("select count(no_booking) from tbl_batal_booking where alasan = '002' and tgl_trans like '%".$bln."%'");
$tot_alasan3 = getFromTable("select count(no_booking) from tbl_batal_booking where alasan = '003' and tgl_trans like '%".$bln."%'");
$tot_alasan4 = getFromTable("select count(no_booking) from tbl_batal_booking where alasan = '004' and tgl_trans like '%".$bln."%'");
$tot_alasan5 = getFromTable("select count(no_booking) from tbl_batal_booking where alasan = '005' and tgl_trans like '%".$bln."%'");

$tot_cekout = getFromTable("select count(id_booking) from tbl_booking where status_booking = 'cekout' and tgl_cekout = CURRENT_DATE ");
$tot_cekout2 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekout') and tgl_cekout like '%".$bln."%'");
$tot_cekot1 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekout') and jns_room = '001' and tgl_cekout like '%".$bln."%'");
$tot_cekot2 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekout') and jns_room = '002' and tgl_cekout like '%".$bln."%'");
$tot_cekot3 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekout') and jns_room = '003' and tgl_cekout like '%".$bln."%'");
$tot_cekot4 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekout') and jns_room = '004' and tgl_cekout like '%".$bln."%'");
$tot_cekot5 = getFromTable("select count(id_booking) from tbl_booking where status_booking in ('cekout') and jns_room = '005' and tgl_cekout like '%".$bln."%'");

?>
<body class="fixed-top">
	<br/>
	<div id="load_latest_scores">
	<div class="row-fluid">
		<div class="span3 responsive" data-tablet="span6" data-desktop="span3">
			<div class="circle-stat block">
				<div class="visual">
					<input class="knobify" data-width="115" data-thickness=".2" data-skin="tron" data-displayprevious="true" value="<?php echo $tot_booking;?>" data-max="<?php echo $tot_rom;?>" data-min="0" />
				</div>
				<div class="details">
					<div class="title">Guest Booking <i class="icon-caret-up"></i></div>
					<div class="number" title="Total Booking Bulan ini">Total : <?php echo $tot_booking2;?></div>
					<span class="label label-success"><i class="icon-home"></i>&nbsp;<?php echo $tot_book1; ?></span>
					<span class="label label-warning"><i class="icon-home"></i>&nbsp;<?php echo $tot_book2; ?></span>
					<span class="label label-info"><i class="icon-home"></i>&nbsp;<?php echo $tot_book3; ?></span>
					<span class="label label-danger"><i class="icon-home"></i>&nbsp;<?php echo $tot_book4; ?></span>
					<span class="label label-important"><i class="icon-home"></i>&nbsp;<?php echo $tot_book5; ?></span>
				</div>
			</div>
		</div>
		<div class="span3 responsive" data-tablet="span6" data-desktop="span3">
			<div class="circle-stat block">
				<div class="visual">
					<input class="knobify" data-width="115" data-fgcolor="#66EE66" data-thickness=".2" data-skin="tron" data-displayprevious="true" value="<?php echo $tot_ceking;?>" data-max="<?php echo $tot_rom;?>" data-min="0" />
				</div>
				<div class="details">
					<div class="title">ChekIn Guest <i class="icon-caret-up"></i></div>
					<div class="number">Total : <?php echo $tot_ceking2;?></div>
					<span class="label label-success"><i class="icon-suitcase"></i>&nbsp;<?php echo $tot_cekin1;?></span>
					<span class="label label-warning"><i class="icon-suitcase"></i>&nbsp;<?php echo $tot_cekin2;?></span>
					<span class="label label-info"><i class="icon-suitcase"></i>&nbsp;<?php echo $tot_cekin3;?></span>
					<span class="label label-danger"><i class="icon-suitcase"></i>&nbsp;<?php echo $tot_cekin4;?></span>
					<span class="label label-important"><i class="icon-suitcase"></i>&nbsp;<?php echo $tot_cekin5;?></span>
				</div>
			</div>
		</div>
		<div class="span3 responsive" data-tablet="span6 fix-margin" data-desktop="span3">
			<div class="circle-stat block">
				<div class="visual">
					<input class="knobify" data-width="115" data-fgcolor="#e23e29" data-thickness=".2" data-skin="tron" data-displayprevious="true" value="<?php echo $tot_cancel; ?>" data-max="<?php echo $tot_rom;?>" data-min="0" />
				</div>
				<div class="details">
					<div class="title">Cancel Booking <i class="icon-caret-down down"></i></div>
					<div class="number">Total : <?php echo $tot_cancel2; ?></div>
					<span class="label label-success"><i class="icon-flag"></i>&nbsp;<?php echo $tot_alasan1;?></span>
					<span class="label label-warning"><i class="icon-flag"></i>&nbsp;<?php echo $tot_alasan2;?></span>
					<span class="label label-info"><i class="icon-flag"></i>&nbsp;<?php echo $tot_alasan3;?></span>
					<span class="label label-danger"><i class="icon-flag"></i>&nbsp;<?php echo $tot_alasan4;?></span>
					<span class="label label-important"><i class="icon-flag"></i>&nbsp;<?php echo $tot_alasan5;?></span>
				</div>
			</div>
		</div>
		<div class="span3 responsive" data-tablet="span6" data-desktop="span3">
			<div class="circle-stat block">
				<div class="visual">
					<input class="knobify" data-width="115" data-fgcolor="#fdbb39" data-thickness=".2" data-skin="tron" data-displayprevious="true" value="<?php echo $tot_cekout;?>" data-max="<?php echo $tot_rom;?>" data-min="0" />
				</div>
				<div class="details">
					<div class="title">Cekout Guest <i class="icon-caret-up"></i></div>
					<div class="number" title="Total Guest Cekout bulan ini">Total : <?php echo $tot_cekout2;?></div>
					<span class="label label-success"><i class="icon-flag"></i>&nbsp;<?php echo $tot_cekot1;?></span>
					<span class="label label-warning"><i class="icon-flag"></i>&nbsp;<?php echo $tot_cekot2;?></span>
					<span class="label label-info"><i class="icon-flag"></i>&nbsp;<?php echo $tot_cekot3;?></span>
					<span class="label label-danger"><i class="icon-flag"></i>&nbsp;<?php echo $tot_cekot4;?></span>
					<span class="label label-important"><i class="icon-flag"></i>&nbsp;<?php echo $tot_cekot5;?></span>
				</div>
			</div>
		</div>
	</div>
		
	<div class="row-fluid">
		<div class="span6">
			<!-- BEGIN RECENT ORDERS PORTLET-->
			<div class="widget">
				<div class="widget-title">
					<h4><i class="icon-shopping-cart"></i>Recent Booking</h4>											
				</div>
				<div class="widget-body">
					<table class="table table-striped table-bordered table-advance table-hover">
						<thead>
							<tr>
								<th style="font-size: 12px;"><i class="icon-calendar"></i> Date Booking</th>
								<th style="font-size: 12px;"><i class="icon-calendar"></i> Date Chekin</th>
								<th style="font-size: 12px;"><i class="icon-user"></i>Guest Name</th>
								<th style="font-size: 12px;"><i class="icon-phone-sign"> </i>Hp</th>
								<th style="font-size: 12px;"></th>
							</tr>
						</thead>
						<tbody>
							<?php
							$sql = " select *, DATEDIFF(tgl_cekin,tgl_booking) as lama from tbl_booking where status_booking = 'booking' order by lama asc limit 10";
							$r = mysql_query($sql);
							$n = mysql_num_rows($r);
							while ($row = mysql_fetch_array($r)) {
								if ($row[lama] < 2){
									$class = "important";
								} elseif ($row[lama] > 1 and $row[lama] < 4 ){
									$class = "warning";
								} else {
									$class = "success";
								}
							?>
							<tr>
								<td class="highlight" style="font-size: 12px;">
									<div class="<?php echo $class; ?>"></div>&nbsp;&nbsp;&nbsp;
									<?php echo $row[tgl_booking];?>
								</td>
								<td style="font-size: 12px;"><?php echo $row[tgl_cekin];?></td>
								<td style="font-size: 12px;"><?php echo $row[nm_lengkap];?></td>
								<td style="font-size: 12px;"><?php echo $row[no_hp];?> </td>
							</tr>
							<?php } ?>
							
						</tbody>
					</table>					
				</div>
			</div>
			<!-- END RECENT ORDERS PORTLET-->
		</div>
		<div class="span6">
			<!-- BEGIN LATEST INVOICES PORTLET-->
			<div class="widget">
				<div class="widget-title">
					<h4><i class="icon-print"></i>Guest in House </h4>											
				</div>
				<div class="widget-body">
					<table class="table table-striped table-bordered table-advance table-hover">
						<thead>
							<tr>
								<th style="font-size: 12px;"><i class="icon-briefcase"></i>ID.Guest</th>
								<th style="font-size: 12px;"><i class="icon-user"></i>Guest Name</th>
								<th style="font-size: 12px;"><i class="icon-question-sign"></i>No.Room</th>
								<th style="font-size: 12px;"><i class="icon-bookmark"></i>Room Type</th>
							</tr>
						</thead>
						<tbody>
							<?php
							$sql1 = " select distinct a.*, c.id as idx, c.no_room, c.kd_jenis, d.keterangan, d.harga, 
									(select max(z.tgl_trans) from tbl_transaksi z where z.no_booking = a.id_booking and z.jns_trans = 'ROOM') as tgl_trans, 
									CURRENT_DATE as tgl, CURRENT_TIME as wkt
									from tbl_booking a
									join tbl_transaksi b on b.no_booking = a.id_booking
									join tbl_room c on c.id = b.item_id
									join tbl_referensi d on d.id = c.kd_jenis and d.kd = 'ROM'
									where a.status_booking = 'cekin' and b.jns_trans = 'ROOM' and b.status_trans = 1
									order by c.no_room desc limit 10";
							$r1 = mysql_query($sql1);
							$n1 = mysql_num_rows($r1);
							while ($row1 = mysql_fetch_array($r1)) {
								if ($row1[tgl_trans] != $row1[tgl]){
									if ($row1[wkt] > "13:00:00"){
										$cek1 = getFromTable("select count(id) from tbl_transaksi");
										$kd = $cek1 + 1;
										if ($row1[guest_type] == "001"){
											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 
											            ('$kd', 'ROOM', CURRENT_DATE, CURRENT_DATE, 
											        	CURRENT_TIME, '".$row1[id_booking]."', '".$row1[idx]."', 1, ".$row1[harga].",
											        	0, ".$row1[harga].", '".$_SESSION[nama_usr]."')");
										} else {	
											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 
											            ('$kd', 'ROOM', CURRENT_DATE, CURRENT_DATE, 
											        	CURRENT_TIME, '".$row1[id_booking]."', '".$row1[id]."', 1, ".$row1[harga].",
											        	".$row1[harga].", 0, '".$_SESSION[nama_usr]."')");
										}
									}
									
								}
								if ($row1[kd_jenis] == "001"){
									$class = "success";
								} elseif ($row1[kd_jenis] == "002"){
									$class = "warning";
								} elseif ($row1[kd_jenis] == "003"){
									$class = "info";
								} elseif ($row1[kd_jenis] == "004"){
									$class = "danger";
								} else {
									$class = "important";
								}
							?>
							<tr>
								<td class="highlight" style="font-size: 12px;">
									<div class="<?php echo $class; ?>"></div>&nbsp;&nbsp;&nbsp;
									<?php echo $row1[id_booking];?>
								</td>
								<td style="font-size: 12px;"><?php echo $row1[nm_lengkap];?></td>
								<td style="font-size: 12px;"><?php echo $row1[no_room];?></td>
								<td style="font-size: 12px;"><?php echo $row1[keterangan];?></td>
							</tr>
							<?php } ?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="">
		<div class="widget-title">
			<h4><i class="icon-leaf"></i>Houskeeping Room Status</h4>											
		</div>
		<br/>
		<?php
		$sql2 = " select * from tbl_room ";
		$r2 = mysql_query($sql2);
		$n2 = mysql_num_rows($r2);
		while ($row2 = mysql_fetch_array($r2)) {
			if  ($row2[status_kmr] == "isi"){
				$class = "danger";
				$ket = "Occupied";
			} elseif ($row2[status_kmr] == "kotor"){
				$class = "warning";
				$ket = "VD";
			} elseif ($row2[status_kmr] == "dibersihkan"){
				$class = "info";
				$ket = "VC";
			} elseif ($row2[status_kmr] == "rusak"){
				$class = "danger";
				$ket = "OO";
			} elseif ($row2[status_kmr] == "kotor2"){
				$class = "danger";
				$ket = "OD";
				} elseif ($row2[status_kmr] == "bersih"){
				$class = "success";
				$ket = "OC";
			}else {
				$class = "success";
				$ket = "Available";
			}
		?>
		<div class="span1 responsive" data-tablet="span1" data-desktop="span1">
			<div class="stats-overview block clearfix">
				<div class="details">
					<div class="title"><?php echo $ket;?></div>
					
					<div class="title center"><?php echo $row2[tipe_bed];?></div>
					<div class="numbers center"><?php echo $row2[no_room];?></div>
					
				</div>
				<div class="progress progress-<?php echo $class;?>">
					<div class="bar" style="width: 100%"></div>
				</div>
			</div>
		</div>
		<?php
		}
		?>
	</div>
	<script src="assets/js/jquery-1.8.2.min.js"></script>	
	<script src="assets/jQuery-slimScroll/jquery-ui-1.9.2.custom.min.js"></script>	
	<script src="assets/jQuery-slimScroll/slimScroll.min.js"></script>		
	<script src="assets/bootstrap/js/bootstrap.min.js"></script>
	<script src="assets/js/jquery.blockui.js"></script>	
	<script src="assets/js/jquery.cookie.js"></script>	

	<script src="assets/jquery-knob/js/jquery.knob.js"></script>
	<script src="assets/flot/jquery.flot.js"></script>
	<script src="assets/flot/jquery.flot.resize.js"></script>
	<script src="assets/js/jquery.peity.min.js"></script>	
	<script type="text/javascript" src="assets/gritter/js/jquery.gritter.js"></script>
	<script type="text/javascript" src="assets/uniform/jquery.uniform.min.js"></script>	
	<script type="text/javascript" src="assets/js/jquery.pulsate.min.js"></script>
	<script src="assets/fancybox/source/jquery.fancybox.pack.js"></script>
	<script src="assets/js/app.js"></script>		
	<script>
		jQuery(document).ready(function() {		
			// initiate layout and plugins
			App.setMainPage(true);
			App.init();
		});
	</script>
	</div>
</body>
<!-- END BODY -->
</html>