<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 tampil_opb(ID){
		var kode = ID;	
		$.ajax({
			type	: "POST",
			url		: "modul/pembelian/cari_kodeopb.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kodeopb").val(kode);
				$("#txt_kodecab").val(data.kodecab);
				$('#form_cari_kodeopb').dialog('close');
				$("#info_opb").hide();
				$("#txt_tanggaljt").focus();
			}
		});		
	}
</script>

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

$cari   =$_GET['cari'];
$kodesup=$_GET['kodesup'];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>No. Pesanan</th>
			<th>Tanggal</th>
			<th>Cabang</th>
			<th>Supplier</th>
			<th>Total Item</th>
			<th>Total Unit</th>
			<th>Total Harga</th>
			<th>Lihat</th>
		</tr>";
		if(!empty($cari))
		    $query = mysql_query("SELECT kode_opb,tanggal,nama_cab,nama_sp,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as totjumlah FROM sopb WHERE kode_sp='$kodesup' AND kode_opb LIKE '%$cari%' AND nofak='' GROUP BY kode_opb");
	    else
	        $query = mysql_query("SELECT kode_opb,tanggal,nama_cab,nama_sp,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as totjumlah FROM sopb WHERE kode_sp='$kodesup' AND nofak='' GROUP BY kode_opb");
		
		$no=1;
		while($r=mysql_fetch_array($query)){
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_opb]</td>
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td>$r[nama_cab]</td>
				<td>$r[nama_sp]</td>
				<td align='center'>$r[totitem]</td>
				<td align='right'>$r[totunit]</td>
				<td align='right'>$r[totjumlah]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"tampil_opb('$r[kode_opb]')\">
						<img src='images/view.png' border='0' id='edit' title='Lihat detail' width='12' height='12' >
					</a>
				</td>
			</tr>";
			$no++;
		}
	echo "</table>";
?>