<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/order_pb/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#op_nourut").val(data.nourut);
				$("#op_kodest").val(data.kodest);
				$("#op_namast").val(data.namast);
				$("#op_zataktif").val(data.zataktif);
				$("#op_bentuk").val(data.bentuk);
				$("#op_tgljualaw").val(data.tgljualaw);
				$("#op_tgljualak").val(data.tgljualak);
				$("#op_jmljual").val(data.jmljual);
				$("#op_jmlstok").val(data.jmlstok);
				$("#op_satuan").val(data.satuan);
				$("#op_jmlunit").val(data.jmlunit);				
				$("#op_harga").val(data.harga);
				$("#op_jumlah").val(data.jumlah);
			}
		});		
	}

	function hapus_data(ID){
		var pilih = confirm('Hapus data SOPB '+ID+ '?');
		
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type	: "POST",
			url	    : "spv/order_pb/hapus.php",
			data	: "kode="+kode,
			success	: function(data){
				$("#info").html(data);
				cari_nourut();
				tampil_data_detail();
			}
		});
		}
	}
	
	function cari_nourut(){
		var kode = $("#op_kode").val();

		$.ajax({
			type	: "POST",
			url	    : "spv/order_pb/cari_nourut.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#op_nourut").val(data.nourut);
			}
		});
	}
	
	function tampil_data_detail(){
		var kode = $("#op_kode").val();
		$("#data_detail").show();
		$("#data_detail").load("spv/order_pb/tampil_data_detail.php?kode="+kode);
		cari_total();
	}
	
	function cari_total(){
		var kode=$("#op_kode").val();
		
		$.ajax({
			type	: "POST",
			url	    : "spv/order_pb/cari_total.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_total").val(data.total);
				format_total();
			}
		});
	}
	
	function format_total(){
		var angka 	= $("#txt_total").val();
		var jhuruf	= angka.length;
		
		$.ajax({
			type	: "POST",
			url	    : "kasir/penjualan/format_rupiah.php",
			data	: "angka="+angka+
					"&jhuruf="+jhuruf,
			dataType: "json",
			success	: function(data){				
				$("#txt_ctotal").val(data.huruf);
				var ctotal=$("#txt_ctotal").val();				
			}
		});
	}	
</script>
<?php
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';

$kode= $_GET['kode'];

echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Zat Aktif</th>
			<th>Bentuk Sediaan</th>
			<th>Periode Penjualan</th>
			<th>Jml.Terjual</th>
			<th>Jml.Stok</th>
			<th>Jml.Unit</th>
			<th>Satuan</th>
			<th>Harga Satuan</th>
			<th>Jumlah Harga</th>
			<th>Keterangan</th>
			<th>Aksi</th>
		</tr>";
		$query = mysql_query("SELECT * FROM sopb WHERE kode_opb='$kode' ORDER BY no_urut");

		$no=1;
		$total=0;		
		$tunit=0;
		while($r=mysql_fetch_array($query)){
			$kode 	= $r['kode_opb'].';'.$r['no_urut'];
			$total	= $total+$r['jumlah'];
			$tunit	= $tunit+$r['jml_unit'];
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[zat_aktif]</td>
				<td>$r[bentuk]</td>
				<td>".jin_date_str($r['tgljual_aw'])." - ".jin_date_str($r['tgljual_ak'])."</td>
				<td align='right'>".number_format($r['jml_jual'],0)."</td>
				<td align='right'>".number_format($r['jml_stok'],0)."</td>
				<td align='right'>".number_format($r['jml_unit'],0)."</td>
				<td>$r[satuan]</td>
				<td align='right'>".number_format($r['harga'],0)."</td>
				<td align='right'>".number_format($r['jumlah'],0)."</td>
				<td>$r[keterangan]</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 align='right'>Total</td>
			<td align='right'>".number_format($tunit,0)."</td>
			<td align='right'></td>
			<td align='right'></td>
			<td align='right'>".number_format($total,0)."</td>
			<td></td>
		</tr>
	</table>";
?>