Penambahn P1 Dev
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user