Penambahan Pemisahan Unit Pembayaran di Simulasi Jabatan
This commit is contained in:
@@ -59,14 +59,15 @@ class SimulasiJabatanController extends Controller
|
||||
// Seluruh dataset (perhitungan berat) dibangun sekali lalu di-cache.
|
||||
// Filter unit kerja / jenis pegawai / pencarian + paginasi dilakukan
|
||||
// di memori supaya tiap request berikutnya nyaris tanpa beban DB.
|
||||
$rows = $this->applyUnitJenisFilter($this->dataset($periode), $request);
|
||||
$splitUnit = $request->boolean('split_unit');
|
||||
$rows = $this->applyUnitJenisFilter($this->dataset($periode, $splitUnit), $request);
|
||||
$recordsTotal = $rows->count();
|
||||
|
||||
if ($search !== '') {
|
||||
$needle = mb_strtolower($search);
|
||||
$rows = $rows->filter(function ($row) use ($needle) {
|
||||
foreach (['nama_pegawai', 'nip', 'unit_kerja', 'jenis_pegawai'] as $field) {
|
||||
if (str_contains(mb_strtolower((string) $row[$field]), $needle)) {
|
||||
foreach (['nama_pegawai', 'nip', 'unit_kerja', 'jenis_pegawai', 'unit_pembayaran'] as $field) {
|
||||
if (str_contains(mb_strtolower((string) ($row[$field] ?? '')), $needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -110,12 +111,13 @@ class SimulasiJabatanController extends Controller
|
||||
$periode = (int) ($request->input('periode') ?: optional(Periode::where('status', true)->first())->id_periode);
|
||||
$search = trim((string) $request->input('search'));
|
||||
|
||||
$rows = $this->applyUnitJenisFilter($this->dataset($periode), $request);
|
||||
$rows = $this->applyUnitJenisFilter($this->dataset($periode, $request->boolean('split_unit')), $request);
|
||||
if ($search !== '') {
|
||||
$needle = mb_strtolower($search);
|
||||
$rows = $rows->filter(fn ($row) => str_contains(mb_strtolower((string) $row['nama_pegawai']), $needle)
|
||||
|| str_contains(mb_strtolower((string) $row['nip']), $needle)
|
||||
|| str_contains(mb_strtolower((string) $row['unit_kerja']), $needle));
|
||||
|| str_contains(mb_strtolower((string) $row['unit_kerja']), $needle)
|
||||
|| str_contains(mb_strtolower((string) ($row['unit_pembayaran'] ?? '')), $needle));
|
||||
}
|
||||
|
||||
$parse = fn ($value) => (float) str_replace(',', '.', str_replace('.', '', $value));
|
||||
@@ -194,9 +196,9 @@ class SimulasiJabatanController extends Controller
|
||||
* sudah menjumlah seluruh bulan jabatan pada periode tersebut. Hasilnya
|
||||
* berupa collection ter-key berdasarkan NIP.
|
||||
*/
|
||||
public static function datasetCacheKey(int $periode): string
|
||||
public static function datasetCacheKey(int $periode, bool $splitUnit = false): string
|
||||
{
|
||||
return "simulasi-jabatan:dataset:{$periode}";
|
||||
return "simulasi-jabatan:dataset:{$periode}".($splitUnit ? ':split-unit' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,9 +210,11 @@ class SimulasiJabatanController extends Controller
|
||||
@set_time_limit(300);
|
||||
$periode = (int) ($request->input('periode') ?: optional(Periode::where('status', true)->first())->id_periode);
|
||||
|
||||
Cache::forget(self::datasetCacheKey($periode));
|
||||
Cache::forget(self::datasetCacheKey($periode, false));
|
||||
Cache::forget(self::datasetCacheKey($periode, true));
|
||||
$start = microtime(true);
|
||||
$rows = $this->dataset($periode);
|
||||
$rows = $this->dataset($periode, false);
|
||||
$this->dataset($periode, true);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
@@ -220,9 +224,9 @@ class SimulasiJabatanController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function dataset(int $periode): \Illuminate\Support\Collection
|
||||
public function dataset(int $periode, bool $splitUnit = false): \Illuminate\Support\Collection
|
||||
{
|
||||
$key = self::datasetCacheKey($periode);
|
||||
$key = self::datasetCacheKey($periode, $splitUnit);
|
||||
|
||||
if ($cached = Cache::get($key)) {
|
||||
return $cached;
|
||||
@@ -231,12 +235,12 @@ class SimulasiJabatanController extends Controller
|
||||
// Halaman memuat tabel + kartu ringkasan sekaligus; keduanya butuh
|
||||
// dataset yang sama. Lock supaya proses berat hanya berjalan sekali
|
||||
// saat cache dingin, request lain menunggu lalu memakai hasilnya.
|
||||
return Cache::lock($key.':lock', 180)->block(185, function () use ($key, $periode) {
|
||||
return Cache::remember($key, now()->addMinutes(30), fn () => $this->buildDataset($periode));
|
||||
return Cache::lock($key.':lock', 180)->block(185, function () use ($key, $periode, $splitUnit) {
|
||||
return Cache::remember($key, now()->addMinutes(30), fn () => $this->buildDataset($periode, $splitUnit));
|
||||
});
|
||||
}
|
||||
|
||||
private function buildDataset(int $periode): \Illuminate\Support\Collection
|
||||
private function buildDataset(int $periode, bool $splitUnit = false): \Illuminate\Support\Collection
|
||||
{
|
||||
// Pastikan file kelas ekspor (yang juga mendefinisikan
|
||||
// SimulasiJabatanSheet) sudah ter-autoload.
|
||||
@@ -244,7 +248,7 @@ class SimulasiJabatanController extends Controller
|
||||
|
||||
$format = fn ($value) => number_format((float) $value, 2, ',', '.');
|
||||
|
||||
return \App\Exports\SimulasiJabatanSheet::rows($periode, null, null, null, true)->mapWithKeys(function ($row) use ($format) {
|
||||
return \App\Exports\SimulasiJabatanSheet::rows($periode, null, null, null, true, false, $splitUnit)->mapWithKeys(function ($row) use ($format, $splitUnit) {
|
||||
$nip = ltrim((string) $row['nip'], "'");
|
||||
|
||||
// Bila perhitungan Remunerasi sudah ada: pakai nilai P2 riil (satu
|
||||
@@ -269,12 +273,17 @@ class SimulasiJabatanController extends Controller
|
||||
$p2_excel = $p2_excel_g12 = $row['total_p2_jf_excel'] + $row['total_p2_jtt_excel'] + $adhocHargaP2;
|
||||
}
|
||||
|
||||
return [$nip => [
|
||||
$unitPembayaranId = $row['unit_pembayaran_id'] ?? null;
|
||||
$key = $splitUnit && $unitPembayaranId !== null ? $nip.'|'.$unitPembayaranId : $nip;
|
||||
|
||||
return [$key => [
|
||||
'nip' => $nip,
|
||||
'nama_pegawai' => $row['nama_pegawai'],
|
||||
'jenis_pegawai' => mb_strtolower((string) $row['jenis_pegawai']),
|
||||
'unit_kerja' => $row['unit_kerja'] === 'Tanpa Unit Kerja' ? '' : $row['unit_kerja'],
|
||||
'unit_kerja_id' => (int) $row['raw_unit_kerja_id'],
|
||||
'unit_pembayaran' => $row['unit_pembayaran'] ?? null,
|
||||
'unit_pembayaran_id' => $unitPembayaranId,
|
||||
'grade12_eligible' => (bool) ($row['raw_grade12_eligible'] ?? false),
|
||||
'poin_kegiatan' => $format($row['raw_poin_kegiatan']),
|
||||
'poin_adhoc' => $format($row['raw_poin_adhoc']),
|
||||
@@ -314,7 +323,7 @@ class SimulasiJabatanController extends Controller
|
||||
* (di luar porsi Adhoc yang tarifnya tetap); versi 374 & Excel diskala menurut
|
||||
* rasio harga jabatan. Return null bila data Remunerasi belum ada (pakai cara lama).
|
||||
*/
|
||||
private function detailFromRemun(Pegawai $pegawai, int $periode, bool $grade12 = false): ?\Illuminate\Http\JsonResponse
|
||||
private function detailFromRemun(Pegawai $pegawai, int $periode, bool $grade12 = false, int|string|null $unitPembayaran = null): ?\Illuminate\Http\JsonResponse
|
||||
{
|
||||
$jp = JabatanPegawai::with(['detail.fungsional', 'detail.tambahan', 'detail.poin'])
|
||||
->where('nip', $pegawai->nip)->where('periode', $periode)->where('active', true)->first();
|
||||
@@ -324,9 +333,15 @@ class SimulasiJabatanController extends Controller
|
||||
}
|
||||
$isTendik = mb_strtolower((string) ($jp->detail->first()->jenis_pegawai ?? $pegawai->jenis_pegawai)) === 'tendik';
|
||||
|
||||
// Bila dibuka dari baris "pecah per unit pembayaran": batasi rincian ke
|
||||
// remunerasi yang dibayar unit tsb saja.
|
||||
$unitScoped = $unitPembayaran !== null && $unitPembayaran !== '';
|
||||
$unitId = (int) $unitPembayaran;
|
||||
|
||||
$rpb = DB::table('verifikator.remunerasi_per_bulans')
|
||||
->whereIn('jabatan_pegawai_detail_id', $jp->detail->pluck('id')->all())
|
||||
->whereNull('deleted_at')
|
||||
->when($unitScoped, fn ($q) => $q->where('unit_pembayaran_id', $unitId))
|
||||
->selectRaw('jabatan_pegawai_detail_id, SUM(poin_p2) as poin_p2, SUM(p2_bruto) as p2_bruto')
|
||||
->groupBy('jabatan_pegawai_detail_id')
|
||||
->get()->keyBy('jabatan_pegawai_detail_id');
|
||||
@@ -334,6 +349,13 @@ class SimulasiJabatanController extends Controller
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($unitScoped) {
|
||||
$jp->setRelation('detail', $jp->detail->filter(fn ($d) => $rpb->has($d->id))->values());
|
||||
if ($jp->detail->isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$excel = collect(json_decode(file_get_contents(public_path('data-jabatan-excel.json')), true) ?: [])
|
||||
->keyBy(fn ($x) => mb_strtolower(trim($x['nama_jabatan'] ?? '')));
|
||||
$jfRiw = fn ($id, $p, $col = 'harga') => $id ? (JabatanFungsionalRiwayat::where('jabatan_fungsional_id', $id)->where('periode', $p)->value($col)) : null;
|
||||
@@ -350,15 +372,21 @@ class SimulasiJabatanController extends Controller
|
||||
$eligibleG12 = $grade12 && ! $isTendik && ! $is1417($gJf) && ! $is1417($gJtt);
|
||||
|
||||
$adhocRows = collect();
|
||||
$data = $jp->detail->sortBy('bulan')->values()->map(function ($d) use ($rpb, $excel, $jfRiw, $jttRiw, $fmt, $isTendik, $eligibleG12, &$adhocRows) {
|
||||
$data = $jp->detail->sortBy('bulan')->values()->map(function ($d) use ($rpb, $excel, $jfRiw, $jttRiw, $fmt, $isTendik, $eligibleG12, $unitScoped, $unitId, &$adhocRows) {
|
||||
$r = $rpb->get($d->id);
|
||||
$poinP2 = $r ? (float) $r->poin_p2 : 0.0;
|
||||
$bruto377 = $r ? (float) $r->p2_bruto : 0.0;
|
||||
|
||||
// Porsi Adhoc bulan ini (tarif tetap Rp 660.000, tidak diskala harga jabatan).
|
||||
// detail_p2 dikelompokkan per unit pembayaran; saat baris dibuka dari
|
||||
// mode "pecah per unit", hanya adhoc unit tsb yang dihitung.
|
||||
$poin = $d->poin;
|
||||
$dp = is_string($poin?->detail_p2) ? json_decode($poin->detail_p2, true) : ($poin?->detail_p2 ?? []);
|
||||
$adhocPoin = collect($dp ?: [])->sum(fn ($u) => collect($u['adhoc_kegiatan'] ?? [])->sum('poin_p2'));
|
||||
$dp = $dp ?: [];
|
||||
if ($unitScoped) {
|
||||
$dp = array_key_exists($unitId, $dp) ? [$unitId => $dp[$unitId]] : [];
|
||||
}
|
||||
$adhocPoin = collect($dp)->sum(fn ($u) => collect($u['adhoc_kegiatan'] ?? [])->sum('poin_p2'));
|
||||
// Porsi Adhoc dikunci maksimal sebesar P2 bulan itu (kasus kontrak/non-PNS).
|
||||
$adhocHarga = min((float) $adhocPoin * 660000 / 6, $bruto377);
|
||||
if ($adhocPoin > 0) {
|
||||
@@ -440,7 +468,8 @@ class SimulasiJabatanController extends Controller
|
||||
|
||||
// Rincian mengikuti aturan Remunerasi > P2 bila datanya sudah ada.
|
||||
// Jatuh ke perhitungan lama hanya bila Remunerasi belum dihitung.
|
||||
if ($fromRemun = $this->detailFromRemun($pegawai, $periode, $request->boolean('grade12'))) {
|
||||
$unitPembayaran = $request->boolean('split_unit') ? $request->input('unit') : null;
|
||||
if ($fromRemun = $this->detailFromRemun($pegawai, $periode, $request->boolean('grade12'), $unitPembayaran)) {
|
||||
return $fromRemun;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user