diff --git a/app/Http/Controllers/LaporanDesaAktifController.php b/app/Http/Controllers/LaporanDesaAktifController.php index d13190951..bee22c1de 100644 --- a/app/Http/Controllers/LaporanDesaAktifController.php +++ b/app/Http/Controllers/LaporanDesaAktifController.php @@ -21,7 +21,7 @@ public function index(Request $request) return view('laporan.desa_aktif.index', compact('title')); } - public function cetak(Request $request) + protected function getDesaAktifData(Request $request): array { $filter = array_filter($request->all()); @@ -46,8 +46,62 @@ public function cetak(Request $request) $params['page[number]'] = 1; // Use ApiProxyService to get data - $response = $this->apiProxyService->get('desa-aktif', $params); + $response = $this->apiProxyService->get('desa-aktif', $params); $data = $response['data'] ?? []; + + return array_map(function ($item) { + $item['attributes']['status_aktif'] = $this->hitungStatusAktif($item['attributes'] ?? []); + + return $item; + }, $data); + } + + protected function hitungStatusAktif(array $attributes): string + { + $loginTerakhir = ! empty($attributes['login_terakhir']) && $attributes['login_terakhir'] !== '0000-00-00' && $attributes['login_terakhir'] !== '0000-00-00 00:00:00' + ? $attributes['login_terakhir'] : null; + $perubahanTerakhir = ! empty($attributes['perubahan_terakhir']) && $attributes['perubahan_terakhir'] !== '0000-00-00' && $attributes['perubahan_terakhir'] !== '0000-00-00 00:00:00' + ? $attributes['perubahan_terakhir'] : null; + + $batas = \Carbon\Carbon::now()->subDays(7); + + $loginAktif = false; + if ($loginTerakhir) { + try { + $loginAktif = \Carbon\Carbon::parse($loginTerakhir)->gte($batas); + } catch (\Exception $e) { + $loginAktif = false; + } + } + + $perubahanAktif = false; + if ($perubahanTerakhir) { + try { + $perubahanAktif = \Carbon\Carbon::parse($perubahanTerakhir)->gte($batas); + } catch (\Exception $e) { + $perubahanAktif = false; + } + } + + return ($loginAktif || $perubahanAktif) ? 'Aktif' : 'Tidak Aktif'; + } + + public function cetak(Request $request) + { + $data = $this->getDesaAktifData($request); + return view('laporan.desa_aktif.cetak', compact('data')); } + + public function exportExcel(Request $request) + { + $data = $this->getDesaAktifData($request); + $excel = true; + + $html = view('laporan.desa_aktif.cetak', compact('data', 'excel'))->render(); + + return response($html) + ->header('Content-Type', 'application/vnd.ms-excel') + ->header('Content-Disposition', 'attachment; filename="laporan-desa-aktif.xls"'); + } } diff --git a/catatan_rilis.md b/catatan_rilis.md index f214e9ae2..9d670ec61 100644 --- a/catatan_rilis.md +++ b/catatan_rilis.md @@ -6,6 +6,7 @@ Di rilis ini, versi 2607.0.0 berisi penambahan dan perbaikan yang diminta penggu 1. [#1094](https://github.com/OpenSID/OpenKab/issues/1094) Perbaikan pangan error data table. 2. [#1098](https://github.com/OpenSID/OpenKab/issues/1098) Perbaikan tampilan durasi lockout akun login (menit dan detik) serta koreksi perhitungan selisih waktu carbon. +3. [#1100](https://github.com/OpenSID/OpenKab/issues/1100) Lengkapi fungsi laporan desa aktif. #### Perubahan Teknis diff --git a/resources/views/laporan/desa_aktif/cetak.blade.php b/resources/views/laporan/desa_aktif/cetak.blade.php index 829a65e68..0b1852783 100644 --- a/resources/views/laporan/desa_aktif/cetak.blade.php +++ b/resources/views/laporan/desa_aktif/cetak.blade.php @@ -9,26 +9,30 @@