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

<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';
	include '../../inc/fungsi_indotgl.php';
	
	$sql=mysql_query("SELECT * FROM company");
	$r=mysql_fetch_assoc($sql);
	$company=$r[nama1];
	
	$tanggal= $_GET['tanggal'];
	$shift	= $_GET['shift'];
	
	if($shift=='1')
		$nshift='PAGI';
	else if($shift=='2')
		$nshift='SIANG';
	else
		$nshift='MALAM';
	
	$sql=mysql_query("SELECT * FROM company");
	$r	=mysql_fetch_assoc($sql);	
	$kop1 = $r[nama1];
	$kop2 = $r[nama2];
	$kop3 = $r[alamat];
	
	echo "<table style='font:11px arial'>
		<tr>
			<td>$kop1</td>
		</tr>
		<tr>
			<td>$kop2</td>
		</tr>
		<tr>
			<td>$kop3</td>
		</tr>
	</table>
		
	<table width='700'>
		<tr>
			<td align='center' style='font:14px arial'><b>LAPORAN HARIAN SHIFT DETAIL</b></td>
		</tr>
		<tr>
			<td align='center' style='font:14px arial'><b>SHIFT : $nshift</b></td>
		</tr>
		<tr>
			<td align='center' style='font:14px arial'><b>TANGGAL : ".tgl_indo($tanggal)."</b></td>
		</tr>
	</table>
	<br>";
		
		$query	= "SELECT * FROM setor_bbm WHERE tanggal='$tanggal' AND shift='$shift' AND batal='' GROUP BY jenis";	
		$data	= mysql_query($query);
		$setor=0;	
		while($r_data=mysql_fetch_array($data)){
			$jenis=$r_data[jenis];
			
			echo "<table>
				<tr>
					<td style='font:11px arial'><b>$jenis</b></td>
				</tr>
			</table>
		
			<table width='700' border='1' style='font:11px arial;border-collapse:collapse'>
				<tr>
					<th>No.</th>
					<th>No. Teller</th>
					<th>Teller Awal</th>
					<th>Teller Akhir</th>
					<th>Liter Keluar</th>
					<th>Liter Tera</th>
					<th>Liter Bon</th>
					<th>Liter Tunai</th>
					<th>Rupiah Tunai</th>		
				</tr>";
		
			$sql = mysql_query("SELECT kode_tl,teller_aw,teller_ak,sum(jml_keluar) as jkel,sum(jml_tera) as jtera,sum(jml_bon) as jbon,sum(jml_tunai) as jtunai,sum(nilai_tunai) as niltun FROM setor_bbm WHERE tanggal='$tanggal' AND shift='$shift' AND jenis='$jenis' AND batal='' GROUP BY kode_sb");
		
			$no=1;
			$tkeluar=0;
			$ttera=0;
			$tbon=0;
			$ttunai=0;
			$tniltun=0;
		
			while($r=mysql_fetch_array($sql)){
		
				echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r[kode_tl]</td>
					<td align='right'>".number_format($r[teller_aw],2)."</td>
					<td align='right'>".number_format($r[teller_ak],2)."</td>
					<td align='right'>".number_format($r[jkel],2)."</td>
					<td align='right'>".number_format($r[jtera],2)."</td>
					<td align='right'>".number_format($r[jbon],2)."</td>
					<td align='right'>".number_format($r[jtunai],2)."</td>
					<td align='right'>".number_format($r[niltun],2)."</td>
				</tr>";
				$no++;
				$tkeluar=$tkeluar+$r[jkel];
				$ttera=$ttera+$r[jtera];
				$tbon=$tbon+$r[jbon];
				$ttunai=$ttunai+$r[jtunai];
				$tniltun=$tniltun+$r[niltun];
			}
	
			echo "<tr>
					<td></td>
					<td></td>
					<td></td>
					<td align='right'>Total</td>
					<td align='right'>".number_format($tkeluar,2)."</td>
					<td align='right'>".number_format($ttera,2)."</td>
					<td align='right'>".number_format($tbon,2)."</td>
					<td align='right'>".number_format($ttunai,2)."</td>
					<td align='right'>".number_format($tniltun,2)."</td>
				</tr>
			</table>
			<br>";
			$setor=$setor+$tniltun;
		
			echo "<table>
				<tr>
					<td align='left' style='font:11px arial'><b>BON $jenis</b></td>
				</tr>
			</table>
			
			<table width='600' border='1' style='font:11px arial;border-collapse:collapse'>
				<tr>
					<th>No.</th>
					<th>Kode Plg</th>
					<th>Nama Pelanggan</th>
					<th>No.Polisi</th>
					<th>Jumlah Liter</th>
					<th>Jumlah Rupiah</th>				
				</tr>";
			
			$sql = mysql_query("SELECT kode_pl,nama_pl,nopol,jml_nopol,nilai_nopol FROM setor_bbm WHERE tanggal='$tanggal' AND shift='$shift' AND jenis='$jenis' AND !(jml_nopol='0') AND batal='' ORDER BY kode_sb");
		
			$no=1;
			$tpol=0;			
			$tnilpol=0;
			while($r=mysql_fetch_array($sql)){
				echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r[kode_pl]</td>
					<td>$r[nama_pl]</td>
					<td>$r[nopol]</td>					
					<td align='right'>".number_format($r[jml_nopol],2)."</td>
					<td align='right'>".number_format($r[nilai_nopol],2)."</td>
				</tr>";
				$no++;
				$tpol=$tpol+$r[jml_nopol];
				$tnilpol=$tnilpol+$r[nilai_nopol];
			}
			echo "<tr>
					<td></td>
					<td></td>
					<td></td>
					<td align='right'>Total</td>
					<td align='right'>".number_format($tpol,2)."</td>			
					<td align='right'>".number_format($tnilpol,2)."</td>
				</tr>
			</table>
			<br>";
		}
	
	echo "<table align='right'>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td><b>Total Penjualan :</td>
			<td align='right'>".number_format($setor,2)."</b></td>
		</tr>
	</table>
	<br>
	
	<table>
		<tr>
			<td style='font:11px arial'><b>PENGELUARAN</b></td>
		</tr>
	</table>
		
	<table width='400' border='1' style='font:11px arial;border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Keterangan</th>			
			<th>Jumlah</th>				
		</tr>";
		
		$sql = mysql_query("SELECT * FROM jurkk WHERE tanggal='$tanggal' AND shift='$shift' ORDER BY no_urut");
		
		$no=1;
		$tjumlah=0;
		while($r=mysql_fetch_array($sql)){
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[keterangan]</td>					
				<td align='right'>".number_format($r[jumlah],2)."</td>					
			</tr>";
			$no++;			
			$tjumlah=$tjumlah+$r[jumlah];
		}
		$setor=$setor-$tjumlah;
		
	echo "<tr>
			<td></td>			
			<td align='right'>Total</td>				
			<td align='right'>".number_format($tjumlah,2)."</td>
		</tr>
	</table>
	<br>
	
	<table width='700' style='font:11px arial'>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td><b>Jumlah Uang Disetor :</td>
			<td align='right'>".number_format($setor,2)."</b></td>
		</tr>
	</table>";
?>
<script type="text/javascript">
	history.back();
</script>