private function process($year, $month, $departemen_id)
 {
     $reportName = "laporan_lplpo";
     $objPHPExcel = $this->loadPHPExcelLib($reportName);
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     $namaBulan = array("1" => "Januari", "2" => "Februari", "3" => "Maret", "4" => "April", "5" => "Mei", "6" => "Juni", "7" => "Juli", "8" => "Agustus", "9" => "September", "10" => "Oktober", "11" => "November", "12" => "Desember");
     $puskesmas_id = NULL;
     $jenisLaporan = "";
     $filter = "";
     if (substr("" . $departemen_id, 0, 4) == "wil_") {
         $jenisLaporan = "summary";
         $puskesmas = Puskesmas::model()->findByPk(substr("" . $departemen_id, 4));
         $puskesmas_id = $puskesmas->id;
         $departemen = NULL;
         $departemen_id = NULL;
         $activeSheet->getCell("A8")->setValue("Wilayah Kerja Puskesmas " . ucwords(strtolower($puskesmas->nama)));
     } else {
         $jenisLaporan = "per_departemen";
         $departemen = Departemen::model()->findByPk($departemen_id);
         $puskesmas = Puskesmas::model()->findByPk($departemen->puskesmas_id);
         $puskesmas_id = $puskesmas->id;
         $activeSheet->getCell("A8")->setValue($departemen->nama);
         $filter = " AND departemen_id = '" . $departemen->id . "'";
     }
     //echo "JL : ".$jenisLaporan.", Pusk : ".$puskesmas_id.", DPID : ".$departemen_id;
     //judul
     $activeSheet->getCell("A5")->setValue("PEMAKAIAN BULAN " . strtoupper($namaBulan[$month]));
     $no = 1;
     $baris = 12;
     $output = KartuStok::getLPLPOData($month, $year, $jenisLaporan, $puskesmas_id, $departemen_id);
     foreach ($output as $element) {
         $activeSheet->setCellValue("A" . $baris, $no);
         $activeSheet->setCellValue("B" . $baris, $element["nama_obat"]);
         $activeSheet->setCellValue("C" . $baris, $element["kemasan"]);
         $activeSheet->setCellValue("D" . $baris, $element["stok_awal"]);
         $activeSheet->setCellValue("E" . $baris, $element["penerimaan"]);
         $activeSheet->setCellValue("F" . $baris, $element["pemakaian"]);
         $activeSheet->setCellValue("G" . $baris, $element["rusak"]);
         $activeSheet->setCellValue("H" . $baris, $element["saldo"]);
         $no++;
         $baris++;
     }
     $activeSheet->getStyle("A12:H" . ($baris - 1))->applyFromArray(array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN))));
     $i = 4;
     $reseps = $this->getDataResep($year, $month, $departemen_id, $puskesmas_id);
     foreach ($reseps as $key => $element) {
         $activeSheet->setCellValueByColumnAndRow($i, 5, $key);
         $activeSheet->setCellValueByColumnAndRow($i, 6, $element);
         $activeSheet->getStyleByColumnAndRow($i, 5)->applyFromArray(array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN))));
         $activeSheet->getStyleByColumnAndRow($i, 6)->applyFromArray(array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN))));
         $i++;
     }
     return array("phpexcel" => $objPHPExcel, "name" => $reportName . "_" . $namaBulan[$month] . "_" . $year);
 }
 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 adjustStokObat($tujuan_id, $departemen_id, $puskesmas_id)
 {
     foreach (Obat::model()->findAll() as $obat) {
         $dataTransaksi = KartuStok::kalkulasiStokObat($obat->id, $tujuan_id, $departemen_id, $puskesmas_id);
         $saldo = 0;
         foreach ($dataTransaksi as $key => $trans) {
             $saldo = $saldo + $trans["masuk"] - $trans["keluar"];
         }
         $obatDept = ObatDepartemen::model()->findByAttributes(array("puskesmas_id" => $puskesmas_id, "departemen_id" => $departemen_id, "distribusi_obat_tujuan_id" => $tujuan_id, "obat_id" => $obat->id));
         if ($obatDept == NULL) {
             $obatDept = new ObatDepartemen();
             $obatDept->puskesmas_id = $puskesmas_id;
             $obatDept->departemen_id = $departemen_id;
             $obatDept->distribusi_obat_tujuan_id = $tujuan_id;
             $obatDept->obat_id = $obat->id;
         }
         $obatDept->stok = $saldo;
         $obatDept->save();
     }
 }