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

$fromdate = isset($_REQUEST['fromdate']) ? $_REQUEST['fromdate'] : $date;
$todate   = isset($_REQUEST['todate']) ? $_REQUEST['todate'] : $date;
$sup_name2= isset($_REQUEST['sup_name2']) ? $_REQUEST['sup_name2'] : "SEMUA";
if($sup_name2=="SEMUA"){$supname = "";}else{ $supname = "AND nm_pemasok LIKE '%$sup_name2%'"; }

$sqlShow 	= mysql_query("SELECT prof_name FROM profil");
$dataShow 	= mysql_fetch_array($sqlShow);

?>
<table width="100%" border="0">
    <tr>
  		<td colspan="15">DATA INBOX (PEMASUKAN)</td>
    </tr>
    <tr>
  		<td colspan="15">PERIODE : <?=$fromdate;?> - <?=$todate;?></td>
    </tr>
</table>	
<table width="100%" border="1">	
  <tr>
	<th rowspan="2">No</th>
	<th rowspan="2">Jenis</th>
	<th rowspan="2">No. Daftar</th>
	<th rowspan="2">Tgl Daftar</th>
	<th rowspan="2">Pemasok</th>
	<th rowspan="2">Valuta</th>
	<th colspan="2">Nilai</th>
	<th rowspan="2">Kurs</th>
	<th rowspan="2">No Jurnal</th>
	<th rowspan="2">Tgl Jurnal<br>YYYY-MM-DD</th>
	<th rowspan="2">NPWP</th>
	<th rowspan="2">No Inv</th>
	<th rowspan="2">Tgl Inv<br>YYYY-MM-DD</th>
	<th rowspan="2">No Faktur</th>	
  </tr>
  <tr>
	<th>Non IDR</th>
	<th>IDR</th>
  </tr>
  </thead>
	<tbody>
  <?php
	$no=1; $gtprice=0;
	$qd = mysql_query("SELECT * FROM incoming WHERE inch_status=20 AND inch_docdate BETWEEN '$fromdate' AND '$todate' 
		  AND (inch_paytype is null OR inch_paytype ='') $supname ORDER BY id DESC"); 
	while($dd=mysql_fetch_array($qd)){	
		$cek = mysql_fetch_array(mysql_query("SELECT incd_currency, SUM(incd_price) nilai_idr, SUM(incd_price_usd) nilai_nidr FROM incoming_detail 
		WHERE incd_hid='$dd[id]' GROUP BY incd_currency"));	
		if($dd['inch_doctype']=="BC 2.3"){
			$nilai_nidr = $cek['nilai_nidr'];
		}else{
			$nilai_nidr = 0;
		}
		if($dd['inch_rate']>0){$inch_rate=$dd['inch_rate'];}else{$inch_rate=0;}
		if(!empty($dd['inch_jurnaldate'])){$inch_jurnaldate=$dd['inch_jurnaldate'];}else{$inch_jurnaldate=date('Y-m-d');}
		if($cek['incd_currency']=="IDR"){$debkred=$cek['nilai_idr'];}else{$debkred=$nilai_nidr;}
	?> 
	 <tr onMouseOver="setTrColor(this, '#FF9900');">
		<td align="center"><?=$no;?>.</td>
		<td align="center"><?=$dd['inch_doctype'];?></td>
		<td align="center"><?=$dd['inch_docno'];?></td>
        <td align="center"><?=$dd['inch_docdate'];?></td>
        <td align="left"><?=$dd['nm_pemasok'];?></td>
		<td align="center"><?=$cek['incd_currency'];?></td>
		<td align="right"><?=number_format($nilai_nidr,2,'.','');?></td>
		<td align="right"><?=number_format($cek['nilai_idr'],0,'','');?></td>
		<td align="center"><?=$inch_rate;?></td>
		<td align="center"><?=$dd['inch_jurnalno'];?></td>
		<td align="center"><?=$inch_jurnaldate;?></td>
		<td align="center"><?=$dd['id_pemasok'];?></td>
		<td align="center"><?=$dd['inch_invno'];?></td>
		<td align="center"><?=$dd['inch_invdate'];?></td>
		<td align="center"><?=$dd['inch_dono'];?></td>			
	  </tr>	
	<?php $no++;} ?>
</table>