<!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 Purchase Order</center></h3><br>
				  <?php					
					header("Content-type: application/vnd-ms-excel");
					header("Content-Disposition: attachment; filename=LaporanPurchaseOrder.xls");
					?>
                  <table id="example1" class="table table-bordered table-striped" border="1">
				  <?php
						

						echo"
                    <thead>
                      <tr>
						<th>No Ord</th>
                        <th>Tanggal</th>
                        <th>Customer</th>
						<th>Total</th>
						<th>Kasir</th>
                      </tr>
                    </thead>
                    <tbody>";
						
						$tglawal = $_GET['awal'];
						$tglakhir = $_GET['akhir'];
							
						$cek = mysql_query("Select * from buy where buy.status <> 'D' and buy.kasir <> '' and (buy.billdate >= '$tglawal' and buy.billdate <= '$tglakhir') order by billno asc ");
						while ($r=mysql_fetch_array($cek)){	
						
							$ord = $r['billno'];
							$tgl = tgl_ind($r['billdate']);
							$supp = mysql_result(mysql_query("select nama from supplier where id = $r[cust]"),0);
							$tot0 = mysql_result(mysql_query("select sum(qty * harga2) from buydetail where billno = $ord"),0);
							$total = format_rupiah($tot0);

							
							echo "<tr>
									<td><a href='pembelianview.php?id=$ord'>$ord</a></td>
									<td>$tgl</td>
									<td>$supp</td>
									<td>$total</td>
									<td>$r[kasir]</td>
								  </tr>";
						}
						?>
					</tbody>
					</table>
</body>
</html>
<?php 

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