Files
2026-10-20 10:24:22 +07:00

51 lines
2.2 KiB
PHP

<?php
namespace App\Services\P1Dev;
use App\Models\Rekapitulasi\P1Dev as P1;
use App\Models\Rekapitulasi\P1Penyesuaian;
use App\Models\Verifikator\JabatanFungsional;
use App\Models\Verifikator\JabatanTugasTambahan;
use Illuminate\Support\Facades\DB;
class P1ChangeHistory
{
public function load(string $nip, int $year): array
{
$jf = JabatanFungsional::with('detail')->get()->keyBy('id');
$jtt = JabatanTugasTambahan::with('detail')->get()->keyBy('id');
$paid = DB::connection('sidia')->table('p_satus')->where('nip', $nip)->where('tahun', (string) $year)
->whereNull('deleted_at')->orderByRaw('paid_at IS NOT NULL')->orderBy('id')->get()
->keyBy(fn ($row) => (int) $row->bulan);
$corrections = P1Penyesuaian::where('nip', $nip)->where('tahun', $year)->orderBy('id')->get()
->keyBy(fn ($row) => (int) $row->bulan);
$result = [];
foreach (P1::where('nip', $nip)->where('tahun', $year)->orderBy('bulan')->get() as $record) {
$month = (int) $record->bulan;
$old = $paid->get($month);
$before = $old ? [
'jafung' => $jf->get($old->jafung_id)?->nama ?? '-',
'grade_jafung' => $jf->get($old->jafung_id)?->detail?->grade,
'jtt' => $jtt->get($old->jtt_id)?->nama ?? '-',
'grade_jtt' => $jtt->get($old->jtt_id)?->detail?->grade,
'golongan' => $old->golongan,
'status_pegawai' => $old->status_pegawai,
] : [];
$correction = $corrections->get($month);
if ($correction) {
$before = array_replace($before, $correction->sebelum ?? []);
}
$result[$month] = ['p1_lama' => $before, 'p1_baru' => [
'jafung' => $record->nama_jabatan_fungsional ?: '-',
'grade_jafung' => $record->grade_jabatan_fungsional,
'jtt' => $record->nama_jabatan_tugas_tambahan ?: '-',
'grade_jtt' => $record->grade_jabatan_tugas_tambahan,
'golongan' => $record->golongan,
'status_pegawai' => $record->status_pegawai,
]];
}
return $result;
}
}