<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 tampil_psb(ID){
		var kode = ID;	
		$.ajax({
			type	: "POST",
			url	: "modul/ubah_status/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);
				$("#txt_tanggal").val(data.tanggal);
				$("#txt_gudang").val(data.gudang);
				$('#form_cari_kodepsb').dialog('close');
				$("#info_psb").hide();
				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_hsl();
				format_sls();
			}
		});
	}
	
	function format_hsl(){
		var angka = $("#txt_tjumlah2").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_sls(){
		var angka = $("#txt_tselisih").val();
		var jhuruf= angka.length;
		
		if(angka=='') var angka='0';
				
		$.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>

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

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode PSB</th>
			<th>Tanggal</th>
			<th>Gudang</th>
			<th>Total Item</th>
			<th>Total Unit Asal</th>
			<th>Total Unit Hasil</th>
			<th>Lihat</th>
		</tr>";
		$query = mysql_query("SELECT kode_psb,tanggal,gudang,count(no_urut) as totitem,sum(jml_unit1) as totunit1,sum(jml_unit2) as totunit2 FROM jurpsb WHERE posting='' AND batal='' GROUP BY kode_psb");
		
		$no=1;
		while($r=mysql_fetch_array($query)){
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_psb]</td>
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td align='center'>$r[gudang]</td>
				<td align='center'>$r[totitem]</td>
				<td align='right'>$r[totunit1]</td>
				<td align='right'>$r[totunit2]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"tampil_psb('$r[kode_psb]')\">
						<img src='images/view.png' border='0' id='edit' title='Lihat detail' width='12' height='12' >
					</a>
				</td>
			</tr>";
			$no++;
		}
	echo "</table>";
?>