<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		: "modul/pembelian/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.tsatuan);
				$("#txt_jmlunit").val(data.jmlunit);
				$("#txt_hgbruto").val(data.hgbruto);
				$("#txt_ppn").val(data.ppn);
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_hgjual").val(data.hgjual);
				$("#txt_jumlah").val(data.jumlah);
			}
		});		
	}

	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type	: "POST",
			url		: "modul/pembelian/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").load("modul/pembelian/tampil_data_detail.php?kode="+kode);
	}
	
	$('#form_lihat_detail').dialog({
		autoOpen: false,
		modal	: true,
		width: 650,
	});
	
	$('#detail').click(function(){
		var kodepj = $("#txt_kode").val();
		$('#form_lihat_detail').dialog('open');
		$("#lihat_nota").show();
		$("#lihat_nota").load("modul/pembelian/detail_nota.php?kodepj="+kodepj);
	});
</script>
<?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>Satuan</th>
			<th>Jml.Unit</th>
			<th>Harga Beli</th>
			<th>PPN %</th>			
			<th>Harga Jual</th>
			<th>Jumlah Harga</th>
			<th>Aksi</th>
		</tr>";
		$sql = "SELECT * FROM faktur_pb WHERE kode_pb='$kode' ORDER BY no_urut";
						
		$query = mysql_query($sql);
		$jml   = mysql_num_rows($query);
		$hide  = $jml-$lim;
		
		$no=1;
		$total=0;
		while($r_data=mysql_fetch_array($query)){
			$kode 	= $r_data[kode_pb].'-'.$r_data[no_urut];
			$total	= $total+$r_data[jumlah];
			$urut	= $r_data[no_urut];
			
			if($urut>$hide){
				echo "<tr>
					<td align='center'>$no</td>
					<td>$r_data[kode_st]</td>
					<td>$r_data[nama_st]</td>
					<td>$r_data[satuan]</td>
					<td align='center'>".number_format($r_data[jml_unit],2)."</td>
					<td align='right'>".number_format($r_data[hg_beli],2)."</td>
					<td align='right'>".number_format($r_data[ppn],0)."</td>
					<td align='right'>".number_format($r_data[hg_jual],0)."</td>
					<td align='right'>".number_format($r_data[jumlah],2)."</td>
					<td align='center'>
						<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></td>
				<td align='right'>Total </td>
				<td align='right'>".number_format($total,2)."</td>
			</tr>";
			
	echo "</table>";	
?>