private function process($_tanggal, $_tanggal2, $tujuan_id) { $reportName = "laporan_obat"; $objPHPExcel = $this->loadPHPExcelLib($reportName); $objPHPExcel->setActiveSheetIndex(0); $activeSheet = $objPHPExcel->getActiveSheet(); $tanggal = $this->reverseDate($_tanggal); $tanggal2 = $this->reverseDate($_tanggal2); $puskesmas_id = Yii::app()->user->puskesmas_id; $puskesmas = Puskesmas::model()->findByPk($puskesmas_id); $departemen_id = Departemen::model()->findByAttributes(array("puskesmas_id" => $puskesmas_id, "departemen_jenis_id" => "1"))->id; $tujuan = DistribusiObatTujuan::model()->findByPk($tujuan_id); $activeSheet->getCell("A8")->setValue(strtoupper($tujuan->nama . " - PUSKESMAS " . $puskesmas->nama)); $activeSheet->getCell("A5")->setValue("PEMAKAIAN TANGGAL " . $_tanggal . " S/D " . $_tanggal2); //echo "$tujuan_id, $departemen_id, $puskesmas_id"; $no = 1; $baris = 12; $obatArr = Obat::model()->findAll(); foreach ($obatArr as $obat) { $data = KartuStok::kalkulasiStokObat($obat->id, $tujuan_id, $departemen_id, $puskesmas_id, FALSE); $masuk = 0; $keluar = 0; foreach ($data as $d) { //echo "Perbandingan : ".strtotime($tanggal)." > ".strtotime($d["date"])." > ".strtotime($tanggal2); //echo "<br>"; if (strtotime($tanggal) <= strtotime($d["date"]) && strtotime($d["date"]) < strtotime($tanggal2) + 86400) { $masuk += $d["masuk"]; $keluar += $d["keluar"]; } else { continue; } } $activeSheet->setCellValue("A" . $baris, $no); $activeSheet->setCellValue("B" . $baris, $obat->nama); $activeSheet->setCellValue("C" . $baris, ObatSatuan::model()->findByPk($obat->kemasan_id)->nama); $activeSheet->setCellValue("D" . $baris, $masuk); $activeSheet->setCellValue("E" . $baris, $keluar); $no++; $baris++; } $activeSheet->getStyle("A12:E" . ($baris - 1))->applyFromArray(array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN)))); return array("phpexcel" => $objPHPExcel, "name" => $reportName . "_" . $_tanggal . "_" . $_tanggal2); }
public static function getLPLPOData($month, $year, $jenisLaporan, $puskesmas_id, $departemen_id) { $output = array(); $obats = Obat::model()->findAll(); foreach ($obats as $obat) { $stokAwal = 0; $penerimaan = 0; $pemakaian = 0; $saldo = 0; $info = array(); if ($jenisLaporan == "summary") { //summary seluruh wilayah $info = KartuStok::kalkulasiStokObat($obat->id, 0, 0, $puskesmas_id); } else { if ($jenisLaporan == "per_departemen") { $info = KartuStok::kalkulasiStokObat($obat->id, 0, $departemen_id, $puskesmas_id); } } foreach ($info as $inf) { //echo $year.str_pad($month, 2, "0", STR_PAD_LEFT) . " DAN " . $bulanTahun; $bulanTahun = date("Ym", strtotime($inf["date"])); if ($year . str_pad($month, 2, "0", STR_PAD_LEFT) == $bulanTahun) { $penerimaan += $inf["masuk"]; $pemakaian += $inf["keluar"]; } else { if ($bulanTahun * 1 < ($year . str_pad($month, 2, "0", STR_PAD_LEFT)) * 1) { $stokAwal += $inf["masuk"]; $stokAwal -= $inf["keluar"]; } } } $rusak = KartuStok::getJumlahObatRusak($puskesmas_id, $departemen_id, $obat->id, $year, $month); $saldo = $stokAwal + $penerimaan - $pemakaian - $rusak; $obj = array(); $obj['nama_obat'] = $obat->nama; $obj['kemasan'] = CHtml::value(ObatSatuan::model()->findByPk($obat->kemasan_id), "nama", "-"); $obj['stok_awal'] = $stokAwal; $obj['penerimaan'] = $penerimaan; $obj['pemakaian'] = $pemakaian; $obj['saldo'] = $saldo; $obj['rusak'] = $rusak; $output[] = $obj; } return $output; }