<!DOCTYPE html>

<?php 
	session_start();
	require_once "../../config/koneksi.php";
	require_once "../../config/fungsi_indotgl.php";
	require_once "../../config/fungsi_rupiah.php";
	
?>
<html>
<body>
		<h3 class="box-title"><center>Laporan Persediaan Akhir</center></h3><br>
				  <?php					
					header("Content-type: application/vnd-ms-excel");
					header("Content-Disposition: attachment; filename=LaporanPersediaanAkhir.xls");
					?>
                  <table id="example1" class="table table-bordered table-striped" border="1">
				  <?php
						

						echo"
                    <thead>
                      <tr>
						<th>Jenis</th>						
						<th>No Beli</th>	
						<th>Tanggal</th>		
						<th>Produk</th>	
						<th>Harga</th>	
						<th>Qty Beli</th>		
						<th>Qty Jual</th>	
						<th>Sisa</th>
						<th>Persediaan</th>
                      </tr>
                    </thead>
                    <tbody>";
						
							
						$cek = mysql_query("Select * from akhir order by id asc ");
						
						while ($r=mysql_fetch_array($cek)){	
						
							$ord = $r['billno'];
							$tgl = tgl_ind($r['belidate']);
							$produk = mysql_result(mysql_query("select produk from produk where id = $r[produk]"),0);
							$harga = format_rupiah($r['beliprice']);
							$sisa = $r['qtybeli'] - $r['qtyjual'];
							$persediaan = format_rupiah($sisa * $r['beliprice']);

							
							echo "<tr>
									<td>$r[jenis]</td>
									<td>$r[belino]</td>
									<td>$tgl</td>
									<td>$produk</td>
									<td>$harga</td>
									<td>$r[qtybeli]</td>
									<td>$r[qtyjual]</td>
									<td>$sisa</td>
									<td>$persediaan</td>
								  </tr>";
						}
						?>
					</tbody>
					</table>
</body>
</html>
<?php 

	echo "<script>window.close();</script>";
?>