<script type="text/javascript">	
	window.print();
</script>
<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';

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

	$tjumlah=0;
	$tdiskon=0;
	$thutang=0;
	$tkurang=0;
	
	$sql2= mysql_query("SELECT * FROM company");
	$r2	 = mysql_fetch_assoc($sql2);
	$kop1 = $r2['nama1'];
	$kop2 = $r2['nama2'];
	$kop3 = $r2['alamat'];
	
	echo "<table width='100%'>
		<tr>
			<td style='font:11px arial;line-height:80%'><b>$kop1</b></td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

	<table width='100%' >
		<tr>
			<td align='center' style='font:15px arial'><b>DAFTAR IMPORT SOP</td>
		</tr>
		<tr>
			<td align='center' style='font:15px arial'><b>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</b></td>
		</tr>";
		if(!$kodeplg==''){
			echo "<tr>
				<td align='center' style='font:14px arial'><b>PELANGGAN : $namaplg ($kodeplg)</b></td>
			</tr>";
		}
	echo "</table>
	<br>
	
<table width='100%' border='1' style='border-collapse:collapse;font:11px arial'>
	<tr>
		<th>No.</th>
		<th>Kode</th>
		<th>Nama Barang</th>
		<th>Barcode</th>
		<th>Satuan</th>
		<th>Jumlah Unit</th>
		<th>Harga Jual</th>
		<th>Disc. Momen</th>
		<th>Total Harga</th>
	</tr>";
	
	if(!$kodeplg=='')
		$data1= mysql_query("SELECT kode_pj,tanggal,kode_plg,nama_plg,count(kode_st) as totitem,user FROM faktur_pjg WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kode_plg='$kodeplg' AND posting='P' AND batal='' GROUP BY kode_pj");
	else
		$data1= mysql_query("SELECT kode_pj,tanggal,kode_plg,nama_plg,count(kode_st) as totitem,user FROM faktur_pjg WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND posting='P' AND batal='' GROUP BY kode_pj");
	
	$tjumlah=0;
	$tpotong=0;	
	$tbayar=0;
	$tkurang=0;
	$tnetto=0;
	
	while($r1=mysql_fetch_array($data1)){
		$kodepj=$r1['kode_pj'];
		echo "<tr>				
			<td><b>Faktur</b></td>
			<td><b>$r1[kode_pj]</b></td>
			<td><b>".jin_date_str($r1['tanggal'])." - Pelanggan : $r1[nama_plg]</b></td>
			<td><b>- $r1[kode_plg]</b></td>
		</tr>";
		$query = mysql_query("SELECT * FROM faktur_pjg WHERE kode_pj='$kodepj'");
		
		$no=1;
		$sjumlah=0;
		$spotong=0;
		$sbayar=0;
		$skurang=0;
		
		while($r=mysql_fetch_array($query)){
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[barcode]</td>
				<td align='center'>$r[satuan]</td>
				<td align='right'>$r[jml_unit]</td>
				<td align='right'>".number_format($r['hg_jual'])."</td>
				<td align='center'>".number_format($r['disc_mm'])." %</td>
				<td align='right'>".number_format($r['jumlah'])."</td>
			</tr>";
			$sjumlah=$sjumlah+$r['jumlah'];
			$spotong=$spotong+$r['potongan'];
			$sbayar	=$sbayar+$r['bayar'];
			$no++;
		}
		$snetto=$sjumlah-$spotong;
		$skurang=$snetto-$bayar;
	
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td align='right'>".number_format($sjumlah)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Potongan</td>
			<td align='right'>".number_format($spotong)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>			
			<td align='right'>Netto</td>
			<td align='right'>".number_format($snetto)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Dibayar</td>
			<td align='right'>".number_format($sbayar)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Kurang Bayar</td>
			<td align='right'>".number_format($skurang)."</td>
		</tr>";
		$tjumlah=$tjumlah+$sjumlah;
		$tpotong=$tpotong+$spotong;
		$tnetto=$tnetto+$snetto;
		$tbayar =$tbayar+$sbayar;
		$tkurang=$tkurang+$skurang;
	}
	echo "<tr></tr>
	<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($tjumlah)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Potongan</td>
		<td align='right'>".number_format($tpotong)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Netto</td>
		<td align='right'>".number_format($tnetto)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Dibayar</td>
		<td align='right'>".number_format($tbayar)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Kurang Bayar</td>
		<td align='right'>".number_format($tkurang)."</td>
	</tr>
</table>";
?>