<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/surat_jln/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
				$("#txt_kodepl").val(data.kodepl);
				$("#txt_namapl").val(data.namapl);
				$("#txt_jmlunit").val(data.jmlunit);
				$("#txt_hgjual").val(data.hgjual);		
				$("#txt_jumlah").val(data.jumlah);
				$("#txt_nokas").val(data.nokas);
			}
		});		
	}
	
	function hapus_data(ID){
		var pilih = confirm('Hapus data surat jalan kode = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type		: "POST",
			url		: "modul/surat_jln/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("modul/surat_jln/tampil_data_detail.php?kode="+kode);
		cari_total();
	}
	
	function cari_total(){
		var kode=$("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url	: "modul/surat_jln/cari_total.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){				
				$("#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	: "modul/surat_jln/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];

echo "<table id='theList' class='detail' width='100%' >
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Pangkalan</th>
			<th>Jml. Unit</th>
			<th>Harga Jual</th>
			<th>Jumlah Harga</th>
			<th>Pembayaran</th>
			<th>Aksi</th>
		</tr>";
		
		$query 	= mysql_query("SELECT * FROM surat_jln WHERE kode_sj='$kode' ORDER BY no_urut");
		$jml   	= mysql_num_rows($query);
		         
		$no=1;
		$total=0;
		$tunit=0;
		while($r_data=mysql_fetch_array($query)){
			$kode 	= $r_data[kode_sj].'-'.$r_data[no_urut];
			$total	= $total+$r_data[jumlah];
			$tunit	= $tunit+$r_data[jml_unit];
			$urut	= $r_data[no_urut];
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r_data[kode_pl]</td>
				<td>$r_data[nama_pl]</td>
				<td align='center'>".number_format($r_data[jml_unit],0)."</td>
				<td align='right'>".number_format($r_data[hg_jual],0)."</td>
				<td align='right'>".number_format($r_data[jumlah],0)."</td>
				<td>$r_data[namakas]</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 align='right'>Total</td>
			<td align='right'>".number_format($tunit,0)."</td>
			<td></td>
			<td align='right'>".number_format($total,0)."</td>
		</tr>
	</table>";
?>