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

$fromdate = $_REQUEST['fromdate'];
$todate   = $_REQUEST['todate'];
$prof 	= mysql_fetch_array(mysql_query("SELECT prof_name FROM profil"));
?>
<table width="100%" border="0">
    <tr>
  		<td colspan="20" align="left"><strong>DATA REKON PEB</strong></td>
    </tr>
    <tr>
  		<td colspan="20" align="left"><strong><?=strtoupper($prof['prof_name']);?></strong></td>
    </tr>
	<tr>
  		<td colspan="20" align="left"><strong>PERIODE : <?=$fromdate;?> S/D <?=$todate;?></strong></td>
    </tr>
</table>	
<table width="100%" border="1">	
  <tr>
    <th align="center" bgcolor="#D1D1D1" rowspan="2">NO</th>
    <th align="center" bgcolor="#D1D1D1" rowspan="2">NO AJU </th>
    <th align="center" bgcolor="#D1D1D1" colspan="2">DOKUMEN BC 3.0 </th>
    <th align="center" bgcolor="#D1D1D1" colspan="2">NOTA PELAYARAN EKPOR </th>
    <th align="center" bgcolor="#D1D1D1">HOUSE BL/FCR/AWB </th>
    <th align="center" bgcolor="#D1D1D1">MASTER BL/FCR/AWB </th>
    <th align="center" bgcolor="#D1D1D1">NO KONTAINER </th>
    <th align="center" bgcolor="#D1D1D1" colspan="2">OUTWARD MANIFES </th>
    <th align="center" bgcolor="#D1D1D1" rowspan="2">POS</th>
    <th align="center" bgcolor="#D1D1D1" rowspan="2">PELABUHAN MUAT </th>
    <th align="center" bgcolor="#D1D1D1" rowspan="2">JUMLAH KEMASAN </th>
    <th align="center" bgcolor="#D1D1D1">BERAT</th>
	<th align="center" bgcolor="#D1D1D1">BARANG</th>
    <th align="center" bgcolor="#D1D1D1">U/PRICE</th>
    <th align="center" bgcolor="#D1D1D1">HARGA BARANG </th>
    <th align="center" bgcolor="#D1D1D1">HARGA MAKLON </th>
    <th align="center" bgcolor="#D1D1D1" rowspan="2">BUYER</th>
  </tr>
  <tr>
    <th align="center" bgcolor="#D1D1D1">NOMOR</th>
    <th align="center" bgcolor="#D1D1D1">TANGGAL</th>
    <th align="center" bgcolor="#D1D1D1">NOMOR</th>
    <th align="center" bgcolor="#D1D1D1">TANGGAL</th>
    <th align="center" bgcolor="#D1D1D1">NOMOR</th>
    <th align="center" bgcolor="#D1D1D1">NOMOR</th>
    <th align="center" bgcolor="#D1D1D1">&nbsp;</th>
    <th align="center" bgcolor="#D1D1D1">NOMOR</th>
    <th align="center" bgcolor="#D1D1D1">TANGGAL</th>
    <th align="center" bgcolor="#D1D1D1">BRUTO</th>
    <th align="center" bgcolor="#D1D1D1">FOB</th>
    <th align="center" bgcolor="#D1D1D1">CMT USD </th>
    <th align="center" bgcolor="#D1D1D1">CMT USD </th>
  </tr>
	<?php
		$qd = mysql_query("SELECT a.*, c.*, CASE WHEN ifnull(a.outh_custid,0)=0 THEN a.nm_penerima ELSE b.cust_name END as penerima, c.harga_maklon harga_maklon2 , 
				c.harga_fob harga_fob2, d.prod_code, d.prod_name, d.prod_sat
				FROM outgoing a LEFT JOIN customer b ON b.id=a.outh_custid 
				INNER JOIN outgoing_detail c ON c.outd_hid=a.id
				INNER JOIN product d ON d.id=c.outd_prodid
				WHERE a.outh_docdate BETWEEN '$fromdate' AND '$todate' AND a.outh_status=20 AND outh_doctype='BC 3.0' ORDER BY a.id DESC");
		$no = 1;
		while($dd=mysql_fetch_array($qd)){		
			$price = $dd['outd_price']/$dd['outd_qty'];
		?> 
		  <tr>
			<td align="center"><?=$no;?></td>
			<td align="center"><?=$dd['no_aju'];?></td>
			<td align="center"><?=$dd['outh_docno'];?></td>
			<td align="center"><?=$dd['outh_docdate'];?></td>
			<td align="center"><?=$dd['nomor_nota'];?></td>
			<td align="center"><?=$dd['tanggal_nota'];?></td>
			<td align="center"><?=$dd['house_bl'];?></td>
			<td align="center"><?=$dd['master_bl'];?></td>
			<td align="center"><?=$dd['no_kontainer'];?></td>
			<td align="center"><?=$dd['nomor_manifes'];?></td>
			<td align="center"><?=$dd['tanggal_manifes'];?></td>
			<td align="center"><?=$dd['pos'];?></td>
			<td><?=$dd['pelabuhan'];?></td>
			<td align="right"><?=number_format($dd['jumlah_kemasan'],2,'.','');?></td>
			<td align="right"><?=number_format($dd['outd_weight'],2,'.','');?></td>
			<td><?=$dd['prod_code'];?> - <?=$dd['prod_name'];?> - <?=$dd['prod_sat'];?></td>
			<td align="right"><?=number_format($dd['harga_fob2'],2,'.','');?></td>
			<td align="right"><?=number_format($dd['outd_price'],2,'.','');?></td>
			<td align="right"><?=number_format($dd['harga_maklon2'],2,'.','');?></td>
			<td><?=$dd['penerima'];?></td>
		  </tr>
      <?php $no++; }  ?>	
</table>