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

$hal	= $_GET['hal'] ? $_GET['hal'] : 0;
$lim	= 6;
$jml = 0;
$tjumlah=0;

$query2	= "SELECT kode_iv,count(urut) as totitem FROM invoice WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_iv ";
$data2	= mysql_query($query2);
$jml = mysql_num_rows($data2);
$max	= ceil($jml/$lim);

echo "<div id='info'>	
	<table id='theList' width='100%'>
	<tr>
		<th width='5%'>No.</th>
		<th width='65%'>Diskripsi</th>
		<th width='5%' >Quantity</th>
		<th width='10%' >Harga</th>
		<th width='15%' >Jumlah Harga</th>
	</tr>";
		
	$query1	= "SELECT kode_iv,tanggal,nomor_po,pemesan,alamat,count(urut) as totitem FROM invoice 
		WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir'	AND batal='' GROUP BY kode_iv LIMIT $hal,$lim";
	$data1	= mysql_query($query1);
	while($r_data1=mysql_fetch_array($data1)){
		$kodeiv=$r_data1['kode_iv'];

		echo "<tr>
				<td><b>Invoice</b></td>
				<td><b>$r_data1[kode_iv] - ".jin_date_str($r_data1['tanggal'])." - $r_data1[pemesan] - $r_data1[alamat]</b></td>				
				<td><b>No. PO</b></td>
				<td><b>$r_data1[nomor_po]</b></td>				
			</tr>";
			
		$sql = "SELECT * FROM invoice WHERE kode_iv='$kodeiv' ";
		$query = mysql_query($sql);
		
		$no=1+$hal;
		$sjumlah=0;
		while($r_data=mysql_fetch_array($query)){			
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r_data[diskripsi]</td>
				<td align='center'>$r_data[jml_unit]</td>				
				<td align='right'>".number_format($r_data['harga'],0)."</td>
				<td align='right'>".number_format($r_data['jumlah'],0)."</td>				
				</tr>";
			$sjumlah=$sjumlah+$r_data['jumlah'];
			$no++;			
		}
		echo "<tr>				
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($sjumlah)."</td>
			</tr>";
			$tjumlah=$tjumlah+$sjumlah;
	}
	echo "<tr>			
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total </td>
			<td align='right'>".number_format($tjumlah)."</td>
		</tr>";
	
	echo "</table>";
	echo "<table width='100%'>
		<tr>
			<td>Jumlah faktur : $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_iv.php?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>";
?>