<script type="text/javascript">	
	window.print();
	history.back();
</script>

<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';
	
	$user	= $_GET[user];
	$tanggal= $_GET[tanggal];

	$text	= "SELECT kode_pj,tanggal,sum(jumlah) as jjual,sum(jml_unit) as junit,waktu FROM faktur_pj WHERE tanggal='$tanggal' AND user='$user' AND batal='' AND jml_unit>0 GROUP BY kode_pj";
	$sql 	= mysql_query($text);
	$r		= mysql_fetch_assoc($sql);
	$jam_aw	= substr($r[waktu],10,9);

	$text1	= "SELECT kode_pj,tanggal,sum(jumlah) as jjual,sum(jml_unit) as junit,waktu FROM faktur_pj WHERE tanggal='$tanggal' AND user='$user' AND batal='' AND jml_unit>0 GROUP BY kode_pj";
	$sql1 	= mysql_query($text1);
	$tjual 	= 0;
	$tnotajl= 0;
	$tunitjl= 0;

	while($r1=mysql_fetch_array($sql1)){
		$tjual	= $tjual+$r1[jjual];
		$tunitjl= $tunitjl+$r1[junit];
		$jam_ak	= substr($r1[waktu],10,9);
		$tnotajl++;
	}

	$text2	= "SELECT kode_pj,tanggal,sum(jumlah) as jretur,sum(jml_unit) as junit FROM faktur_pj WHERE tanggal='$tanggal' AND user='$user' AND batal='' AND jml_unit<0 GROUP BY kode_pj";
	$sql2 	= mysql_query($text2);
	$tretur	= 0;
	$tnotart= 0;
	$tunitrt= 0;

	while($r2=mysql_fetch_array($sql2)){
		$tretur	= $tretur+$r2[jretur];
		$tunitrt= $tunitrt+$r2[junit];	
		$tnotart++;
	}
	$tjumlah=$tjual+$tretur;
	$tnota	=$tnotajl+$tnotart;
	$tunit	=$tunitjl+$tunitrt;
	$retur	=$tretur*-1;

	echo "<table style='font:13px arial' width='100%'>
		<tr>
			<td align='center'><b>LAPORAN PENUTUPAN KASIR</b></td>
		</tr>
		<tr>
			<td align='center'>TANGGAL : ".jin_date_str($tanggal)."</td>
		</tr>
		<tr>
			<td align='center'>KASIR : $user</td></b>
		</tr>
		</table>
		<hr>";
		
	echo "<table style='font:13px arial' width='100%'>
		<tr>
			<td>Nama Kasir</td>
			<td>:</td>
			<td>$user</td>
		</tr>
		<tr>
			<td>Jam Pelayanan</td>
			<td>:</td>
			<td>$jam_aw - $jam_ak</td>
		</tr>
		<tr>
			<td>Jumlah Nota</td>
			<td>:</td>
			<td align='right'>$tnota</td>
		</tr>
		<tr>
			<td>Jumlah Barang</td>
			<td>:</td>
			<td align='right'>".number_format($tunit,2)." unit</td>
		</tr>
		<tr>
			<td>Total Penjualan</td>
			<td>: Rp</td>
			<td align='right'>".number_format($tjual,0)."</td>
		</tr>
		<tr>
			<td>Total Retur</td>
			<td style='border-bottom:double 2px' >: Rp</td>
			<td style='border-bottom:double 2px' align='right'>".number_format($retur,0)."</td>
		</tr>
		<tr>
			<td>Penjualan Netto</td>
			<td>: Rp</td>
			<td align='right'>".number_format($tjumlah,0)."</td>
		</tr>
	</table>
	<hr>";
?>