Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions app/Http/Controllers/LaporanDesaAktifController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand 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"');
}
}
1 change: 1 addition & 0 deletions catatan_rilis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion resources/views/laporan/desa_aktif/cetak.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,40 @@
<tr class="border thick">
<th class="padat">No</th>
<th class="padat">Desa</th>
<th class="padat">Kecamatan</th>
<th class="padat">Artikel Terbit</th>
<th class="padat">Jumlah Akses</th>
<th class="padat">Jml Surat</th>
<th class="padat">Penduduk</th>
<th class="padat">Status</th>
</tr>
</thead>
<tbody>
@if (empty($data))
<tr>
<td colspan="6" class="text-center">Tidak ada data</td>
<td colspan="8" class="text-center">Tidak ada data</td>
</tr>
@else
@foreach ($data as $index => $item)
<tr>
<td class="padat">{{ ((int) $index) + 1 }}</td>
<td>{{ $item['attributes']['nama_desa'] ?? '' }}</td>
<td>{{ $item['attributes']['nama_kecamatan'] ?? '' }}</td>
<td class="text-center">{{ $item['attributes']['artikel'] ?? 0 }}</td>
<td class="text-center">{{ $item['attributes']['traffic'] ?? 0 }}</td>
<td class="text-center">{{ $item['attributes']['surat'] ?? 0 }}</td>
<td class="text-center">{{ $item['attributes']['penduduk'] ?? 0 }}</td>
<td class="text-center">{{ $item['attributes']['status_aktif'] ?? 'Tidak Aktif' }}</td>
</tr>
@endforeach
@endif
</tbody>
</table>
@stop
@push('scripts')
@if (!isset($excel))
<script nonce="{{ csp_nonce() }}">
window.print();
</script>
@endif
@endpush
51 changes: 51 additions & 0 deletions resources/views/laporan/desa_aktif/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<button id="cetak" type="button" class="btn btn-primary btn-sm" data-url=""><i
class="fa fa-print"></i>
Cetak</button>
<button id="export-excel" type="button" class="btn btn-success btn-sm"><i
class="fa fa-file-excel"></i>
Excel</button>
</div>
<div class="card-body">
<div class="table-responsive">
Expand All @@ -23,10 +26,12 @@ class="fa fa-print"></i>
<tr>
<th width="50">No</th>
<th>Desa</th>
<th>Kecamatan</th>
<th class="text-center">Artikel<br>Terbit</th>
<th class="text-center">Jumlah<br>Akses</th>
<th class="text-center">Jml Surat</th>
<th class="text-center">Penduduk</th>
<th class="text-center">Status</th>
</tr>
</thead>
<tbody></tbody>
Expand Down Expand Up @@ -81,6 +86,9 @@ class="fa fa-print"></i>
{
data: 'attributes.nama_desa'
},
{
data: 'attributes.nama_kecamatan'
},
{
data: 'attributes.artikel',
className: 'text-center'
Expand All @@ -97,12 +105,49 @@ className: 'text-center'
data: 'attributes.penduduk',
className: 'text-center'
},
{
data: null,
className: 'text-center'
},
],
columnDefs: [{
targets: 0,
render: function(data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1;
}
},
{
targets: 7,
render: function(data, type, row) {
const attr = row.attributes || {};
const loginTerakhir = attr.login_terakhir;
const perubahanTerakhir = attr.perubahan_terakhir;

const batasWaktu = new Date();
batasWaktu.setDate(batasWaktu.getDate() - 7);

let loginAktif = false;
if (loginTerakhir && loginTerakhir !== '0000-00-00' && loginTerakhir !== '0000-00-00 00:00:00') {
const tglLogin = new Date(loginTerakhir);
if (!isNaN(tglLogin.getTime()) && tglLogin >= batasWaktu) {
loginAktif = true;
}
}

let perubahanAktif = false;
if (perubahanTerakhir && perubahanTerakhir !== '0000-00-00' && perubahanTerakhir !== '0000-00-00 00:00:00') {
const tglPerubahan = new Date(perubahanTerakhir);
if (!isNaN(tglPerubahan.getTime()) && tglPerubahan >= batasWaktu) {
perubahanAktif = true;
}
}

const aktif = loginAktif || perubahanAktif;

return aktif
? '<span class="badge badge-success">Aktif</span>'
: '<span class="badge badge-danger">Tidak Aktif</span>';
}
}],
order: [
[1, 'asc']
Expand All @@ -115,6 +160,12 @@ className: 'text-center'
window.open(url.href, '_blank');
});

$('#export-excel').on('click', function() {
let url = new URL("{{ url('laporan/desa-aktif/export-excel') }}");
url.searchParams.append("search", $('input[aria-controls="desaAktifTable"]').val() ?? '');
window.open(url.href, '_blank');
});

})
</script>
@endpush
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@
Route::prefix('laporan')->group(function () {
Route::prefix('desa-aktif')->group(function () {
Route::get('', [App\Http\Controllers\LaporanDesaAktifController::class, 'index'])->name('laporan.desa-aktif.index');
Route::get('cetak', [App\Http\Controllers\LaporanDesaAktifController::class, 'cetak'])->name('laporan.desa-aktif.cetak');
Route::get('cetak', [App\Http\Controllers\LaporanDesaAktifController::class, 'cetak'])->name('laporan.desa-aktif.cetak');
Route::get('export-excel', [App\Http\Controllers\LaporanDesaAktifController::class, 'exportExcel'])->name('laporan.desa-aktif.export-excel');
});
});
Route::prefix('data-presisi')->group(function () {
Expand Down