From 6ec3775f210f9162b4efe86b1bf4e66f5d591196 Mon Sep 17 00:00:00 2001 From: Ariyutta Date: Mon, 26 Oct 2026 19:12:36 +0700 Subject: [PATCH] Perbaikan API Dawai --- app/Services/DawaiService.php | 37 ++++++- .../tri-dharma/bawahan/index-dekan.blade.php | 96 +++++++++++++++---- .../tri-dharma/bawahan/index.blade.php | 83 +++++++++++++--- 3 files changed, 182 insertions(+), 34 deletions(-) diff --git a/app/Services/DawaiService.php b/app/Services/DawaiService.php index 88cccf79..9ecb8081 100644 --- a/app/Services/DawaiService.php +++ b/app/Services/DawaiService.php @@ -269,7 +269,7 @@ class DawaiService $response = $this->client->post('api/v1/siskaPengajuanPresensi', [ 'multipart' => $multipart, - 'timeout' => 15, + 'timeout' => 90, ]); $result = json_decode($response->getBody()->getContents(), true); @@ -287,10 +287,19 @@ class DawaiService return true; } catch (ClientException $e) { - $pesan = json_decode((string) $e->getResponse()->getBody(), true)['meta']['message'] ?? ''; + $body = (string) $e->getResponse()->getBody(); + $decoded = json_decode($body, true); + $pesan = $decoded['meta']['message'] ?? ''; if ($e->getResponse()->getStatusCode() === 400 && str_contains(strtolower($pesan), 'sudah ada')) { - Log::warning("DAWAI siskaPengajuanPresensi: data sudah ada di DAWAI ({$data['nip']} {$data['tanggal_mulai']}): $pesan"); + $dawaiId = $this->cariDawaiIdTersimpan($decoded, $data, $pengajuan); + + if ($pengajuan && $dawaiId) { + $pengajuan->update(['dawai_id' => $dawaiId]); + Log::warning("DAWAI siskaPengajuanPresensi: data sudah ada di DAWAI ({$data['nip']} {$data['tanggal_mulai']}), dawai_id $dawaiId disimpan: $pesan"); + } else { + Log::warning("DAWAI siskaPengajuanPresensi: data sudah ada di DAWAI ({$data['nip']} {$data['tanggal_mulai']}), dawai_id tidak ditemukan (pengajuan #".($pengajuan?->id ?? '-')."): $pesan | $body"); + } return true; } @@ -307,6 +316,28 @@ class DawaiService } } + private function cariDawaiIdTersimpan(?array $respons, array $data, ?PengajuanPresensi $pengajuan): int|string|null + { + foreach (['data.id', 'meta.data.id', 'data', 'id'] as $kunci) { + $nilai = data_get($respons, $kunci); + if (is_scalar($nilai) && is_numeric($nilai)) { + return $nilai; + } + } + + if (! $pengajuan) { + return null; + } + + return PengajuanPresensi::where('tipe', $pengajuan->tipe) + ->where('nip', $pengajuan->nip) + ->where('kategori', $pengajuan->getRawOriginal('kategori')) + ->whereDate('tanggal_mulai', $data['tanggal_mulai']) + ->whereNotNull('dawai_id') + ->whereKeyNot($pengajuan->getKey()) + ->value('dawai_id'); + } + public function listJabatanFungsional(?int $id) { try { diff --git a/resources/views/verifikasi/tri-dharma/bawahan/index-dekan.blade.php b/resources/views/verifikasi/tri-dharma/bawahan/index-dekan.blade.php index b9863aa5..309f42b3 100644 --- a/resources/views/verifikasi/tri-dharma/bawahan/index-dekan.blade.php +++ b/resources/views/verifikasi/tri-dharma/bawahan/index-dekan.blade.php @@ -35,7 +35,7 @@ @if (count($ketuaJurusanList) > 0)
- +
@@ -94,7 +94,7 @@

-
No
+
@@ -119,9 +119,52 @@ const ketuaJurusanList = @json($ketuaJurusanList); $(document).ready(function() { - const modalDetailBawahan = new bootstrap.Modal(document.getElementById('modalDetailBawahan')); + const modalEl = document.getElementById('modalDetailBawahan'); + const modalDetailBawahan = new bootstrap.Modal(modalEl); - $('.kajur-row').on('click', function() { + // Nomor urut ulang setelah search/sort/paging + function renumber(table) { + const start = table.page.info().start; + table.column(0, { + search: 'applied', + order: 'applied', + page: 'current' + }).nodes().each(function(cell, i) { + cell.innerHTML = start + i + 1; + }); + } + + // Daftar Ketua Jurusan + if ($('#kajur-table').length) { + const kajurTable = $('#kajur-table').DataTable({ + order: [ + [1, 'asc'] + ], + columnDefs: [{ + targets: 0, + orderable: false, + searchable: false + }], + language: { + emptyTable: 'Tidak ada data Ketua Jurusan' + } + }); + kajurTable.on('draw.dt', function() { + renumber(kajurTable); + }).draw(false); + } + + // Tabel bawahan di modal (dibangun ulang setiap dibuka) + let modalTable = null; + + modalEl.addEventListener('shown.bs.modal', function() { + if (modalTable) { + modalTable.columns.adjust(); + } + }); + + // Delegasi event supaya baris di halaman lain tetap bisa diklik + $(document).on('click', '.kajur-row', function() { const index = $(this).data('index'); const kajur = ketuaJurusanList[index]; @@ -132,21 +175,40 @@ $('#modalKajurNama').text(kajur.nama); $('#modalKajurKeterangan').text(kajur.keterangan || kajur.jabatan || '-'); + if (modalTable) { + modalTable.destroy(); + modalTable = null; + } + const $body = $('#modalKajurBawahanBody').empty(); - if (kajur.bawahan && kajur.bawahan.length > 0) { - kajur.bawahan.forEach(function(b, idx) { - $body.append( - '' + - '' + - '' + - '' + - '' - ); - }); - } else { - $body.append(''); - } + (kajur.bawahan || []).forEach(function(b, idx) { + $body.append( + '' + + '' + + '' + + '' + + '' + ); + }); + + modalTable = $('#modalKajurTable').DataTable({ + autoWidth: false, + order: [ + [1, 'asc'] + ], + columnDefs: [{ + targets: 0, + orderable: false, + searchable: false + }], + language: { + emptyTable: 'Belum ada bawahan yang ditugaskan' + } + }); + modalTable.on('draw.dt', function() { + renumber(modalTable); + }).draw(false); modalDetailBawahan.show(); }); diff --git a/resources/views/verifikasi/tri-dharma/bawahan/index.blade.php b/resources/views/verifikasi/tri-dharma/bawahan/index.blade.php index a6290f41..e586f04d 100644 --- a/resources/views/verifikasi/tri-dharma/bawahan/index.blade.php +++ b/resources/views/verifikasi/tri-dharma/bawahan/index.blade.php @@ -42,17 +42,13 @@ - @forelse ($allPegawais as $index => $peg) + @foreach ($allPegawais as $index => $peg) - + - + - @empty - - - - @endforelse + @endforeach
No
' + (idx + 1) + '' + b.nama + '' + b.nip + '
Belum ada bawahan yang ditugaskan
' + (idx + 1) + '' + b.nama + '' + b.nip + '
{{ $index + 1 }}{{ $index + 1 }} {{ $peg->nama }}{{ $peg->nip }}{{ $peg->nip }}
Tidak ada data atasan
@@ -143,7 +139,7 @@
- +
@@ -467,13 +463,51 @@ const modalEl = document.getElementById('modalBawahan'); const modalBawahan = new bootstrap.Modal(modalEl); - function renderModalTable() { - const $body = $('#modalBawahanBody').empty(); + // Nomor urut ulang setelah search/sort/paging + function renumber(table) { + const start = table.page.info().start; + table.column(0, { + search: 'applied', + order: 'applied', + page: 'current' + }).nodes().each(function(cell, i) { + cell.innerHTML = start + i + 1; + }); + } - if (currentBawahan.length === 0) { - $body.append(''); - return; + // Daftar atasan + const atasanTable = $('#atasan-table').DataTable({ + order: [ + [1, 'asc'] + ], + columnDefs: [{ + targets: 0, + orderable: false, + searchable: false + }], + language: { + emptyTable: 'Tidak ada data atasan' } + }); + atasanTable.on('draw.dt', function() { + renumber(atasanTable); + }).draw(false); + + // Tabel bawahan di modal (dibangun ulang setiap data berubah) + let modalDataTable = null; + + function destroyModalTable() { + if (modalDataTable) { + modalDataTable.destroy(); + modalDataTable = null; + } + } + + function renderModalTable() { + const page = modalDataTable ? modalDataTable.page() : 0; + destroyModalTable(); + + const $body = $('#modalBawahanBody').empty(); currentBawahan.forEach(function(b, idx) { $body.append( @@ -485,6 +519,25 @@ '' ); }); + + modalDataTable = $('#modalBawahanTable').DataTable({ + autoWidth: false, + order: [ + [2, 'asc'] + ], + columnDefs: [{ + targets: [0, 3], + orderable: false, + searchable: false + }], + language: { + emptyTable: 'Belum ada bawahan yang ditugaskan' + } + }); + modalDataTable.on('draw.dt', function() { + renumber(modalDataTable); + }); + modalDataTable.page(Math.min(page, Math.max(modalDataTable.page.info().pages - 1, 0))).draw('page'); } function renderModalSelectOptions() { @@ -511,6 +564,7 @@ function loadModalData(nip, nama) { currentNipAtasan = nip; $('#modalAtasanNama').text(nama); + destroyModalTable(); $('#modalBawahanBody').html(''); currentBawahan = []; availablePegawais = []; @@ -531,6 +585,7 @@ renderModalSelectOptions(); }, error: function() { + destroyModalTable(); $('#modalBawahanBody').html(''); } });
No
Belum ada bawahan yang ditugaskan
Memuat data...
Gagal memuat data