<script type="text/javascript">	
	window.print();
</script>
<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';

	$tgl_awal	= $_GET['tgl_awal'];
	$tgl_akhir	= $_GET['tgl_akhir'];	
	
	$sql2= mysql_query("SELECT * FROM company");
	while($r2=mysql_fetch_array($sql2)){
		$kop1 = $r2['nama1'];
		$kop2 = $r2['nama2'];
		$kop3 = $r2['alamat'];
	}
	
	echo "<table width='100%'>
		<tr>
			<td style='font:13px arial;line-height:80%'><b>$kop1</b></td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop3</td>
		</tr>
		</table>

		<table width='100%' font='arial:15px' align='center'>
		<tr>
			<td><b>DAFTAR KERUSAKAN BARANG</td>
		</tr>
		<tr>
			<td><b>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</b></td>
		</tr>
		</table>
		<br>
	
		<table width='390' border='1' style='border-collapse:collapse;font:11px arial'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Pokok</th>
			<th>Jumlah Kerusakan</th>			
			<th>Nilai Kerusakan</th>
			<th>Posting</th>
		</tr>";
	
		$sql1 = "SELECT * FROM jurkrsb WHERE posting='' GROUP BY kode_kb";
		$query1 = mysql_query($sql1);
		
		$no=1;
		$tnilai=0;
		
		while($data1=mysql_fetch_array($query1)){
			$kodekb = $data1['kode_kb'];
			echo "<tr>
				<td></td>				
				<td><b>$data1[kode_kb]</b></td>
				<td><b>".jin_date_str($data1['tanggal'])."</b></td>
				<td><b>$data1[jenis_st]</b></td>
			</tr>";
				
			$sql = "SELECT * FROM jurkrsb WHERE kode_kb='$kodekb' ORDER BY kode_kb";
			$query = mysql_query($sql);
			$snilai = 0;
			$no=1;
			
			while($data=mysql_fetch_array($query)){
			
				echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$data[kode_st]</td>
					<td>$data[nama_st]</td>
					<td>$data[satuan]</td>					
					<td align='right'>".number_format($data['hg_pokok'],2)."</td>
					<td align='right'>".number_format($data['jml_unit'],2)."</td>
					<td align='right'>".number_format($data['nilai_kr'],0)."</td>
					<td align='center'>$data[posting]</td>
				</tr>";
				$no++;
				$snilai=$snilai+$data['nilai_kr'];
			}
			
			echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>				
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($snilai,2)."</td>
			</tr>";	
			$tnilai=$tnilai+$snilai;
		}
		
		echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>				
				<td align='right'>Total</td>
				<td align='right'>".number_format($tnilai,2)."</td>
			</tr>";
			
	echo "</table>";
?>
<script type="text/javascript">
	history.back();
</script>