<meta name="viewport" content="width=device-width, initial-scale=1">
<?php
include_once 'mod/sw-header.php';

if(!isset($_COOKIE['COOKIES_CUSTNO']) && !isset($_COOKIE['COOKIES_COOKIES'])){
        setcookie('COOKIES_CUSTNO', '', 0, '/');
        setcookie('COOKIES_COOKIES', '', 0, '/');
        // Login tidak ditemukan
        setcookie("COOKIES_CUSTNO", "", time()-$expired_cookie);
        setcookie("COOKIES_COOKIES", "", time()-$expired_cookie);
        session_destroy();
        header("location:./index");
} else {        

include 'connect.php';
//include_once 'sw-header.php';
define('YBASE',true);
session_start();


if (isset($_GET['id'])) {
    $query = mysqli_query($con,"SELECT a.custno,a.custname,a.alamat1,a.alamat2,a.lmt,DATE_FORMAT(b.tgl,'%d-%m-%Y') as tgl,b.cekin,b.cekout,b.salesorder,b.bayar FROM customer a
	left join customer_log b on b.custno=a.custno 
	WHERE a.custno = '$_GET[id]' order by b.tgl desc limit 1;");
    $data  = mysqli_fetch_array($query);
} else {
    echo "ID tidak tersedia! $_GET[id]
<a href='listcustomer.php'>Kembali 1</a>";
    exit();
} 
if ($data === false) {
    echo "Data tidak ditemukan!
<a href='listcustomer.php'>Kembali</a>";
    exit();
}
$_SESSION['custno'] = $data['custno'];
$jabat=$_SESSION['jabat'];
$slm=$_SESSION['yuser'];	
if ($jabat=='1') {
$tagih= mysqli_query($con,"select sum(a.nilai) as total,sum(a.nofaktur) as tfaktur,GROUP_CONCAT(CONCAT(a.nofaktur,' / Rp. ',a.nilai))  as nofaktur from tagihandetail a
	left join tagihanheader b on a.nobukti=b.nobukti
	where b.kdslm='$_SESSION[yuser]' and a.custno='$data[custno]' and b.tgltagih=curdate();");
}
else {
	$tagih= mysqli_query($con,"select sum(a.nilai) as total,sum(a.nofaktur) as tfaktur,GROUP_CONCAT(CONCAT(a.nofaktur,' / Rp. ',a.nilai))  as nofaktur from tagihandetail a
	left join tagihanheader b on a.nobukti=b.nobukti
	where b.kdslm='$slm' and a.custno='$data[custno]' and b.tgltagih=curdate();");
}
$lph=mysqli_fetch_array($tagih);
$COOKIES_CUSTNO  = ($data['custno']);
$COOKIES_ORDER ='Z';
$expired_cookie = time()+60*60*24*7;
?>
<html>
 <head>
  <title>IBS</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="css/layout.css">
    <link rel="stylesheet" type="text/css" href="css/stylesheet.css">
    <link rel="stylesheet" type="text/css" href="css/easyui.css">
    <link rel="stylesheet" type="text/css" href="css/icon.css">
	<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.css">
    <link rel="stylesheet" type="text/css" href="css/jquery_notification.css">
    <link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css"/>
    <link rel="stylesheet" type="text/css" href="css/jpaging.css">
    <link rel="stylesheet" type="text/css" href="css/ui.datepicker.css"/>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.20.custom.min.js"></script>
    <script type='text/javascript' src='js/jquery.paginate.js'></script>
    <script type="text/javascript" src="js/ui.core.js"></script>
    <script type='text/javascript' src="js/jquery.autocomplete.js"></script>
    <script type="text/javascript" src="js/ui.datepicker.js"></script>
    <script type="text/javascript" src="js/jquery.PrintArea.js"></script>
	<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="js/clock.js"></script>
    <script type="text/javascript" src="js/jquery_notification_v.1.js"></script>
	<script type="text/javascript">    
    //fungsi displayTime yang dipanggil di bodyOnLoad dieksekusi tiap 1000ms = 1detik
    function tampilkanwaktu(){
        //buat object date berdasarkan waktu saat ini
        var waktu = new Date();
        //ambil nilai jam, 
        //tambahan script + "" supaya variable sh bertipe string sehingga bisa dihitung panjangnya : sh.length
        var sh = waktu.getHours() + ""; 
        //ambil nilai menit
        var sm = waktu.getMinutes() + "";
        //ambil nilai detik
        var ss = waktu.getSeconds() + "";
        //tampilkan jam:menit:detik dengan menambahkan angka 0 jika angkanya cuma satu digit (0-9)
        document.getElementById("clock").innerHTML = (sh.length==1?"0"+sh:sh) + "." + (sm.length==1?"0"+sm:sm) + "." + (ss.length==1?"0"+ss:ss);
    }
</script>
	<style type="text/css">
.classname {
	-moz-box-shadow:inset 0px 1px 0px 0px #cae3fc;
	-webkit-box-shadow:inset 0px 1px 0px 0px #cae3fc;
	box-shadow:inset 0px 1px 0px 0px #cae3fc;
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #79bbff), color-stop(1, #4197ee) );
	background:-moz-linear-gradient( center top, #79bbff 5%, #4197ee 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#79bbff', endColorstr='#4197ee');
	background-color:#79bbff;
	-webkit-border-top-left-radius:20px;
	-moz-border-radius-topleft:20px;
	border-top-left-radius:20px;
	-webkit-border-top-right-radius:20px;
	-moz-border-radius-topright:20px;
	border-top-right-radius:20px;
	-webkit-border-bottom-right-radius:20px;
	-moz-border-radius-bottomright:20px;
	border-bottom-right-radius:20px;
	-webkit-border-bottom-left-radius:20px;
	-moz-border-radius-bottomleft:20px;
	border-bottom-left-radius:20px;
	text-indent:0;
	border:1px solid #469df5;
	display:inline-block;
	color:#ffffff;
	font-family:Verdana;
	font-size:15px;
	font-weight:bold;
	font-style:normal;
	height:25px;
	line-height:25px;
	width:131px;
	text-decoration:none;
	text-align:center;
	text-shadow:1px 1px 0px #287ace;
}
.classname:hover {
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #4197ee), color-stop(1, #79bbff) );
	background:-moz-linear-gradient( center top, #4197ee 5%, #79bbff 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#4197ee', endColorstr='#79bbff');
	background-color:#4197ee;
}.classname:active {
	position:relative;
	top:1px;
}

    tbody > tr:nth-child(2n+1) > td, tbody > tr:nth-child(2n+1) > th {
        background-color: #ededed;
    }
    table{
        width: 95%;
        margin: auto;
        border-collapse: collapse;
        box-shadow: darkgrey 3px;
    }
    thead tr {
        background-color: #36c2ff;
    }
	
</style>
<style type="text/css">
.timbul {
	-moz-box-shadow:inset 0px 1px 0px 0px #fce2c1;
	-webkit-box-shadow:inset 0px 1px 0px 0px #fce2c1;
	box-shadow:inset 0px 1px 0px 0px #fce2c1;
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #3a0cf0), color-stop(1, #176157) );
	background:-moz-linear-gradient( center top, #3a0cf0 5%, #176157 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#3a0cf0', endColorstr='#176157');
	background-color:#3a0cf0;
	-webkit-border-top-left-radius:10px;
	-moz-border-radius-topleft:10px;
	border-top-left-radius:10px;
	-webkit-border-top-right-radius:10px;
	-moz-border-radius-topright:10px;
	border-top-right-radius:10px;
	-webkit-border-bottom-right-radius:10px;
	-moz-border-radius-bottomright:10px;
	border-bottom-right-radius:10px;
	-webkit-border-bottom-left-radius:10px;
	-moz-border-radius-bottomleft:10px;
	border-bottom-left-radius:10px;
	text-indent:0px;
	border:2px solid #ed5197;
	display:inline-block;
	color:#dcdeed;
	font-family:Arial Black;
	font-size:12px;
	font-weight:bold;
	font-style:normal;
	height:25px;
	line-height:25px;
	width:100px;
	text-decoration:none;
	text-align:center;
	text-shadow:0px 1px 0px #cc9f52;
}
.timbul:hover {
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #176157), color-stop(1, #3a0cf0) );
	background:-moz-linear-gradient( center top, #176157 5%, #3a0cf0 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#176157', endColorstr='#3a0cf0');
	background-color:#176157;
}.timbul:active {
	position:relative;
	top:1px;
}</style>
</head>
<body onload="tampilkanwaktu();setInterval('tampilkanwaktu()', 1000);">
<?php

$hari = date('l');
/*$new = date('l, F d, Y', strtotime($Today));*/
if ($hari=="Sunday") {
	echo "Minggu, ";
}elseif ($hari=="Monday") {
	echo "Senin, ";
}elseif ($hari=="Tuesday") {
	echo "Selasa, ";
}elseif ($hari=="Wednesday") {
	echo "Rabu, ";
}elseif ($hari=="Thursday") {
	echo("Kamis, ");
}elseif ($hari=="Friday") {
	echo "Jum'at, ";
}elseif ($hari=="Saturday") {
	echo "Sabtu, ";
}
$tgl =date('d-m-Y : ');
echo $tgl;
 
?>
<span id="clock"></span> 
</div>
			
	</div>
	</div>
	
<div style="width:95%; margin: auto;">
	<h3>
    Detail Customer
	</h3>
     <hr>
    <form action="cekin.php" method="post">
	<table>
        <p><tr><td>Kode  </td><td> : </td><td><?php echo $data['custno']; ?></td></tr></p>
        <p><tr><td>Nama  </td><td> : </td><td><?php echo $data['custname']; ?></td></tr></p>
        <p><tr><td>Alamat</td><td> : </td><td><?php echo $data['alamat1']; ?></td></tr></p>
		<p><tr><td>Kota</td><td> : </td><td><?php echo $data['alamat2']; ?></td></tr></p>
        <p><tr><td>Limit </td><td> : </td><td>Rp. <?php echo number_format($data['lmt']); ?></td></tr></p>
		<p><tr><td>Kunjungan</td><td> : </td><td><?php echo $data['tgl']; ?></td></tr></p>
		<p><tr><td>Jam </td><td> : </td><td><?php echo $data['cekin']."  s/d  ".$data['cekout']; ?></td></tr></p>
		<p><tr><td>N.Order</td><td> : </td><td>Rp. <?php echo number_format($data['salesorder']); ?></td></tr></p>
		<p><tr><td>N.Bayar</td><td> : </td><td>Rp. <?php echo number_format($data['bayar']); ?></td></tr></p>
		<p><tr><td>Piutang </td><td> : </td><td>Rp. <b color='red'><?php echo number_format($lph['total']); ?></b></td></tr></p>
		<p><tr><td>No Faktur</td><td> : </td><td>Rp.<?php echo $lph['nofaktur']; ?></td></tr></p>
		<p><tr><td>Sisa Limit</td><td> : </td><td>Rp. <b color='red'><?php echo number_format($data['lmt']-$lph['total']); ?></b></td></tr></p>
	</table>	
	
	</form>
<hr>	
</div> 
<?php 
setcookie('COOKIES_COOKIES', $COOKIES_COOKIES, $expired_cookie, '/');
setcookie('COOKIES_CUSTNO', $COOKIES_CUSTNO, $expired_cookie, '/');
setcookie('COOKIES_ORDER', $COOKIES_ORDER, $expired_cookie, '/');

?>
<td align='center'  type='submit' style='width:70px'><a class='timbul' href="../present">CHEK IN</a></td>
<td align='center'  type='submit' style='width:70px'><a class='timbul' href="../listcustomer">NEXT</a></td>
</body>
 </html>
<?php } ?>