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

session_start();

$tgl_awal	= $_GET['tgl_awal'];
$tgl_akhir	= $_GET['tgl_akhir'];
$cari     	= $_GET['cari'];
$kodecab    = $_SESSION['kodecab'];
$cabang     = $_SESSION['namacab'];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>No.Faktur</th>
			<th>Tgl.Faktur</th>
			<th>Saldo</th>
			<th>Bayar Tunai</th>
			<th>Potongan</th>
			<th>Sisa</th>
		</tr>";
		
		if(!empty($cari))
			$query1 = "SELECT kode_ppi,tanggal,kode_pl,nama_pl,kode_cab FROM jurppi WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND (kode_pl LIKE '%$cari%' OR nama_pl LIKE '%$cari%') AND kode_cab='$kodecab' AND posting='P' AND batal='' GROUP BY kode_ppi ORDER BY tanggal";
		else
			$query1 = "SELECT kode_ppi,tanggal,kode_pl,nama_pl,kode_cab FROM jurppi WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kode_cab='$kodecab' AND posting='P' AND batal='' GROUP BY kode_ppi ORDER BY tanggal";
		$data1	= mysql_query($query1);
		
		$tpiut=0;
		$ttunai=0;		
		$tpot=0;
		$tsisa=0;
		$jdata=0;
		while($r1=mysql_fetch_array($data1)){
			$kodeppi = $r1['kode_ppi'];
			
			echo "<tr>
				<td></td>
				<td>No.PPI : $r1[kode_ppi]</td>
				<td>".jin_date_str($r1['tanggal'])."</td>
				<td>$r1[kode_pl] - $r1[nama_pl]</td>
				<td>Cabang : $cabang</td>
			</tr>";
			$query = mysql_query("SELECT * FROM jurppi WHERE kode_ppi='$kodeppi' ");
		    
			$no=1;
			$spiut=0;
			$stunai=0;			
			$spot=0;
			$ssisa=0;
			while($r=mysql_fetch_array($query)){
				echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r[nofak]</td>
					<td align='center'>".jin_date_str($r['tgl_fak'])."</td>
					<td align='right'>".number_format($r['jml_piut'],0)."</td>
					<td align='right'>".number_format($r['tunai'],0)."</td>
					<td align='right'>".number_format($r['potongan'],0)."</td>
					<td align='right'>".number_format($r['sisa'],0)."</td>
				</tr>";
				$spiut=$spiut+$r['jml_piut'];
				$stunai=$stunai+$r['tunai'];				
				$spot=$spot+$r['potongan'];
				$ssisa=$ssisa+$r['sisa'];
				$no++;
				$jdata++;
			}
			
			echo "<tr>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($spiut,0)."</td>
				<td align='right'>".number_format($stunai,0)."</td>
				<td align='right'>".number_format($spot,0)."</td>
				<td align='right'>".number_format($ssisa,0)."</td>
			</tr>";
			$tpiut=$tpiut+$spiut;
			$ttunai=$ttunai+$stunai;			
			$tpot=$tpot+$spot;
			$tsisa=$tsisa+$ssisa;
		}
		echo "<tr></tr>
		<tr>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tpiut,0)."</td>
			<td align='right'>".number_format($ttunai,0)."</td>
			<td align='right'>".number_format($tpot,0)."</td>
			<td align='right'>".number_format($tsisa,0)."</td>
		</tr>
	</table>
	<table width='100%'>
		<tr>
			<td>Jumlah data : $jdata</td>
		</tr>
	</table>";
?>