<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 pilih(ID){
		var kode		= ID;
		var tglawal 	= $("#imp_tglaw").val();
		var tglakhir 	= $("#imp_tglak").val();
		var tjumlah 	= $("#txt_tjumlah").val();
		
		$.ajax({
			type	: "POST",
			url	: "std/penjualan/pilih_faktur.php",
			data	: "kode="+kode+
					"&tjumlah="+tjumlah+
					"&tglawal="+tglawal+
					"&tglakhir="+tglakhir,
			dataType	: "json",
			success	: function(data){
				$("#txt_timport").val(data.timport);
				$("#txt_prosen").val(data.prosen);
				$("#tampil_detail_imp").show();
				$("#tampil_detail_imp").load('std/penjualan/tampil_detail_imp.php?tglawal='+tglawal+'&tglakhir='+tglakhir);
				format_import();
			}
		});
	}
	
	function format_import(){
		var angka= $("#txt_timport").val();
		var jhuruf	= angka.length;
				
		$.ajax({
			type	: "POST",
			url	: "kasir/penjualan/format_rupiah.php",
			data	: "angka="+angka+
					"&jhuruf="+jhuruf,
			dataType: "json",
			success	: function(data){				
				$("#txt_cimport").val(data.huruf);
			}
		});
	}
	
	function batal(ID){
		var kode		= ID;
		var tglawal 	= $("#imp_tglaw").val();
		var tglakhir 	= $("#imp_tglak").val();
		var tjumlah 	= $("#txt_tjumlah").val();
		
		$.ajax({
			type	: "POST",
			url	: "std/penjualan/batal_pilih.php",
			data	: "kode="+kode+
					"&tjumlah="+tjumlah+
					"&tglawal="+tglawal+
					"&tglakhir="+tglakhir,
			dataType	: "json",
			success	: function(data){
				$("#txt_timport").val(data.timport);
				$("#txt_prosen").val(data.prosen);
				$("#tampil_detail_imp").show();
				$("#tampil_detail_imp").load('std/penjualan/tampil_detail_imp.php?tglawal='+tglawal+'&tglakhir='+tglakhir);
				format_import();
			}
		});
	}
</script>

<?php
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';

$tgl_awal = $_GET['tglawal'];
$tgl_akhir = $_GET['tglakhir'];

echo "<table id='theList' width='100%'>
		<tr>			
			<th>Tanggal</th>
			<th>Nomor Faktur</th>			
			<th>Pelanggan</th>
            <th>Jml. Item</th>
            <th>Jml. Unit</th>
            <th>Total Harga</th>
			<th>Jenis Bayar</th>
			<th>Chek</th>
			<th>Aksi</th>
		</tr>";
		$query = mysql_query("SELECT kode_pj,tanggal,nama_pl,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as tjumlah,sum(potongan) as tpotong,jenis_by,import FROM faktur_pj WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' AND posting='P' GROUP BY kode_pj ORDER BY tanggal,kode_pj");
		
		$no=1;
		$g_total=0;
		while($r=mysql_fetch_array($query)){
			$kodepj	=$r['kode_pj'];
			$jenisby	=$r['jenis_by'];
			$netto 		=$r['tjumlah']-$r['tpotong'];
			
			if($jenisby==''){
				$sql1=mysql_query("SELECT * FROM faktur_pj WHERE kode_pj='$kodepj' AND !(jenis_by='')");
				$r1	 =mysql_fetch_assoc($sql1);
				$jenisby=$r1['jenis_by'];
			}
			
			echo "<tr>				
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td align='center'>$r[kode_pj]</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'>$jenisby</td>
				<td align='center'>$r[import]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r[kode_pj]')\">Pilih</a>
					<a href='javascript:void(0)' onClick=\"batal('$r[kode_pj]')\">Batal</a>
				</td>
			</tr>";
			$no++;			
		}
	echo "</table>";
?>