<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_kode").val(kode);
					$("#t_tanggal").val(data.tgl);
					$("#t_kodeplg").val(data.kodeplg);
					$("#t_namaplg").val(data.namaplg);
					$("#t_jttempo").val(data.jttempo);
					$("#t_tanggaljt").val(data.tanggaljt);
					$("#t_total").val(data.total);
					$("#t_bayar").val(data.tbayar);					
					$("#t_kurang").val(data.tkurang);
					$("#t_thpp").val(data.thpp);
					$("#pencarian").hide();
					$("#tampil_data").hide();
					$("#info_jual").show();
					$("#tampil_detail").show();
					$("#tampil_detail").load('modul/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>Pelanggan</th>
			<th>Total Item</th>
			<th>Total Unit</th>
			<th>Total Harga</th>
			<th>Aksi</th>
		</tr>";
		$sql = "SELECT kode_pj,tanggal,nama_plg,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as tjumlah,user FROM faktur_pj
			WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_pj";
		$query = mysql_query($sql);
		
		$no=1;
		$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 align='center'>$r_data[nama_plg]</td>
				<td align='center'>$r_data[totitem]</td>
				<td align='right'>".number_format($r_data[totunit])."</td>
				<td align='right'>".number_format($r_data[tjumlah],0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"batal_ft('$r_data[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_data[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>";
?>