<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/import_sop/cari_kode.php",
				data	: "kode="+kode,
				dataType: "json",
				success	: function(data){
					$("#t_kode").val(kode);
					$("#t_tanggal").val(data.tgl);
					$("#t_kodesop").val(data.kodesop);					
					$("#t_kodeplg").val(data.kodeplg);
					$("#t_namaplg").val(data.namaplg);
					$("#t_tanggaljt").val(data.tanggaljt);
					$("#t_total").val(data.total);
					$("#t_potong").val(data.potong);
					$("#t_bayar").val(data.bayar);
					$("#t_kurang").val(data.kurang);
					$("#t_thpp").val(data.thpp);
					$("#pencarian").hide();
					$("#tampil_data").hide();
					$("#info_jual").show();
					$("#tampil_detail").show();
					$("#tampil_detail").load('spv/import_sop/tampil_data_batal.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>Nomor SOP</th>
			<th>Kode Plg</th>
			<th>Nama Pelanggan</th>
			<th>Total Item</th>
			<th>Total Unit</th>
			<th>Total Harga</th>
			<th>Aksi</th>
		</tr>";		
		$query = mysql_query("SELECT kode_pj,tanggal,kode_sop,kode_plg,nama_plg,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as totjumlah FROM faktur_pjg
			WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' AND posting='P' GROUP BY kode_pj ORDER BY kode_pj");
			
		$no=1;
		$g_total=0;
		while($r=mysql_fetch_array($query)){			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[kode_pj]</td>
				<td>".jin_date_str($r['tanggal'])."</td>
				<td align='center'>$r[kode_plg]</td>
				<td>$r[kode_sop]</td>
				<td>$r[nama_plg]</td>
				<td align='center'>$r[totitem]</td>
				<td align='right'>$r[totunit]</td>
				<td align='right'>".number_format($r['totjumlah'],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['totjumlah'];
		}
		echo "<tr>
			<td></td>
			<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>";
?>