<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 batal_ft(ID){
		var pilih = confirm('Batalkan faktur penjualan kode '+ID+' ?');

		if (pilih==true) {
			var kode = ID;
			$.ajax({
				type	: "POST",
				url		: "spv/penjualan/cari_kode.php",
				data	: "kode="+kode,
				dataType: "json",
				success	: function(data){
					$("#t_kodepj").val(kode);
					$("#t_tanggal").val(data.tgl);
					$("#t_kodepl").val(data.kodepl);
					$("#t_namapl").val(data.namapl);
					$("#t_jenisby").val(data.jenisby);
					$("#t_nobank").val(data.nobank);
					$("#t_user").val(data.user);
					$("#t_total").val(data.total);
					$("#t_charge").val(data.charge);
					$("#t_bayar").val(data.tbayar);
					$("#t_kembali").val(data.tkembali);
					$("#t_potong").val(data.tpotong);
					$("#t_thpp").val(data.thpp);
					$("#pencarian").hide();
					$("#tampil_data").hide();
					$("#info_jual").show();
					$("#tampil_detail").show();
					$("#tampil_detail").load('kasir/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'];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>No.Faktur</th>
			<th>Tanggal</th>
			<th>Kasir</th>
			<th>Total Item</th>
			<th>Total Unit</th>
			<th>Total Harga</th>
			<th>Aksi</th>
		</tr>";		
		$query = mysql_query("SELECT kode_pj,tanggal,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as tjumlah,sum(potongan) as tpotong,user FROM faktur_pj WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_pj");
		
		$no=1;
		$g_total=0;
		while($r=mysql_fetch_array($query)){
			$netto = $r['tjumlah']-$r['tpotong'];
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_pj]</td>
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td align='center'>$r[user]</td>
				<td align='center'>$r[totitem]</td>
				<td align='right'>".number_format($r['totunit'])."</td>
				<td align='right'>".number_format($netto,0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"batal_ft('$r[kode_pj]')\">
						<img src='icon/thumb_down.png' border='0' id='edit' title='Batal' width='12' height='12' >
					</a>
				</td>
			</tr>";
			$no++;
			$g_total=$g_total+$r['tjumlah'];
		}
		echo "<tr>
			<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>";
?>