<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 pilih(ID){
		var kode 	= ID;
		
		$.ajax({
			type	: "POST",
			url 	: "spv/order_pb/cari_kodeopb.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#op_kode").val(kode);
				$("#op_tanggal").val(data.tanggal);
				$("#op_kodecab").val(data.kodecab);
				$("#op_kodesp").val(data.kodesp);
				$("#op_namasp").val(data.namasp);
				$("#form_cari_sopb").dialog('close');
				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){
				$("#op_total").val(data.total);
				format_total();
			}
		});
	}
	
	function format_total(){
		var angka 	= $("#op_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){				
				$("#op_ctotal").val(data.huruf);
				var ctotal=$("#op_ctotal").val();
			}
		});
	}
</script>

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

$cari 	= $_POST['cari'];
$tanggal= date('Y-m-d');

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Nomor Bukti</th>
			<th>Tanggal</th>
			<th>Kode</th>
			<th>Nama Supplier</th>
			<th>Batas Kirim</th>
			<th>Tgl. Batas Kr.</th>
			<th>Jml.Item</th>
			<th>Jml.Unit</th>
			<th>Jml.Nominal</th>
			<th>Pilih</th>
		</tr>";
		
		if(!empty($cari))
			$query = "SELECT kode_opb,tanggal,kode_sp,nama_sp,batas_kr,tanggal_bk,count(no_urut) as totitem,sum(jml_unit) as tunit,sum(jumlah) as tjumlah FROM sopb WHERE kode_opb like '%$cari%' GROUP BY kode_opb desc";
		else
			$query = "SELECT kode_opb,tanggal,kode_sp,nama_sp,batas_kr,tanggal_bk,count(no_urut) as totitem,sum(jml_unit) as tunit,sum(jumlah) as tjumlah FROM sopb WHERE 1 GROUP BY kode_opb desc";
		$sql= mysql_query($query);
				
		$no=1;
		while($r=mysql_fetch_array($sql)){
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_opb]</td>
				<td>".jin_date_str($r['tanggal'])."</td>
				<td align='center'>$r[kode_sp]</td>
				<td>$r[nama_sp]</td>
				<td>$r[batas_kr] hari</td>
				<td>".jin_date_str($r['tanggal_bk'])."</td>
				<td align='center'>$r[totitem]</td>
				<td align='right'>$r[tunit]</td>
				<td align='right'>".number_format($r['tjumlah'],0)."</td>
				<td align='center'><a href='javascript:void(0)' onClick=\"pilih('$r[kode_opb]')\">
					<img src='images/view.png' border='0' id='edit' title='Pilih SOP' width='12' height='12' ></a>
				</td>
			</tr>";
			$no++;								
		}
	echo "</table>";
?>