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

$tjumlah=0;
$tbayar=0;
$tkurang=0;

echo "<div id='info'>	
	<table id='theList' width='100%'>
	<tr>
		<th>No.</th>
		<th>Kode</th>
		<th>Nama Barang</th>
		<th>Satuan</th>
		<th>Jumlah Unit</th>
		<th>Harga Jual</th>
		<th>Total Harga</th>
	</tr>";
		
	If($kodeplg=='')
		$sql1= mysql_query("SELECT kode_pj,tanggal,kode_plg,nama_plg,tanggal_jt FROM faktur_pj WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_pj");
	else
		$sql1= mysql_query("SELECT kode_pj,tanggal,kode_plg,nama_plg,tanggal_jt FROM faktur_pj WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kode_plg='$kodeplg' AND batal='' GROUP BY kode_pj");
	
	while($r_data1=mysql_fetch_array($sql1)){
		$kodepj=$r_data1[kode_pj];

		echo "<tr>				
				<td align='center'><b>Faktur</b></td>
				<td><b>$r_data1[kode_pj]</b></td>
				<td align='center'><b>Tanggal : ".jin_date_str($r_data1[tanggal])."</b></td>
				<td><b>Plg.: $r_data1[kode_plg]</b></td>
				<td><b>$r_data1[nama_plg]</b></td>
			</tr>";
			
		$sql = mysql_query("SELECT * FROM faktur_pj WHERE kode_pj='$kodepj' ORDER BY no_urut");
		
		$no=1;
		$sjumlah=0;
		$sbayar=0;
		$skurang=0;
		while($r_data=mysql_fetch_array($sql)){
			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r_data[kode_st]</td>
				<td>$r_data[nama_st]</td>
				<td align='center'>$r_data[satuan]</td>
				<td align='right'>$r_data[jml_unit]</td>
				<td align='right'>".number_format($r_data[hg_jual])."</td>				
				<td align='right'>".number_format($r_data[jumlah])."</td>
			</tr>";
			$sjumlah=$sjumlah+$r_data[jumlah];
			$sbayar=$sbayar+$r_data[bayar];
			$no++;
		}
		if($sbayar>$sjumlah)
			$sbayar=$sjumlah;
		else
			$skurang=$sjumlah-$sbayar;
		
		echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($sjumlah)."</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Dibayar</td>
				<td align='right'>".number_format($sbayar)."</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Kurang bayar</td>
				<td align='right'>".number_format($skurang)."</td>
			</tr>";
		$tjumlah=$tjumlah+$sjumlah;
		$tbayar=$tbayar+$sbayar;
		$tkurang=$tkurang+$skurang;
	}
	
	echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tjumlah)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Dibayar</td>
			<td align='right'>".number_format($tbayar)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Kurang bayar</td>
			<td align='right'>".number_format($tkurang)."</td>
		</tr>
	</table>";
echo "</div>";
?>