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

	$tgl_awal	= $_GET['tgl_awal'];
	$tgl_akhir= $_GET['tgl_akhir'];
	$total=0;
	$no=0;

	$content = "<b><li>LAPORAN LABA RUGI PENJUALAN</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 Barang</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Jumlah Unit</th>
			<th>Harga Netto</th>
			<th>Harga Pokok</th>
			<th>Laba Kotor</th>			
		</tr>";
				
		$data	= mysql_query($query);
		$query	= "SELECT kode_st,nama_st,satuan,sum(jml_unit) as tunit,sum(jumlah) as tjumlah,sum(hpp) as thpp FROM faktur_pj 
			WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir'	AND batal='' GROUP BY kode_st ";
		$data	= mysql_query($query);
		$no=1
		$gtotal=0;
		$gthpp=0;
		$gtlaba=0;
		
		while($r_data=mysql_fetch_array($data)){
			$laba=$r_data[tjumlah]-$r_data[thpp];
			$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[tunit]</td>
				<td align='right'>".number_format($r_data[tjumlah],0)."</td>
				<td align='right'>".number_format($r_data[thpp],0)."</td>
				<td align='right'>".number_format($laba,0)."</td>				
			</tr>";
			$gtotal=$gtotal+$r_data[tjumlah];
			$gthpp=$gthpp+$r_data[thpp];
			$gtlaba=$gtlaba+$laba;			
			$no++;
		}
		
		$content .= "<tr>
			<td></td>
			<td></td>
			<td></td>			
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($gtotal)."</td>
			<td align='right'>".number_format($gthpp)."</td>
			<td align='right'>".number_format($gtlaba)."</td>			
		</tr>";
		
		$content .= "</table>";
			
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=laba_pjl.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>
