<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;
		var kodetk = $("#txt_kodetk").val();
						
		$.ajax({
			type	: "POST",
			url		: "modul/ubahstatus/edit.php",
			data	: "kode="+kode+
					"&kodetk="+kodetk,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
				$("#txt_kodest1").val(data.kodest);
				$("#txt_namast1").val(data.namast);
				$("#txt_satuan1").val(data.satuan);
				$("#txt_jmlunit1").val(data.jmlunit);				
				$("#txt_harga1").val(data.harga);
				$("#txt_jumlah").val(data.jumlah);
			}
		});
	}
	
	function hapus_data(ID){
		var pilih = confirm('Hapus data pemakaian kode '+ID+ '?');
		
		if (pilih==true) {
			var kode = ID;
			var kodetk = $("#txt_kodetk").val();
			
			$.ajax({
				type	: "POST",
				url		: "modul/ubahstatus/hapus.php",
				data	: "kode="+kode+
						"&kodetk="+kodetk,
				success	: function(data){				
					$("#info").html(data);
					tampil_data_detail();
				}			
			});
		}
	}
	
	function tampil_data_detail(){
		var kode = $("#txt_kode").val();
		var kodetk = $("#txt_kodetk").val();
		$("#data_detail").show();
		$("#data_detail").load('modul/ubahstatus/tampil_data_detail.php?kode='+kode+'$kodetk='+kodetk);
		hitung_total();
	}
	
	function hitung_total(){
		var kode   = $("#txt_kode").val();
		var kodetk = $("#txt_kodetk").val();
		var jumlahasl = $("#txt_jumlahasl").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/ubahstatus/cari_total.php",
			data	: "kode="+kode+
					"&kodetk="+kodetk+
					"&jumlahasl="+jumlahasl,
			dataType: "json",
			success	: function(data){
				$("#txt_total").val(data.total);
				$("#txt_selisih").val(data.selisih);
			}
		});
	}
</script>

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

$kode	= $_GET[kode];
$kodetk = $_GET[kodetk];

echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Jumlah Hasil</th>
			<th>Satuan</th>
			<th>Harga Pokok</th>
			<th>Nilai Hasil</th>
			<th>Aksi</th>
		</tr>";
		$sql = "SELECT * FROM jurpsb WHERE kode_ps='$kode' AND kode_tk='$kodetk' ORDER BY no_urut";
				
		$query = mysql_query($sql);
		$jml_data = mysql_num_rows($query);
		$no=1;		
		$total=0;		
		while($r_data=mysql_fetch_array($query)){
			$kode = $r_data[kode_ps].'-'.$r_data[no_urut];
			
			echo "<tr>
					<td align='center'>$no</td>
					<td>$r_data[kode_st1]</td>
					<td>$r_data[nama_st1]</td>
					<td align='right'>".number_format($r_data[jml_unit1],3)."</td>
					<td>$r_data[satuan1]</td>
					<td align='right'>".number_format($r_data[harga1],2)."</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++;			
			$total=$total+$r_data[jumlah];
		}
		echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total </td>
				<td align='right'>".number_format($total,2)."</td>
			</tr>
		</table>";
?>