<meta name="viewport" content="width=device-width, initial-scale=1">
<?php
include 'connect.php';	
define('YBASE',true);
session_start();

if (isset($_SESSION['yuser'])) {
			include_once 'config/log.php';
	$mtime = microtime(); $mtime = explode (" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tstart = $mtime;
} else {
	header('location:login.php');	
}	
$jabat=$_SESSION['jabat'];
if ($jabat=='1') {
$slm=$_SESSION['yuser'];
}
else {
$slm=$_GET['id']; }
if ($jabat=='2') {
	$tgltr=$_SESSION['tgltr'];
} elseif ($jabat=='5') {
	$tgltr=$_SESSION['tgltr'];
} elseif ($jabat=='6') {
	$tgltr=$_SESSION['tgltr'];
}


//$jabatan=mysqli_query($con,"select username,nama_lengkap,jabatan from ypos_users where username='$_SESSION[yuser]';");
//$jabat1=mysqli_fetch_array($jabatan);
//$jabat=$jabat1['jabatan'];

//sales
if ($jabat=='1') 	{
$ctotal =mysqli_query($con,"SELECT sum(a.nilaibayar) as cash,sum(a.nilaigiro) as giro ,count(nofaktur) as jfak from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
where c.tgltagih=curdate() and c.kdslm='$_SESSION[yuser]' ;");}
//spv
elseif ($jabat=='2') {
$ctotal =mysqli_query($con,"SELECT sum(a.nilaibayar) as cash,sum(a.nilaigiro) as giro ,count(nofaktur) as jfak from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
left join salesman d on c.kdslm=d.kdslm
where c.tgltagih='$tgltr' and d.kdslm='$_GET[id]' ;");}
//debtur
elseif ($jabat=='3') {
$ctotal =mysqli_query($con,"SELECT sum(a.nilaibayar) as cash,sum(a.nilaigiro) as giro,count(nofaktur) as jfak  from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
where c.tgltagih=curdate() and c.kdslm='$_GET[id]'");}
//kasir
elseif ($jabat=='4') {
$ctotal =mysqli_query($con,"SELECT sum(totalbayar) as cash,sum(totalgiro) as giro from tagihanmobileheader 
where tgl=curdate(); ");}

elseif ($jabat=='5') {
$ctotal =mysqli_query($con,"SELECT sum(a.nilaibayar) as cash,sum(a.nilaigiro) as giro,count(nofaktur) as jfak  from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
where c.tgltagih='$tgltr' and c.kdslm='$_GET[id]'");
}
elseif ($jabat=='6') {
$ctotal =mysqli_query($con,"SELECT sum(a.nilaibayar) as cash,sum(a.nilaigiro) as giro,count(nofaktur) as jfak  from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
where c.tgltagih='$tgltr' and c.kdslm='$_GET[id]'");}
$total=mysqli_fetch_array($ctotal);
?>
<html>
 <head>
  <title>IBS</title>
  <!-- <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> --> <!-- old version, doesnt work in localhost --> 
  
    <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:10px;
	font-weight:bold;
	font-style:normal;
	height:15px;
	line-height:15px;
	width:50px;
	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>

<body onload="tampilkanwaktu();setInterval('tampilkanwaktu()', 1000);">
<div class="panel-header" fit="true" style="height:21px;padding-top:8px;padding-right:15px;width=80%;">
		<div style="float:left;">
		<a style="color:#fff;" href="index.php" iconcls="icon-home"><span>
        <span style="padding-left: 20px;" class="icon-home">Home</span></span></a>
        <a style="color:#fff;" href="page=about" iconcls="icon-home"><span">
        <span style="padding-left: 20px;" class="icon-home">About</span></a>
		<a style="color:#fff;" href="logout.php" iconcls="icon-logout"><span">
        <span style="padding-left: 20px;" class="icon-logout">Logout</span></span></a>
        </div>
		
		<div style="float:right"  color="#fff">
		<?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 style="height:35px;padding-top:8px;padding-right:25px;width=95%;">
			<table >
				<tr>
					<td>
						<form class='w3-tiny' action='' method='GET'>	
							<div class='w3-row'>
								<div class='w3-col s5'> <label class='w3-label'>Search</label>
									<input type='text' name='cari' class='w3-input' placeholder='Nama customer/Sales...'>
									<button type='submit' class='w3-btn w3-tiny'><i class='fa fa-paper-plane'></i> GO</button>
								</div>
							</div>
						</form>
					</td>
				</tr>
				
			</table>
</div>		
		<div style="height:35px;padding-top:8px;padding-right:25px;width=95%;">
				<table>
				<td>
					<button   readonly><font color='blue' >Cash Rp.<?php echo number_format($total['cash']);?></font> </button>
					<button   readonly><font color='blue' >Giro Rp.<?php echo number_format($total['giro']);?></font> </button>
					</td>
				</table>
		</div>		
		
  
		
 
 
<table border="1">
	<thead>
        <tr>
            <th>No.LPH</th>
			<th>No.Faktur</th>
			<th>Nama</th>
			<th>Cash</th>
			<th>Giro</th>
			<th>ST</th>
			
        </tr>
    </thead>
     
    <tbody>
	
<?php
$system="Select cabang,kdgudang from system limit 1";
$dsystem=mysqli_query($con,$system);  
$datasystem= mysqli_fetch_array($dsystem);

if ($jabat=='1') {
$query = "SELECT a.cabang,a.nobukti,a.nofaktur,a.custno,b.custname,a.nilai,a.nilaibayar,a.nilaigiro from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
where c.tgltagih=curdate() and c.kdslm='$_SESSION[yuser]' ;";}
elseif ($jabat=='2') {
$query = "SELECT a.cabang,a.nobukti,a.nofaktur,a.custno,b.custname,a.nilai,a.nilaibayar,a.nilaigiro from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
left join salesman d on c.kdslm=d.kdslm
where c.tgltagih='$tgltr' and c.kdslm='$_GET[id]' ;";}
elseif ($jabat=='3'){
$query = "SELECT a.cabang,a.nobukti,a.nofaktur,a.custno,b.custname,a.nilai,a.nilaibayar,a.nilaigiro from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
left join salesman d on c.kdslm=d.kdslm
where c.tgltagih=curdate() and c.kdslm='$_GET[id]' ;";}
elseif ($jabat=='4') {
$query = "SELECT a.cabang,a.nobukti,a.nofaktur,a.custno,b.custname,a.nilai,a.nilaibayar,a.nilaigiro from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
left join salesman d on c.kdslm=d.kdslm
where c.tgltagih=curdate() and c.kdslm='$_GET[id]' ;";}
elseif ($jabat=='5') {
$query = "SELECT a.cabang,a.nobukti,a.nofaktur,a.custno,b.custname,a.nilai,a.nilaibayar,a.nilaigiro from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
left join salesman d on c.kdslm=d.kdslm
where c.tgltagih='$tgltr' and c.kdslm='$_GET[id]' ;";}
elseif ($jabat=='6') {
$query = "SELECT a.cabang,a.nobukti,a.nofaktur,a.custno,b.custname,a.nilai,a.nilaibayar,a.nilaigiro from tagihandetail a
left join customer b on a.custno=b.custno
left join tagihanheader c on a.nobukti=c.nobukti
left join salesman d on c.kdslm=d.kdslm
where c.tgltagih='$tgltr' and c.kdslm='$_GET[id]' ;";}

//if(!empty($_GET['cari']))
//{	
//$cari=$_GET['cari'];
//$hideinp = "<input type='hidden' name='cari' value='$_GET[cari]'>";
//$query .= " and UPPER(custName) LIKE UPPER('%$cari%')";

//}


$sql0 = mysqli_query($con,$query);  
$satu=mysqli_num_rows($sql0);

if ($satu>0) {

$no = 1; // Untuk penomoran tabel, di awal set dengan 1
while($data = mysqli_fetch_array($sql0)){
	$custno=$data['custno'];
	$stok=$data['nilai'];
	$sisa=($data['nilai']-($data['nilaibayar']+$data['nilaigiro']));
    if ($sisa<=0) {$st='Lunas';}
	else {$st='Cicil';}
	
	if (($data['nilaibayar']+$data['nilaigiro']) <> 0) {
// $nilait=$nilait+$data['jumlah'];
	
				echo "<tr>";
				echo "<td><font size='2'>".$data['nobukti']."</font></td>";
				echo "<td><font size='2'>".$data['nofaktur']."</font></td>";
				echo "<td>".$data['custname']."</td>";
				echo "<td align ='right'>".number_format($data['nilaibayar'])."</td>";
				echo "<td align ='right'>".number_format($data['nilaigiro'])."</td>";
				echo "<td align ='right'>".$st."</td>";
				echo "</tr>";
	
	}	
				$no++; // Tambah 1 setiap kali looping
			}
}
		
	else
				{
					echo"<tr>
						<td colspan='5'><div class='w3-center'><i>Data Pembayaran Not Found.</i></div></td>
					</tr>";
				}		
	
	?>

    </tbody>
	
</table>
<div align='center' style="width:95%; margin: auto;" >
<?php if ($jabat=='2') {?>
<td align='center'  type='submit' style='width:70px'><a class='timbul' href="listbayarsaleskanvas.php?id=<?php echo $tgltr ?>">Kembali</a></td>
<?php } elseif ($jabat=='5') {?>
<td align='center'  type='submit' style='width:70px'><a class='timbul' href="listbayarsaleskanvas.php?id=<?php echo $tgltr ?>">Kembali</a></td>
<?php } elseif ($jabat=='6') {?>
<td align='center'  type='submit' style='width:70px'><a class='timbul' href="listbayarsaleskanvas.php?id=<?php echo $tgltr ?>">Kembali</a></td>
<?php } else { ?>
<td align='center'  type='submit' style='width:70px'><a class='timbul' href="listbayarkanvas.php?id=<?php echo $slm ?>">Kembali</a></td>
<?php }?>
</div>

</body>
</html>
	
