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

$py_tipe	 	= isset($_REQUEST['py_tipe']) ? $_REQUEST['py_tipe'] : '';
$pyd_tanggal	= isset($_REQUEST['pyd_tanggal']) ? $_REQUEST['pyd_tanggal'] : $date;
 if($py_tipe=="0"){
	$search    = "";
 }else{
	$search    = "id='$py_tipe' AND";
 }

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

?>
<table width="100%" border="0">
    <tr>
  		<td colspan="12">DATA AKTIVA TETAP</td>
    </tr>
    <tr>
  		<td colspan="12"><?=strtoupper($dataShow['prof_name']);?></td>
    </tr>
    <tr>
  		<td colspan="12">&nbsp;</td>
    </tr>
</table>	
<table border="1" cellpadding="0" cellspacing="0">
  <tr>
	<th>No</th>
	<th>Tanggal</th>
	<th>Nama Barang</th>
	<th>Satuan</th>
	<th>Jumlah</th>
	<th>Umur</th>
	<th>Nilai<br>Perolehan</th>
	<th>Tarif</th>
	<th>Nilai<br><?=$pyd_tanggal;?></th>
	<th>Total<br>Disusutkan</th>
	<th>Sisa</th>
	<th>Nilai Susut<br>/bulan</th>
  </tr>
  <?php
  	$gtnilai=0;$gtpay=0;$gtsisa=0;$gtda= 0;
	$qh=mysql_query("SELECT id, pyt_tipe FROM penyusutan_tipe WHERE $search pyt_status=10 ORDER BY id ASC");
	while($dh=mysql_fetch_array($qh)){
	?> 
    <tr bgcolor="#FFFFCC">
        <td colspan="12">Tipe Penyusutan :<?=$dh['pyt_tipe'];?></td>
    </tr>
    <?php
	$no=1;$tnilai=0;$tpay=0;$tsisa=0;$tda= 0;
	$qd=mysql_query("SELECT * FROM penyusutan WHERE py_status<>100 AND py_tipe='$dh[id]'");
	while($dd=mysql_fetch_array($qd)){	
		$da = mysql_fetch_array(mysql_query("SELECT pyd_nilai FROM penyusutan_detail WHERE pyd_hid='$dd[id]' AND pyd_status=10 AND pyd_tanggal='$pyd_tanggal'"));
		$py =mysql_fetch_array(mysql_query("SELECT SUM(pyd_nilai) susut FROM penyusutan_detail WHERE pyd_hid='$dd[id]' AND pyd_status=10"));
		$sisa   = $dd['py_nilai'] - $py['susut']; 
		#if($sisa>0){
		$tnilai = $tnilai+$dd['py_nilai'];
		$tpay   = $tpay+$py['susut'];
		$tsisa  = $tsisa+$sisa;	
		$tda    = $tda + $da['pyd_nilai'];
		if($dd['py_nilai']>0 && $dd['py_jumlah']>0 && $dd['py_umur']>0){
			$nsusut = (($dd['py_nilai'] / $dd['py_jumlah']) / ($dd['py_umur']));
		}else{
			$nsusut = 0;
		}
		#$nsusut = (($dd['py_nilai']/$dd['py_jumlah'])/($dd['py_umur']));
	?>
	 <tr onmouseover="setTrColor(this, '#FF9900');">
		<td align="center"><?=$no;?>.</td>
		<td align="center"><?=$dd['py_tanggal'];?></td>
		<td align="left"><?=$dd['py_nmbarang'];?></td>
        <td align="center"><?=$dd['py_stbarang'];?></td>
        <td align="right"><?=number_format($dd['py_jumlah'],0,'.',',');?></td>
		<td align="right"><?=number_format($dd['py_umur'],0,'.',',');?>&nbsp;bulan</td>
        <td align="right"><?=number_format($dd['py_nilai'],2,'.',',');?></td>
		<td align="right"><?=number_format($dd['py_tarif'],2,'.',',');?>&nbsp;%</td>
		<td align="right"><?= number_format($da['pyd_nilai'],2,'.',''); ?></td>
        <td align="right"><?=number_format($py['susut'],2,'.',',');?></td>
        <td align="right"><?=number_format($sisa,2,'.',',');?></td>
		<td align="right"><?=number_format($nsusut,2,'.',',');?></td>        
	  </tr>	  
  <?php $no++; } 
   #} 
   ?> 
  	  <tr bgcolor="#CCFFCC">
      	<td>&nbsp;</td>
        <td colspan="5"><b>Total</b></td>
        <td align="right"><b><?=number_format($tnilai,2,'.','');?></b></td>
		<td>&nbsp;</td>		
		<td align="right"><b><?= number_format($tda, 2, '.', ''); ?></b></td>
        <td align="right"><b><?=number_format($tpay,2,'.','');?></b></td>
        <td align="right"><b><?=number_format($tsisa,2,'.','');?></b></td>
        <td>&nbsp;</td>
      </tr>
   <?php 
   		$gtnilai= $gtnilai+$tnilai; 
		$gtpay  = $gtpay+$tpay;
		$gtsisa = $gtsisa+$tsisa;
		$gtda   = $gtda + $tda;
	}  ?>  
   <tr bgcolor="#CCFFFF">
    <td>&nbsp;</td>
    <td colspan="5"><b>Grand Total</b></td>
    <td align="right"><b><?=number_format($gtnilai,2,'.','');?></b></td>
	<td>&nbsp;</td>
    <td align="right"><b><?=number_format($gtda,2,'.','');?></b></td>
	<td align="right"><b><?=number_format($gtpay,2,'.','');?></b></td>
    <td align="right"><b><?=number_format($gtsisa,2,'.','');?></b></td>
    <td>&nbsp;</td>
  </tr>  
</table>