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

	$tgl_awal	= $_GET['tgl_awal'];
	$tgl_akhir= $_GET['tgl_akhir'];
	$jml = 0;
	$tjumlah=0;

	$content = "<b><li>DAFTAR PEMBELIAN BARANG DAGANGAN</li>
		<li>TANGGAL z: ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</li></b>
		<br>
	
		<table width='390' border='1' style='border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Kode Barang</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Jumlah Unit</th>
			<th>Harga Satuan</th>
			<th>Total Harga</th>
		</tr>";
		
		$query2	= "SELECT kode_pb,tanggal,nomor_fk,count(kode_st) as totitem FROM faktur_pb 
				WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir'	AND batal='' GROUP BY kode_pb	";
		$data2	= mysql_query($query2);
		while($r_data2=mysql_fetch_array($data2)){
			$kodepb=$r_data2[kode_pb];

		$content .= "<tr>	
				<td></td>
				<td align='center'><b>No.Faktur :</b></td>
				<td><b>$r_data2[nomor_fk]</b></td>
				<td align='center'><b>".jin_date_str($r_data2[tanggal])."</b></td>				
			</tr>";
			
		$sql = "SELECT * FROM faktur_pb WHERE kode_pb='$kodepb' ";		
		$query = mysql_query($sql);
		
		$no=1+$hal;
		$sjumlah=0;
		while($r_data=mysql_fetch_array($query)){
				
		$content .= "<tr>	
				<td align='center'>$no</td>
				<td align='center'>$r_data[kode_st]</td>
				<td>$r_data[nama_st]</td>
				<td align='center'>$r_data[satuan]</td>
				<td align='right'>$r_data[jml_unit]</td>
				<td align='right'>".number_format($r_data[hg_beli])."</td>
				<td align='right'>".number_format($r_data[jumlah])."</td>
				</tr>";
			$sjumlah=$sjumlah+$r_data[jumlah];
			$no++;
			$jml++;			
		}
		$content .= "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($sjumlah)."</td>
			</tr>";
			$tjumlah=$tjumlah+$sjumlah;
		}
		
		$content .= "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total </td>
				<td align='right'>".number_format($tjumlah)."</td>
			</tr>";
		$content .= "</table>";
		
		$content .= "<table>
			<tr>
				<td>Jumlah Data : $jml</td>
			</tr>
			</table>";
				
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=daftar_pbl.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>
