<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';

	$tgl_awal= $_GET['tgl_awal'];
	$tgl_akhir= $_GET['tgl_akhir'];
	$jml = 0;
	$tjumlah=0;

	$content = "<b><li>JURNAL PENERIMAAN KAS</li>
		<li>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</li></b>
		<br>
	
		<table width='390' border='1' style='border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Kode Akun</th>
			<th>Kode BP</th>
			<th>Nama Akun</th>
			<th>Nama BP</th>
			<th>No.Faktur</th>
			<th>Keterangan</th>			
			<th>Jumlah</th>
			<th>Posting</th>
		</tr>";
		
		$query2 = "SELECT kode_km,tanggal,nokas,namakas,pembayar FROM jurkm WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' GROUP BY kode_km ORDER BY tanggal";
		$data2	= mysql_query($query2);
		while($r_data2=mysql_fetch_array($data2)){
			$kodekm=$r_data2[kode_km];
		
		$content .= "<tr>	
				<td></td>
				<td><b>No. BKM :</b></td>
				<td><b>$r_data2[kode_km]</b></td>
				<td><b>Tanggal : ".jin_date_str($r_data2[tanggal])."</b></td>
				<td><b>Akun Kas : $r_data2[nokas] - $r_data2[namakas]</b>
				<td><b>$r_data2[pembayar]</b></td>
				<td></td>
			</tr>";
			
		$sql = "SELECT * FROM jurkm WHERE kode_km='$kodekm' ";		
		$query = mysql_query($sql);
		
		$no=1+$hal;
		$sjumlah=0;
		while($r_data=mysql_fetch_array($query)){
				
		$content .= "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r_data[noakun]</td>
				<td align='center'>$r_data[nobp]</td>
				<td>$r_data[naakun]</td>
				<td>$r_data[namabp]</td>
				<td>$r_data[nofak]</td>
				<td>$r_data[keterangan]</td>
				<td align='right'>".number_format($r_data[jumlah])."</td>
				<td align='center'>$r_data[posting]</td>
				</tr>";
			$sjumlah=$sjumlah+$r_data[jumlah];
			$no++;
			$jml++;			
		}
		$content .= "<tr>
				<td></td>
				<td></td>
				<td></td>				
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($sjumlah)."</td>
				<td></td>
			</tr>";
			$tjumlah=$tjumlah+$sjumlah;
		}
		
		$content .= "<tr>				
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total </td>
				<td align='right'>".number_format($tjumlah)."</td>
				<td></td>
			</tr>";
		$content .= "</table>";
		
		$content .= "<li>Jumlah data : $jml</li>";
				
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=jurnal_km.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>