<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList.detail tr:even").addClass("stripe1");
        $("#theList.detail tr:odd").addClass("stripe2");

        $("#theList.detail tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function edit_data(ID){
		var kode = ID;
						
		$.ajax({
			type	: "POST",
			url		: "kasir/penjualan/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
				$("#txt_kodest").val(data.kodest);
				$("#txt_namast").val(data.namast);
				$("#txt_barcode").val(data.barcode);
				$("#txt_satuan").val(data.satuan);
				$("#txt_jmlunit").val(data.jmlunit);
				$("#txt_hgjual").val(data.hgjual);
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_jumlah").val(data.jumlah);
				$("#txt_jmlunit").focus();
			}
		});		
	}
	
	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type	: "POST",
			url	    : "kasir/penjualan/hapus.php",
			data	: "kode="+kode,
			success	: function(data){
				$("#info").html(data);
				tampil_data_detail();
			}
		});
		}
	}
	
	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_bruto").val(data.tbruto);
				$("#txt_total").val(data.total);
				$("#txt_ctotal").val(data.total);
				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>

<style type="text/css">
.detail{
	font-size:14px;	
}
</style>
<?php
include '../../inc/inc.koneksi.php';
$kode	= $_GET['kode'];

$lim	= 10;
echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Barcode</th>
			<th>Satuan</th>
			<th>Jml. Unit</th>
			<th>Harga Jual</th>
			<th>Jml. Harga</th>
			<th>Aksi</th>
		</tr>";		
		$query 	= mysql_query("SELECT * FROM faktur_pj WHERE kode_pj='$kode' ORDER BY no_urut");
		$jml   	= mysql_num_rows($query);
		$hide  	= $jml-$lim;
		         
		$no=1;
		$total=0;
		while($r=mysql_fetch_array($query)){
			$kode 	= $r['kode_pj'].';'.$r['no_urut'];
			$total	= $total+$r['jumlah'];
			$urut	= $r['no_urut'];
			
			if($urut>$hide){
				echo "<tr>
					<td align='center' style='font:15px verdana'>$no</td>
					<td style='font:15px verdana'>$r[kode_st]</td>
					<td style='font:15px verdana'>$r[nama_st]</td>
					<td style='font:15px verdana'>$r[barcode]</td>
					<td style='font:15px verdana'>$r[satuan]</td>
					<td align='center' style='font:15px verdana'>".number_format($r['jml_unit'],2)."</td>
					<td align='right' style='font:15px verdana'>".number_format($r['hg_jual'],0)."</td>
					<td align='right' style='font:15px verdana'>".number_format($r['jumlah'],0)."</td>
					<td align='center' style='font:15px verdana'>
						<a href='javascript:void(0)' onClick=\"edit_data('$kode')\">
						<img src='icon/thumb_up.png' border='0' id='edit' title='Edit' width='12' height='12' ></a>
						<a href='javascript:void(0)' onClick=\"hapus_data('$kode')\">
						<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' ></a>					
					</td>
				</tr>";				
			}
			$no++;
		}		
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right' style='font:15px verdana'>Total</td>
			<td align='right' style='font:15px verdana'>".number_format($total,0)."</td>
		</tr>
	</table>";
?>