<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		: "spv/outstan_do/edit.php",
			data		: "kode="+kode,
			dataType	: "json",
			success	: function(data){
				$("#txt_kode").val(kode);
				$("#txt_tanggal").val(data.tanggal);
				$("#txt_nobukti").val(data.nobukti);
				$("#txt_jenis").val(data.jenis);
				$("#txt_jmlliter").val(data.jmlliter);
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_jumlah").val(data.jumlah);
			}
		});		
	}

	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type		: "POST",
			url		: "spv/outstan_do/hapus.php",
			data	: "kode="+kode,
			success	: function(data){
				$("#info").html(data);
				tampil_data_detail();
			}
		});
		}
	}
	
	function tampil_data_detail(){
		$("#data_detail").load("spv/outstan_do/tampil_data_detail.php?");
	}
</script>

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

echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode DO</th>
			<th>Tanggal</th>
			<th>Nomor DO</th>
			<th>Jenis BBM</th>
			<th>Jumlah Liter</th>
			<th>Harga Beli</th>
			<th>Jumlah Harga</th>
			<th>Aksi</th>
		</tr>";
		$sql = "SELECT * FROM stock_do WHERE !(jml_liter='0') ORDER BY kode_do";
						
		$query = mysql_query($sql);
		$no=1;
		$total=0;
		while($r_data=mysql_fetch_array($query)){
			$total	= $total+$r_data[jumlah];
			echo "<tr>
					<td align='center'>$no</td>
					<td>$r_data[kode_do]</td>
					<td align='center'>".jin_date_str($r_data[tanggal])."</td>
					<td>$r_data[nobukti]</td>
					<td>$r_data[jenis]</td>
					<td align='right'>$r_data[jml_liter]</td>
					<td align='right'>".number_format($r_data[hg_beli],2)."</td>
					<td align='right'>".number_format($r_data[jumlah],0)."</td>
					<td align='center'>
						<a href='javascript:void(0)' onClick=\"edit_data('$r_data[kode_do]')\">
						<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('$r_data[kode_do]')\">
						<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 align='right'>Total </td>
				<td align='right'>".number_format($total,0)."</td>
			</tr>";
			
	echo "</table>";	
?>