<?php
include "../include/config.php";
include "../function/inc_function.php";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="excel_lap_pemasukan_all'.get_datetime().'.xls"');
header('Cache-Control: max-age=0');

$start_date = $_REQUEST['fromdate'];
$end_date   = $_REQUEST['todate'];
$doc_type   = $_REQUEST['doc_type'];

$month 		= substr($start_date,5,2);
$year		= substr($start_date,0,4);
$cek        = $month-1;
if($cek==0){
	$bln = 12;
	$thn = $year-1;
}else{
	$bln = $cek;
	$thn = $year;
}
$sqlShow 	= mysql_query("SELECT prof_name FROM profil");
$dataShow 	= mysql_fetch_array($sqlShow);
?>
<table width="100%" border="0">
    <tr>
  		<td colspan="13">LAPORAN PEMASUKAN BARANG PER DOKUMEN PABEAN</td>
    </tr>
    <tr>
  		<td colspan="13">KAWASAN BERIKAT <?=strtoupper($dataShow['prof_name']);?></td>
    </tr>
    <tr>
  		<td colspan="13">PERIODE <?=DateToIndo($start_date);?> S/D <?=DateToIndo($end_date);?> </td>
    </tr>
    <tr>
  		<td colspan="13">&nbsp;</td>
    </tr>
</table>	
<table width="100%" border="1">	
  <tr>
    <th align="center"bgcolor="#D1D1D1" rowspan="2">No</th>
    <th align="center"bgcolor="#D1D1D1" colspan="3">Dokumen Pabean</th>
    <th align="center"bgcolor="#D1D1D1" colspan="2">Bukti Penerimaan Barang </th>
    <th align="center"bgcolor="#D1D1D1" rowspan="2">Pemasok</th>
    <th align="center"bgcolor="#D1D1D1" rowspan="2">Kode Barang </th>
    <th align="center"bgcolor="#D1D1D1" rowspan="2">Nama Barang </th>
    <th align="center"bgcolor="#D1D1D1" rowspan="2">Satuan </th>
    <th align="center"bgcolor="#D1D1D1" rowspan="2">Jumlah </th>
    <th align="center"bgcolor="#D1D1D1" rowspan="2">Valuta</th>
    <th align="center"bgcolor="#D1D1D1" rowspan="2">Nilai Barang </th>
  </tr>
  <tr>
    <th align="center"bgcolor="#D1D1D1">Jenis</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">Tanggal</th>
  </tr>
	<?php	
	    $no=0;	
		$qd = mysql_query("CALL spvw_bln_incomingall ('$start_date','$end_date');");
		while($dd=mysql_fetch_object($qd)){
		if($dd->incd_currency=="IDR"){
			$incd_price = $dd->incd_price;
		}else{
			$incd_price = $dd->incd_price_usd;
		}		
		$no++;
		?> 
		  <tr>
			<td align="center"><?=$no;?></td>
			<td align="center"><?=$dd->doc_type;?></td>
			<td align="center"><?php echo "'"."$dd->inch_docno";?></td>
			<td align="center"><?=DateToIndo($dd->inch_docdate);?></td>
			<td align="center"><?=$dd->inch_bpbno;?></td>
			<td align="center"><?=DateToIndo($dd->inch_bpbdate);?></td>
			<td align="left"><?=$dd->sup_name;?></td>
			<td align="left"><?=$dd->prod_code;?></td>
			<td align="left"><?=$dd->prod_name;?></td>
			<td align="left"><?=$dd->prod_sat;?></td>
			<td align="right"><?=number_format($dd->incd_qty,2,'.','');?></td>
			<td align="center"><?=$dd->incd_currency;?></td>
			<td align="right"><?=number_format($incd_price,2,'.','');?></td>
		  </tr>
      <?php }  ?>	
</table>