<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'];
    $cari     	= $_GET['cari'];
    $gudang    	= $_GET['gudang'];

	$query2 = mysql_query("SELECT * FROM company");
	$r2		=mysql_fetch_assoc($query2);
	$kop1 	= $r2['nama1'];
	$kop2 	= $r2['nama2'];
	$kop3 	= $r2['alamat'];
	
	echo "<table width='100%'>
		<tr>
			<td style='font:11px arial;line-height:80%'><b>$kop1</b></td>
		</tr>
		<tr>
			<td style='font:10px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:10px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

	<table width='100%'>
		<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>DAFTAR PERUBAHAN STATUS BARANG</b></td>
		</tr>
		<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>TANGGAL : ".jin_date_str($tglawal)." S/D ".jin_date_str($tglakhir)."</b></td>
		</tr>";
		if(!empty($cari)){
			echo "<tr>
				<td style='font:13px arial;line-height:75%' align='center'><b>PENCARIAN : $cari</td>
			</tr>";
		}
		if(!empty($gudang)){
			echo "<tr>
				<td style='font:13px arial;line-height:75%' align='center'><b>GUDANG : $gudang</td>
			</tr>";
		}
	echo "</table>
	<br>
	
	<table width='100%' border='1' style='border-collapse:collapse; font:11px arial'>
		<tr>
			<th>No.</th>
			<th>Kode Asal</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Pokok</th>
			<th>Jml. Unit</th>
			<th>Jumlah Harga</th>
			<th>Kode Hasil</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Pokok</th>
			<th>Jml. Unit</th>
			<th>Jumlah Harga</th>
		</tr>";
		if(!empty($cari)){
		    if(!empty($gudang))
			    $query1 = mysql_query("SELECT kode_psb,tanggal,gudang,keterangan FROM jurpsb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND (nama_st2 LIKE '%$cari%' OR kode_st2 LIKE '%$cari%') AND gudang='$gudang' AND posting='P' AND batal='' GROUP BY kode_psb");
		    else
		        $query1 = mysql_query("SELECT kode_psb,tanggal,gudang,keterangan FROM jurpsb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND (nama_st2 LIKE '%$cari%' OR kode_st2 LIKE '%$cari%') AND posting='P' AND batal='' GROUP BY kode_psb");
		}else{
		    if(!empty($gudang))
		        $query1 = mysql_query("SELECT kode_psb,tanggal,gudang,keterangan FROM jurpsb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND gudang='$gudang' AND posting='P' AND batal='' GROUP BY kode_psb");
		    else
		        $query1 = mysql_query("SELECT kode_psb,tanggal,gudang,keterangan FROM jurpsb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND posting='P' AND batal='' GROUP BY kode_psb");
		}

		$jml=0;
		$tunit1=0;
		$tjumlah1=0;
		$tunit2=0;
		$tjumlah2=0;
		while($r1=mysql_fetch_array($query1)){
			$kodepsb=$r1['kode_psb'];
			
			echo "<tr>
				<td></td>
				<td><b>Kode PSB</b></td>
				<td><b>$r1[kode_psb] - ".jin_date_str($r1['tanggal'])."</td>
				<td><b>Gudang : $r1[gudang]</b></td>
				<td></td>
				<td></td>
				<td></td>
				<td><b>Keterangan</td>
				<td><b>$r1[keterangan]</b></td>
			</tr>";
			$jml++;
			
			if(!empty($cari))
				$sql=mysql_query("SELECT * FROM jurpsb WHERE kode_psb='$kodepsb' AND (nama_st2 LIKE '%$cari%' OR kode_st2 LIKE '%$cari%') ORDER BY no_urut");
			else
				$sql=mysql_query("SELECT * FROM jurpsb WHERE kode_psb='$kodepsb' ORDER BY no_urut");
				
			$no=1;
			$sunit1=0;
			$sjumlah1=0;
			$sunit2=0;
			$sjumlah2=0;
			while($r=mysql_fetch_array($sql)){
				echo "<tr>
					<td align='center'>$no</td>
					<td>$r[kode_st1]</td>
					<td>$r[nama_st1]</td>
					<td>$r[satuan1]</td>
					<td align='right'>".number_format($r['hg_beli1'],2)."</td>
					<td align='right'>".number_format($r['jml_unit1'],0)."</td>
					<td align='right'>".number_format($r['jumlah1'],0)."</td>
					<td>$r[kode_st2]</td>
					<td>$r[nama_st2]</td>
					<td>$r[satuan2]</td>
					<td align='right'>".number_format($r['hg_beli2'],2)."</td>
					<td align='right'>".number_format($r['jml_unit2'],0)."</td>
					<td align='right'>".number_format($r['jumlah2'],0)."</td>
				</tr>";
				$no++;
				$sunit1=$sunit1+$r['jml_unit1'];
				$sjumlah1=$sjumlah1+$r['jumlah1'];
				$sunit2=$sunit2+$r['jml_unit2'];
				$sjumlah2=$sjumlah2+$r['jumlah2'];
			}
			echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah </td>
				<td align='right'>".number_format($sunit1,0)."</td>
				<td align='right'>".number_format($sjumlah1,0)."</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>".number_format($sunit2,0)."</td>
				<td align='right'>".number_format($sjumlah2,0)."</td>
			</tr>";
			$tunit1=$tunit1+$sunit1;
			$tjumlah1=$tjumlah1+$sjumlah1;
			$tunit2=$tunit2+$sunit2;
			$tjumlah2=$tjumlah2+$sjumlah2;
		}		
		echo "<tr></tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total </td>
			<td align='right'>".number_format($tunit1,0)."</td>
			<td align='right'>".number_format($tjumlah1,0)."</td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>".number_format($tunit2,0)."</td>
			<td align='right'>".number_format($tjumlah2,0)."</td>
		</tr>
	</table>
	<table>
		<tr>
			<td>Jumlah transaksi : $jml</td>
		</tr>
	</table>";
?>