<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");
            }
        );
    });
});

	function pilih(ID){
		var kode = ID;	

		$.ajax({
			type	: "POST",
			url	    : "spv/jual_kd/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#t_kode").val(kode);
				$("#t_tanggal").val(data.tgl);
				$("#t_kodesp").val(data.kodesp);
				$("#t_namasp").val(data.namasp);
				$("#t_kodedv").val(data.kodedv);
				$("#t_namadv").val(data.namadv);
				$("#t_nopol").val(data.nopol);
				$("#t_tunit").val(data.tunit);
				$("#t_total").val(data.total);
				$("#pencarian").hide();
				$("#tampil_data").hide();
				$("#info_pj").show();
				$("#tampil_detail").show();
				$("#tampil_detail").load('spv/jual_kd/tampil_detail_pj.php?kode='+kode);
			}
		});
	}	
</script>

<?php
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';

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

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>No.Faktur</th>
			<th>Tanggal</th>
			<th>SPBE</th>
			<th>Pengemudi</th>
			<th>Nomor Polisi</th>
			<th>Total Item</th>
			<th>Total Unit</th>
			<th>Total Harga</th>
			<th>Ambil</th>
		</tr>";
		$sql = "SELECT kode_pj,tanggal,nama_sp,nama_dv,nopol,count(kode_pl) as totitem,sum(jml_unit) as totunit,sum(jumlah) as tjumlah FROM faktur_sj
			WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' AND posting='P' GROUP BY kode_pj";
		$query = mysql_query($sql);
		
		$no=1;
		$g_tunit=0;
		$g_total=0;
		while($r_data=mysql_fetch_array($query)){
			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r_data[kode_pj]</td>
				<td align='center'>".jin_date_str($r_data[tanggal])."</td>
				<td>$r_data[nama_sp]</td>
				<td>$r_data[nama_dv]</td>
				<td>$r_data[nopol]</td>
				<td align='center'>$r_data[totitem]</td>
				<td align='right'>$r_data[totunit]</td>
				<td align='right'>".number_format($r_data[tjumlah],0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r_data[kode_pj]')\">
						<img src='images/view.png' border='0' id='edit' title='Pilih' width='12' height='12' >
					</a>
				</td>
			</tr>";
			$no++;
			$g_tunit=$g_tunit+$r_data[totunit];
			$g_total=$g_total+$r_data[tjumlah];
		}
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>$g_tunit</td>
			<td align='right'>".number_format($g_total,0)."</td>
		</tr>
	</table>";
?>