first commit
This commit is contained in:
@@ -0,0 +1,571 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Remunerasi;
|
||||
|
||||
use App\Models\Verifikator\KategoriRubrik;
|
||||
use App\Models\Verifikator\Periode;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use App\Services\PerhitunganKegiatanService;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
|
||||
class CekHitungRemunerasiCommand extends Command
|
||||
{
|
||||
protected $signature = 'remunerasi:cek-hitung
|
||||
{--nip= : Filter berdasarkan NIP pegawai}
|
||||
{--unit-pembayaran-id= : Filter berdasarkan unit pembayaran ID}
|
||||
{--periode= : Filter berdasarkan ID periode (default: periode aktif)}';
|
||||
|
||||
protected $description = 'Hitung dan tampilkan remunerasi sementara tanpa menyimpan ke database';
|
||||
|
||||
private const NAMA_BULAN = [
|
||||
1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April',
|
||||
5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus',
|
||||
9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember',
|
||||
];
|
||||
|
||||
private const PENUNJANG_ORDER = [
|
||||
'penunjang_luar_homebase_universitas' => 'Penunjang (LHB Univ)',
|
||||
'penunjang_luar_homebase_fakultas' => 'Penunjang (LHB Fak)',
|
||||
'penunjang_homebase' => 'Penunjang (HB)',
|
||||
];
|
||||
|
||||
/** @var array<int, array{nama: string, limit: float|null}> */
|
||||
private array $penunjangLimits = [];
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$nip = $this->option('nip');
|
||||
$unitPembayaranId = $this->option('unit-pembayaran-id');
|
||||
$unitPembayaranId = $unitPembayaranId !== null ? (int) $unitPembayaranId : null;
|
||||
|
||||
$periode = (int) ($this->option('periode') ?? Periode::where('status', true)->value('id_periode'));
|
||||
|
||||
if (! $periode) {
|
||||
$this->error('Tidak ada periode aktif. Gunakan --periode=<id_periode>.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$bulan = $periode % 2 === 1 ? [1, 2, 3, 4, 5, 6] : [7, 8, 9, 10, 11, 12];
|
||||
|
||||
$this->loadPenunjangLimits();
|
||||
$this->displayHeader($periode, $nip, $unitPembayaranId);
|
||||
|
||||
$nips = $this->resolveNips($nip, $periode, $unitPembayaranId);
|
||||
|
||||
if ($nips->isEmpty()) {
|
||||
$this->warn('Tidak ada pegawai ditemukan untuk filter yang diberikan.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info(sprintf(' Memproses %d pegawai...', $nips->count()));
|
||||
$this->newLine();
|
||||
|
||||
$service = new PerhitunganKegiatanService;
|
||||
$grandTotal = ['bruto' => 0, 'tax' => 0, 'netto' => 0];
|
||||
$num = 0;
|
||||
|
||||
foreach ($nips as $pegawai) {
|
||||
$num++;
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$kegiatans = $service->listKegiatan($pegawai->nip, $periode, $bulan, $unitPembayaranId, false);
|
||||
} catch (Exception) {
|
||||
DB::rollBack();
|
||||
$this->warn(" [{$num}] {$pegawai->nip} - {$pegawai->nama} → Gagal dihitung, dilewati.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
DB::rollBack();
|
||||
|
||||
if (empty($kegiatans)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->displayPegawai($num, $pegawai, $kegiatans, $grandTotal);
|
||||
}
|
||||
|
||||
$this->displayGrandTotal($grandTotal, $num);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function resolveNips(?string $nip, int $periode, ?int $unitPembayaranId)
|
||||
{
|
||||
return Pegawai::query()
|
||||
->select('verifikator.pegawais.nip', 'verifikator.pegawais.nama')
|
||||
->join('verifikator.jabatan_pegawais as jp', 'jp.nip', '=', 'verifikator.pegawais.nip')
|
||||
->join('verifikator.jabatan_pegawai_details as jpd', 'jpd.jabatan_pegawai_id', '=', 'jp.id')
|
||||
->where('jp.periode', $periode)
|
||||
->where('jp.active', true)
|
||||
->when($nip, fn ($q) => $q->where('verifikator.pegawais.nip', $nip))
|
||||
->when($unitPembayaranId !== null && $unitPembayaranId !== 0, fn ($q) => $q->where('jpd.unit_pembayaran_id', $unitPembayaranId))
|
||||
->orderBy('verifikator.pegawais.nip')
|
||||
->distinct()
|
||||
->get();
|
||||
}
|
||||
|
||||
private function displayPegawai(int $num, Pegawai $pegawai, array $kegiatans, array &$grandTotal): void
|
||||
{
|
||||
$this->line(sprintf('<fg=cyan> [%d] %s — %s</>', $num, $pegawai->nip, $pegawai->nama));
|
||||
$this->newLine();
|
||||
|
||||
ksort($kegiatans);
|
||||
|
||||
$unitTotals = [];
|
||||
|
||||
foreach ($kegiatans as $bulan => $data) {
|
||||
$this->displayBulanSection($bulan, $data, $unitTotals);
|
||||
}
|
||||
|
||||
// Filter unit yang ada nilainya
|
||||
$activeUnits = array_filter($unitTotals, fn ($u) => $u['bruto'] > 0);
|
||||
$multiUnit = count($activeUnits) > 1;
|
||||
$totalBruto = $totalTax = $totalNetto = 0;
|
||||
|
||||
$this->line(' <fg=white;options=bold>TOTAL KESELURUHAN</>');
|
||||
|
||||
foreach ($activeUnits as $unitId => $unit) {
|
||||
$label = $multiUnit
|
||||
? sprintf(' [%s] %-30s', $unitId, $unit['nama'])
|
||||
: ' Total ';
|
||||
|
||||
$this->line(sprintf(
|
||||
'<fg=yellow>%s Bruto: Rp %s │ Pajak: Rp %s │ Netto: Rp %s</>',
|
||||
$label,
|
||||
number_format($unit['bruto'], 0, ',', '.'),
|
||||
number_format($unit['tax'], 0, ',', '.'),
|
||||
number_format($unit['netto'], 0, ',', '.'),
|
||||
));
|
||||
$totalBruto += $unit['bruto'];
|
||||
$totalTax += $unit['tax'];
|
||||
$totalNetto += $unit['netto'];
|
||||
}
|
||||
|
||||
$this->line(' ──────────────────────────────────────────────────────────');
|
||||
$this->newLine();
|
||||
|
||||
$grandTotal['bruto'] += $totalBruto;
|
||||
$grandTotal['tax'] += $totalTax;
|
||||
$grandTotal['netto'] += $totalNetto;
|
||||
}
|
||||
|
||||
private function displayBulanSection(int $bulan, array $data, array &$unitTotals): void
|
||||
{
|
||||
$namaBulan = self::NAMA_BULAN[$bulan] ?? "Bulan $bulan";
|
||||
$this->line(sprintf(' <fg=white;options=bold>┌─ %s %s</>', $namaBulan, str_repeat('─', max(0, 50 - mb_strlen($namaBulan)))));
|
||||
|
||||
// Kegiatan detail table
|
||||
$kegiatanRows = $this->buildKegiatanRows($data);
|
||||
|
||||
if (! empty($kegiatanRows)) {
|
||||
$this->table(['#', 'Kegiatan', 'Poin Total', 'Poin Remun', 'Poin P2', 'Nominal (Rp)'], $kegiatanRows);
|
||||
} else {
|
||||
$this->line(' <fg=gray> (Tidak ada kegiatan dengan poin)</>');
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
// Ringkasan poin & batas
|
||||
$this->displayRingkasanPoin($data);
|
||||
|
||||
// P2 per unit (hanya yang non-zero)
|
||||
$units = collect($data['units'] ?? [])->filter(fn ($u) => ($u['p2']['ratio'] ?? 0) > 0);
|
||||
|
||||
if ($units->isNotEmpty()) {
|
||||
foreach ($units as $unit) {
|
||||
$unitId = $unit['id'];
|
||||
|
||||
if (! isset($unitTotals[$unitId])) {
|
||||
$unitTotals[$unitId] = ['nama' => $unit['nama'], 'bruto' => 0, 'tax' => 0, 'netto' => 0];
|
||||
}
|
||||
|
||||
$unitTotals[$unitId]['bruto'] += $unit['p2']['ratio'] ?? 0;
|
||||
$unitTotals[$unitId]['tax'] += $unit['p2']['tax'] ?? 0;
|
||||
$unitTotals[$unitId]['netto'] += $unit['p2']['netto'] ?? 0;
|
||||
|
||||
$rasio = $unit['rasio'] ?? 1;
|
||||
$this->line(sprintf(
|
||||
' <fg=yellow> P2 [%s] %-25s Rasio: %s%% │ Bruto: Rp %s │ Pajak: Rp %s │ Netto: Rp %s</>',
|
||||
$unitId,
|
||||
mb_substr($unit['nama'], 0, 25),
|
||||
number_format($rasio * 100, 0),
|
||||
number_format($unit['p2']['ratio'] ?? 0, 0, ',', '.'),
|
||||
number_format($unit['p2']['tax'] ?? 0, 0, ',', '.'),
|
||||
number_format($unit['p2']['netto'] ?? 0, 0, ',', '.'),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
private function buildKegiatanRows(array $data): array
|
||||
{
|
||||
$grouped = $this->collectKegiatanByGroup($data);
|
||||
|
||||
// Nilai per poin: distribusikan total P2 (ratio) proporsional ke tiap poin_p2 kegiatan
|
||||
$totalP2Ratio = collect($data['units'] ?? [])->sum(fn ($u) => $u['p2']['ratio'] ?? 0);
|
||||
$totalPoinP2Kegiatan = (float) ($data['total_poin']['poin_p2']['kegiatan'] ?? 0);
|
||||
$nilaiPerPoin = $totalPoinP2Kegiatan > 0 ? $totalP2Ratio / $totalPoinP2Kegiatan : 0;
|
||||
|
||||
$rows = [];
|
||||
$isFirstGroup = true;
|
||||
|
||||
foreach ($grouped as $label => $items) {
|
||||
if (empty($items)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $isFirstGroup) {
|
||||
$rows[] = new TableSeparator;
|
||||
}
|
||||
$isFirstGroup = false;
|
||||
|
||||
$num = 0;
|
||||
$rows[] = ['', "<fg=#FF69B4;options=bold> $label </>", '', '', '', ''];
|
||||
|
||||
$currentSubGroup = null;
|
||||
$isFirstSubGroup = true;
|
||||
$groupTotals = ['poin_total' => 0.0, 'poin_remun' => 0.0, 'poin_p2' => 0.0, 'nominal' => 0.0];
|
||||
$subGroupTotals = ['poin_total' => 0.0, 'poin_remun' => 0.0, 'poin_p2' => 0.0, 'nominal' => 0.0, 'count' => 0];
|
||||
|
||||
foreach ($items as $item) {
|
||||
// Sub-group header (mis. per kategori penunjang atau per jenjang)
|
||||
if (($item['sub_group'] ?? null) !== $currentSubGroup) {
|
||||
// Flush subtotal sub-group sebelumnya
|
||||
if ($currentSubGroup !== null && $subGroupTotals['count'] > 0) {
|
||||
$rows[] = $this->buildSubtotalRow("Subtotal {$currentSubGroup}", $subGroupTotals, 'subgroup');
|
||||
$subGroupTotals = ['poin_total' => 0.0, 'poin_remun' => 0.0, 'poin_p2' => 0.0, 'nominal' => 0.0, 'count' => 0];
|
||||
}
|
||||
|
||||
$currentSubGroup = $item['sub_group'] ?? null;
|
||||
|
||||
if ($currentSubGroup !== null) {
|
||||
if (! $isFirstSubGroup) {
|
||||
$rows[] = new TableSeparator;
|
||||
}
|
||||
$isFirstSubGroup = false;
|
||||
|
||||
$limitStr = $item['sub_limit'] !== null
|
||||
? ' <fg=yellow>[Maks: '.(int) $item['sub_limit'].' pengajuan]</>'
|
||||
: '';
|
||||
$rows[] = ['', "<fg=cyan> {$currentSubGroup}{$limitStr}</>", '', '', '', ''];
|
||||
$num = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$num++;
|
||||
$nominal = $item['poin_p2'] * $nilaiPerPoin;
|
||||
$cut = ($item['poin_total'] - $item['poin_remun']) > 0.001;
|
||||
$p1Cut = ! $cut && $item['poin_p2'] < 0.001;
|
||||
|
||||
if ($cut) {
|
||||
$rows[] = [
|
||||
"<fg=red>{$num}</>",
|
||||
'<fg=red>'.$this->truncateName($item['nama']).'</>',
|
||||
'<fg=red>'.number_format($item['poin_total'], 2, ',', '.').'</>',
|
||||
'<fg=red>'.number_format($item['poin_remun'], 2, ',', '.').' ↓</>',
|
||||
'<fg=red>'.number_format($item['poin_p2'], 2, ',', '.').'</>',
|
||||
'<fg=red>'.number_format($nominal, 0, ',', '.').'</>',
|
||||
];
|
||||
} elseif ($p1Cut) {
|
||||
$rows[] = [
|
||||
"<fg=#FFA500>{$num}</>",
|
||||
'<fg=#FFA500>'.$this->truncateName($item['nama']).'</>',
|
||||
'<fg=#FFA500>'.number_format($item['poin_total'], 2, ',', '.').'</>',
|
||||
'<fg=#FFA500>'.number_format($item['poin_remun'], 2, ',', '.').'</>',
|
||||
'<fg=#FFA500>'.number_format($item['poin_p2'], 2, ',', '.').' ↓P1</>',
|
||||
'<fg=#FFA500>'.number_format($nominal, 0, ',', '.').'</>',
|
||||
];
|
||||
} else {
|
||||
$rows[] = [
|
||||
$num,
|
||||
$this->truncateName($item['nama']),
|
||||
number_format($item['poin_total'], 2, ',', '.'),
|
||||
number_format($item['poin_remun'], 2, ',', '.'),
|
||||
number_format($item['poin_p2'], 2, ',', '.'),
|
||||
number_format($nominal, 0, ',', '.'),
|
||||
];
|
||||
}
|
||||
|
||||
$subGroupTotals['poin_total'] += $item['poin_total'];
|
||||
$subGroupTotals['poin_remun'] += $item['poin_remun'];
|
||||
$subGroupTotals['poin_p2'] += $item['poin_p2'];
|
||||
$subGroupTotals['nominal'] += $nominal;
|
||||
$subGroupTotals['count']++;
|
||||
|
||||
$groupTotals['poin_total'] += $item['poin_total'];
|
||||
$groupTotals['poin_remun'] += $item['poin_remun'];
|
||||
$groupTotals['poin_p2'] += $item['poin_p2'];
|
||||
$groupTotals['nominal'] += $nominal;
|
||||
}
|
||||
|
||||
// Flush subtotal sub-group terakhir
|
||||
if ($currentSubGroup !== null && $subGroupTotals['count'] > 0) {
|
||||
$rows[] = $this->buildSubtotalRow("Subtotal {$currentSubGroup}", $subGroupTotals, 'subgroup');
|
||||
}
|
||||
|
||||
// Total per group (kategori)
|
||||
$rows[] = new TableSeparator;
|
||||
$rows[] = $this->buildSubtotalRow("Total {$label}", $groupTotals, 'group');
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** @param array{poin_total: float, poin_remun: float, poin_p2: float, nominal: float} $totals */
|
||||
private function buildSubtotalRow(string $label, array $totals, string $type): array
|
||||
{
|
||||
$color = $type === 'group' ? '#FF69B4' : 'cyan';
|
||||
|
||||
return [
|
||||
'',
|
||||
"<fg={$color};options=bold> {$label} </>",
|
||||
'<fg='.$color.';options=bold>'.number_format($totals['poin_total'], 2, ',', '.').'</>',
|
||||
'<fg='.$color.';options=bold>'.number_format($totals['poin_remun'], 2, ',', '.').'</>',
|
||||
'<fg='.$color.';options=bold>'.number_format($totals['poin_p2'], 2, ',', '.').'</>',
|
||||
'<fg='.$color.';options=bold>'.number_format($totals['nominal'], 0, ',', '.').'</>',
|
||||
];
|
||||
}
|
||||
|
||||
private function collectKegiatanByGroup(array $data): array
|
||||
{
|
||||
// Urutan grup mencerminkan urutan pemotongan di PerhitunganKegiatanService
|
||||
$groups = [
|
||||
'Mengajar (HB)' => [],
|
||||
'Membimbing (HB)' => [],
|
||||
'Menguji (HB)' => [],
|
||||
'Lainnya (HB)' => [],
|
||||
'Mengajar (LHB)' => [],
|
||||
'Membimbing (LHB)' => [],
|
||||
'Menguji (LHB)' => [],
|
||||
'Lainnya (LHB)' => [],
|
||||
'Penunjang (LHB Univ)' => [],
|
||||
'Penunjang (LHB Fak)' => [],
|
||||
'Penunjang (HB)' => [],
|
||||
'Semester Antara (HB)' => [],
|
||||
'Semester Antara (LHB)' => [],
|
||||
];
|
||||
|
||||
// HB Mengajar, Membimbing, Menguji — per jenjang sesuai urutan service
|
||||
foreach (['S1', 'S2', 'S3', 'MKWU'] as $jenjang) {
|
||||
foreach ($data['tri_dharma_homebase']['mengajar'][$jenjang] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Mengajar (HB)', $jenjang);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['Akademik', 'D3', 'PROFESI', 'S1', 'S2', 'S3'] as $jenjang) {
|
||||
foreach ($data['tri_dharma_homebase']['membimbing'][$jenjang] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Membimbing (HB)', $jenjang);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['D3', 'PROFESI', 'S1', 'S2', 'S3'] as $jenjang) {
|
||||
foreach ($data['tri_dharma_homebase']['menguji'][$jenjang] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Menguji (HB)', $jenjang);
|
||||
}
|
||||
}
|
||||
|
||||
// HB Lainnya (Collection langsung, tidak per jenjang)
|
||||
foreach (['mengajarLainnya', 'membimbingLainnya', 'mengujiLainnya', 'pengabdian', 'penelitian', 'asesor', 'reviewer', 'modul'] as $subKey) {
|
||||
foreach ($data['tri_dharma_homebase'][$subKey] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Lainnya (HB)');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data['tri_dharma_homebase']['buku_ajar'] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Buku Ajar (HB)');
|
||||
}
|
||||
|
||||
// LHB Mengajar, Membimbing, Menguji — per jenjang
|
||||
foreach (['S1', 'S2', 'S3', 'MKWU'] as $jenjang) {
|
||||
foreach ($data['tri_dharma_luar_homebase']['mengajar'][$jenjang] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Mengajar (LHB)', $jenjang);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['Akademik', 'D3', 'PROFESI', 'S1', 'S2', 'S3'] as $jenjang) {
|
||||
foreach ($data['tri_dharma_luar_homebase']['membimbing'][$jenjang] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Membimbing (LHB)', $jenjang);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['D3', 'PROFESI', 'S1', 'S2', 'S3'] as $jenjang) {
|
||||
foreach ($data['tri_dharma_luar_homebase']['menguji'][$jenjang] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Menguji (LHB)', $jenjang);
|
||||
}
|
||||
}
|
||||
|
||||
// LHB Lainnya
|
||||
foreach (['mengajarLainnya', 'membimbingLainnya', 'mengujiLainnya', 'pengabdian', 'penelitian'] as $subKey) {
|
||||
foreach ($data['tri_dharma_luar_homebase'][$subKey] ?? [] as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Lainnya (LHB)');
|
||||
}
|
||||
}
|
||||
|
||||
// Penunjang: LHB Univ → LHB Fak → HB (sesuai urutan service)
|
||||
foreach (self::PENUNJANG_ORDER as $key => $groupName) {
|
||||
foreach (collect($data[$key] ?? []) as $item) {
|
||||
$katId = (int) ($item->id_kategori ?? 0);
|
||||
$katInfo = $this->penunjangLimits[$katId] ?? ['nama' => 'Penunjang', 'limit' => null];
|
||||
$this->addItemToGroup($item, $groups, $groupName, $katInfo['nama'], $katInfo['limit'], $katId);
|
||||
}
|
||||
|
||||
usort($groups[$groupName], fn ($a, $b) => ($a['sub_group_order'] ?? 0) <=> ($b['sub_group_order'] ?? 0));
|
||||
}
|
||||
|
||||
// Semester Antara: HB → LHB
|
||||
foreach (collect($data['semester_antara_homebase'] ?? []) as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Semester Antara (HB)');
|
||||
}
|
||||
|
||||
foreach (collect($data['semester_antara_luar_homebase'] ?? []) as $item) {
|
||||
$this->addItemToGroup($item, $groups, 'Semester Antara (LHB)');
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
private function addItemToGroup(
|
||||
mixed $item,
|
||||
array &$groups,
|
||||
string $groupName,
|
||||
?string $subGroup = null,
|
||||
?float $subLimit = null,
|
||||
?int $subGroupOrder = null,
|
||||
): void {
|
||||
if ($item instanceof Collection) {
|
||||
$item = (object) $item->all();
|
||||
}
|
||||
|
||||
$poinTotal = (float) ($item->poin_total ?? 0);
|
||||
|
||||
// Tampilkan semua item yang punya poin_total > 0, termasuk yang dipotong ke 0
|
||||
if ($poinTotal == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rawNama = $item->nama_kegiatan ?? $item->kegiatan?->nama_kegiatan ?? $item->nama ?? $item->judul ?? '-';
|
||||
|
||||
$groups[$groupName][] = [
|
||||
'nama' => preg_replace('/\s+/', ' ', trim((string) $rawNama)),
|
||||
'poin_total' => $poinTotal,
|
||||
'poin_remun' => (float) ($item->poin_remunerasi ?? 0),
|
||||
'poin_p2' => (float) ($item->poin_p2 ?? 0),
|
||||
'sub_group' => $subGroup,
|
||||
'sub_limit' => $subLimit,
|
||||
'sub_group_order' => $subGroupOrder,
|
||||
];
|
||||
}
|
||||
|
||||
private function truncateName(string $nama, int $max = 50): string
|
||||
{
|
||||
if (mb_strlen($nama) <= $max) {
|
||||
return $nama;
|
||||
}
|
||||
|
||||
return mb_substr($nama, 0, $max - 3).'...';
|
||||
}
|
||||
|
||||
private function loadPenunjangLimits(): void
|
||||
{
|
||||
$this->penunjangLimits = KategoriRubrik::with('limitPenunjang')
|
||||
->get()
|
||||
->keyBy('id')
|
||||
->map(fn ($k) => [
|
||||
'nama' => $k->nama ?? '-',
|
||||
'limit' => $k->limitPenunjang?->limit !== null ? (float) $k->limitPenunjang->limit : null,
|
||||
])
|
||||
->all();
|
||||
}
|
||||
|
||||
private function displayRingkasanPoin(array $data): void
|
||||
{
|
||||
$totalPoin = $data['total_poin'] ?? [];
|
||||
$poinRemun = $totalPoin['poin_remunerasi'] ?? [];
|
||||
$poinP2 = $totalPoin['poin_p2'] ?? [];
|
||||
$limitKegiatan = $totalPoin['limit']['poin_kegiatan'] ?? null;
|
||||
$jenis = $data['jenis_pegawai'] ?? 'dosen';
|
||||
$cap = $jenis === 'dosen' ? 68 : 54;
|
||||
|
||||
$totalRemun = array_sum($poinRemun);
|
||||
$totalP2 = array_sum($poinP2);
|
||||
$setelahCap = min($totalRemun, $cap);
|
||||
$p1Deduction = max(0, round($setelahCap - $totalP2, 2));
|
||||
|
||||
$labels = [
|
||||
'kegiatan' => 'Kegiatan',
|
||||
'skp' => 'SKP',
|
||||
'presensi' => 'Presensi / Absen',
|
||||
'grade_14_17' => 'Grade 14-17',
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($labels as $key => $label) {
|
||||
$remun = (float) ($poinRemun[$key] ?? 0);
|
||||
$p2 = (float) ($poinP2[$key] ?? 0);
|
||||
|
||||
if ($remun == 0 && $p2 == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = [$label, number_format($remun, 2, ',', '.'), number_format($p2, 2, ',', '.')];
|
||||
}
|
||||
|
||||
if (empty($rows)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rows[] = ['<options=bold>Total</>', number_format($totalRemun, 2, ',', '.'), number_format($totalP2, 2, ',', '.')];
|
||||
|
||||
$this->table(['Komponen Poin', 'Poin Remun', 'Poin P2'], $rows);
|
||||
|
||||
// Info batas
|
||||
$batasInfo = sprintf('Batas maks: %d', $cap);
|
||||
|
||||
if ($limitKegiatan !== null) {
|
||||
$batasInfo .= sprintf(
|
||||
' | Limit kegiatan: %s (tercapai: %s)',
|
||||
number_format($limitKegiatan['limit'], 0, ',', '.'),
|
||||
number_format($limitKegiatan['current'], 2, ',', '.'),
|
||||
);
|
||||
}
|
||||
|
||||
$batasInfo .= sprintf(' | Potongan P1: %s', number_format($p1Deduction, 2, ',', '.'));
|
||||
|
||||
$this->line(sprintf(' <fg=gray> %s</>', $batasInfo));
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
private function displayHeader(int $periode, ?string $nip, ?int $unitPembayaranId): void
|
||||
{
|
||||
$this->newLine();
|
||||
$this->info('══════════════════════════════════════════════════════════════');
|
||||
$this->info(' CEK PERHITUNGAN REMUNERASI (SEMENTARA / PREVIEW) ');
|
||||
$this->info('══════════════════════════════════════════════════════════════');
|
||||
$this->info(sprintf(' Periode : %s', $periode));
|
||||
$this->info(sprintf(' NIP : %s', $nip ?? 'Semua'));
|
||||
$this->info(sprintf(' Unit Pembayaran : %s', $unitPembayaranId ?? 'Semua'));
|
||||
$this->info(' * Tidak ada data yang disimpan ke database ');
|
||||
$this->info('══════════════════════════════════════════════════════════════');
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
private function displayGrandTotal(array $grandTotal, int $totalPegawai): void
|
||||
{
|
||||
$this->info('══════════════════════════════════════════════════════════════');
|
||||
$this->info(sprintf(' TOTAL PEGAWAI DIPROSES : %d', $totalPegawai));
|
||||
$this->info(sprintf(' GRAND TOTAL BRUTO : Rp %s', number_format($grandTotal['bruto'], 0, ',', '.')));
|
||||
$this->info(sprintf(' GRAND TOTAL PAJAK : Rp %s', number_format($grandTotal['tax'], 0, ',', '.')));
|
||||
$this->info(sprintf(' GRAND TOTAL NETTO : Rp %s', number_format($grandTotal['netto'], 0, ',', '.')));
|
||||
$this->info('══════════════════════════════════════════════════════════════');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Remunerasi;
|
||||
|
||||
use App\Models\Verifikator\Periode;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class GenerateSpecificNipsP2JsonCommand extends Command
|
||||
{
|
||||
protected $signature = 'remunerasi:generate-specific-nips-p2 {periode?}';
|
||||
|
||||
protected $description = 'Generate JSON file untuk data P2 pegawai tertentu';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$specificNips = [
|
||||
'198011252006042002',
|
||||
'198902072018031001',
|
||||
'198402142019031010',
|
||||
'198112242009121003',
|
||||
'198112202009122003',
|
||||
'198301192008122001',
|
||||
'198310302008121002',
|
||||
];
|
||||
|
||||
$periodeInput = $this->argument('periode');
|
||||
$periodeAktif = $periodeInput
|
||||
? Periode::where('id_periode', $periodeInput)->first()
|
||||
: Periode::where('status', true)->first();
|
||||
|
||||
if (! $periodeAktif) {
|
||||
$this->error('Periode tidak ditemukan!');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$periode = $periodeAktif->id_periode;
|
||||
$this->info("Generating data untuk Periode: {$periode} - {$periodeAktif->nama}");
|
||||
|
||||
$data = [];
|
||||
$bar = $this->output->createProgressBar(count($specificNips));
|
||||
$bar->start();
|
||||
|
||||
foreach ($specificNips as $nip) {
|
||||
try {
|
||||
$pegawai = Pegawai::where('nip', $nip)->first();
|
||||
if (! $pegawai) {
|
||||
$bar->advance();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil data dari API remunerasi
|
||||
$apiUrl = "https://verifikator.untan.ac.id/api/v1/remunerasi/{$nip}";
|
||||
$response = @file_get_contents($apiUrl);
|
||||
|
||||
if (! $response) {
|
||||
$bar->advance();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$apiData = json_decode($response, true);
|
||||
|
||||
// Ambil hanya array 'data' dari API response dan map unit IDs
|
||||
$detailP2 = [];
|
||||
if (isset($apiData['data']) && is_array($apiData['data'])) {
|
||||
// Map unit IDs untuk setiap bulan data
|
||||
foreach ($apiData['data'] as $bulanData) {
|
||||
$detailP2[] = $this->mapUnitIdsInApiResponse($bulanData);
|
||||
}
|
||||
}
|
||||
|
||||
// Tambahkan data pegawai dengan detail P2 dari API
|
||||
$data[] = [
|
||||
'nip' => $pegawai->nip,
|
||||
'nama' => $pegawai->nama,
|
||||
'unit_kerja' => $pegawai->unit_kerja_nama,
|
||||
'detail_p2' => $detailP2, // Langsung array 'data' dari API response
|
||||
];
|
||||
|
||||
$bar->advance();
|
||||
} catch (\Exception $e) {
|
||||
$this->error("\nError untuk NIP {$nip}: ".$e->getMessage());
|
||||
$bar->advance();
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
|
||||
// Buat direktori jika belum ada
|
||||
$directory = storage_path('app/public/remunerasi/p2/kekurangan');
|
||||
if (! File::exists($directory)) {
|
||||
File::makeDirectory($directory, 0755, true);
|
||||
}
|
||||
|
||||
// Simpan ke file JSON
|
||||
$filename = "periode-{$periode}.json";
|
||||
$filepath = "{$directory}/{$filename}";
|
||||
|
||||
File::put($filepath, json_encode([
|
||||
'periode' => $periode,
|
||||
'periode_nama' => $periodeAktif->nama,
|
||||
'generated_at' => now()->toDateTimeString(),
|
||||
'data' => $data,
|
||||
], JSON_PRETTY_PRINT));
|
||||
|
||||
$this->info("File berhasil disimpan di: {$filepath}");
|
||||
$this->info('Total pegawai: '.count($data));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function mapUnitIdProductionToLocal(int $productionId, string $unitNama): int
|
||||
{
|
||||
// Mapping unit ID dari production/dokumen siremun (public) ke verifikator (local)
|
||||
// Dokumen Siremun Public -> Verifikator
|
||||
$mappingByName = [
|
||||
'Universitas Tanjungpura' => 0,
|
||||
'Fakultas Hukum' => 1,
|
||||
'Fakultas Ekonomi dan Bisnis' => 2,
|
||||
'Fakultas Pertanian' => 3,
|
||||
'Fakultas Teknik' => 4,
|
||||
'Fakultas Ilmu Sosial dan Ilmu Politik' => 5,
|
||||
'Fakultas Keguruan dan Ilmu Pendidikan' => 6,
|
||||
'Fakultas Kehutanan' => 7,
|
||||
'Fakultas Matematika dan Ilmu Pengetahuan Alam' => 8,
|
||||
'Fakultas Kedokteran' => 9,
|
||||
];
|
||||
|
||||
// Direct ID mapping (jika nama tidak tersedia)
|
||||
// Production ID -> Local ID
|
||||
$mappingById = [
|
||||
1 => 0, // Universitas
|
||||
2 => 1, // Fakultas Hukum
|
||||
3 => 2, // Fakultas Ekonomi dan Bisnis
|
||||
4 => 3, // Fakultas Pertanian
|
||||
5 => 4, // Fakultas Teknik
|
||||
6 => 5, // Fakultas Ilmu Sosial dan Ilmu Politik
|
||||
7 => 6, // Fakultas Keguruan dan Ilmu Pendidikan
|
||||
8 => 7, // Fakultas Kehutanan
|
||||
9 => 8, // Fakultas MIPA
|
||||
10 => 9, // Fakultas Kedokteran
|
||||
];
|
||||
|
||||
// Coba map berdasarkan nama dulu (lebih akurat)
|
||||
if (isset($mappingByName[$unitNama])) {
|
||||
return $mappingByName[$unitNama];
|
||||
}
|
||||
|
||||
// Fallback ke ID mapping
|
||||
if (isset($mappingById[$productionId])) {
|
||||
return $mappingById[$productionId];
|
||||
}
|
||||
|
||||
// Last fallback ke production ID jika tidak ada mapping
|
||||
return $productionId;
|
||||
}
|
||||
|
||||
private function mapUnitIdsInApiResponse(array $apiData): array
|
||||
{
|
||||
// Rekursif map semua unit IDs dalam API response
|
||||
if (isset($apiData['unit']['id'], $apiData['unit']['nama'])) {
|
||||
$productionId = $apiData['unit']['id'];
|
||||
$unitNama = $apiData['unit']['nama'];
|
||||
$apiData['unit']['id'] = $this->mapUnitIdProductionToLocal($productionId, $unitNama);
|
||||
$apiData['unit']['id_production'] = $productionId; // Simpan original ID untuk referensi
|
||||
}
|
||||
|
||||
foreach ($apiData as $key => &$value) {
|
||||
if (is_array($value)) {
|
||||
$value = $this->mapUnitIdsInApiResponse($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $apiData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Remunerasi;
|
||||
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use App\Services\RemunerasiService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class StorePoinDanP2Command extends Command
|
||||
{
|
||||
protected $signature = 'remunerasi:store-p2
|
||||
{--nip= : Filter by specific NIP}
|
||||
{--all : Process all pegawai (default)}';
|
||||
|
||||
protected $description = 'Calculate and store P2 values for all poin columns';
|
||||
|
||||
private const COLUMNS = [
|
||||
'mengajar',
|
||||
'batas_mengajar',
|
||||
'membimbing',
|
||||
'batas_membimbing',
|
||||
'menguji',
|
||||
'batas_menguji',
|
||||
'mpd',
|
||||
'batas_mpd',
|
||||
'buku_ajar',
|
||||
'batas_buku_ajar',
|
||||
'mbkm',
|
||||
'batas_mbkm',
|
||||
'lms',
|
||||
'batas_lms',
|
||||
'pendidikan_lainnya',
|
||||
'batas_pendidikan_lainnya',
|
||||
'penelitian',
|
||||
'batas_penelitian',
|
||||
'pengabdian',
|
||||
'batas_pengabdian',
|
||||
'penunjang',
|
||||
'batas_penunjang',
|
||||
'penunjang_perumus_kebijakan',
|
||||
'batas_penunjang_perumus_kebijakan',
|
||||
'penunjang_tim_adhoc',
|
||||
'batas_penunjang_tim_adhoc',
|
||||
'penunjang_kepanitiaan_adhoc',
|
||||
'batas_penunjang_kepanitiaan_adhoc',
|
||||
'penunjang_kompetisi',
|
||||
'batas_penunjang_kompetisi',
|
||||
'penunjang_pengelola_jurnal',
|
||||
'batas_penunjang_pengelola_jurnal',
|
||||
'penunjang_jabatan_fungsional',
|
||||
'batas_penunjang_jabatan_fungsional',
|
||||
'penunjang_penjamin_mutu',
|
||||
'batas_penunjang_penjamin_mutu',
|
||||
'penunjang_ukpbj',
|
||||
'batas_penunjang_ukpbj',
|
||||
'penunjang_ujian_komprehensif',
|
||||
'batas_penunjang_ujian_komprehensif',
|
||||
'penunjang_cbt',
|
||||
'batas_penunjang_cbt',
|
||||
'penunjang_editor_jurnal_s1',
|
||||
'batas_penunjang_editor_jurnal_s1',
|
||||
'penunjang_editor_jurnal_s3',
|
||||
'batas_penunjang_editor_jurnal_s3',
|
||||
'penunjang_editor_jurnal_s5',
|
||||
'batas_penunjang_editor_jurnal_s5',
|
||||
'penunjang_editor_jurnal_nasional',
|
||||
'batas_penunjang_editor_jurnal_nasional',
|
||||
'penunjang_editor_jurnal_internasional_bereputasi',
|
||||
'batas_penunjang_editor_jurnal_internasional_bereputasi',
|
||||
'penunjang_editor_jurnal_internasional',
|
||||
'batas_penunjang_editor_jurnal_internasional',
|
||||
'penunjang_pusat_lembaga',
|
||||
'batas_penunjang_pusat_lembaga',
|
||||
'penunjang_asesor',
|
||||
'batas_penunjang_asesor',
|
||||
'penunjang_reviewer',
|
||||
'batas_penunjang_reviewer',
|
||||
'penunjang_pengawas_ujian',
|
||||
'batas_penunjang_pengawas_ujian',
|
||||
'penunjang_fk',
|
||||
'batas_penunjang_fk',
|
||||
'penunjang_layanan',
|
||||
'batas_penunjang_layanan',
|
||||
'penunjang_upt_bahasa',
|
||||
'batas_penunjang_upt_bahasa',
|
||||
'penunjang_sidang_senat',
|
||||
'batas_penunjang_sidang_senat',
|
||||
];
|
||||
|
||||
private int $processedCount = 0;
|
||||
|
||||
private int $errorCount = 0;
|
||||
|
||||
public function __construct(
|
||||
private RemunerasiService $remunerasiService
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$pegawais = $this->getPegawais();
|
||||
|
||||
if ($pegawais->isEmpty()) {
|
||||
$this->error('No pegawai found with the given criteria.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$this->displayHeader($pegawais->count());
|
||||
$this->processPegawais($pegawais);
|
||||
$this->displaySummary($pegawais->count());
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function getPegawais()
|
||||
{
|
||||
$query = Pegawai::query()->with('poin');
|
||||
|
||||
if ($nip = $this->option('nip')) {
|
||||
$query->where('nip', $nip);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
private function displayHeader(int $totalPegawai): void
|
||||
{
|
||||
$this->info('══════════════════════════════════════════════════════');
|
||||
$this->info(' STORE P2 CALCULATION ');
|
||||
$this->info('══════════════════════════════════════════════════════');
|
||||
$this->info('Total Pegawai: ' . $totalPegawai);
|
||||
$this->info('Total Kolom per Pegawai: ' . count(self::COLUMNS));
|
||||
$this->info('══════════════════════════════════════════════════════');
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
private function processPegawais($pegawais): void
|
||||
{
|
||||
$totalPegawai = $pegawais->count();
|
||||
$totalColumns = count(self::COLUMNS);
|
||||
|
||||
// Reserve lines for progress bar
|
||||
echo str_repeat("\n", 7);
|
||||
|
||||
foreach ($pegawais as $index => $pegawai) {
|
||||
$currentPegawai = $index + 1;
|
||||
|
||||
if (! $pegawai->poin) {
|
||||
$this->updateProgress(
|
||||
$currentPegawai,
|
||||
$totalPegawai,
|
||||
0,
|
||||
$totalColumns,
|
||||
$pegawai,
|
||||
'Data poin tidak ditemukan',
|
||||
true
|
||||
);
|
||||
$this->errorCount++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->processPegawaiColumns($pegawai, $currentPegawai, $totalPegawai, $totalColumns);
|
||||
}
|
||||
|
||||
// Clear progress lines
|
||||
echo "\033[F\033[F\033[F\033[F\033[F\033[F\033[F";
|
||||
}
|
||||
|
||||
private function processPegawaiColumns(
|
||||
Pegawai $pegawai,
|
||||
int $currentPegawai,
|
||||
int $totalPegawai,
|
||||
int $totalColumns
|
||||
): void {
|
||||
foreach (self::COLUMNS as $index => $column) {
|
||||
$currentColumn = $index + 1;
|
||||
|
||||
$this->updateProgress(
|
||||
$currentPegawai,
|
||||
$totalPegawai,
|
||||
$currentColumn,
|
||||
$totalColumns,
|
||||
$pegawai,
|
||||
$column
|
||||
);
|
||||
|
||||
if (! $this->shouldProcessColumn($pegawai, $column)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->calculateAndStoreP2($pegawai, $column);
|
||||
|
||||
usleep(500); // Visual feedback delay
|
||||
}
|
||||
}
|
||||
|
||||
private function shouldProcessColumn(Pegawai $pegawai, string $column): bool
|
||||
{
|
||||
if (! isset($pegawai->poin->{$column})) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $pegawai->poin->{$column} !== 0;
|
||||
}
|
||||
|
||||
private function calculateAndStoreP2(Pegawai $pegawai, string $column): void
|
||||
{
|
||||
$poin = $pegawai->poin->{$column};
|
||||
$p2 = $this->remunerasiService->p2Sk($pegawai->nip, $poin);
|
||||
|
||||
$pegawai->poin->{"p2_{$column}"} = $p2['total'];
|
||||
$pegawai->poin->save();
|
||||
|
||||
$this->processedCount++;
|
||||
}
|
||||
|
||||
private function updateProgress(
|
||||
int $currentPegawai,
|
||||
int $totalPegawai,
|
||||
int $currentColumn,
|
||||
int $totalColumns,
|
||||
Pegawai $pegawai,
|
||||
string $column,
|
||||
bool $isError = false
|
||||
): void {
|
||||
// Move cursor up to overwrite previous output
|
||||
echo "\033[F\033[F\033[F\033[F\033[F\033[F\033[F";
|
||||
|
||||
// Calculate percentages
|
||||
$progressPegawai = number_format(($currentPegawai / $totalPegawai) * 100, 2);
|
||||
$progressColumn = $totalColumns > 0
|
||||
? number_format(($currentColumn / $totalColumns) * 100, 2)
|
||||
: 0;
|
||||
|
||||
// Create progress bars
|
||||
$pegawaiBar = $this->createProgressBar($currentPegawai, $totalPegawai);
|
||||
$columnBar = $this->createProgressBar($currentColumn, $totalColumns);
|
||||
|
||||
// Display progress information
|
||||
$this->info("Pegawai: {$currentPegawai}/{$totalPegawai} ({$progressPegawai}%)");
|
||||
$this->info("Progress: |{$pegawaiBar}|");
|
||||
$this->info('NIP: ' . str_pad($pegawai->nip, 25) . " | Kolom: {$currentColumn}/{$totalColumns} ({$progressColumn}%)");
|
||||
$this->info('Nama: ' . str_pad(substr($pegawai->nama, 0, 35), 35));
|
||||
$this->info("Kolom Progress: |{$columnBar}|");
|
||||
|
||||
if ($isError) {
|
||||
$this->error('Status: ERROR - ' . $column);
|
||||
} else {
|
||||
$displayName = ucwords(str_replace('_', ' ', $column));
|
||||
$this->info('Status: Memproses - ' . str_pad(substr($displayName, 0, 30), 30));
|
||||
}
|
||||
|
||||
$this->info('');
|
||||
}
|
||||
|
||||
private function createProgressBar(int $current, int $total, int $length = 40): string
|
||||
{
|
||||
if ($total === 0) {
|
||||
return str_repeat('░', $length);
|
||||
}
|
||||
|
||||
$filledLength = round(($length * $current) / $total);
|
||||
|
||||
return str_repeat('█', $filledLength) . str_repeat('░', $length - $filledLength);
|
||||
}
|
||||
|
||||
private function displaySummary(int $totalPegawai): void
|
||||
{
|
||||
$this->newLine();
|
||||
$this->info('══════════════════════════════════════════════════════');
|
||||
$this->info(' PROSES SELESAI ');
|
||||
$this->info('══════════════════════════════════════════════════════');
|
||||
$this->info('Total Pegawai Diproses: ' . $totalPegawai);
|
||||
$this->info('Total Data P2 Tersimpan: ' . $this->processedCount);
|
||||
|
||||
if ($this->errorCount > 0) {
|
||||
$this->warn('Total Error: ' . $this->errorCount);
|
||||
}
|
||||
|
||||
$this->info('══════════════════════════════════════════════════════');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user