<?php	
	ini_set("max_execution_time", 0);
	header("Content-Disposition: attachment; filename=\"Rekap Pendapatan Perdiagnosa Rajal ". 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 Jalan 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;">Poli</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;">Konsultasi</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;">Registrasi</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 $no=1; $tkonsul=0;$treg=0;$ttind=0;$tob=0;$top=0;$tlab=0;$trad=0;$ttamp=0;$tsubt=0;$ttot=0;
			foreach($result as $dtrj): 
				$diagxx=explode("|",$dtrj->penyakit);
				$idx=sizeof($diagxx)-1;
				$diagnosa=$diagxx[$idx];
				
				if(isset($konsul[$dtrj->no_rawat])){
					$konsultasi=$konsul[$dtrj->no_rawat];
				}else{
					$konsultasi=0;
				}
				if(isset($regis[$dtrj->no_rawat])){
					$regise=$regis[$dtrj->no_rawat];
				}else{
					$regise=0;
				}
				if(isset($obat[$dtrj->no_rawat])){
					$obate=$obat[$dtrj->no_rawat];
				}else{
					$obate=0;
				}
				if(isset($tindakan[$dtrj->no_rawat])){
					$tindakane=$tindakan[$dtrj->no_rawat];
				}else{
					$tindakane=0;
				}
				if(isset($operasi[$dtrj->no_rawat])){
					$operasie=$operasi[$dtrj->no_rawat];
				}else{
					$operasie=0;
				}
				if(isset($laborat[$dtrj->no_rawat])){
					$laborate=$laborat[$dtrj->no_rawat];
				}else{
					$laborate=0;
				}
				if(isset($radiologi[$dtrj->no_rawat])){
					$radio=$radiologi[$dtrj->no_rawat];
				}else{
					$radio=0;
				}
				if(isset($tampot[$dtrj->no_rawat])){
					$tampotex=$tampot[$dtrj->no_rawat];
				}else{
					$tampotex=0;
				}
				
				if(isset($eksesx[$dtrj->no_rawat])){
					$exses="-".$eksesx[$dtrj->no_rawat];
				}else{
					$exses=0;
				}
				
				$tampote=$tampotex+$exses;
				$subt=$konsultasi+$regise+$tindakane+$obate+$operasie+$laborate+$radio;
				$tot=$subt+$tampote;
				
				$tkonsul=$tkonsul+$konsultasi;
				$treg=$treg+$regise;
				$ttind=$ttind+$tindakane;
				$tob=$tob+$obate;
				$top=$top+$operasie;
				$tlab=$tlab+$laborate;
				$trad=$trad+$radio;
				$ttamp=$ttamp+$tampote;
				$tsubt=$tsubt+$subt;
				$ttot=$ttot+$tot;
			?>
				<tr>
					<td><?php echo $no;?></td>
					<td><?php echo $dtrj->no_rkm_medis;?></td>
					<td><?php echo $dtrj->nm_pasien;?></td>
					<td><?php echo $dtrj->png_jawab;?></td>
					<td></td>
					<td><?php echo $dtrj->nm_poli;?></td>
					<td><?php echo $dtrj->tgl_masuk;?></td>
					<td><?php echo $dtrj->tgl_keluar;?></td>
					<td><?php echo $dtrj->nm_dokter;?></td>
					<td><?php echo $diagnosa;?></td>
																	
					<td><?php echo number_exc_koma($konsultasi);?></td>
					<td><?php echo number_exc_koma($tindakane);?></td>
					<td><?php echo number_exc_koma($operasie);?></td>
					<td><?php echo number_exc_koma($laborate);?></td>
					<td><?php echo number_exc_koma($radio);?></td>
					<td><?php echo number_exc_koma($obate);?></td>
					<td><?php echo number_exc_koma($regise);?></td>
					<td><?php echo number_exc_koma($subt);?></td>
					<td><?php echo number_exc_koma($tampote);?></td>
					<td><?php echo number_exc_koma($tot);?></td>
					
				</tr>
			<?php $no++; endforeach;?>
			
				<tr>
					<td colspan="10"><strong>Total</strong></td>
					
					<td><strong><?php echo number_exc_koma($tkonsul);?></strong></td>
					<td><strong><?php echo number_exc_koma($ttind);?></strong></td>
					<td><strong><?php echo number_exc_koma($top);?></strong></td>
					<td><strong><?php echo number_exc_koma($tlab);?></strong></td>
					<td><strong><?php echo number_exc_koma($trad);?></strong></td>
					<td><strong><?php echo number_exc_koma($tob);?></strong></td>
					<td><strong><?php echo number_exc_koma($treg);?></strong></td>
					<td><strong><?php echo number_exc_koma($tsubt);?></strong></td>
					<td><strong><?php echo number_exc_koma($ttamp);?></strong></td>
					<td><strong><?php echo number_exc_koma($ttot);?></strong></td>
					
				</tr>
			
		</table>
		
	</body>
</html>