Penambahan Filter Jenjang Pendidikan untuk menu P2 dan Simulasi Jabatan
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Helpers\JenjangPendidikanHelper;
|
||||
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
||||
use App\Models\Verifikator\JabatanPegawai;
|
||||
use App\Models\Verifikator\JabatanTugasTambahanRiwayat;
|
||||
@@ -26,6 +27,7 @@ class P2Export implements FromCollection, ShouldAutoSize, WithColumnFormatting,
|
||||
private readonly ?int $periode,
|
||||
private readonly mixed $unitKerjaId,
|
||||
private readonly ?string $jenisPegawai,
|
||||
private readonly ?string $jenjangPendidikan = null,
|
||||
) {}
|
||||
|
||||
public function title(): string
|
||||
@@ -65,6 +67,10 @@ class P2Export implements FromCollection, ShouldAutoSize, WithColumnFormatting,
|
||||
$query->where('jpd.jenis_pegawai', $this->jenisPegawai);
|
||||
}
|
||||
|
||||
if ($this->jenjangPendidikan !== null && $this->jenjangPendidikan !== '') {
|
||||
JenjangPendidikanHelper::applyQueryFilter($query, 'verifikator.pegawais.pendidikan_terakhir', $this->jenjangPendidikan);
|
||||
}
|
||||
|
||||
$data = $query->get();
|
||||
|
||||
if ($data->isEmpty()) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Helpers\JenjangPendidikanHelper;
|
||||
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
||||
use App\Models\Verifikator\JabatanPegawaiDetail;
|
||||
use App\Models\Verifikator\JabatanTugasTambahanRiwayat;
|
||||
@@ -53,11 +54,12 @@ class SimulasiJabatanExport implements WithMultipleSheets
|
||||
private readonly ?string $jenis = null,
|
||||
private readonly int|string|null $unitKerjaId = null,
|
||||
private readonly bool $grade12 = false,
|
||||
private readonly ?string $jenjangPendidikan = null,
|
||||
) {}
|
||||
|
||||
public function sheets(): array
|
||||
{
|
||||
$rows = SimulasiJabatanSheet::rows($this->periode, $this->bulan, $this->unitKerjaId, $this->jenis, false, $this->grade12);
|
||||
$rows = SimulasiJabatanSheet::rows($this->periode, $this->bulan, $this->unitKerjaId, $this->jenis, false, $this->grade12, false, $this->jenjangPendidikan);
|
||||
$sheets = [new SimulasiJabatanSheet('All', $rows)];
|
||||
foreach ($rows->groupBy(fn ($row) => $row['unit_kerja'] ?: 'Tanpa Unit Kerja') as $unit => $unitRows) {
|
||||
$sheets[] = new SimulasiJabatanSheet($unit, $unitRows->values());
|
||||
@@ -70,12 +72,13 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
||||
{
|
||||
public function __construct(private readonly string $sheetTitle, private readonly Collection $items) {}
|
||||
|
||||
public static function rows(int $periode, ?int $bulan = null, int|string|null $unitKerjaId = null, ?string $jenis = null, bool $raw = false, bool $grade12 = false, bool $splitUnit = false): Collection
|
||||
public static function rows(int $periode, ?int $bulan = null, int|string|null $unitKerjaId = null, ?string $jenis = null, bool $raw = false, bool $grade12 = false, bool $splitUnit = false, ?string $jenjangPendidikan = null): Collection
|
||||
{
|
||||
$q = JabatanPegawaiDetailPoin::query()->select([
|
||||
'verifikator.jabatan_pegawais.nip', 'verifikator.poin_per_bulans.jabatan_pegawai_detail_id',
|
||||
'verifikator.pegawais.nama as nama_pegawai', 'verifikator.jabatan_pegawai_details.jenis_pegawai',
|
||||
'verifikator.pegawais.unit_kerja_nama as unit_kerja', 'verifikator.pegawais.unit_kerja_id',
|
||||
'verifikator.pegawais.pendidikan_terakhir',
|
||||
'verifikator.poin_per_bulans.poin_kegiatan',
|
||||
'verifikator.poin_per_bulans.poin_absen', 'verifikator.poin_per_bulans.poin_skp',
|
||||
'verifikator.poin_per_bulans.poin_grade_14_17', 'verifikator.poin_per_bulans.detail_p2',
|
||||
@@ -113,6 +116,7 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
||||
$q->where('verifikator.pegawais.unit_kerja_id', (int) $unitKerjaId);
|
||||
}
|
||||
if ($jenis) $q->where('verifikator.jabatan_pegawai_details.jenis_pegawai', $jenis);
|
||||
if ($jenjangPendidikan) JenjangPendidikanHelper::applyQueryFilter($q, 'verifikator.pegawais.pendidikan_terakhir', $jenjangPendidikan);
|
||||
$excel = collect(json_decode(file_get_contents(public_path('data-jabatan-excel.json')), true) ?: [])->keyBy(fn ($x) => mb_strtolower(trim($x['nama_jabatan'] ?? '')));
|
||||
$source = $q->get();
|
||||
$details = JabatanPegawaiDetail::with(['fungsional','tambahan'])->whereIn('id', $source->pluck('jabatan_pegawai_detail_id'))->get()->keyBy('id');
|
||||
@@ -297,6 +301,7 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
||||
$out['raw_p2_final_374_g12'] = $final374g12;
|
||||
$out['raw_p2_final_377_g12'] = $final377g12;
|
||||
$out['raw_p2_final_excel_g12'] = $finalExcelg12;
|
||||
$out['raw_pendidikan_terakhir'] = (string) ($r->pendidikan_terakhir ?? '');
|
||||
}
|
||||
|
||||
// Mode gabung (default): satu baris per pegawai — total seluruh unit bayar.
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
|
||||
class JenjangPendidikanHelper
|
||||
{
|
||||
/**
|
||||
* Nilai sentinel untuk kategori "belum diisi" (pendidikan_terakhir NULL/kosong).
|
||||
* Tanpa ini, pegawai yang datanya kosong tidak akan pernah muncul di filter
|
||||
* manapun sehingga jumlah per kategori bisa lebih kecil dari total keseluruhan.
|
||||
*/
|
||||
public const KOSONG = '__KOSONG__';
|
||||
|
||||
public const KOSONG_LABEL = '(Belum Diisi)';
|
||||
|
||||
/**
|
||||
* Daftar jenjang pendidikan unik (sudah dinormalisasi) untuk dropdown filter.
|
||||
*/
|
||||
public static function options(): array
|
||||
{
|
||||
$raw = Pegawai::withoutGlobalScopes()
|
||||
->whereNotNull('pendidikan_terakhir')
|
||||
->distinct()
|
||||
->pluck('pendidikan_terakhir');
|
||||
|
||||
$options = $raw->map(fn ($value) => self::normalize($value))
|
||||
->unique()
|
||||
->sort()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$options[] = self::KOSONG;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/** Angka diploma -> angka romawi setara, dipakai untuk gabungkan "DIII" ke "D3", dst. */
|
||||
private const DIPLOMA_ROMAN = ['2' => 'ii', '3' => 'iii', '4' => 'iv'];
|
||||
|
||||
/**
|
||||
* Gabungkan varian penulisan (mis. "S-1 Adm Publik", "S-1" -> "S1";
|
||||
* "SMA / sederajat", "SMA/SMK" -> "SMA"; "DIII" -> "D3";
|
||||
* "Profesi", "Sp-1" -> "S1") jadi satu kategori.
|
||||
*/
|
||||
public static function normalize(string $value): string
|
||||
{
|
||||
$trimmed = trim($value);
|
||||
|
||||
if (preg_match('/^(Profesi|Sp-?1)\b/i', $trimmed)) {
|
||||
return 'S1';
|
||||
}
|
||||
|
||||
if (preg_match('/^S-?([123])\b/i', $trimmed, $matches)) {
|
||||
return 'S'.$matches[1];
|
||||
}
|
||||
|
||||
if (preg_match('/^SMA\b/i', $trimmed)) {
|
||||
return 'SMA';
|
||||
}
|
||||
|
||||
if (preg_match('/^D-?(2|II|3|III|4|IV)\b/i', $trimmed, $matches)) {
|
||||
$digit = array_search(strtolower($matches[1]), self::DIPLOMA_ROMAN, true) ?: $matches[1];
|
||||
|
||||
return 'D'.$digit;
|
||||
}
|
||||
|
||||
return $trimmed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Terapkan filter jenjang pendidikan ke query builder, mencocokkan seluruh
|
||||
* varian penulisan yang tergabung dalam satu kategori (S1/S2/S3/SMA/D2/D3/D4).
|
||||
*/
|
||||
public static function applyQueryFilter($query, string $column, string $jenjangPendidikan): void
|
||||
{
|
||||
if ($jenjangPendidikan === self::KOSONG) {
|
||||
$query->whereNull($column);
|
||||
} elseif ($jenjangPendidikan === 'S1') {
|
||||
$query->whereRaw("{$column} ~* ?", ['^(s-?1|profesi|sp-?1)']);
|
||||
} elseif (preg_match('/^S([23])$/', $jenjangPendidikan, $matches)) {
|
||||
$query->whereRaw("{$column} ~* ?", ['^s-?'.$matches[1]]);
|
||||
} elseif ($jenjangPendidikan === 'SMA') {
|
||||
$query->whereRaw("{$column} ~* ?", ['^sma']);
|
||||
} elseif (preg_match('/^D([234])$/', $jenjangPendidikan, $matches)) {
|
||||
$roman = self::DIPLOMA_ROMAN[$matches[1]];
|
||||
$query->whereRaw("{$column} ~* ?", ['^d-?('.$matches[1].'|'.$roman.')\y']);
|
||||
} else {
|
||||
$query->where($column, $jenjangPendidikan);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Terapkan filter jenjang pendidikan ke collection di memori (dataset yang
|
||||
* sudah di-cache), dengan nilai per baris yang sudah dinormalisasi lebih dulu.
|
||||
*/
|
||||
public static function applyCollectionFilter(\Illuminate\Support\Collection $rows, string $column, string $jenjangPendidikan): \Illuminate\Support\Collection
|
||||
{
|
||||
$target = $jenjangPendidikan === self::KOSONG ? '' : $jenjangPendidikan;
|
||||
|
||||
return $rows->where($column, $target);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Lainnya\SimulasiJabatan;
|
||||
|
||||
use App\Helpers\JenjangPendidikanHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Verifikator\JabatanPegawaiDetailPoin;
|
||||
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
||||
@@ -24,8 +25,9 @@ class SimulasiJabatanController extends Controller
|
||||
$title = 'Simulasi Jabatan';
|
||||
$periodes = Periode::orderByDesc('id_periode')->get();
|
||||
$periodeNow = optional(Periode::where('status', true)->first())->id_periode;
|
||||
$jenjangPendidikanList = JenjangPendidikanHelper::options();
|
||||
|
||||
return view('lainnya.simulasi-jabatan.index', compact('title', 'periodes', 'periodeNow'));
|
||||
return view('lainnya.simulasi-jabatan.index', compact('title', 'periodes', 'periodeNow', 'jenjangPendidikanList'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +48,10 @@ class SimulasiJabatanController extends Controller
|
||||
$rows = $rows->where('jenis_pegawai', $request->input('jenis_pegawai'));
|
||||
}
|
||||
|
||||
if ($request->filled('jenjang_pendidikan')) {
|
||||
$rows = JenjangPendidikanHelper::applyCollectionFilter($rows, 'jenjang_pendidikan', $request->input('jenjang_pendidikan'));
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
@@ -144,6 +150,9 @@ class SimulasiJabatanController extends Controller
|
||||
if ($request->filled('jenis_pegawai')) {
|
||||
$rows = $rows->where('jenis_pegawai', $request->input('jenis_pegawai'));
|
||||
}
|
||||
if ($request->filled('jenjang_pendidikan')) {
|
||||
$rows = JenjangPendidikanHelper::applyCollectionFilter($rows, 'jenjang_pendidikan', $request->input('jenjang_pendidikan'));
|
||||
}
|
||||
|
||||
$parse = fn ($value) => (float) str_replace(',', '.', str_replace('.', '', (string) $value));
|
||||
|
||||
@@ -199,7 +208,9 @@ class SimulasiJabatanController extends Controller
|
||||
*/
|
||||
public static function datasetCacheKey(int $periode, bool $splitUnit = false): string
|
||||
{
|
||||
return "simulasi-jabatan:dataset:{$periode}".($splitUnit ? ':split-unit' : '');
|
||||
// v3: aturan normalisasi jenjang_pendidikan berubah (mis. Profesi/Sp-1 -> S1,
|
||||
// DIII -> D3) — versi dinaikkan supaya cache lama tidak dipakai ulang.
|
||||
return "simulasi-jabatan:dataset:v3:{$periode}".($splitUnit ? ':split-unit' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,6 +292,7 @@ class SimulasiJabatanController extends Controller
|
||||
'nip' => $nip,
|
||||
'nama_pegawai' => $row['nama_pegawai'],
|
||||
'jenis_pegawai' => mb_strtolower((string) $row['jenis_pegawai']),
|
||||
'jenjang_pendidikan' => JenjangPendidikanHelper::normalize((string) ($row['raw_pendidikan_terakhir'] ?? '')),
|
||||
'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,
|
||||
@@ -312,9 +324,10 @@ class SimulasiJabatanController extends Controller
|
||||
$periode = (int) ($request->input('periode') ?: optional(Periode::where('status', true)->first())->id_periode);
|
||||
$jenis = $request->input('jenis_pegawai') ?: null;
|
||||
$unitKerjaId = $request->input('unit_kerja_id') ?: null;
|
||||
$jenjangPendidikan = $request->input('jenjang_pendidikan') ?: null;
|
||||
$grade12 = $request->boolean('grade12');
|
||||
$suffix = ($unitKerjaId ? '-unit'.$unitKerjaId : '').($grade12 ? '-grade12' : '');
|
||||
return Excel::download(new SimulasiJabatanExport($periode, null, $jenis, $unitKerjaId, $grade12), 'simulasi-jabatan-'.$periode.$suffix.'.xlsx');
|
||||
return Excel::download(new SimulasiJabatanExport($periode, null, $jenis, $unitKerjaId, $grade12, $jenjangPendidikan), 'simulasi-jabatan-'.$periode.$suffix.'.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Perhitungan\Remunerasi;
|
||||
|
||||
use App\Exports\P2Export;
|
||||
use App\Helpers\JabatanPegawaiTambahanHelper;
|
||||
use App\Helpers\JenjangPendidikanHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Perhitungan\PlenoPenunjang\RasioP2Controller;
|
||||
use App\Models\Verifikator\Periode;
|
||||
@@ -39,8 +40,9 @@ class P2Controller extends Controller
|
||||
$team = Team::find(session('team_id'));
|
||||
$periodes = Periode::orderBy('id_periode', 'desc')->get();
|
||||
$periodeNow = Periode::where('status', true)->first()?->id_periode;
|
||||
$jenjangPendidikanList = JenjangPendidikanHelper::options();
|
||||
|
||||
return view('perhitungan.remunerasi.p2.index', compact('title', 'team', 'periodes', 'periodeNow'));
|
||||
return view('perhitungan.remunerasi.p2.index', compact('title', 'team', 'periodes', 'periodeNow', 'jenjangPendidikanList'));
|
||||
}
|
||||
|
||||
public function data(Request $request): JsonResponse
|
||||
@@ -53,9 +55,9 @@ class P2Controller extends Controller
|
||||
return DataTables::of(collect([]))->make();
|
||||
}
|
||||
|
||||
[$unitKerjaId, $jenisPegawai, $periode] = $this->resolveFilters($request, $team);
|
||||
[$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan] = $this->resolveFilters($request, $team);
|
||||
|
||||
$query = $this->buildQuery($periode, $unitKerjaId, $jenisPegawai);
|
||||
$query = $this->buildQuery($periode, $unitKerjaId, $jenisPegawai, $jenjangPendidikan);
|
||||
|
||||
return DataTables::of($query)
|
||||
->editColumn('nip', fn ($row) => ltrim($row->nip ?? '', "'"))
|
||||
@@ -75,7 +77,7 @@ class P2Controller extends Controller
|
||||
|
||||
$team = Team::find(session('team_id'));
|
||||
|
||||
[$unitKerjaId, $jenisPegawai, $periode] = $this->resolveFilters($request, $team);
|
||||
[$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan] = $this->resolveFilters($request, $team);
|
||||
|
||||
$periodeNama = Periode::where('id_periode', $periode)->first()?->nama ?? $periode;
|
||||
$unitNama = $unitKerjaId !== null && $unitKerjaId !== '' ? (UnitKerja::find($unitKerjaId)?->nama ?? 'Semua Unit') : 'Semua Unit';
|
||||
@@ -85,7 +87,7 @@ class P2Controller extends Controller
|
||||
.'_'.str_replace(['/', ' ', '.'], '_', $unitNama)
|
||||
.$jenisPegawaiNama.'.xlsx';
|
||||
|
||||
return Excel::download(new P2Export($periode, $unitKerjaId, $jenisPegawai), $filename);
|
||||
return Excel::download(new P2Export($periode, $unitKerjaId, $jenisPegawai, $jenjangPendidikan), $filename);
|
||||
}
|
||||
|
||||
public function detail(Request $request, string $nip): View
|
||||
@@ -117,11 +119,12 @@ class P2Controller extends Controller
|
||||
$periodeNow = Periode::where('status', true)->first()?->id_periode;
|
||||
$periode = $request->periode ?? $periodeNow;
|
||||
$jenisPegawai = $request->jenis_pegawai ?: null;
|
||||
$jenjangPendidikan = $request->jenjang_pendidikan ?: null;
|
||||
|
||||
return [$unitKerjaId, $jenisPegawai, $periode];
|
||||
return [$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan];
|
||||
}
|
||||
|
||||
private function buildQuery(mixed $periode, mixed $unitKerjaId, ?string $jenisPegawai)
|
||||
private function buildQuery(mixed $periode, mixed $unitKerjaId, ?string $jenisPegawai, ?string $jenjangPendidikan = null)
|
||||
{
|
||||
$fakultasIds = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
@@ -133,6 +136,7 @@ class P2Controller extends Controller
|
||||
->select(['verifikator.pegawais.nip', 'verifikator.pegawais.nama'])
|
||||
->selectRaw('MAX(ukp.nama) as nama_unit')
|
||||
->selectRaw('MAX(jpd.jenis_pegawai) as jenis_pegawai')
|
||||
->selectRaw('MAX(verifikator.pegawais.pendidikan_terakhir) as jenjang_pendidikan')
|
||||
->selectRaw('SUM(rpb.p2_bruto) as total_p2_bruto')
|
||||
->selectRaw('SUM(rpb.p2_bruto) - SUM(rpb.p2_netto) as total_p2_pajak')
|
||||
->selectRaw('SUM(rpb.p2_netto) as total_p2_netto')
|
||||
@@ -151,6 +155,10 @@ class P2Controller extends Controller
|
||||
$query->where('jpd.jenis_pegawai', $jenisPegawai);
|
||||
}
|
||||
|
||||
if ($jenjangPendidikan !== null && $jenjangPendidikan !== '') {
|
||||
JenjangPendidikanHelper::applyQueryFilter($query, 'verifikator.pegawais.pendidikan_terakhir', $jenjangPendidikan);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user