<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_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#t_kodeopb").val(kode);
				$("#t_tanggal").val(data.tgl);
				$("#t_kodesp").val(data.kodesp);
				$("#t_namasp").val(data.namasp);
				$("#t_bataskr").val(data.bataskr);
				$("#t_tanggalbk").val(data.tanggalbk);				
				$('#tampil_data_sopb').hide();
				$('#tampil_detail').show();
				tampil_detail();
			}
		});		
	}
	
	function tampil_detail(){
		var kode = $("#t_kodeopb").val();
		$("#pencarian").hide();
		$("#info_sopb").show();
		$("#tampil_detail").load("spv/order_pb/tampil_detail_sopb.php?kode="+kode);
	}
</script>

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

$tgl_awal = $_GET['tgl_awal'];
$tgl_akhir= $_GET['tgl_akhir'];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Nomor SOPB</th>
			<th>Tanggal</th>
			<th>Kode</th>
			<th>Nama Supplier</th>
			<th>Batas Krm</th>
			<th>Tgl. Batas Krm</th>
			<th>Jml.Item</th>
			<th>Jml.Unit</th>			
			<th>Jml.Nominal</th>
			<th>Pilih</th>
		</tr>";
		
		$sql= mysql_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 tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' GROUP BY kode_opb");
				
		$no=1;
		while($r=mysql_fetch_array($sql)){
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_opb]</td>
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td align='center'>$r[kode_sp]</td>
				<td>$r[nama_sp]</td>
				<td align='center'>$r[batas_kr] hari</td>
				<td align='center'>".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>";
?>