<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;
		
		$.ajax({
			type	: "POST",
			url		: "kasir/penjualan/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);
				$("#txt_kodepl").val(data.kodepl);
				$("#txt_namapl").val(data.namapl);
				$("#form_ambil_pending").dialog('close');
				$("#txt_barcode").focus();
				cari_nourut();
				tampil_data_detail();
			}
		});
	}
	
	function cari_nourut(){
		var kode = $("#txt_kode").val();
				
		$.ajax({
			type	: "POST",
			url		: "kasir/penjualan/cari_nourut.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){				
				$("#txt_nourut").val(data.nourut);		
			}
		});
	}
	
	function tampil_data_detail(){
		var kode = $("#txt_kode").val();
		$("#data_detail").show();
		$("#data_detail").load("kasir/penjualan/tampil_data_detail.php?kode="+kode);
		cari_total();
	}
	
	function cari_total(){
		var kode=$("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "kasir/penjualan/cari_total.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_total").val(data.total);
				$("#txt_netto").val(data.total);
				$("#txt_gtotal").val(data.total);
				$("#txt_ctotal").val(data.total);
				$("#txt_tothpp").val(data.tothpp);
				format_total();
			}
		});
	}
	
	function format_total(){
		var angka = $("#txt_total").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_ctotal").val(data.huruf);
				var ctotal=$("#txt_ctotal").val();				
			}
		});
	}
</script>

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

$tanggal = $_GET['tanggal'];
$user    = $_GET['user'];

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>View</th>
		</tr>";
		$query = mysql_query("SELECT kode_pj,tanggal,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as tjumlah,user FROM faktur_pj
			WHERE tanggal='$tanggal' AND user='$user' AND posting='' GROUP BY kode_pj");
		
		$no=1;
		$g_total=0;
		while($r=mysql_fetch_array($query)){			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_pj]</td>
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td>$r[user]</td>					
				<td align='center'>$r[totitem]</td>
				<td align='right'>$r[totunit]</td>
				<td align='right'>".number_format($r['tjumlah'],0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r[kode_pj]')\">
						<img src='icon/download.gif' border='0' id='edit' title='Ambil pending' 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>";
?>