Penambahan Bar Chart Simulasi Jabatan

This commit is contained in:
Ariyutta
2026-09-04 13:49:00 +07:00
parent 8057449276
commit b88c7c8a47
3 changed files with 151 additions and 0 deletions
@@ -120,6 +120,65 @@ class SimulasiJabatanController extends Controller
return response()->json($totals->all());
}
/**
* Agregat Total P2 per unit kerja untuk visualisasi grafik batang.
* Pengelompokan mengikuti menu Remunerasi > P2: fakultas 1-9 + "Universitas"
* (seluruh unit non-fakultas). Filter unit kerja diabaikan supaya seluruh
* unit tetap tampil; filter periode & jenis pegawai tetap dihormati.
*/
public function chart(Request $request)
{
@set_time_limit(300);
$periode = (int) ($request->input('periode') ?: optional(Periode::where('status', true)->first())->id_periode);
$rows = $this->dataset($periode);
if ($request->filled('jenis_pegawai')) {
$rows = $rows->where('jenis_pegawai', $request->input('jenis_pegawai'));
}
$parse = fn ($value) => (float) str_replace(',', '.', str_replace('.', '', (string) $value));
$labels = [
1 => 'Fakultas Hukum',
2 => 'Fakultas Ekonomi dan Bisnis',
3 => 'Fakultas Pertanian',
4 => 'Fakultas Teknik',
5 => 'Fakultas Ilmu Sosial dan Ilmu Politik',
6 => 'Fakultas Keguruan dan Ilmu Pendidikan',
7 => 'Fakultas Kehutanan',
8 => 'Fakultas Matematika dan Ilmu Pengetahuan Alam',
9 => 'Fakultas Kedokteran',
SimulasiJabatanExport::UNIT_UNIVERSITAS => 'Universitas',
];
$short = [
1 => 'FH', 2 => 'FEB', 3 => 'FP', 4 => 'FT', 5 => 'FISIP',
6 => 'FKIP', 7 => 'FHUT', 8 => 'FMIPA', 9 => 'FK',
SimulasiJabatanExport::UNIT_UNIVERSITAS => 'UNIV',
];
$groups = collect($labels)->map(function ($nama, $id) use ($rows, $parse, $short) {
$subset = (int) $id === SimulasiJabatanExport::UNIT_UNIVERSITAS
? $rows->whereNotIn('unit_kerja_id', SimulasiJabatanExport::FAKULTAS_IDS)
: $rows->where('unit_kerja_id', (int) $id);
$sum = fn ($key) => round($subset->sum(fn ($r) => $parse($r[$key])), 2);
return [
'unit_kerja' => $nama,
'unit_kerja_short' => $short[$id],
'pegawai' => $subset->count(),
'p2_374' => $sum('p2_total_374'),
'p2_377' => $sum('p2_total_377'),
'p2_excel' => $sum('p2_total_excel'),
'p2_374_g12' => $sum('p2_total_374_g12'),
'p2_377_g12' => $sum('p2_total_377_g12'),
'p2_excel_g12' => $sum('p2_total_excel_g12'),
];
})->values();
return response()->json($groups->all());
}
/**
* Bangun dan cache seluruh baris simulasi untuk satu periode.
*