<script type="text/javascript">
$(document).ready(function() {
    $(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'];
$kodesp   	=$_GET['kodesp'];
$kodecab  	=$_GET['kodecab'];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Zat Aktif</th>
			<th>Bentuk Sediaan</th>
			<th>Periode Penjualan</th>
			<th>Jml.Terjual</th>
			<th>Jml.Stok</th>
			<th>Jml.Pesan</th>
			<th>Satuan</th>
			<th>Harga Satuan</th>
			<th>Jumlah Harga</th>
			<th>Keterangan</th>
			<th>Tgl. Kirim</th>
			<th>No. Faktur</th>
		</tr>";
		if(!empty($kodecab)){
		    if(!empty($kodesp))
		        $query = mysql_query("SELECT kode_opb,tanggal,nama_cab,kode_sp,nama_sp FROM sopb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kode_cab='$kodecab' AND kode_sp='$kodesp' GROUP BY kode_opb");
            else
                $query = mysql_query("SELECT kode_opb,tanggal,nama_cab,kode_sp,nama_sp FROM sopb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kode_cab='$kodecab' GROUP BY kode_opb");
		}
		else{
		    if(!empty($kodesp))
		        $query = mysql_query("SELECT kode_opb,tanggal,nama_cab,kode_sp,nama_sp FROM sopb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kode_sp='$kodesp' GROUP BY kode_opb");
		    else
		        $query = mysql_query("SELECT kode_opb,tanggal,nama_cab,kode_sp,nama_sp FROM sopb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' GROUP BY kode_opb");
		}
		
		$tjumlah=0;
		$tunit=0;
		$jml=0;
		while($r=mysql_fetch_array($query)){
		    
			echo "<tr>
				<td></td>
				<td>No.SOPB : $r[kode_opb]</td>
				<td>Tanggal : ".jin_date_str($r['tanggal'])."</td>
				<td>Supplier : $r[kode_sp]</td>
				<td>$r[nama_sp]</td>				
				<td>Apotik : $r[nama_cab]</td>
			</tr>";
			$kodeopb=$r['kode_opb'];
			
			$sql = mysql_query("SELECT * FROM sopb WHERE kode_opb='$kodeopb' ORDER BY no_urut");
			
			$no=1;
			$sjumlah=0;
			$sunit=0;
			while($r=mysql_fetch_array($sql)){
				echo "<tr>
					<td align='center'>$no</td>
				    <td>$r[kode_st]</td>
				    <td>$r[nama_st]</td>
				    <td>$r[zat_aktif]</td>
				    <td>$r[bentuk]</td>
				    <td>".jin_date_str($r['tgljual_aw'])." - ".jin_date_str($r['tgljual_ak'])."</td>
				    <td align='right'>".number_format($r['jml_jual'],0)."</td>
				    <td align='right'>".number_format($r['jml_stok'],0)."</td>
				    <td align='right'>".number_format($r['jml_unit'],0)."</td>
				    <td>$r[satuan]</td>
				    <td align='right'>".number_format($r['harga'],0)."</td>
				    <td align='right'>".number_format($r['jumlah'],0)."</td>
				    <td>$r[keterangan]</td>
				    <td>".jin_date_str($r['tgl_kirim'])."</td>
				    <td>$r[nofak]</td>
				</tr>";
				$no++;
				$jml++;
				$sjumlah=$sjumlah+$r['jumlah'];
				$sunit	=$sunit+$r['jml_unit'];
			}
			echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($sunit,0)."</td>
				<td align='right'></td>
				<td align='right'></td>
				<td align='right'>".number_format($sjumlah,0)."</td>
				<td></td>
				<td></td>
				<td></td>
			</tr>";
			$tjumlah=$tjumlah+$sjumlah;
			$tunit	=$tunit+$sunit;
		}
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td align='right'>".number_format($tunit,0)."</td>
			<td align='right'></td>
			<td align='right'></td>
			<td align='right'>".number_format($tjumlah,0)."</td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
	</table>
	
	<table width='100%'>
		<tr>
			<td>Jumlah data : $jml</td>
		</tr>
	</table>";
?>