<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'];
	$kodesp   = $_GET['kodesp'];
	$namasp   = $_GET['namasp'];
	$jml = 0;
	$tjumlah=0;

	$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:11px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

<table width='100%'>
	<tr>
		<td style='font:13px arial;line-height:75%' align='center'><b>DAFTAR RETUR PEMBELIAN</b></td>
	</tr>
	<tr>
		<td style='font:13px arial;line-height:75%' align='center'><b>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</b></td>
	</tr>";
	if(!empty($kodesp)){
		echo "<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>SUPPLIER : $namasp ($kodesp)</b></td>
		</tr>";
	}
echo "</table>
<br>
	
<table width='100%' border='1' style='border-collapse:collapse;font:11px arial'>
	<tr>
		<th>No.</th>
		<th>Kode</th>
		<th>Nama Barang</th>
		<th>Jumlah Unit</th>
		<th>Satuan</th>
		<th>HB. Asal</th>
		<th>HB. Retur</th>
		<th>Jumlah Asal</th>
		<th>Jumlah Retur</th>
		<th>Rugi Retur</th>
		<th>Keterangan</th>
	</tr>";
	$data2= mysql_query("SELECT * FROM retur_pb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_rb");
	$jml= mysql_num_rows($data2);
	
	$tjumlah=0;
	$tasal=0;
	$trugi=0;
    while($r2=mysql_fetch_array($data2)){
		$koderb=$r2['kode_rb'];

		echo "<tr>
			<td></td>
			<td><b>No.Retur</b></td>
			<td><b>$r2[kode_rb]</b></td>
			<td><b>Tanggal</b></td>
			<td><b>".jin_date_str($r2['tanggal'])."</b></td>
			<td><b>No.Faktur</b></td>
			<td><b>$r2[nomor_fk]</b></td>
			<td><b>Tanggal</b></td>
			<td><b>".jin_date_str($r2['tanggal_fk'])."</b></td>
            <td><b>Supplier</b></td>
			<td><b>$r2[nama_sup]</b></td>
		</tr>";
		$query = mysql_query("SELECT * FROM retur_pb WHERE kode_rb='$koderb'");

		$no=1;
		$sjumlah=0;
		$sasal=0;
		$srugi=0;
		while($r=mysql_fetch_array($query)){
			$rugi=$r['jumlah_asal']-$r['jumlah'];
			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td align='right'>$r[jml_retur]</td>
				<td align='center'>$r[satuan]</td>
				<td align='right'>".number_format($r['hb_asal'],2)."</td>
				<td align='right'>".number_format($r['hg_beli'],2)."</td>
				<td align='right'>".number_format($r['jumlah_asal'],2)."</td>
				<td align='right'>".number_format($r['jumlah'],2)."</td>
				<td align='right'>".number_format($rugi,2)."</td>
				<td>$r[keterangan]</td>
			</tr>";
			$sjumlah=$sjumlah+$r['jumlah'];
			$sasal=$sasal+$r['jumlah_asal'];
			$srugi=$srugi+$rugi;
			$no++;			
		}
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td align='right'>".number_format($sasal,2)."</td>
			<td align='right'>".number_format($sjumlah,2)."</td>
			<td align='right'>".number_format($srugi,2)."</td>
		</tr>";
		$tjumlah=$tjumlah+$sjumlah;
		$tasal=$tasal+$sasal;
		$trugi=$trugi+$srugi;
	}
	echo "<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Total </td>
		<td align='right'>".number_format($tasal,2)."</td>
		<td align='right'>".number_format($tjumlah,2)."</td>
		<td align='right'>".number_format($trugi)."</td>
	</tr>
</table>";
?>