<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 tampil_ft(ID){
		var kode = ID;	
		
		$.ajax({
			type	: "POST",
			url		: "adm_jual/penjualan/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#t_kodepj").val(kode);					
				$("#t_tanggal").val(data.tgl);
				$("#t_kodeplg").val(data.kodeplg);
				$("#t_namaplg").val(data.namaplg);
				$("#t_kodesl").val(data.kodesl);
				$("#t_namasl").val(data.namasl);
				$("#t_unit").val(data.unit);
				$("#t_jttempo").val(data.jttempo);
				$("#t_tanggaljt").val(data.tanggaljt);
				$("#t_total").val(data.total);
				$("#pencarian").hide();
				$("#tampil_data").hide();
				$("#info_jual").show();
				$("#tampil_detail").show();
				$("#tampil_detail").load('adm_jual/penjualan/tampil_data_ft.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'];
$user     = $_GET['user'];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>No.Faktur</th>
			<th>Tanggal</th>
			<th>Kode</th>
			<th>Nama Pelanggan</th>
			<th>Salesman</th>
			<th>Unit Usaha</th>
			<th>Total Item</th>
			<th>Total Unit</th>
			<th>Total Harga</th>
			<th>View</th>
		</tr>";
		$sql = "SELECT kode_pj,tanggal,kode_plg,nama_plg,nama_sl,unit,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as tjumlah,sum(diskon) as tdiskon,user FROM faktur_pj
			WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND user='$user' AND batal='' GROUP BY kode_pj";
		$query = mysql_query($sql);
		
		$no=1;
		$g_total=0;
		while($r_data=mysql_fetch_array($query)){
			$netto = $r_data[tjumlah]-$r_data[tdiskon];
			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[kode_plg]</td>
					<td>$r_data[nama_plg]</td>
					<td>$r_data[nama_sl]</td>
					<td>$r_data[unit]</td>
					<td align='center'>$r_data[totitem]</td>
					<td align='right'>$r_data[totunit]</td>
					<td align='right'>".number_format($netto,0)."</td>
					<td align='center'>
					<a href='javascript:void(0)' onClick=\"tampil_ft('$r_data[kode_pj]')\">
						<img src='images/view.png' border='0' id='edit' title='Lihat faktur' width='12' height='12' >
					</a>
					</td>
				</tr>";
			$no++;
			$g_total=$g_total+$netto;
		}
		echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>				
				<td align='right'>Total</td>
				<td align='right'>".number_format($g_total,0)."</td>
			</tr>
		</table>";
?>