<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");
            }
        );
    });
});
</script>

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

$cari	  = $_GET[cari];
$tglawal  = $_GET[tglawal];
$tglakhir = $_GET[tglakhir];
$kodetk   = $_GET[kodetk];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Pokok</th>
			<th>Jumlah Hasil</th>
			<th>Nilai Hasil</th>
		</tr>";

		if (!empty($cari))
			$sql1= "SELECT kode_ps,tanggal,kode_st,nama_st,jml_unit,satuan FROM jurpsb WHERE kode_tk='$kodetk' AND tanggal BETWEEN '$tglawal' AND '$tglakhir' AND batal='' AND (nama_st like '%$cari%') GROUP BY kode_ps";
		else
			$sql1= "SELECT kode_ps,tanggal,kode_st,nama_st,jml_unit,satuan FROM jurpsb WHERE kode_tk='$kodetk' AND tanggal BETWEEN '$tglawal' AND '$tglakhir' AND batal='' GROUP BY kode_ps";
		$query1 = mysql_query($sql1);
		
		$tjumlah=0;
		$tselisih=0;
		$tjasal=0;
		$tunit=0;
		while($data1=mysql_fetch_array($query1)){
			$kodeps=$data1[kode_ps];
			$jmlasal=$data1[jumlah_asl];
			echo "<tr>
				<td></td>
				<td><b>Nomor : $data1[kode_ps]</b></td>
				<td><b>Tanggal : ".jin_date_str($data1[tanggal])."</b></td>
				<td><b>Barang :</b></td>
				<td><b>$data1[kode_st]-$data1[nama_st]</b></td>
				<td><b>Jumlah : $data1[jml_unit] $data1[satuan]</b></td>
				<td><b>Nilai : ".number_format($data[jumlah_asl],2)."</b></td>
			</tr>";
		
			$sql   = "SELECT * FROM jurpsb WHERE kode_ps='$kodeps' AND kode_tk='$kodetk' ORDER BY no_urut";
			$query = mysql_query($sql);
		
			$no=1;
			$sjumlah=0;			
			$sunit=0;
			while($data=mysql_fetch_array($query)){
				$sjumlah =$sjumlah+$data[jumlah];
				$sunit   =$sunit+$data[jml_unit];
				echo "<tr>
					<td align='center'>$no</td>
					<td>$data[kode_st1]</td>
					<td>$data[nama_st1]</td>
					<td>$data[satuan1]</td>
					<td align='right'>".number_format($data[harga1],2)."</td>
					<td align='right'>".number_format($data[jml_unit1],2)."</td>
					<td align='right'>".number_format($data[jumlah1],2)."</td>
				</tr>";
				$no++;
			}
			$selisih=$sjumlah-$jmlasl;
		
			echo "<tr>
					<td></td>
					<td></td>
					<td>Selisih : ".number_format($selisih,2)."</td>
					<td></td>
					<td align='right'>Jumlah</td>
					<td align='right'>".number_format($sunit,2)."</td>
					<td align='right'>".number_format($sjumlah,2)."</td>
				</tr>";
			$tjumlah=$tjumlah+$sjumlah;
			$tunit =$tunit+$sunit;
			$tjasal=$tjasal+$jmlasl;
			$tselisih=$tselisih+$selisih;
		}
		echo "<tr>
				<td></td>
				<td></td>
				<td>Selisih : ".number_format($telisih,2)."</td>
				<td></td>
				<td align='right'>Total</td>
				<td align='right'>".number_format($tunit,3)."</td>
				<td align='right'>".number_format($tjumlah,2)."</td>
			</tr>";
	echo "</table>";
echo "</div>";
?>