<?php
	
	ini_set("max_execution_time", 0);
	header("Content-Disposition: attachment; filename=\"Pendapatan Ranap Per Kamar  ". tgl_id_short($tglawal)."-".tgl_id_short($tglakhir).".xls\"");
	header("Content-type: application/vnd.ms-excel");   
	?>
	<h3 align="center">Pendapatan Rawat Inap Per Kamar </h3>
	<h4 align="center">Periode : <?php echo tgl_id($tglawal);?> s/d <?php echo tgl_id($tglakhir);?> </h4>
<table border="1" align="center">
	
		<tr>
			<th rowspan="2">No</th>
			<th rowspan="2">Kamar</th>
			<th rowspan="2">Kelas</th>
			<th colspan="2">Pasien Umum</th>
			<th colspan="4">Pasien BPJ</th>
			<th colspan="4">Pasien Asuransi Lainya</th>
			<th rowspan="2">Px Ekses</th>
			<th rowspan="2">Jml Pasien</th>
			<th rowspan="2">Jml Pendapatan </th>
		</tr>
		<tr>
			<th>Jml Px</th>
			<th>Sub Total</th>
			<th>Jml Px</th>
			<th>Sub Total</th>
			<th>Px Ekses</th>
			<th>Ekses</th>
			<th>Jml Px</th>
			<th>Sub Total</th>
			<th>Px Ekses</th>
			<th>Ekses</th>
		</tr>
	
	<?php $no=1;$tpxumum=0;$tpxbpjs=0;$tpxlainya=0;$tpxbpjex=0;$tpxlainex=0;
		  $tpxall=0;$tumum=0;$tbpjs=0;$tlainya=0;$tbpjex=0;$tlainex=0;
		  $tpendatan=0;$jmlpx=0;$tpexes=0;
	foreach($result as $dtrj): 
		$tpxumum=$tpxumum + $dtrj->px_umum;
		$tpxbpjs=$tpxbpjs + $dtrj->px_bpjs;
		$tpxlainya=$tpxlainya + $dtrj->px_lainnya;
		$tpxall=$tpxall + $dtrj->px_jml;
		$tpxbpjex=$tpxbpjex + $dtrj->px_exesbpjs;
		$tpxlainex=$tpxlainex + $dtrj->px_exesas;
		
		$tumum=$tumum + $dtrj->umum;
		$tbpjs=$tbpjs + $dtrj->bpjs;
		$tlainya=$tlainya + $dtrj->lainnya;
		$tpendatan=$tpendatan + $dtrj->subtotal;
		$tbpjex=$tbpjex + $dtrj->exes_bpjs;
		$tlainex=$tlainex + $dtrj->exes_lainnya;
		
		$jmlpx=$dtrj->px_umum+$dtrj->px_bpjs+$dtrj->px_lainnya;
		$jmlexe=$dtrj->px_exesbpjs+$dtrj->px_exesas;
		
		$tpxall=$tpxall + $jmlpx;
		$tpexes=$tpexes + $jmlexe;
	?>
		<tr>
			<td class="center"><?php echo $no;?></td>
			<td class=""><?php echo $dtrj->nm_bangsal;?></td>
			<td class="center"><?php echo $dtrj->kelas;?></td>
			<td class="center"><?php echo $dtrj->px_umum;?></td>
			<td><span class="pull-right"><?php echo number_exc_koma($dtrj->umum);?></span></td>
			<td class="center"><?php echo $dtrj->px_bpjs;?></td>
			<td><span class="pull-right"><?php echo number_exc_koma($dtrj->bpjs);?></span></td>
			<td class="center"><?php echo $dtrj->px_exesbpjs;?></td>
			<td><span class="pull-right"><?php echo number_exc_koma($dtrj->exes_bpjs);?></span></td>
			<td class="center"><?php echo $dtrj->px_lainnya;?></td>
			<td><span class="pull-right"><?php echo number_exc_koma($dtrj->lainnya);?></span></td>
			<td class="center"><?php echo $dtrj->px_exesas;?></a></td>
			<td><span class="pull-right"><?php echo number_exc_koma($dtrj->exes_lainnya);?></span></td>
			<td class="center"><?php echo $jmlexe;?></td>
			<td class="center"><?php echo $jmlpx;?></td>
			<td><span class="pull-right"><?php echo number_exc_koma($dtrj->subtotal);?></span></td>
			
		</tr>
	<?php $no++; endforeach;?>
		<tr>
			<td class="center" colspan="3"><strong>Total</strong></td>
			<td class="center"><strong><?php echo $tpxumum;?></strong></td>
			<td><strong><span class="pull-right"><?php echo number_exc_koma($tumum);?></span></strong></td>
			<td class="center"><strong><?php echo $tpxbpjs;?></strong></td>
			<td><strong><span class="pull-right"><?php echo number_exc_koma($tbpjs);?></span></strong></td>
			<td class="center"><strong><?php echo $tpxbpjex;?></strong></td>
			<td><strong><span class="pull-right"><?php echo number_exc_koma($tbpjex);?></span></strong></td>
			<td class="center"><strong><?php echo $tpxlainya;?></strong></td>
			<td><strong><span class="pull-right"><?php echo number_exc_koma($tlainya);?></span></strong></td>
			<td class="center"><strong><?php echo $tpxlainex;?></strong></td>
			<td><strong><span class="pull-right"><?php echo number_exc_koma($tlainex);?></span></strong></td>
			<td class="center"><strong><?php echo $tpexes;?></strong></td>
			<td class="center"><strong><?php echo $tpxall;?></strong></td>
			<td><strong><span class="pull-right"><?php echo number_exc_koma($tpendatan);?></span></strong></td>
			
		</tr>
	
</table>