From c4fe692f3bfb515b1c1620483dd905f845fcc169 Mon Sep 17 00:00:00 2001 From: Ariyutta Date: Wed, 30 Sep 2026 03:21:42 +0700 Subject: [PATCH] Penambahan Kekurangan P2 Manual --- .../GenerateKekuranganP2JsonCommand.php | 143 ++++++++++++++++++ .../Remunerasi/KeseluruhanController.php | 18 ++- resources/data/2026/kekurangan_p2_401.json | 60 ++++++++ .../remunerasi/keseluruhan/index.blade.php | 8 +- 4 files changed, 219 insertions(+), 10 deletions(-) create mode 100644 app/Console/Commands/Remunerasi/GenerateKekuranganP2JsonCommand.php diff --git a/app/Console/Commands/Remunerasi/GenerateKekuranganP2JsonCommand.php b/app/Console/Commands/Remunerasi/GenerateKekuranganP2JsonCommand.php new file mode 100644 index 00000000..b508bd9f --- /dev/null +++ b/app/Console/Commands/Remunerasi/GenerateKekuranganP2JsonCommand.php @@ -0,0 +1,143 @@ +option('periode') ?? Periode::where('status', true)->value('id_periode')); + + if (! $periode) { + $this->error('Tidak ada periode aktif. Gunakan --periode=.'); + + return self::FAILURE; + } + + $namaPeriode = (string) Periode::where('id_periode', $periode)->value('nama'); + $tahun = (int) ($this->option('tahun') ?: (preg_match('/\d{4}/', $namaPeriode, $m) ? $m[0] : 0)); + + if (! $tahun) { + $this->error('Tahun tidak dapat ditentukan dari nama periode. Gunakan --tahun=.'); + + return self::FAILURE; + } + + $bulan = $periode % 2 === 1 ? [1, 2, 3, 4, 5, 6] : [7, 8, 9, 10, 11, 12]; + $service = new PerhitunganKegiatanService; + $hasil = []; + + foreach ($this->argument('nip') as $nip) { + $nip = preg_replace("/['.\-\s]/", '', $nip); + + $pegawai = Pegawai::withoutGlobalScope('aktif') + ->with([ + 'jabatans' => fn ($q) => $q->where('periode', $periode), + 'jabatans.detail' => fn ($q) => $q->whereIn('bulan', $bulan), + ]) + ->where(fn ($q) => $q->where('nip', $nip)->orWhere('nip_siakad', $nip)) + ->first(); + + if (! $pegawai) { + $this->warn("{$nip}: pegawai tidak ditemukan, dilewati."); + + continue; + } + + // listKegiatan menulis ke DB (hapus/buat remunerasi) untuk bulan tanpa p2_jf/p2_jtt walau save=false. + // Karena itu hanya bulan yang berhak P2 (p2_jf atau p2_jtt true) yang dihitung; bulan lain dilewati + // (nilai P2-nya memang 0) sehingga tidak ada penulisan ke DB. + $details = ($pegawai->jabatans->first()?->detail ?? collect()); + $bulanLayak = $details->filter(fn ($d) => $d->p2_jf === true || $d->p2_jtt === true)->pluck('bulan')->sort()->values()->all(); + $bulanDilewati = $details->pluck('bulan')->diff($bulanLayak)->sort()->values()->all(); + + if ($bulanLayak === []) { + $this->warn("{$nip} ({$pegawai->nama}): tidak ada bulan yang berhak P2 di periode ini, dilewati."); + + continue; + } + + if ($bulanDilewati !== []) { + $this->line(" {$nip}: bulan ".implode(', ', $bulanDilewati).' dilewati (tanpa p2_jf/p2_jtt); dihitung bulan '.implode(', ', $bulanLayak).'.'); + } + + try { + $kegiatans = $service->listKegiatan($pegawai->nip, $periode, $bulanLayak, null, false); + } catch (Exception $e) { + $this->warn("{$nip} ({$pegawai->nama}): gagal dihitung - {$e->getMessage()}"); + + continue; + } + + // Jumlahkan P2 seluruh unit pembayaran pada semua bulan di periode. + $total = ['p2_bruto' => 0.0, 'p2_pajak' => 0.0, 'p2_netto' => 0.0]; + foreach ($kegiatans ?: [] as $dataBulan) { + foreach ($dataBulan['units'] ?? [] as $unit) { + $total['p2_bruto'] += (float) ($unit['p2']['ratio'] ?? 0); + $total['p2_pajak'] += (float) ($unit['p2']['tax'] ?? 0); + $total['p2_netto'] += (float) ($unit['p2']['netto'] ?? 0); + } + } + + $hasil[$pegawai->nip] = array_map(fn ($v) => $this->rapikan($v), $total); + + $this->line(sprintf( + '%s %-35s bruto: Rp %s | pajak: Rp %s | netto: Rp %s', + $pegawai->nip, + mb_substr((string) $pegawai->nama, 0, 35), + number_format($total['p2_bruto'], 2, ',', '.'), + number_format($total['p2_pajak'], 2, ',', '.'), + number_format($total['p2_netto'], 2, ',', '.'), + )); + } + + if ($hasil === []) { + $this->warn('Tidak ada data yang bisa disimpan.'); + + return self::FAILURE; + } + + if ($this->option('dry-run')) { + $this->info('Dry-run: file JSON tidak diubah.'); + + return self::SUCCESS; + } + + $path = resource_path("data/{$tahun}/kekurangan_p2_{$periode}.json"); + $existing = is_file($path) ? (json_decode((string) file_get_contents($path), true) ?: []) : []; + $merged = array_replace($existing, $hasil); + ksort($merged, SORT_STRING); + + File::ensureDirectoryExists(dirname($path)); + File::put($path, json_encode($merged, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + + $this->info(sprintf('✓ %d pegawai disimpan/diperbarui di %s (total %d entri)', count($hasil), $path, count($merged))); + + return self::SUCCESS; + } + + /** + * Bulatkan 2 desimal dan buang ".0" pada bilangan bulat agar format sama dengan isi file yang sudah ada. + */ + private function rapikan(float $nilai): int|float + { + $nilai = round($nilai, 2); + + return $nilai == floor($nilai) ? (int) $nilai : $nilai; + } +} diff --git a/app/Http/Controllers/Perhitungan/Remunerasi/KeseluruhanController.php b/app/Http/Controllers/Perhitungan/Remunerasi/KeseluruhanController.php index 92dc3952..94e4c122 100644 --- a/app/Http/Controllers/Perhitungan/Remunerasi/KeseluruhanController.php +++ b/app/Http/Controllers/Perhitungan/Remunerasi/KeseluruhanController.php @@ -227,7 +227,11 @@ class KeseluruhanController extends Controller */ private function rekapCacheKey(int $tahun, ?string $jenisPegawai, string $sumberP1): string { - $key = 'remunerasi_keseluruhan_v8_'.$tahun.'_'.($jenisPegawai ?: 'semua'); + $key = 'remunerasi_keseluruhan_v9_'.$tahun.'_'.($jenisPegawai ?: 'semua'); + + // Cache ikut berganti bila JSON kekurangan P2 diubah. + $mtimeP2 = collect(glob(resource_path("data/{$tahun}/kekurangan_p2_*.json")) ?: [])->map(fn ($f) => filemtime($f))->max(); + $key .= '_p2json_'.($mtimeP2 ?? 0); if ($sumberP1 === 'dawai') { $file = P1DawaiSnapshot::latestPath($tahun); @@ -341,11 +345,11 @@ class KeseluruhanController extends Controller $p2Pajak = $p2Rows->map(fn ($row) => (float) $row->total_pajak); $p2Netto = $p2Rows->map(fn ($row) => (float) $row->total_netto); - // Fallback untuk pegawai (CPNS) yang P2-nya belum tersimpan di remunerasi_per_bulans: - // ambil dari snapshot JSON hasil perhitungan (read-only), tanpa menulis ke DB. + // Snapshot JSON hasil perhitungan (read-only, tanpa menulis ke DB): bila pegawai ada di JSON + // dengan P2 > 0, nilai JSON menimpa nilai dari DB (juga untuk pegawai yang belum ada di DB, mis. CPNS). foreach ($this->loadP2Snapshot($tahun, $periodeSemester1) as $nip => $nilai) { $key = $normalize($nip); - if (! $p2->has($key) && ($nilai['p2_bruto'] ?? 0) > 0) { + if (($nilai['p2_bruto'] ?? 0) > 0) { $p2->put($key, (float) $nilai['p2_bruto']); $p2Pajak->put($key, (float) ($nilai['p2_pajak'] ?? 0)); $p2Netto->put($key, (float) ($nilai['p2_netto'] ?? 0)); @@ -374,9 +378,9 @@ class KeseluruhanController extends Controller $r13 = collect($r13Data)->keyBy(fn ($row) => $normalize($row['nip'] ?? ''))->map(fn ($row) => (float) ($row['total_r13'] ?? 0)); $r13Netto = collect($r13Data)->keyBy(fn ($row) => $normalize($row['nip'] ?? ''))->map(fn ($row) => (float) ($row['total_r13_setelah_pajak'] ?? 0)); - // 5. Publikasi = seluruh periode yang namanya memuat tahun terpilih (mis. "2026 Semester 1" - // maupun "2025/2026 Ganjil"), karena publikasi tidak terikat pada satu format periode tertentu. - $periodeIds = Periode::where('nama', 'LIKE', "%{$tahun}%")->pluck('id_periode'); + // 5. Publikasi = hanya periode Semester 1 tahun terpilih (mis. 401 untuk 2026), sama seperti P2; + // Semester 2 belum waktunya perhitungan dan periode Ganjil/Genap tahun sebelumnya tidak dihitung. + $periodeIds = collect($periodeSemester1 ? [$periodeSemester1] : []); $publikasiQuery = Publikasi::query() ->whereIn('periode', $periodeIds) diff --git a/resources/data/2026/kekurangan_p2_401.json b/resources/data/2026/kekurangan_p2_401.json index 351ddfef..d19f81e9 100644 --- a/resources/data/2026/kekurangan_p2_401.json +++ b/resources/data/2026/kekurangan_p2_401.json @@ -1,4 +1,64 @@ { + "196801131992032001": { + "p2_bruto": 4936330, + "p2_pajak": 246816.5, + "p2_netto": 4689513.5 + }, + "196802291993032001": { + "p2_bruto": 11615019, + "p2_pajak": 580750.95, + "p2_netto": 11034268.05 + }, + "196803052014091004": { + "p2_bruto": 12094075.5, + "p2_pajak": 604703.77, + "p2_netto": 11489371.73 + }, + "196804012000032001": { + "p2_bruto": 17887577.5, + "p2_pajak": 894378.88, + "p2_netto": 16993198.63 + }, + "196804152007012001": { + "p2_bruto": 10354750, + "p2_pajak": 517737.5, + "p2_netto": 9837012.5 + }, + "196804241987021001": { + "p2_bruto": 23308480, + "p2_pajak": 1165424, + "p2_netto": 22143056 + }, + "196806011987031001": { + "p2_bruto": 5432000, + "p2_pajak": 271600, + "p2_netto": 5160400 + }, + "196808191996031003": { + "p2_bruto": 13853527.5, + "p2_pajak": 692676.38, + "p2_netto": 13160851.13 + }, + "198006032005012002": { + "p2_bruto": 14041210, + "p2_pajak": 702060.5, + "p2_netto": 13339149.5 + }, + "198410182008012002": { + "p2_bruto": 3184142.5, + "p2_pajak": 159207.13, + "p2_netto": 3024935.38 + }, + "198601172012122004": { + "p2_bruto": 8219175, + "p2_pajak": 410958.75, + "p2_netto": 7808216.25 + }, + "198908032022032005": { + "p2_bruto": 3387288, + "p2_pajak": 169364.4, + "p2_netto": 3217923.6 + }, "199002132025062005": { "p2_bruto": 0, "p2_pajak": 0, diff --git a/resources/views/perhitungan/remunerasi/keseluruhan/index.blade.php b/resources/views/perhitungan/remunerasi/keseluruhan/index.blade.php index 82f36a8f..bd87510b 100644 --- a/resources/views/perhitungan/remunerasi/keseluruhan/index.blade.php +++ b/resources/views/perhitungan/remunerasi/keseluruhan/index.blade.php @@ -211,12 +211,12 @@ '"> ' + jenis.toUpperCase() + ''; } - // Penanda pegawai yang P2-nya diambil dari snapshot JSON (CPNS), warna tosca. + // Penanda pegawai yang P2-nya diambil dari snapshot JSON, warna tosca. function renderCpnsTag(sumber) { if (sumber !== 'json') { return ''; } - return ' CPNS'; + return ' P2 JSON'; } var table = $('#keseluruhan-table').DataTable({ @@ -257,7 +257,9 @@ { data: 'jumlah_thr', name: 'jumlah_thr', className: 'text-end font-monospace' }, { data: 'jumlah_r13', name: 'jumlah_r13', className: 'text-end font-monospace' }, { data: 'jumlah_publikasi', name: 'jumlah_publikasi', className: 'text-end font-monospace' }, - { data: 'total', name: 'total', className: 'text-end font-monospace fw-bold' } + { data: 'total', name: 'total', className: 'text-end font-monospace fw-bold' }, + // Kolom tersembunyi supaya pencarian tabel juga bisa memakai NIP. + { data: 'nip', name: 'nip', visible: false, searchable: true, orderable: false } ], order: [], language: { -- 2.52.0