Penambahan Detail P1 Export

This commit is contained in:
Ariyutta
2026-09-28 12:38:46 +07:00
parent d01d4b090c
commit c21910fb7c
2 changed files with 120 additions and 54 deletions
@@ -108,25 +108,39 @@ class KeseluruhanController extends Controller
private function buildRekap(int $tahun, ?string $jenisPegawai): Collection
{
$cacheKey = 'remunerasi_keseluruhan_v1_'.$tahun.'_'.($jenisPegawai ?: 'semua');
$cacheKey = 'remunerasi_keseluruhan_v2_'.$tahun.'_'.($jenisPegawai ?: 'semua');
return collect(Cache::remember($cacheKey, now()->addHours(6), fn () => $this->computeRekap($tahun, $jenisPegawai)));
}
/**
* Bulan terakhir yang diikutkan dalam akumulasi P1 "Januari - Sekarang": bulan berjalan kalau
* tahun yang dipilih adalah tahun sekarang, atau Desember kalau tahun yang dipilih sudah lewat.
* Dipakai bersama oleh computeRekap() dan KeseluruhanExport supaya jumlah kolom bulanan konsisten.
*/
public function getBulanTerakhir(int $tahun): int
{
return $tahun === (int) now()->year ? (int) now()->month : 12;
}
private function computeRekap(int $tahun, ?string $jenisPegawai): array
{
$normalize = fn ($nip) => preg_replace("/['.\-]/", '', (string) $nip);
// 1. P1 = akumulasi Januari s.d. bulan berjalan (atau Desember untuk tahun yang sudah lewat)
$bulanTerakhir = $tahun === (int) now()->year ? (int) now()->month : 12;
$bulanTerakhir = $this->getBulanTerakhir($tahun);
$p1 = P1::query()
$p1Rows = P1::query()
->where('tahun', $tahun)
->whereBetween('bulan', [1, $bulanTerakhir])
->when($jenisPegawai, fn ($q) => $q->whereRaw('LOWER(jenis_pegawai) = ?', [strtolower($jenisPegawai)]))
->get()
->groupBy(fn ($row) => $normalize($row->nip))
->map(fn ($rows) => (float) $rows->sum('gaji_yang_dibayarkan'));
->groupBy(fn ($row) => $normalize($row->nip));
$p1 = $p1Rows->map(fn ($rows) => (float) $rows->sum('gaji_yang_dibayarkan'));
// Rincian per bulan (dipakai untuk breakdown kolom bulanan di export Excel).
$p1Bulanan = $p1Rows->map(fn ($rows) => $rows->groupBy('bulan')->map(fn ($bulanRows) => (float) $bulanRows->sum('gaji_yang_dibayarkan')));
// 2. P2 = Semester 1 tahun terpilih
$periodeSemester1 = Periode::where('nama', 'LIKE', "%{$tahun} Semester 1%")->value('id_periode');
@@ -211,7 +225,7 @@ class KeseluruhanController extends Controller
->get()
->keyBy(fn ($row) => $normalize($row->nip));
return $allNips->map(function ($nip) use ($pegawaiInfo, $p1, $p2, $thr, $r13, $publikasi, $jenisPegawai) {
return $allNips->map(function ($nip) use ($pegawaiInfo, $p1, $p1Bulanan, $bulanTerakhir, $p2, $thr, $r13, $publikasi, $jenisPegawai) {
$info = $pegawaiInfo->get($nip);
if (! $info) {
@@ -233,6 +247,12 @@ class KeseluruhanController extends Controller
return null;
}
$bulananNip = $p1Bulanan->get($nip);
$jumlahP1Bulanan = [];
for ($bulan = 1; $bulan <= $bulanTerakhir; $bulan++) {
$jumlahP1Bulanan[$bulan] = $bulananNip?->get($bulan, 0.0) ?? 0.0;
}
return [
'nip' => ltrim($info->nip ?? $nip, "'"),
'nama' => $info->nama ?? '-',
@@ -240,6 +260,7 @@ class KeseluruhanController extends Controller
'unit_kerja_id' => $info->unit_kerja_id,
'nama_unit' => $info->nama_unit ?? '-',
'jumlah_p1' => $jumlahP1,
'jumlah_p1_bulanan' => $jumlahP1Bulanan,
'jumlah_p2' => $jumlahP2,
'jumlah_thr' => $jumlahThr,
'jumlah_r13' => $jumlahR13,