<?php
include "../../include/config.php";
include "../../function/inc_function.php";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="data_po_sales_'.date('Y-m-d H:i:s').'.xls"');
header('Cache-Control: max-age=0');

$fromdate = $_REQUEST['fromdate'];
$todate   = $_REQUEST['todate'];
?>
<table width="100%" border="0">
    <tr>
  		<td colspan="13" align="left"><strong>DATA SALES ORDER</strong></td>
    </tr>
	<tr>
  		<td colspan="13" align="left"><strong>PERIODE : <?=$fromdate;?> s/d <?=$todate;?></strong></td>
    </tr>
</table>	
<table width="100%" border="1">	
  <tr>
    <th align="center" bgcolor="#D1D1D1">NO</th>
	<th align="center" bgcolor="#D1D1D1">NOMOR SO</th>
    <th align="center" bgcolor="#D1D1D1">TANGGAL SO</th>
	<th align="center" bgcolor="#D1D1D1">PIC</th>
	<th align="center" bgcolor="#D1D1D1">CUSTOMER</th>
	<th align="center" bgcolor="#D1D1D1">TANGGAL KIRIM</th>
	<th align="center" bgcolor="#D1D1D1">KODE BARANG</th>
	<th align="center" bgcolor="#D1D1D1">NAMA BARANG</th>
	<th align="center" bgcolor="#D1D1D1">SATUAN</th>
	<th align="center" bgcolor="#D1D1D1">JUMLAH</th>	
	<th align="center" bgcolor="#D1D1D1">HARGA</th>
	<th align="center" bgcolor="#D1D1D1">CURENCY</th>
	<th align="center" bgcolor="#D1D1D1">TOTAL</th>
  </tr>
	<?php		
		$qd = mysql_query("SELECT a.po_no, a.po_date, a.po_pic, c.cust_name, a.po_deldate, d.prod_code, d.prod_name, d.prod_sat, b.pod_qty, b.pod_price, a.po_currency, b.pod_amount
			FROM purchase_order a INNER JOIN purchase_order_detail b ON b.po_no=a.po_no AND b.pod_status=10
			INNER JOIN customer c ON c.id=a.po_idcust INNER JOIN product d ON d.id=b.pod_prodid
			WHERE a.po_status <> 100 AND a.po_date BETWEEN '$fromdate' AND '$todate' AND po_type='Sales' ORDER BY a.id DESC");
		$no = 1;
		while($dd=mysql_fetch_object($qd)){			
		?> 
		 <tr>
			<td align="center"><?=$no;?></td>
			<td align="center"><?=$dd->po_no;?></td>
			<td align="center"><?=$dd->po_date;?></td>
			<td align="left"><?=$dd->po_pic;?></td>
			<td align="left"><?=$dd->cust_name;?></td>
			<td align="center"><?=$dd->po_deldate;?></td>
			<td align="left"><?=$dd->prod_code;?></td>
			<td align="left"><?=$dd->prod_name;?></td>
			<td align="center"><?=$dd->prod_sat;?></td>
			<td align="right"><?=number_format($dd->pod_qty,2,'.','');?></td>
			<td align="right"><?=number_format($dd->pod_price,2,'.','');?></td>			
			<td align="center"><?=$dd->po_currency;?></td>
			<td align="right"><?=number_format($dd->pod_amount,2,'.','');?></td>
		  </tr>
      <?php $no++; }  ?>	
</table>