<?php	
	ini_set("max_execution_time", 0);
	header("Content-Disposition: attachment; filename=\"Rekap Pendapatan Perdiagnosa Ranap  ". tgl_id_short($tglawal)."-".tgl_id_short($tglakhir).".xls\"");
	header("Content-type: application/vnd.ms-excel");  
?>
	
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>RS Insan Permata</title>
		<meta name="author" content="mbelink21" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
	</head>

	<body>
		<h3 align="left">Rekap Pendapatan Rawat Inap Berdasarkan Diagnosa </h3>
		<h4 align="left">Periode : <?php echo tgl_id_short($tglawal);?> s/d <?php echo tgl_id_short($tglakhir);?> </h4>
		
		<table border="1">														
			<tr>
				<th style="background-color:#8c0023;color:#ffffff;">No</th>
				<th style="background-color:#8c0023;color:#ffffff;">No RM</th>
				<th style="background-color:#8c0023;color:#ffffff;">Pasien</th>
				<th style="background-color:#8c0023;color:#ffffff;">Penjamin</th>
				<th style="background-color:#8c0023;color:#ffffff;">Kelas</th>
				<th style="background-color:#8c0023;color:#ffffff;">Ruangan</th>
				<th style="background-color:#8c0023;color:#ffffff;">Tgl Masuk</th>
				<th style="background-color:#8c0023;color:#ffffff;">Tgl Keluar</th>
				<th style="background-color:#8c0023;color:#ffffff;">DPJP</th>
				<th style="background-color:#8c0023;color:#ffffff;">Diagnosa</th>
				<th style="background-color:#8c0023;color:#ffffff;">Kamar</th>
				<th style="background-color:#8c0023;color:#ffffff;">Konsultasi</th>
				<th style="background-color:#8c0023;color:#ffffff;">Visit</th>
				<th style="background-color:#8c0023;color:#ffffff;">Tindakan</th>
				<th style="background-color:#8c0023;color:#ffffff;">Operasi</th>
				<th style="background-color:#8c0023;color:#ffffff;">Laborat</th>
				<th style="background-color:#8c0023;color:#ffffff;">Radiologi</th>
				<th style="background-color:#8c0023;color:#ffffff;">Obat & BHP</th>
				<th style="background-color:#8c0023;color:#ffffff;">Administrasi</th>
				<th style="background-color:#8c0023;color:#ffffff;">Sub Total</th>
				<th style="background-color:#8c0023;color:#ffffff;">Pot/Tamb</th>
				<th style="background-color:#8c0023;color:#ffffff;">Total</th>
			</tr>
			
			<?php $nori=1; $tkonsulri=0;$tadmin=0;$ttindri=0;$tobri=0;$topri=0;$tlabri=0;$tradri=0;$ttampri=0;$tsubtri=0;$ttotri=0;$tkamareri=0;$tvisitri=0;
			foreach($resultri as $dtri): 
				$diagxxri=explode("|",$dtri->penyakit);
				$idxri=sizeof($diagxxri)-1;
				$diagnosari=$diagxxri[$idxri];
				
				if(isset($konsulri[$dtri->no_rawat])){
					$konsultasiri=$konsulri[$dtri->no_rawat];
				}else{
					$konsultasiri=0;
				}
				if(isset($visitri[$dtri->no_rawat])){
					$visiteri=$visitri[$dtri->no_rawat];
				}else{
					$visiteri=0;
				}
				if(isset($kamarri[$dtri->no_rawat])){
					$kamareri=$kamarri[$dtri->no_rawat];
				}else{
					$kamareri=0;
				}
				if(isset($adminri[$dtri->no_rawat])){
					$admineri=$adminri[$dtri->no_rawat];
				}else{
					$admineri=0;
				}
				if(isset($harianri[$dtri->no_rawat])){
					$harianeri=$harianri[$dtri->no_rawat];
				}else{
					$harianeri=0;
				}
				if(isset($obatri[$dtri->no_rawat])){
					$obateri=$obatri[$dtri->no_rawat];
				}else{
					$obateri=0;
				}
				if(isset($tindakanri[$dtri->no_rawat])){
					$tindakaneri=$tindakanri[$dtri->no_rawat];
				}else{
					$tindakaneri=0;
				}
				if(isset($operasiri[$dtri->no_rawat])){
					$operasieri=$operasiri[$dtri->no_rawat];
				}else{
					$operasieri=0;
				}
				if(isset($laboratri[$dtri->no_rawat])){
					$laborateri=$laboratri[$dtri->no_rawat];
				}else{
					$laborateri=0;
				}
				if(isset($radiologiri[$dtri->no_rawat])){
					$radiori=$radiologiri[$dtri->no_rawat];
				}else{
					$radiori=0;
				}
				if(isset($tampotri[$dtri->no_rawat])){
					$tampotexri=$tampotri[$dtri->no_rawat];
				}else{
					$tampotexri=0;
				}
				
				if(isset($eksesxri[$dtri->no_rawat])){
					$exsesri="-".$eksesxri[$dtri->no_rawat];
				}else{
					$exsesri=0;
				} 
				$administrasi=$admineri+$harianeri;
				
				$tampoteri=$tampotexri+$exsesri;
				$subtri=$konsultasiri+$administrasi+$tindakaneri+$obateri+$operasieri+$laborateri+$radiori+$kamareri+$visiteri;
				$totri=$subtri+$tampoteri;
				
				$tkamareri=$tkamareri+$kamareri;
				$tvisitri=$tvisitri+$visiteri;
				$tkonsulri=$tkonsulri+$konsultasiri;
				$tadmin=$tadmin+$administrasi;
				$ttindri=$ttindri+$tindakaneri;
				$tobri=$tobri+$obateri;
				$topri=$topri+$operasieri;
				$tlabri=$tlabri+$laborateri;
				$tradri=$tradri+$radiori;
				$ttampri=$ttampri+$tampoteri;
				$tsubtri=$tsubtri+$subtri;
				$ttotri=$ttotri+$totri;
			?>
			<tr>
				<td><?php echo $nori;//." ".$exses;?></td>
				<td><?php echo $dtri->no_rkm_medis;?></td>
				<td><?php echo $dtri->nm_pasien;?></td>
				<td><?php echo $dtri->png_jawab;?></td>
				<td><?php echo $dtri->kelas;?></td>
				<td><?php echo $dtri->nm_bangsal;?></td>
				<td><?php echo $dtri->tgl_masuk;?></td>
				<td><?php echo $dtri->tgl_keluar;?></td>
				<td><?php echo $dtri->dokter_dpjp;?></td>
				<td><?php echo $diagnosari;//echo sizeof($diagxx)."-".$dtri->penyakit;?></td>
																
				<td><?php echo number_exc_koma($kamareri);?></td>
				<td><?php echo number_exc_koma($konsultasiri);?></td>
				<td><?php echo number_exc_koma($visiteri);?></td>
				<td><?php echo number_exc_koma($tindakaneri);?></td>
				<td><?php echo number_exc_koma($operasieri);?></td>
				<td><?php echo number_exc_koma($laborateri);?></td>
				<td><?php echo number_exc_koma($radiori);?></td>
				<td><?php echo number_exc_koma($obateri);?></td>
				<td><?php echo number_exc_koma($administrasi);?></td>
				<td><?php echo number_exc_koma($subtri);?></td>
				<td><?php echo number_exc_koma($tampoteri);?></td>
				<td><?php echo number_exc_koma($totri);?></td>
				
			</tr>
			<?php $nori++; endforeach;?>
			
			<tr>
				<td colspan="10"><strong>Total</strong></td>
				<td><strong><?php echo number_exc_koma($tkamareri);?></strong></td>
				<td><strong><?php echo number_exc_koma($tkonsulri);?></strong></td>
				<td><strong><?php echo number_exc_koma($tvisitri);?></strong></td>
				<td><strong><?php echo number_exc_koma($ttindri);?></strong></td>
				<td><strong><?php echo number_exc_koma($topri);?></strong></td>
				<td><strong><?php echo number_exc_koma($tlabri);?></strong></td>
				<td><strong><?php echo number_exc_koma($tradri);?></strong></td>
				<td><strong><?php echo number_exc_koma($tobri);?></strong></td>
				<td><strong><?php echo number_exc_koma($tadmin);?></strong></td>
				<td><strong><?php echo number_exc_koma($tsubtri);?></strong></td>
				<td><strong><?php echo number_exc_koma($ttampri);?></strong></td>
				<td><strong><?php echo number_exc_koma($ttotri);?></strong></td>
				
			</tr>			
		</table>
		
	</body>
</html>