<?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 RETUR PEMBELIAN</li>
		<li>TANGGAL : ".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</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Jml.Kirim</th>
			<th>Jml.Retur</th>
			<th>Harga Beli</th>
			<th>Nilai Retur</th>
			<th>Keterangan</th>			
		</tr>";
		
		$query2	= "SELECT kode_rb,tanggal,nomor_fk,tanggal_fk,count(kode_st) as totitem FROM retur_pb 
			WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir'	AND batal='' GROUP BY kode_rb";
		$data2	= mysql_query($query2);
		while($r_data2=mysql_fetch_array($data2)){
			$koderb=$r_data2[kode_rb];

		$content .= "<tr>	
				<td></td>
				<td><b>No.Retur :</b></td>
				<td><b>$r_data2[kode_rb] - ".jin_date_str($r_data2[tanggal])."</b></td>
				<td><b>Faktur :</td>
				<td><b>$r_data2[nomor_fk]</b></td>
				<td><b>Tanggal :</td>
				<td><b>".jin_date_str($r_data2[tanggal_fk])."</b></td>				
			</tr>";
			
		$sql = "SELECT * FROM retur_pb WHERE kode_rb='$koderb' ";		
		$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='center'>$r_data[jml_kirim]</td>
				<td align='center'>$r_data[jml_retur]</td>
				<td align='right'>$r_data[hg_beli]</td>
				<td align='right'>$r_data[jumlah]</td>
				<td>$r_data[keterangan]</td>	
			</tr>";
			$sjumlah=$sjumlah+$r_data[jumlah];
			$no++;			
		}
		$content .= "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>				
				<td align='right'>Jumlah</td>
				<td align='right'>$sjumlah</td>
			</tr>";
			$tjumlah=$tjumlah+$sjumlah;
		}
		
		$content .= "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total </td>
				<td align='right'>$tjumlah</td>
			</tr>";
		$content .= "</table>";
		
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=daftar_rpb.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>
