<script type="text/javascript">
    $(function() {
        $("#theList tr:even").addClass("stripe1");
        $("#theList tr:odd").addClass("stripe2");

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });
</script>

<?php
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';

$tgl_awal = $_GET['tgl_awal'];
$tgl_akhir= $_GET['tgl_akhir'];

echo "<div id='info'>	
<table id='theList' width='100%'>
	<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>
<table width='100%'>
	<tr>
		<td>Jumlah faktur : $jml</td>
	</tr>
</table>";

echo "</div>";
?>