<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(ID){
		var pilih = confirm('Batalkan faktur penjualan kode '+ID+' ?');
		
		if (pilih==true) {
			var kode = ID;	
			$.ajax({
				type	: "POST",
				url	: "modul/returjual/cari_kode.php",
				data	: "kode="+kode,
				dataType: "json",
				success	: function(data){
					$("#t_koderj").val(kode);
					$("#t_tanggal").val(data.tgl);
					$("#t_kodeplg").val(data.kodeplg);
					$("#t_namaplg").val(data.namaplg);
					$("#t_nomorfk").val(data.nomorfk);
					$("#t_tanggalfk").val(data.tanggalfk);
				
					$("#pencarian").hide();
					$("#tampil_data").hide();
					$("#info_retur").show();
					$("#tampil_detail").show();
					$("#tampil_detail").load('modul/returjual/tampil_data_rj.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'];
$hal	= $_GET['hal'] ? $_GET['hal'] : 0;
$lim	= 10;

	$query2	= "SELECT * FROM retur_pj WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' ";
	$data2	= mysql_query($query2);
	$jml	= mysql_num_rows($data2);
	
	$max	= ceil($jml/$lim);

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode Retur</th>
			<th>Tanggal</th>
			<th>Kode Plg</th>
			<th>Nama Pelanggan</th>
			<th>Nomor Faktur</th>
			<th>Tanggal Faktur</th>
			<th>Total Item</th>
			<th>Total Retur</th>
			<th>Total Nilai</th>
			<th>Aksi</th>
		</tr>";
		$sql = "SELECT kode_rj,tanggal,kode_plg,nama_plg,nomor_fk,tanggal_fk,count(kode_st) as totitem,sum(jml_retur) as totretur,sum(jumlah) as totnilai FROM retur_pj
			WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir'	AND batal='' GROUP BY kode_rj LIMIT $hal,$lim";

		$query = mysql_query($sql);
		
		$no=1+$hal;
		while($r_data=mysql_fetch_array($query)){
			
			echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r_data[kode_rj]</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[nomor_fk]</td>
					<td align='center'>".jin_date_str($r_data[tanggal_fk])."</td>
					<td align='center'>$r_data[totitem]</td>
					<td align='center'>$r_data[totretur]</td>
					<td align='right'>".number_format($r_data[totnilai])."</td>
					<td align='center'>
					<a href='javascript:void(0)' onClick=\"batal('$r_data[kode_rj]')\">
						<img src='icon/thumb_down.png' border='0' id='edit' title='Lihat detail' width='12' height='12' >
					</a>
					</td>
					</tr>";
			$no++;			
		}
		
	echo "</table>";
	
	echo "<table width='100%'>
		<tr>
			<td>Jumlah Data : $jml</td>
			<td align='right'>Halaman :";
			for ($h = 1; $h <= $max; $h++) {
					$list[$h] = $lim * $h - $lim;
					echo " <a href='javascript:void(0)' ";?> 
                    onClick="$.get('spv/returjual/tampil_data.php?tgl_awal=<?php echo $_GET[tgl_awal];?>
                    &tgl_akhir=<?php echo $_GET[tgl_akhir];?>
                    &hal=<?php echo $list[$h]; ?>', 
                    null, function(data) {$('#tampil_data').html(data);})" <?php echo">".$h."</a> ";
				}
	echo "</td>
		</tr>
		</table>";
?>