<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';

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

$hal	= $_GET['hal'] ? $_GET['hal'] : 0;
$lim	= 10;
$tjumlah=0;
$tdiskon=0;

$query2= "SELECT kode_pj,kode_plg,tanggal,count(kode_st) as totitem FROM faktur_pj 
	WHERE kode_plg='$kodeplg' AND tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_pj ";
$data2	= mysql_query($query2);
$jml = mysql_num_rows($data2);
$max	= ceil($jml/$lim);

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 Bruto</th>
		<th>Potongan</th>
		<th>Harga Netto</th>
		<th>Total Harga</th>
	</tr>";
		
	$query1= "SELECT kode_pj,tanggal,kode_plg,nama_plg,count(kode_st) as totitem FROM faktur_pj 
		WHERE kode_plg='$kodeplg' AND tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_pj LIMIT $hal,$lim";
	$data1	= mysql_query($query1);
	while($r_data1=mysql_fetch_array($data1)){
		$kodepj=$r_data1[kode_pj];

		echo "<tr>				
				<td align='center'><b>Faktur</b></td>
				<td><b>$r_data1[kode_pj]</b></td>
				<td><b>".jin_date_str($r_data1[tanggal])."</b></td>
			</tr>";
			
		$sql = "SELECT * FROM faktur_pj WHERE kode_pj='$kodepj' ";
		$query = mysql_query($sql);
		
		$no=1+$hal;
		$sjumlah=0;
		$sdiskon=0;
		while($r_data=mysql_fetch_array($query)){
			$hgnet=$r_data[hg_jual]-$r_data[potongan];
			
			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[potongan])."</td>
				<td align='right'>".number_format($hgnet)."</td>
				<td align='right'>".number_format($r_data[jumlah])."</td>
				</tr>";
			$sjumlah=$sjumlah+$r_data[jumlah];
			$sdiskon=$sdiskon+$r_data[diskon];
			$no++;			
		}
		$netto=$sjumlah-$sdiskon;
		
		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($sjumlah)."</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Diskon</td>
				<td align='right'>".number_format($sdiskon)."</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Netto</td>
				<td align='right'>".number_format($netto)."</td>
			</tr>";
		$tjumlah=$tjumlah+$sjumlah;
		$tdiskon=$tdiskon+$sdiskon;
	}
	$netto=$tjumlah-$tdiskon;
	
	echo "<tr>
			<td></td>
			<td></td>
			<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></td>
			<td></td>
			<td align='right'>Total </td>
			<td align='right'>".number_format($tdiskon)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total </td>
			<td align='right'>".number_format($netto)."</td>
		</tr>";
	
	echo "</table>";
	echo "<table width='100%'>
		<tr>
			<td>Jumlah Data : $jml</td>
			<td align='right'>Halaman :";
			for ($h = 1; $h <= $max; $h++) {
				$list[$h] = $lim * $h - $lim;
				echo " <a href='javascript:void(0)' ";?> 
					onClick="$.get('modul/report/tampil_data_pjpl.php?kodeplg=<?php echo $_GET[kodeplg]; ?>
					&tgl_awal=<?php echo $_GET[tgl_awal];?>
                    &tgl_akhir=<?php echo $_GET[tgl_akhir];?>
					&hal=<?php echo $list[$h]; ?>', 
					null, function(data) {$('#info').html(data);})" <?php echo">".$h."</a> ";
			}
	echo "</td>
		</tr>
		</table>";
echo "</div>";
?>
