Penambahan Pemisahan Unit Pembayaran di Simulasi Jabatan
This commit is contained in:
@@ -33,6 +33,20 @@ class SimulasiJabatanExport implements WithMultipleSheets
|
||||
/** Plafon Total Poin (basis P2) per pegawai; rumus P2 memakai min(68, ...). */
|
||||
public const TOTAL_POIN_MAX = 68;
|
||||
|
||||
/** Nama unit pembayaran (verifikator.remunerasi_per_bulans.unit_pembayaran_id). */
|
||||
public const UNIT_PEMBAYARAN_LABELS = [
|
||||
0 => 'Universitas',
|
||||
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',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly int $periode,
|
||||
private readonly ?int $bulan = null,
|
||||
@@ -56,7 +70,7 @@ 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): 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): Collection
|
||||
{
|
||||
$q = JabatanPegawaiDetailPoin::query()->select([
|
||||
'verifikator.jabatan_pegawais.nip', 'verifikator.poin_per_bulans.jabatan_pegawai_detail_id',
|
||||
@@ -122,6 +136,21 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
||||
->selectRaw('rd.jabatan_pegawai_id, SUM(rpb.poin_p2) as poin_p2_sum, SUM(rpb.p2_bruto) as p2_bruto_sum')
|
||||
->get()->keyBy('jabatan_pegawai_id');
|
||||
|
||||
// Untuk mode "pecah per Unit Pembayaran": porsi P2 (p2_bruto) per unit
|
||||
// pembayaran, dipakai sebagai bobot pembagian baris pegawai jadi
|
||||
// beberapa baris (satu per unit bayar). Nilai poin tetap utuh; hanya
|
||||
// kolom nominal (rupiah) yang diskala menurut porsi tiap unit.
|
||||
$remunByUnit = collect();
|
||||
if ($splitUnit) {
|
||||
$remunByUnit = DB::table('verifikator.remunerasi_per_bulans as rpb')
|
||||
->join('verifikator.jabatan_pegawai_details as rd', 'rpb.jabatan_pegawai_detail_id', '=', 'rd.id')
|
||||
->whereIn('rd.jabatan_pegawai_id', $details->pluck('jabatan_pegawai_id')->filter()->unique()->all())
|
||||
->whereNull('rpb.deleted_at')
|
||||
->groupBy('rd.jabatan_pegawai_id', 'rpb.unit_pembayaran_id')
|
||||
->selectRaw('rd.jabatan_pegawai_id, rpb.unit_pembayaran_id, SUM(rpb.p2_bruto) as bruto')
|
||||
->get()->groupBy('jabatan_pegawai_id');
|
||||
}
|
||||
|
||||
// Poin Adhoc (tarif tetap Rp 660.000, tidak ikut skala harga jabatan)
|
||||
// dijumlahkan lintas seluruh bulan pada periode, per NIP.
|
||||
$adhocByNip = JabatanPegawaiDetailPoin::query()
|
||||
@@ -137,7 +166,7 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
||||
return collect($dp ?: [])->sum(fn ($u) => collect($u['adhoc_kegiatan'] ?? [])->sum('poin_p2'));
|
||||
}));
|
||||
|
||||
return $source->map(function ($r) use ($excel, $details, $monthCounts, $jfPrices, $jttPrices, $remunSums, $adhocByNip, $raw, $grade12) {
|
||||
return $source->flatMap(function ($r) use ($excel, $details, $monthCounts, $jfPrices, $jttPrices, $remunSums, $adhocByNip, $raw, $grade12, $splitUnit, $remunByUnit) {
|
||||
$d = $details->get($r->jabatan_pegawai_detail_id);
|
||||
$price = function ($id, $model, $period) use ($jfPrices, $jttPrices) { return $id ? (float) (($model === JabatanFungsionalRiwayat::class ? $jfPrices : $jttPrices)->get($id.'-'.$period)?->harga ?? 0) : 0; };
|
||||
$jf374=$price($d?->jabatan_fungsional_id, JabatanFungsionalRiwayat::class,374); $jf377=$price($d?->jabatan_fungsional_id,JabatanFungsionalRiwayat::class,377);
|
||||
@@ -269,7 +298,41 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
||||
$out['raw_p2_final_377_g12'] = $final377g12;
|
||||
$out['raw_p2_final_excel_g12'] = $finalExcelg12;
|
||||
}
|
||||
return $out;
|
||||
|
||||
// Mode gabung (default): satu baris per pegawai — total seluruh unit bayar.
|
||||
if (! $splitUnit || ! $hasRemun) {
|
||||
return [$out];
|
||||
}
|
||||
|
||||
// Mode pecah: satu baris per unit pembayaran. Kolom nominal diskala
|
||||
// menurut porsi p2_bruto unit tsb; kolom poin tetap utuh (poin milik
|
||||
// pegawai, bukan milik unit bayar).
|
||||
$units = $remunByUnit->get($d?->jabatan_pegawai_id);
|
||||
$totalBruto = $units ? (float) $units->sum('bruto') : 0.0;
|
||||
if (! $units || $totalBruto <= 0) {
|
||||
return [$out];
|
||||
}
|
||||
$moneyKeys = [
|
||||
'p2_jf_374', 'total_p2_jf_374', 'p2_jf_377', 'total_p2_jf_377', 'p2_jf_excel', 'total_p2_jf_excel',
|
||||
'p2_jtt_374', 'total_p2_jtt_374', 'p2_jtt_377', 'total_p2_jtt_377', 'p2_jtt_excel', 'total_p2_jtt_excel',
|
||||
'raw_adhoc_p2', 'raw_p2_final_374', 'raw_p2_final_377', 'raw_p2_final_excel',
|
||||
'raw_p2_final_374_g12', 'raw_p2_final_377_g12', 'raw_p2_final_excel_g12',
|
||||
];
|
||||
|
||||
return $units->sortBy('unit_pembayaran_id')->map(function ($u) use ($out, $totalBruto, $moneyKeys) {
|
||||
$share = (float) $u->bruto / $totalBruto;
|
||||
$row = $out;
|
||||
foreach ($moneyKeys as $k) {
|
||||
if (array_key_exists($k, $row) && is_numeric($row[$k])) {
|
||||
$row[$k] = round((float) $row[$k] * $share, 2);
|
||||
}
|
||||
}
|
||||
$row['unit_pembayaran_id'] = (int) $u->unit_pembayaran_id;
|
||||
$row['unit_pembayaran'] = SimulasiJabatanExport::UNIT_PEMBAYARAN_LABELS[(int) $u->unit_pembayaran_id]
|
||||
?? ('Unit '.$u->unit_pembayaran_id);
|
||||
|
||||
return $row;
|
||||
})->values()->all();
|
||||
});
|
||||
}
|
||||
public function collection() { $rows=$this->items->map(fn($r)=>array_values($r)); $total=array_fill_keys(array_keys($this->items->first() ?? []),''); foreach($this->items as $item) foreach($item as $key=>$value) if(is_numeric($value)) $total[$key]=(float)($total[$key] === '' ? 0 : $total[$key])+(float)$value; $total['nama_pegawai']='TOTAL'; return $rows->push(array_values($total)); }
|
||||
|
||||
Reference in New Issue
Block a user