<!DOCTYPE html>

<?php 
	session_start();
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.php";
	include "../../config/fungsi_indotgl.php";
	include "../head.php";

	
	if ($_SESSION['nama'] == ''){
		header('Location:index.php');
	}
	else{
		$blnx = date('M');
		$thnx = date('Y');
		$harini = date('d-m-Y');
		$awal = $_GET['awal'];
		$akhir = $_GET['akhir'];
		$awal2 = date('d-m-Y', strtotime($awal));
		$akhir2 = date('d-m-Y', strtotime($akhir));
?>
<html>

  <body class="hold-transition skin-blue sidebar-mini layout-boxed">
                  <h3 class="box-title"><center>Penjualan CS from <?php echo "$awal2 s/d $akhir2 , tgl cetak : $harini"; ?></center></h3><br>
				  <?php					
					header("Content-type: application/vnd-ms-excel");
					header("Content-Disposition: attachment; filename=Laporan-Bulan-$blnx-$thnx.xls");
					?>
                  <table id="example1" class="table table-bordered table-striped" border="1">
                    <thead>
                      <tr>
						<th>No Order</th>						
						<th>Tanggal</th>	
						<th>Customer</th>		
						<th>Subtotal</th>								
						<th>Ongkir</th>	
						<th>Grandtotal</th>	
						<th>Kasir</th>	
                      </tr>
                    </thead>
                    <tbody>
					<?php
						$cek = mysql_query("Select * from jualcs where billdate >= '$awal' and billdate <= '$akhir' order by billno asc");
						while ($r=mysql_fetch_array($cek))
						{	
							if ($r['billdate'] =="0000-00-00"){
								$tgl = "";
							}else{
								$tgl = date('d-M-Y', strtotime($r['billdate']));
							}
							$cust = mysql_result(mysql_query("select nama from customer where id = $r[cust]"),0);
							$subtotal = mysql_result(mysql_query("select sum(qty * (harga-promo)) from jualcsdetail where billno = $r[billno]"),0);
							$subtotal1 = format_rupiah($subtotal);
							$ongkir = format_rupiah($r['ongkir']);
							$grandtotal = format_rupiah($r['ongkir'] + $subtotal);
							
							echo "<tr>";
							echo "<td>".$r['billno']."</td>";
							echo "<td>".$tgl."</td>";	
							echo "<td>'".$cust."</td>";	
							echo "<td>".$subtotal1."</td>";	
							echo "<td>".$ongkir."</td>";
							echo "<td>".$grandtotal."</td>";
							echo "<td>".$r['kasir']."</td>";
							echo "</tr>";
						}
					?>
                        
                     
                    </table>
                </div><!-- /.row -->
  </body>
</html>
<?php 
	}
	echo "<script>window.close();</script>";
	#header("Location: laporan1.php");
	#exit;
?>