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

echo "<div id='info'>	
	<table id='theList' width='100%'>
	<tr>
		<th>No.</th>
		<th>Kode</th>
		<th>Nama Barang</th>
		<th>Satuan</th>
		<th>Jml.Unit</th>
		<th>Harga Beli</th>
		<th>Harga Jual</th>
		<th>Jumlah Harga</th>
	</tr>";
		
	If(!($kodesup==''))
		$query2	= "SELECT kode_pb,tanggal,nomor_fk,kode_sup,nama_sup,count(kode_st) as totitem FROM faktur_pb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kodesup='$kodesup' AND batal='' AND posting='P' GROUP BY kode_pb";	
	else $query2= "SELECT kode_pb,tanggal,nomor_fk,kode_sup,nama_sup,count(kode_st) as totitem FROM faktur_pb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' AND posting='P' GROUP BY kode_pb";
		
	$data2	= mysql_query($query2);
	$tjumlah=0;
	$tbayar=0;
	$tkurang=0;
	$tpotong=0;
	while($r_data2=mysql_fetch_array($data2)){
		$kodepb=$r_data2[kode_pb];

		echo "<tr>
			<td></td>
			<td><b>No.Faktur</b></td>
			<td><b>: $r_data2[nomor_fk]</b></td>
			<td align='center'><b>".jin_date_str($r_data2[tanggal])."</b></td>
			<td align='center'><b>Supplier</b></td>
			<td><b>: $r_data2[kode_sup]</td>
			<td><b>$r_data2[nama_sup]</b></td>
		</tr>";
			
		$sql = "SELECT * FROM faktur_pb WHERE kode_pb='$kodepb' ";		
		$query = mysql_query($sql);
		
		$no=1;
		$sjumlah=0;
		$sbayar=0;
		$skurang=0;
		$spotong=0;
		while($r_data=mysql_fetch_array($query)){
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r_data[kode_st]</td>
				<td>$r_data[nama_st]</td>
				<td>$r_data[satuan]</td>
				<td align='center'>".number_format($r_data[jml_unit],2)."</td>
				<td align='right'>".number_format($r_data[hg_beli],2)."</td>
				<td align='right'>".number_format($r_data[hg_jual],0)."</td>
				<td align='right'>".number_format($r_data[jumlah],2)."</td>
			</tr>";
			$sjumlah=$sjumlah+$r_data[jumlah];
			$spotong=$spotong+$r_data[potong];
			$sbayar=$sbayar+$r_data[bayar];
			$skurang=$skurang+$r_data[kurang];
			$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($sjumlah,2)."</td>
		</tr>";
		
		if(!$spotong==0){
			$netto=$sjumlah-$spotong;
			echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Potongan</td>
				<td align='right'>".number_format($spotong,2)."</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Netto</td>
				<td align='right'>".number_format($netto,2)."</td>
			</tr>";
		}
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Dibayar</td>
			<td align='right'>".number_format($sbayar,2)."</td>			
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Kurang</td>
			<td align='right'>".number_format($skurang,2)."</td>
		</tr>";
		$tjumlah	=$tjumlah+$sjumlah;
		$tpotong	=$tpotong+$spotong;
		$tbayar	=$tbayar+$sbayar;
		$tkurang	=$tkurang+$skurang;
	}
	echo "<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Total</td>
		<td align='right'>".number_format($tjumlah,2)."</td>
	</tr>";
		
	if(!$tpotong==0){
		$netto=$tjumlah-$tpotong;
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Potongan</td>
			<td align='right'>".number_format($tpotong,2)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Netto</td>
			<td align='right'>".number_format($netto,2)."</td>
		</tr>";
	}
	echo "<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Dibayar</td>
		<td align='right'>".number_format($tbayar,2)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Kurang</td>
		<td align='right'>".number_format($tkurang,2)."</td>
	</tr>
	</table>
	
	<table width='100%'>
		<tr>
			<td>Jumlah faktur : $jml</td>			
		</tr>
	</table>";
echo "</div>";
?>