<?php
	include '../../inc/inc.koneksi.php';
	include '../../inc/fungsi_tanggal.php';
	
	$kode 		= $_GET['kode'];
	$kodeplg	= $_GET['kodeplg'];
	$tanggal	= $_GET['tgl'];
	$nomorfk	= $_GET['nomorfk'];
	$tglfk		= $_GET['tglfk'];
	
	$sql1		= "SELECT * FROM customer WHERE kode_pl='$kodeplg' ORDER BY kode_pl";
	$query1 	= mysql_query($sql1);
		
	while($r1=mysql_fetch_array($query1)){
		$namaplg = $r1['nama'];
		$alamat  = $r1['alamat'];
	}
	
	$sql2		= "SELECT * FROM company";		
	$query2 	= mysql_query($sql2);
		
	while($r2=mysql_fetch_array($query2)){
		$kop1 = $r2['nama1'];
		$kop2 = $r2['alamat'];
	}
	
	$content = "<b><h2>$kop1</h2></b>
		<li>$kop2</li>
		<div span='12' align='center'>
			<h2 aligh='center'><b>MEMO KREDIT</b></h2>
		</div>
	
		<table>
		<tr>
			<td>Kepada Yth</td>
			<td>:</td>
			<td>$namaplg</td>			
			<td></td>
			<td>No. Bukti</td>
			<td>: $kode</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td>$alamat</td>			
			<td></td>
			<td>Tanggal</td>
			<td>: ".jin_date_str($tanggal)."</td>
		</tr>
		<tr>			
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td>No. Faktur</td>
			<td>: $nomorfk</td>
		</tr>
		<tr>			
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td>Tgl. Faktur</td>
			<td>: $tglfk</td>
		</tr>
		</table>
		<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>Jumlah Unit</th>
			<th>Harga Netto</th>			
			<th>Total Harga</th>		
		</tr>";
	
		$sql	= "SELECT * FROM retur_pj WHERE kode_rj='$kode' ORDER BY kode_rj";		
		$query = mysql_query($sql);
		
		$no=1;				
		$tjumlah=0;
		
		while($r=mysql_fetch_array($query)){
			
			$content .= "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td align='center'>$r[satuan]</td>
				<td align='right'>$r[jml_unit]</td>
				<td align='right'>$r[hg_jual]</td>				
				<td align='right'>$r[jumlah]</td>
				</tr>";
			$tjumlah=$tjumlah+$r['jumlah'];
			$no++;
		}
	
		$content .= "</table>";
		
		$content .= "<table width='390' border='0' style='border-collapse:collapse'>
				<tr>				
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td border='1' style='border-collapse:collapse' align='right'>Jumlah</td>
				<td border='1' style='border-collapse:collapse'align='right'>$tjumlah</td>
			</tr>";
					
		$content .= "</table>";
		
		$content .= "<table width='390' border='0' style='border-collapse:collapse'>
				<tr>
					<td></td>
					<td></td>					
					<td align='center'>Customer</td>
					<td align='center'>Bag Gudang</td>
					<td></td>
					<td align='center'>Bag. Penjualan</td>
				</tr>			
				<tr>
					<td></td>					
				</tr>
				<tr>
					<td></td>					
				</tr>
				<tr>
					<td></td>
					<td></td>
					<td>_______________</td>					
					<td>_______________</td>
					<td>_______________</td>
				</tr>";
					
		$content .= "</table>";
				
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=$kode.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>