<?php
include "../include/config.php";
include "../function/inc_function.php";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="laporan_bulanan_bc23_pemasukan_'.date('Y-m-d H:i:s').'.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;
}
$prof 	= mysql_fetch_array(mysql_query("SELECT prof_name FROM profil"));
?>
<table width="100%" border="0">
    <tr>
  		<td colspan="39" align="center"><strong>BUKU CATATAN PABEAN</strong></td>
    </tr>
    <tr>
  		<td colspan="39" align="center"><strong>BC 2.3 IMPORT SPPB-TPB</strong></td>
    </tr>
</table>	
<table width="100%" border="1">	
  <tr>
    <th align="center" bgcolor="#D1D1D1" rowspan="3">NO</th>
    <th align="center" bgcolor="#D1D1D1" colspan="6">BC 2.3</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">NAMA PEMASOK</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">KODE BARANG</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">NO URUT</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">NAMA BARANG</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">KODE HS</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">TARIF</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">SATUAN</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">JUMLAH</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">VALAS</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">NDPBM</th>	
	<th align="center" bgcolor="#D1D1D1" rowspan="3">FOB</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">FREIGHT</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">NILAI CIF</th>	
	<th align="center" bgcolor="#D1D1D1" rowspan="3">NILAI CIF IDR</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="2" colspan="2">INVOICE</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="2" colspan="2">HBL</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">VESEL</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">ETA JKT</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="2" colspan="3">KONTAINER</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="2" colspan="3">KEMASAN</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">BERAT</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">PELABUHAN</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">SELESAI MASUK</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="2" colspan="2">IJIN PEMASUKAN</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="3">TUJUAN</th>
  </tr>
  <tr>
    <th align="center" bgcolor="#D1D1D1" colspan="2">PENGAJUAN</th>
    <th align="center" bgcolor="#D1D1D1" colspan="2">PENDAFTARAN</th>
    <th align="center" bgcolor="#D1D1D1" colspan="2">SPPB</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">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">TANGGAL</th>
	<th align="center" bgcolor="#D1D1D1">NOMOR</th>
	<th align="center" bgcolor="#D1D1D1">TIPE</th>
    <th align="center" bgcolor="#D1D1D1">UKURAN</th>
	<th align="center" bgcolor="#D1D1D1">KODE</th>
	<th align="center" bgcolor="#D1D1D1">JENIS</th>
    <th align="center" bgcolor="#D1D1D1">JUMLAH</th>
	<th align="center" bgcolor="#D1D1D1">NOMOR</th>
    <th align="center" bgcolor="#D1D1D1">TANGGAL</th>
  </tr>
	<?php		
		$qd = mysql_query("CALL spvw_blnexcel_incoming ('$start_date','$end_date','$doc_type');");
		$no = 1;
		while($dd=mysql_fetch_object($qd)){	
		if($dd->incd_currency=="IDR"){
			$incd_price = $dd->incd_price;
		}else{
			$incd_price = $dd->incd_price_usd;
		}	
		?> 
		  <tr>
			<td align="center"><?=$no;?></td>
			<td align="center">'<?=$dd->no_aju;?></td>
			<td align="center"><?=$dd->tgl_aju;?></td>
			<td align="center">'<?=$dd->inch_docno;?></td>
			<td align="center"><?=$dd->inch_docdate;?></td>
			<td align="center">'<?=$dd->no_sppb;?></td>
			<td align="center"><?=$dd->tgl_sppb;?></td>
			<td align="left"><?=$dd->nm_pemasok;?></td>
			<td align="center"><?=$dd->prod_code;?></td>
			<td align="center"><?=$dd->no_urut;?></td>
			<td align="left"><?=$dd->prod_name;?></td>
			<td align="center"><?=$dd->kode_hs;?></td>
			<td align="right"><?=number_format($dd->tarif,2,'.','');?>%</td>
			<td align="center"><?=$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($dd->inch_rate,2,'.','');?></td>			
			<td align="right"><?=number_format($dd->incd_fob,2,'.','');?></td>
			<td align="right"><?=number_format($dd->inch_freight,2,'.','');?></td>
			<td align="right"><?=number_format($dd->incd_price_usd,2,'.','');?></td>
			<td align="right"><?=number_format($dd->incd_price,2,'.','');?></td>
			<td align="center"><?=$dd->inch_invno;?></td>
			<td align="center"><?=$dd->inch_invdate;?></td>
			<td align="center"><?=$dd->no_hbl;?></td>
			<td align="center"><?=$dd->tgl_hbl;?></td>
			<td align="left"><?=$dd->vesel;?></td>
			<td align="center"><?=$dd->eta_jkt;?></td>
			<td align="center"><?=$dd->no_kontainer;?></td>
			<td align="center"><?=$dd->tipe_kontainer;?></td>
			<td align="center"><?=$dd->ukuran_kontainer;?></td>
			<td align="center"><?=$dd->kode_kemasan;?></td>
			<td align="center"><?=$dd->jenis_kemasan;?></td>
			<td align="center"><?=$dd->jumlah_kemasan;?></td>
			<td align="right"><?=number_format($dd->incd_weight,2,'.','');?></td>
			<td align="left"><?=$dd->pelabuhan;?></td>
			<td align="center"><?=$dd->inch_bpbdate;?></td>
			<td align="center"><?=$dd->no_izin;?></td>
			<td align="center"><?=$dd->tgl_izin;?></td>
			<td align="left"><?=$dd->tujuan;?></td>
		  </tr>
      <?php $no++; }  ?>	
</table>