<?php
	
	ini_set("max_execution_time", 0);
	header("Content-Disposition: attachment; filename=\"Pendapatan ".$keter." Per Jaminan  ". tgl_id_short($tglawal)."-".tgl_id_short($tglakhir).".xls\"");
	header("Content-type: application/vnd.ms-excel"); 
	?>
	<h3 align="center">Pendapatan <?php echo $keterl;?> Per Jaminan </h3>
	<h4 align="center">Periode : <?php echo tgl_id($tglawal);?> s/d <?php echo tgl_id($tglakhir);?> </h4>
<table border="1" align="center">
	<thead>
		<!--tr>
			<th rowspan="2">Tanggal</th>
			<th colspan="2">Pasien Umum</th>
			<th colspan="2">Pasien BPJS</th>
			<th colspan="2">Pasien Asuransi Lainya</th>
			<th rowspan="2">Jml Pasien</th>
			<th rowspan="2">Total Pendapatan </th>
		</tr>
		<tr>
			<th>Jml Pasien</th>
			<th>Sub Total</th>
			<th>Jml Pasien</th>
			<th>Sub Total</th>
			<th>Jml Pasien</th>
			<th>Sub Total</th>
		</tr-->
		<tr>
			<th rowspan="2" class="center" width="9">Tanggal</th>
			<th colspan="2" class="center">Pasien Umum</th>
			<th colspan="4" class="center">Pasien BPJ</th>
			<th colspan="4" class="center">Pasien Asuransi Lainya</th>
			<th rowspan="2" class="center" width="10">px Ekses</th>
			<th rowspan="2" class="center" width="10">Jml Pasien</th>
			<th rowspan="2" class="center" width="15">Jml Pendapatan </th>
		</tr>
		<tr>
			<th class="center" width="7">Jml Px</th>
			<th class="center" width="15">Sub Total</th>
			<th class="center" width="7">Jml Px</th>
			<th class="center" width="15">Sub Total</th>
			<th class="center" width="7">Px Ekses</th>
			<th class="center" width="15">Ekses</th>
			<th class="center" width="7">Jml Px</th>
			<th class="center" width="15">Sub Total</th>
			<th class="center" width="7">Px Ekses</th>
			<th class="center" width="15">Ekses</th>
		</tr>
	</thead>

	<tbody>
	<?php $tpxumum=0;$tpxbpjs=0;$tpxlainya=0;$tpxbpjsexe=0;$tpxlainyaexe=0;
		  $tpxall=0;$tumum=0;$tbpjs=0;$tlainya=0;$tbpjsexe=0;$tlainyaexe=0;
		  $tpendatan=0;$ttpxexe=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;
		$tpxbpjsexe=$tpxbpjsexe + $dtrj->px_exesbpjs;
		$tpxlainyaexe=$tpxlainyaexe + $dtrj->px_exesas;
		$tpx=$dtrj->px_umum + $dtrj->px_bpjs + $dtrj->px_lainnya;
		$tpxall=$tpxall + $tpx;
		$tpxekses=$dtrj->px_exesbpjs + $dtrj->px_exesas;
		$ttpxexe=$ttpxexe + $tpxekses;
		
		$tumum=$tumum + $dtrj->umum;
		$tbpjs=$tbpjs + $dtrj->bpjs;
		$tlainya=$tlainya + $dtrj->lainnya;
		$tpendatan=$tpendatan + $dtrj->subtotal;
		$tbpjsexe=$tbpjsexe + $dtrj->exes_bpjs;
		$tlainyaexe=$tlainyaexe + $dtrj->exes_lainnya;
		
		/* if($_POST['sts']=='1'){
			$tglnya=$dtrj->tgl_registrasi;
		}else{
			$tglnya=$dtrj->tgl_nota;
		} */
	?>
		<tr>
			<td><?php echo $dtrj->tgl_nota?></td>
			<td><?php echo $dtrj->px_umum;?></td>
			<td><?php echo $dtrj->umum;?></td>
			<td><?php echo $dtrj->px_bpjs;?></td>
			<td><?php echo $dtrj->bpjs;?></td>
			<td><?php echo $dtrj->px_exesbpjs;?></td>
			<td><?php echo $dtrj->exes_bpjs;?></td>
			<td><?php echo $dtrj->px_lainnya;?></td>
			<td><?php echo $dtrj->lainnya;?></td>
			<td><?php echo $dtrj->px_exesas;?></td>
			<td><?php echo $dtrj->exes_lainnya;?></td>
			<td><?php echo $tpxekses;?></td>
			<td><?php echo $tpx;?></td>
			<td><?php echo $dtrj->subtotal;?></td>
			
		</tr>
	<?php endforeach;?>
		<tr>
			<td><strong>Total</strong></td>
			<td><strong><?php echo $tpxumum;?></strong></td>
			<td><strong><?php echo $tumum;?></strong></td>
			<td><strong><?php echo $tpxbpjs;?></strong></td>
			<td><strong><?php echo $tbpjs;?></strong></td>
			<td><strong><?php echo $tpxbpjsexe;?></strong></td>
			<td><strong><?php echo $tbpjsexe;?></strong></td>
			<td><strong><?php echo $tpxlainya;?></strong></td>
			<td><strong><?php echo $tlainya;?></strong></td>
			<td><strong><?php echo $tpxlainyaexe;?></strong></td>
			<td><strong><?php echo $tlainyaexe;?></strong></td>
			<td><strong><?php echo $ttpxexe;?></strong></td>
			<td><strong><?php echo $tpxall;?></strong></td>
			<td><strong><?php echo $tpendatan;?></strong></td>
			
		</tr>
	</tbody>
</table>