public function getDataResep($year, $month, $departemen_id, $puskesmas_id)
 {
     $data = array();
     $jps = JenisPembayaran::model()->findAllByAttributes(array("status" => "1"));
     foreach ($jps as $jp) {
         $data[$jp->id] = 0;
     }
     $filter = "year(waktu) = '{$year}' AND month(waktu) = '{$month}' AND puskesmas_id = '{$puskesmas_id}' ";
     if ($departemen_id != NULL) {
         $filter = $filter . " AND departemen_id = '" . $departemen_id . "'";
     }
     foreach (TransaksiObatNonInjeksi::model()->findAll($filter . " GROUP BY medical_record_id ASC") as $transaksi) {
         $medical = TransaksiMedicalRecord::model()->findByPk($transaksi->medical_record_id);
         $kunjungan = TransaksiKunjungan::model()->findByPk($medical->kunjungan_id);
         $data[$kunjungan->jenis_pembayaran_id] += 1;
     }
     $output = array();
     foreach ($jps as $jp) {
         $output[$jp->nama] = $data[$jp->id];
     }
     return $output;
 }
 private function processKTP($tanggal, $tanggal2, $departemen_id)
 {
     $reportName = "laporan_pembayaran_ktp";
     $objPHPExcel = $this->loadPHPExcelLib($reportName);
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     $filter = "";
     if (substr("" . $departemen_id, 0, 4) == "wil_") {
         $puskesmas = Puskesmas::model()->findByPk(substr("" . $departemen_id, 4));
         $departemen = NULL;
         $activeSheet->setCellValue("A2", "Wilayah Puskesmas " . ucwords(strtolower($puskesmas->nama)));
     } else {
         $departemen = Departemen::model()->findByPk($departemen_id);
         $puskesmas = Puskesmas::model()->findByPk($departemen->puskesmas_id);
         $activeSheet->setCellValue("A2", $departemen->nama);
         $filter = " AND departemen_id = '" . $departemen->id . "'";
     }
     //judul
     $activeSheet->setCellValue("A4", "Tanggal " . $tanggal . " s/d " . $tanggal2);
     $tanggal = $this->reverseDate($tanggal);
     $tanggal2 = $this->reverseDate($tanggal2);
     $baris = 10;
     $trs = TransaksiKunjungan::model()->findAll("waktu between '{$tanggal} 00:00:00' AND '{$tanggal2} 23:59:00' AND puskesmas_id = '" . $puskesmas->id . "'" . $filter);
     foreach ($trs as $t) {
         if ($t->jenis_pembayaran_id == 1) {
             //UMUM
             $pasien = Pasien::model()->findByPk($t->pasien_id);
             if ($pasien->dalam_wilayah == 1) {
                 $wilayah[0] += 1;
             } else {
                 if ($pasien->dalam_wilayah == 2) {
                     $wilayah[1] += 1;
                 } else {
                     $wilayah[2] += 1;
                 }
             }
             $umur = date_diff(date_create($pasien->tanggal_lahir), date_create(date("Y-m-d", strtotime($t->waktu))))->y;
             if ($umur > 200) {
                 $umur = 0;
             }
             $activeSheet->setCellValue("A" . $baris, $baris - 9);
             $activeSheet->setCellValueExplicit("B" . $baris, $pasien->kode, PHPExcel_Cell_DataType::TYPE_STRING);
             $activeSheet->setCellValue("C" . $baris, $pasien->nama);
             $activeSheet->setCellValue("D" . $baris, $umur);
             $activeSheet->setCellValue("E" . $baris, $t->jenis_kunjungan == "B" ? "1" : "0");
             $activeSheet->setCellValue("F" . $baris, $t->jenis_kunjungan == "L" ? "1" : "0");
             $activeSheet->setCellValue("G" . $baris, $pasien->jenis_kelamin == "L" ? "1" : "0");
             $activeSheet->setCellValue("H" . $baris, $pasien->jenis_kelamin == "P" ? "1" : "0");
             $activeSheet->setCellValue("I" . $baris, $pasien->dalam_wilayah == "1" ? "1" : "0");
             $activeSheet->setCellValue("J" . $baris, $pasien->dalam_wilayah == "2" ? "1" : "0");
             $activeSheet->setCellValue("K" . $baris, $pasien->dalam_wilayah == "3" ? "1" : "0");
             $activeSheet->setCellValue("L" . $baris, date("d-m-Y", strtotime($t->waktu)));
             $activeSheet->setCellValue("M" . $baris, $pasien->alamat);
             $activeSheet->setCellValueExplicit("N" . $baris, $pasien->no_ktp . "", PHPExcel_Cell_DataType::TYPE_STRING);
             $activeSheet->setCellValue("O" . $baris, "10000");
             $antrian = TransaksiAntrian::model()->findByAttributes(array("kunjungan_id" => $t->id));
             //BP
             if ($antrian->poli_tujuan == 1) {
                 $activeSheet->setCellValue("P" . $baris, $t->jenis_kunjungan == "B" ? "1" : "0");
                 $activeSheet->setCellValue("Q" . $baris, $t->jenis_kunjungan == "L" ? "1" : "0");
             }
             if ($antrian->poli_tujuan == 3) {
                 $activeSheet->setCellValue("R" . $baris, $t->jenis_kunjungan == "B" ? "1" : "0");
                 $activeSheet->setCellValue("S" . $baris, $t->jenis_kunjungan == "L" ? "1" : "0");
             }
             if ($antrian->poli_tujuan == 4) {
                 $activeSheet->setCellValue("T" . $baris, $t->jenis_kunjungan == "B" ? "1" : "0");
                 $activeSheet->setCellValue("U" . $baris, $t->jenis_kunjungan == "L" ? "1" : "0");
             }
             $baris++;
         }
     }
     $activeSheet->getStyle("A10:S" . $baris)->applyFromArray($this->getNormalStyle());
     $activeSheet->setCellValue("E" . $baris, "=SUM(E10:E" . ($baris - 1) . ")");
     /*$activeSheet->setCellValue("F".$baris, "=SUM(F10:F".($baris-1).")");
       $activeSheet->setCellValue("G".$baris, "=SUM(G10:G".($baris-1).")");
       $activeSheet->setCellValue("H".$baris, "=SUM(H10:H".($baris-1).")");
       $activeSheet->setCellValue("I".$baris, "=SUM(I10:I".($baris-1).")");
       
       $activeSheet->setCellValue("N".$baris, "=SUM(N10:N".($baris-1).")");
       $activeSheet->setCellValue("O".$baris, "=SUM(O10:O".($baris-1).")");
       $activeSheet->setCellValue("P".$baris, "=SUM(P10:P".($baris-1).")");
       $activeSheet->setCellValue("Q".$baris, "=SUM(Q10:Q".($baris-1).")");
       $activeSheet->setCellValue("R".$baris, "=SUM(R10:R".($baris-1).")");
       $activeSheet->setCellValue("S".$baris, "=SUM(S10:S".($baris-1).")");*/
     return array("phpexcel" => $objPHPExcel, "name" => $reportName . "_" . $tanggal . "_" . $tanggal2);
 }
 private function process($tanggal, $tanggal2, $departemen_id, $jenis_kunjungan, $jenis_pembayaran_id, $jenis_kelamin, $jenis_laporan, $klinik, $wilayah)
 {
     $reportName = "laporan_kunjungan_loket_harian";
     $tanggal = $this->reverseDate($tanggal);
     $tanggal2 = $this->reverseDate($tanggal2);
     $objPHPExcel = $this->loadPHPExcelLib($reportName);
     $rekapArray = array();
     foreach (JenisPembayaran::model()->findAll("status = '1'") as $jp) {
         $rekapArray[$jp->nama] = array();
         foreach (Poli::model()->findAllByAttributes(array("jenis" => 1, "status" => 1)) as $poli) {
             $rekapArray[$jp->nama][$poli->nama] = array("L" => 0, "P" => 0);
         }
     }
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     //judul
     $activeSheet->getCell("B4")->setValue("Tanggal : " . $tanggal);
     $filter = "";
     if (substr("" . $departemen_id, 0, 4) == "wil_") {
         $puskesmas = Puskesmas::model()->findByPk(substr("" . $departemen_id, 4));
         $departemen = NULL;
         $activeSheet->getCell("B3")->setValue("Wilayah Puskesmas " . ucwords(strtolower($puskesmas->nama)));
     } else {
         $departemen = Departemen::model()->findByPk($departemen_id);
         $puskesmas = Puskesmas::model()->findByPk($departemen->puskesmas_id);
         $activeSheet->getCell("B3")->setValue($departemen->nama);
         $filter = " AND departemen_id = '" . $departemen->id . "'";
     }
     if ($jenis_kunjungan != "") {
         $filter .= " AND jenis_kunjungan = '" . $jenis_kunjungan . "' ";
     }
     if ($jenis_pembayaran_id != "") {
         $filter .= " AND jenis_pembayaran_id = '" . $jenis_pembayaran_id . "' ";
     }
     if ($jenis_laporan != "") {
         $arrayDiagnosaKhusus = array();
         foreach (Lb1JenisLaporanDetail::model()->findAllByAttributes(array("jenis_id" => $jenis_laporan)) as $data) {
             $arrayDiagnosaKhusus[] = $data->penyakit_id;
         }
     }
     //header
     $baris = 8;
     $no = 1;
     $transaksiArray = TransaksiKunjungan::model()->findAll("waktu between '{$tanggal} 00:00:00' AND '{$tanggal2} 23:59:00' AND puskesmas_id = '" . $puskesmas->id . "'" . $filter);
     foreach ($transaksiArray as $kunjungan) {
         $pasien = Pasien::model()->findByPk($kunjungan->pasien_id);
         if ($jenis_kelamin != "" && $pasien->jenis_kelamin != $jenis_kelamin) {
             continue;
         }
         if ($wilayah != "" && $pasien->dalam_wilayah != $wilayah) {
             continue;
         }
         $ada = FALSE;
         $kosong = TRUE;
         $jenis_pembayaran = JenisPembayaran::model()->findByPk($kunjungan->jenis_pembayaran_id);
         $poli = Poli::model()->findByPk($kunjungan->poli_tujuan);
         $diagnosaArray = array();
         $idDiagnosaArray = array();
         $meds = TransaksiMedicalRecord::model()->findAllByAttributes(array("kunjungan_id" => $kunjungan->id));
         foreach ($meds as $med) {
             $diags = TransaksiDiagnosa::model()->findAllByAttributes(array("medical_record_id" => $med->id));
             foreach ($diags as $diag) {
                 $kosong = FALSE;
                 $ada = TRUE;
                 /*
                                     if($jenis_laporan != "" && !in_array($diag->penyakit_id, $arrayDiagnosaKhusus)){
                                         
                                     }else{
                                         $ada = TRUE;
                                     }*/
                 $penyakit = Penyakit::model()->findByAttributes(array("id" => $diag->penyakit_id));
                 $diagnosaArray[] = "[" . $penyakit->kode . "/" . $diag->jenis_kasus . "] " . ($penyakit->nama_indonesia == "" ? $penyakit->nama : $penyakit->nama_indonesia);
             }
         }
         $ada2 = FALSE;
         $kosong2 = TRUE;
         $bpArray = array();
         $ants = TransaksiAntrian::model()->findAllByAttributes(array("kunjungan_id" => $kunjungan->id));
         foreach ($ants as $ant) {
             $kosong2 = FALSE;
             if ($klinik != "" && $ant->poli_tujuan != $klinik) {
             } else {
                 $ada2 = TRUE;
             }
             $polie = Poli::model()->findByPk($ant->poli_tujuan);
             $rekapArray[$jenis_pembayaran->nama][$polie->nama][$pasien->jenis_kelamin] += 1;
             $bpArray[] = $polie->nama;
         }
         if ($kosong || $kosong2 || $ada && $ada2) {
         } else {
             continue;
         }
         $activeSheet->getCellByColumnAndRow(1, $baris)->setValue($no . ".");
         $activeSheet->getCellByColumnAndRow(2, $baris)->setValue(date("d-m-Y", strtotime($kunjungan->waktu)));
         $activeSheet->getCellByColumnAndRow(3, $baris)->setValueExplicit($pasien->kode, PHPExcel_Cell_DataType::TYPE_STRING);
         $activeSheet->getCellByColumnAndRow(4, $baris)->setValue($pasien->nama);
         $age = date_diff(date_create($pasien->tanggal_lahir), date_create($kunjungan->waktu))->y;
         if ($age > 200) {
             $age = 0;
         }
         $activeSheet->getCellByColumnAndRow(5, $baris)->setValue($age);
         $activeSheet->getCellByColumnAndRow(6, $baris)->setValue($pasien->jenis_kelamin);
         $activeSheet->getCellByColumnAndRow(7, $baris)->setValue($pasien->alamat);
         $activeSheet->getCellByColumnAndRow(8, $baris)->setValue($pasien->nama_kepala_keluarga);
         $activeSheet->getCellByColumnAndRow(9, $baris)->setValueExplicit($pasien->no_ktp, PHPExcel_Cell_DataType::TYPE_STRING);
         $activeSheet->getCellByColumnAndRow(10, $baris)->setValue($jenis_pembayaran->nama);
         $activeSheet->getCellByColumnAndRow(11, $baris)->setValueExplicit($kunjungan->kode_asuransi, PHPExcel_Cell_DataType::TYPE_STRING);
         $activeSheet->getCellByColumnAndRow(12, $baris)->setValue($kunjungan->jenis_kunjungan == "B" ? "Baru" : "Lama");
         $activeSheet->getCellByColumnAndRow(13, $baris)->setValue(implode(", ", $diagnosaArray));
         //diagnosa
         $activeSheet->getCellByColumnAndRow(14, $baris)->setValue(implode(", ", $bpArray));
         //bp
         $tujuan = $poli->nama . " : " . ucwords(strtolower(Departemen::model()->findByPk($kunjungan->departemen_id)->nama));
         $activeSheet->getCellByColumnAndRow(15, $baris)->setValue($tujuan);
         $baris++;
         $no++;
     }
     $activeSheet->getStyle("B8:P" . ($baris - 1))->applyFromArray(array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN))));
     //Pindah ke sheet 2
     $objPHPExcel->setActiveSheetIndex(1);
     $activeSheet = $objPHPExcel->getActiveSheet();
     $smbaris = 4;
     foreach ($rekapArray as $key => $rekap) {
         $num = 2;
         $activeSheet->getCellByColumnAndRow(1, $smbaris)->setValue($key);
         foreach (Poli::model()->findAllByAttributes(array("jenis" => 1, "status" => 1)) as $poli) {
             if ($smbaris == 4) {
                 //set judul
                 $activeSheet->getCellByColumnAndRow($num, 2)->setValue($poli->nama);
                 $activeSheet->getCellByColumnAndRow($num, 3)->setValue("Lk");
                 $activeSheet->getCellByColumnAndRow($num + 1, 3)->setValue("Pr");
                 $activeSheet->getCellByColumnAndRow($num + 2, 3)->setValue("Total");
                 $activeSheet->mergeCellsByColumnAndRow($num, 2, $num + 2, 2);
             }
             $activeSheet->getCellByColumnAndRow($num, $smbaris)->setValue($rekap[$poli->nama]["L"]);
             $activeSheet->getCellByColumnAndRow($num + 1, $smbaris)->setValue($rekap[$poli->nama]["P"]);
             $activeSheet->getCellByColumnAndRow($num + 2, $smbaris)->setValue($rekap[$poli->nama]["L"] + $rekap[$poli->nama]["P"]);
             $num += 3;
         }
         if ($smbaris == 4) {
             $activeSheet->getStyle("B2:" . $this->get_col_letter($num - 1) . "3")->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => '8B0000')), 'font' => array('color' => array('rgb' => 'FFFFFF'))));
         }
         $smbaris++;
     }
     $this->fillBorder($activeSheet, "B2:" . $this->get_col_letter($num - 1) . ($smbaris - 1));
     $activeSheet->getStyle("B4:" . $this->get_col_letter($num - 1) . ($smbaris - 1))->applyFromArray(array('font' => array('color' => array('rgb' => '000000'), 'size' => 13, 'name' => 'Calibri')));
     $activeSheet->getStyle("C4:" . $this->get_col_letter($num - 1) . ($smbaris - 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     return array("phpexcel" => $objPHPExcel, "name" => $reportName . "_" . $tanggal);
 }
 private function process($tanggal, $tanggal2, $departemen_id)
 {
     $reportName = "laporan_tindakan";
     $tahun = date("Y", strtotime($this->reverseDate($tanggal)));
     $objPHPExcel = $this->loadPHPExcelLib($reportName);
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     $filter = "";
     if (substr("" . $departemen_id, 0, 4) == "wil_") {
         $puskesmas = Puskesmas::model()->findByPk(substr("" . $departemen_id, 4));
         $departemen = NULL;
         $activeSheet->setCellValue("A4", "WILAYAH " . $puskesmas->nama);
     } else {
         $departemen = Departemen::model()->findByPk($departemen_id);
         $puskesmas = Puskesmas::model()->findByPk($departemen->puskesmas_id);
         $activeSheet->setCellValue("A4", $departemen->nama);
         $filter = " AND departemen_id = '" . $departemen->id . "'";
     }
     //judul
     $activeSheet->setCellValue("A1", "REKAPITULASI RETRIBUSI PUSKESMAS TAHUN " . $tahun);
     $activeSheet->setCellValue("A3", "PUSKESMAS " . $puskesmas->nama);
     $activeSheet->setCellValue("A4", "Tanggal " . $tanggal . " s/d " . $tanggal2);
     $tanggal = $this->reverseDate($tanggal);
     $tanggal2 = $this->reverseDate($tanggal2);
     $query = "puskesmas_id = '" . $puskesmas->id . "' AND waktu between '{$tanggal} 00:00:00' AND '{$tanggal2} 23:59:00' ";
     for ($baris = 7; $baris <= 42; $baris++) {
         $i = $activeSheet->getCell("I" . $baris)->getValue();
         $j = $activeSheet->getCell("J" . $baris)->getValue();
         $k = $activeSheet->getCell("K" . $baris)->getValue();
         $l = $activeSheet->getCell("L" . $baris)->getValue();
         $tes = "0";
         $data = "";
         if ($i != "") {
             $jml = TransaksiTindakan::model()->count("tindakan_id = '" . $i . "' AND " . $query . $filter);
             $tes = "1";
         } else {
             if ($j != "") {
                 //echo "select transaksi_tindakan.* from transaksi_tindakan, tindakan WHERE transaksi_tindakan.tindakan_id = tindakan.id AND tindakan.kategori_id = '".$j."' AND transaksi_tindakan.".$query.$filter."<br>";
                 $jml = TransaksiTindakan::model()->countBySql("select count(transaksi_tindakan.id) from transaksi_tindakan, tindakan WHERE transaksi_tindakan.tindakan_id = tindakan.id AND tindakan.kategori_id = '" . $j . "' AND transaksi_tindakan." . $query . $filter);
                 $tes = "2";
             } else {
                 if ($k != "") {
                     $jml = TransaksiLaborat::model()->count("laborat_id = '" . $k . "' AND " . $query . $filter);
                     $tes = "3";
                 } else {
                     if ($l != "") {
                         $jml = TransaksiLaborat::model()->countBySql("select count(transaksi_laborat.id) from transaksi_laborat, laborat WHERE transaksi_laborat.laborat_id = laborat.id AND laborat.kategori_id = '" . $l . "' AND transaksi_laborat." . $query . $filter);
                         $tes = "4";
                     }
                 }
             }
         }
         //$activeSheet->setCellValue("H".$baris, $tes);
         $activeSheet->setCellValue("E" . $baris, $jml * 1);
     }
     $activeSheet->removeColumn("L");
     $activeSheet->removeColumn("K");
     $activeSheet->removeColumn("J");
     $activeSheet->removeColumn("I");
     $askes = TransaksiKunjungan::model()->count("jenis_pembayaran_id = '5' AND " . $query . $filter);
     $gratis = TransaksiKunjungan::model()->count("jenis_pembayaran_id = '11' AND " . $query . $filter);
     $activeSheet->setCellValue("E43", $askes);
     $activeSheet->setCellValue("E44", $gratis);
     $activeSheet->setCellValue("F43", $askes);
     $activeSheet->setCellValue("F44", $gratis);
     return array("phpexcel" => $objPHPExcel, "name" => $reportName . "_" . $tanggal . "_" . $tanggal2);
 }
 private function process2($year, $departemen_id)
 {
     $reportName = "laporan_kunjungan_loket_lengkap";
     $objPHPExcel = $this->loadPHPExcelLib($reportName);
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     $activeSheet->setCellValue("A1", "Tahun " . $year);
     $filter = "";
     if (substr("" . $departemen_id, 0, 4) == "wil_") {
         $puskesmas = Puskesmas::model()->findByPk(substr("" . $departemen_id, 4));
         $departemen = NULL;
         $activeSheet->getCell("C3")->setValue($puskesmas->nama);
     } else {
         $departemen = Departemen::model()->findByPk($departemen_id);
         $puskesmas = Puskesmas::model()->findByPk($departemen->puskesmas_id);
         $activeSheet->getCell("C3")->setValue($departemen->nama);
         $filter = "AND departemen_id = '" . $departemen_id . "' ";
     }
     $baris = 11;
     for ($bulan = 1; $bulan <= 12; $bulan++) {
         $baseQuery = "year(waktu) = '{$year}' AND month(waktu) = '{$bulan}' AND puskesmas_id = '" . $puskesmas->id . "'" . $filter;
         //kunjungan baru
         $kunjunganBaru = TransaksiKunjungan::model()->count($baseQuery . " AND jenis_kunjungan = 'B'");
         $activeSheet->setCellValue("C" . $baris, $kunjunganBaru);
         //kunjungan lama
         $kunjunganLama = TransaksiKunjungan::model()->count($baseQuery . " AND jenis_kunjungan = 'L'");
         $activeSheet->setCellValue("D" . $baris, $kunjunganLama);
         //BP
         $criteria = new CDbCriteria();
         $criteria->condition = $baseQuery . " AND poli_tujuan IN(1, 24)";
         $criteria->order = "id";
         $criteria->group = "kunjungan_id";
         $bp = TransaksiAntrian::model()->count($criteria);
         $activeSheet->setCellValue("F" . $baris, $bp);
         $criteria = new CDbCriteria();
         $criteria->condition = $baseQuery . " AND poli_tujuan = '3'";
         $criteria->order = "id";
         $criteria->group = "kunjungan_id";
         $bpg = TransaksiAntrian::model()->count($criteria);
         $activeSheet->setCellValue("G" . $baris, $bpg);
         $criteria = new CDbCriteria();
         $criteria->condition = $baseQuery . " AND poli_tujuan IN(4,5,6)";
         $criteria->order = "id";
         $criteria->group = "kunjungan_id";
         $kia = TransaksiAntrian::model()->count($criteria);
         $activeSheet->setCellValue("H" . $baris, $kia);
         $criteria = new CDbCriteria();
         $criteria->condition = $baseQuery . " AND poli_tujuan = '17'";
         $criteria->order = "id";
         $criteria->group = "kunjungan_id";
         $p2 = TransaksiAntrian::model()->count($criteria);
         $activeSheet->setCellValue("I" . $baris, $p2);
         $criteria = new CDbCriteria();
         $criteria->condition = $baseQuery . " AND poli_tujuan IN(2,12,13)";
         $criteria->order = "id";
         $criteria->group = "kunjungan_id";
         $ugd = TransaksiAntrian::model()->count($criteria);
         $activeSheet->setCellValue("J" . $baris, $ugd);
         //dalam luar wilayah
         $wilayah = array(0, 0, 0);
         //jenis pembayaran
         $jp = array(0, 0, 0, 0, 0, 0);
         $trs = TransaksiKunjungan::model()->findAll($baseQuery);
         foreach ($trs as $t) {
             if ($t->jenis_pembayaran_id == 1) {
                 //UMUM
                 $pasien = Pasien::model()->findByPk($t->pasien_id);
                 if ($pasien->dalam_wilayah == 1) {
                     $wilayah[0] += 1;
                 } else {
                     if ($pasien->dalam_wilayah == 2) {
                         $wilayah[1] += 1;
                     } else {
                         $wilayah[2] += 1;
                     }
                 }
             } else {
                 if ($t->jenis_pembayaran_id == 3) {
                     //PBI
                     $jp[0] += 1;
                 } else {
                     if ($t->jenis_pembayaran_id == 5) {
                         //NON PBI ASKES / TNI POLRI
                         $jp[1] += 1;
                     } else {
                         if ($t->jenis_pembayaran_id == 4) {
                             //NON MANDIRI
                             $jp[2] += 1;
                         } else {
                             if ($t->jenis_pembayaran_id == 6) {
                                 //JAMKESDA
                                 $jp[3] += 1;
                             } else {
                                 if ($t->jenis_pembayaran_id == 2) {
                                     //JAMKESDA
                                     $jp[4] += 1;
                                 } else {
                                     if (in_array($t->jenis_pembayaran_id, array(7, 8, 9, 10, 11))) {
                                         //GRATIS
                                         $jp[5] += 1;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $activeSheet->setCellValue("L" . $baris, $wilayah[0]);
         $activeSheet->setCellValue("M" . $baris, $wilayah[1]);
         $activeSheet->setCellValue("N" . $baris, $wilayah[2]);
         $activeSheet->setCellValue("O" . $baris, $jp[0]);
         $activeSheet->setCellValue("P" . $baris, $jp[1]);
         $activeSheet->setCellValue("Q" . $baris, $jp[2]);
         $activeSheet->setCellValue("R" . $baris, $jp[3]);
         $activeSheet->setCellValue("S" . $baris, $jp[4]);
         $activeSheet->setCellValue("T" . $baris, $jp[5]);
         //rujuk
         //dalam luar wilayah
         $wilayah = array(0, 0, 0);
         //jenis pembayaran
         $jp = array(0, 0, 0, 0, 0, 0);
         $baseQuery = "year(waktu_periksa) = '{$year}' AND month(waktu_periksa) = '{$bulan}' AND puskesmas_id = '" . $puskesmas->id . "'" . $filter;
         $trans = TransaksiMedicalRecord::model()->findAll($baseQuery . " AND keadaan_akhir_id = '9'");
         foreach ($trans as $meds) {
             $t = TransaksiKunjungan::model()->findByPk($meds->kunjungan_id);
             if ($t->jenis_pembayaran_id == 1) {
                 //UMUM
                 $pasien = Pasien::model()->findByPk($t->pasien_id);
                 if ($pasien->dalam_wilayah == 1) {
                     $wilayah[0] += 1;
                 } else {
                     if ($pasien->dalam_wilayah == 2) {
                         $wilayah[1] += 1;
                     } else {
                         $wilayah[2] += 1;
                     }
                 }
             } else {
                 if ($t->jenis_pembayaran_id == 3) {
                     //PBI
                     $jp[0] += 1;
                 } else {
                     if ($t->jenis_pembayaran_id == 5) {
                         //NON PBI ASKES / TNI POLRI
                         $jp[1] += 1;
                     } else {
                         if ($t->jenis_pembayaran_id == 4) {
                             //NON MANDIRI
                             $jp[2] += 1;
                         } else {
                             if ($t->jenis_pembayaran_id == 6) {
                                 //JAMKESDA
                                 $jp[3] += 1;
                             } else {
                                 if ($t->jenis_pembayaran_id == 2) {
                                     //JAMKESDA
                                     $jp[4] += 1;
                                 } else {
                                     if (in_array($t->jenis_pembayaran_id, array(7, 8, 9, 10, 11))) {
                                         //GRATIS
                                         $jp[5] += 1;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $activeSheet->setCellValue("V" . $baris, $wilayah[0]);
         $activeSheet->setCellValue("W" . $baris, $wilayah[1]);
         $activeSheet->setCellValue("X" . $baris, $wilayah[2]);
         $activeSheet->setCellValue("Y" . $baris, $jp[0]);
         $activeSheet->setCellValue("Z" . $baris, $jp[1]);
         $activeSheet->setCellValue("AA" . $baris, $jp[2]);
         $activeSheet->setCellValue("AB" . $baris, $jp[3]);
         $activeSheet->setCellValue("AC" . $baris, $jp[4]);
         $activeSheet->setCellValue("AD" . $baris, $jp[5]);
         $baris++;
     }
     return array("phpexcel" => $objPHPExcel, "name" => $reportName . "_" . $year);
 }