<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList.detail tr:even").addClass("stripe2");
        $("#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/ubah_status/editms.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
				$("#txt_kodest2").val(data.kodest2);
				$("#txt_namast2").val(data.namast2);
				$("#txt_satuan2").val(data.satuan2);
				$("#txt_hgbeli2").val(data.hgbeli2);
				$("#txt_jmlunit2").val(data.jmlunit2);
				$("#txt_jumlah2").val(data.jumlah2);
			}
		});		
	}
	
	function hapus_data(ID){
		var pilih = confirm('Hapus data barang hasil '+ID+' ?');
		if (pilih==true){
		var kode = ID;
		$.ajax({
			type	: "POST",
			url	: "modul/ubah_status/hapus.php",
			data	: "kode="+kode,
			success	: function(data){
				$("#info").html(data);
				cari_nourut();
				tampil_data_kl();
				tampil_data_ms();
			}
		});
		}
	}
	
	function cari_nourut(){
		var kode = $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/ubah_status/cari_nourut.php",
			data	: "kode="+kode,
			dataType: "json",
			success : function(data){
				$("#txt_nourut").val(data.nourut);
			}
		});
	}
	
	function tampil_data_kl(){
		var kode = $("#txt_kode").val();
		$("#data_detail_kl").show();
		$("#data_detail_kl").load("modul/ubah_status/tampil_data_kl.php?kode="+kode);
		cari_total_kl();
	}
	
	function cari_total_kl(){
		var kode = $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/ubah_status/hitung_totkl.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_tjumlah1").val(data.tjumlah1);
				format_asal();
			}
		});
	}
	
	function format_asal(){
		var angka = $("#txt_tjumlah1").val();
		var jhuruf= angka.length;
		
		$.ajax({
			type	: "POST",
			url		: "modul/ubah_status/format_rupiah.php",
			data	: "angka="+angka+
					"&jhuruf="+jhuruf,
			dataType: "json",
			success	: function(data){
				$("#txt_ctotasal").val(data.huruf);
			}
		});
	}
	
	function tampil_data_ms(){
		var kode = $("#txt_kode").val();
		$("#data_detail_ms").show();
		$("#data_detail_ms").load("modul/ubah_status/tampil_data_ms.php?kode="+kode);
		cari_total_ms();
	}
	
	function cari_total_ms(){
		var kode = $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url	: "modul/ubah_status/hitung_totms.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_tjumlah2").val(data.tjumlah2);
				$("#txt_tselisih").val(data.tselisih);
				format_hasil();
				format_selisih();
			}
		});
	}
	
	function format_hasil(){
		var angka = $("#txt_jumlah2").val();
		var jhuruf= angka.length;
		
		$.ajax({
			type	: "POST",
			url	: "modul/ubah_status/format_rupiah.php",
			data	: "angka="+angka+
					"&jhuruf="+jhuruf,
			dataType	: "json",
			success	: function(data){
				$("#txt_ctothasil").val(data.huruf);
			}
		});
	}
	
	function format_selisih(){
		var angka 	= $("#txt_tselisih").val();
		var jhuruf	= angka.length;
		
		$.ajax({
			type	: "POST",
			url	: "modul/ubah_status/format_rupiah.php",
			data	: "angka="+angka+
					"&jhuruf="+jhuruf,
			dataType	: "json",
			success	: function(data){
				$("#txt_cselisih").val(data.huruf);
			}
		});
	}
</script>

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

$kode	= $_GET['kode'];

echo "<table id='theList' class='detail' width='100%' >
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Pokok</th>
			<th>Jumlah Unit</th>
			<th>Jumlah Harga</th>
			<th>Aksi</th>
		</tr>";
		$sql = mysql_query("SELECT * FROM jurpsb WHERE kode_psb='$kode' AND !(kode_st2='') ORDER BY no_urut");
         
		$no=1;
		$tunit=0;
		$tjumlah=0;		
		while($r=mysql_fetch_array($sql)){
			$kode 	= $r['kode_psb'].';'.$r['no_urut'];
			$tunit  = $tunit+$r['jml_unit2'];
			$tjumlah= $tjumlah+$r['jumlah2'];
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[kode_st2]</td>
				<td>$r[nama_st2]</td>
				<td>$r[satuan2]</td>
				<td align='right'>".number_format($r['hg_beli2'],2)."</td>
				<td align='right'>".number_format($r['jml_unit2'],0)."</td>
				<td align='right'>".number_format($r['jumlah2'],0)."</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 align='right'>Total</td>
			<td align='right'>".number_format($tunit,0)."</td>
			<td align='right'>".number_format($tjumlah,0)."</td>
		</tr>
	</table>";
?>