<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/jurnal_umum/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
				$("#txt_noakun").val(data.noakun);
				$("#txt_nobp").val(data.nobp);
				$("#txt_naakun").val(data.naakun);
				$("#txt_nofak").val(data.nofak);
				$("#txt_kodest").val(data.kodest);
				$("#txt_jmlunit").val(data.jmlunit);
				$("#txt_ket").val(data.ket);
				$("#txt_debet").val(data.debet);
				$("#txt_kredit").val(data.kredit);
				$("#txt_jumlah").val(data.jumlah);
				$("#txt_posting").val(data.posting);
				var posting = $("#txt_posting").val();
				
				if(posting=='P'){
					alert('Maaf, pengeluaran bank kode '+kode+' sudah diposting, data tidak dapat diedit.');
					return(false);
				}
			}
		});		
	}

	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type	: "POST",
			url		: "modul/jurnal_umum/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/jurnal_umum/tampil_data_detail.php?kode="+kode);
		cari_total();
	}
	
	function cari_total(){
		var kode = $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/jurnal_umum/cari_total.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_tdebet").val(data.tdebet);
				$("#txt_tkredit").val(data.tkredit);				
			}
		});
	}		
</script>

<?php
include '../../inc/inc.koneksi.php';
$kode	= $_GET[kode];
echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode Akun</th>
			<th>Nama Akun</th>
			<th>Kode BP</th>
			<th>Nama BP</th>
			<th>No.Faktur</th>
			<th>Kode Stok</th>
			<th>Jml.Unit</th>
			<th>Keterangan</th>
			<th>Debet</th>
			<th>Kredit</th>
			<th>Aksi</th>
		</tr>";
		$sql = "SELECT * FROM jurnalum WHERE kode_ju='$kode' ORDER BY kode_ju";
						
		$query = mysql_query($sql);
		$no=1;
		$tdebet=0;
		$tkredit=0;
		while($r_data=mysql_fetch_array($query)){
			$kode  = $r_data[kode_ju].'-'.$r_data[no_urut];
			$tdebet = $tdebet+$r_data[debet];
			$tkredit = $tkredit+$r_data[kredit];
			echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r_data[noakun]</td>
					<td>$r_data[naakun]</td>
					<td align='center'>$r_data[nobp]</td>
					<td>$r_data[namabp]</td>
					<td align='center'>$r_data[nofak]</td>
					<td align='center'>$r_data[kode_st]</td>
					<td align='center'>$r_data[jml_unit]</td>
					<td>$r_data[keterangan]</td>
					<td align='right'>".number_format($r_data[debet],2)."</td>
					<td align='right'>".number_format($r_data[kredit],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></td>
				<td align='right'>Total </td>
				<td align='right'>".number_format($tdebet,2)."</td>
				<td align='right'>".number_format($tkredit,2)."</td>
			</tr>";
			
	echo "</table>";	
?>