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

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

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

?>
<table width="100%" border="0">
    <tr>
  		<td colspan="15">DATA OUTBOX (PENGELUARAN)</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">Penerima</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">No Inv</th>
	<th rowspan="2">Tgl Inv<br>YYYY-MM-DD</th>
	<th rowspan="2">No Faktur</th>
	<th rowspan="2">NPWP</th>
  </tr>
  <tr>
	<th>Non IDR</th>
	<th>IDR</th>
  </tr>
  </thead>
	<tbody>
  <?php
    $no=1; $gtprice=0;
	$qd = mysql_query("SELECT * FROM outgoing WHERE outh_status=20 AND outh_docdate BETWEEN '$fromdate' AND '$todate' AND (outh_paytype is null OR outh_paytype='') 
	      $custname ORDER BY id DESC");
	while($dd=mysql_fetch_array($qd)){		
		$cek = mysql_fetch_array(mysql_query("SELECT outd_currency, SUM(outd_price) nilai_idr, SUM(outd_price_usd) nilai_nidr  FROM outgoing_detail 
		       WHERE outd_hid='$dd[id]' GROUP BY outd_currency"));
		if($dd['outh_rate']>0){$outh_rate=$dd['outh_rate'];}else{$outh_rate=0;}
		if(!empty($dd['outh_jurnaldate'])){$outh_jurnaldate=$dd['outh_jurnaldate'];}else{$outh_jurnaldate="";}	
		if($cek['outd_currency']=="IDR"){$debkred=$cek['nilai_idr'];}else{$debkred=$cek['nilai_nidr'];}   
	?> 
	 <tr onMouseOver="setTrColor(this, '#FF9900');">
		<td align="center"><?=$no;?>.</td>
		<td align="center"><?=$dd['outh_doctype'];?></td>
		<td align="center"><?=$dd['outh_docno'];?></td>
        <td align="center"><?=$dd['outh_docdate'];?></td>
        <td align="left"><?=$dd['nm_penerima'];?></td>
		<td align="center"><?=$cek['outd_currency'];?></td>
		<td align="right"><?=number_format($cek['nilai_nidr'],0,'','');?></td>
		<td align="right"><?=number_format($cek['nilai_idr'],0,'',',');?></td>
		<td align="center"><?=$outh_rate;?></td>
		<td align="center"><?=$dd['outh_jurnalno'];?></td>
		<td align="center"><?=$dd['outh_invdate'];?></td>
		<td align="center"><?=$dd['outh_invno'];?></td>
		<td align="center"><?=$dd['outh_invdate'];?></td>
		<td align="center"><?=$dd['outh_dono'];?></td>
		<td align="center"><?=$dd['id_penerima'];?></td>		
	  </tr>	  
  <?php $no++; }  ?> 
</table>