201 lines
7.8 KiB
PHP
201 lines
7.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Remunerasi;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Verifikator\Periode;
|
|
use App\Models\Verifikator\View\Pegawai;
|
|
use App\Services\PerhitunganKegiatanService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class RemunerasiController extends Controller
|
|
{
|
|
protected PerhitunganKegiatanService $perhitunganKegiatanService;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->perhitunganKegiatanService = new PerhitunganKegiatanService;
|
|
}
|
|
|
|
/**
|
|
* Menampilkan data remunerasi pegawai
|
|
*/
|
|
public function index(Request $request, string $nip): JsonResponse
|
|
{
|
|
// Ambil periode dari request atau gunakan periode aktif
|
|
$periodeId = $request->input('periode');
|
|
|
|
if ($periodeId) {
|
|
$periodeModel = Periode::where('id_periode', $periodeId)->first();
|
|
|
|
if (! $periodeModel) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => 'Periode tidak valid',
|
|
'periode' => null,
|
|
'data' => [],
|
|
]);
|
|
}
|
|
} else {
|
|
$periodeModel = Periode::where('status', true)->first();
|
|
}
|
|
|
|
$pegawai = Pegawai::where('nip', $nip)
|
|
->orWhere('nip_siakad', $nip)
|
|
->first();
|
|
|
|
if (str_contains($nip, '202521')) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => 'Pegawai belum memenuhi syarat pembayaran P2',
|
|
'periode' => $periodeModel?->nama ?? null,
|
|
'data' => [],
|
|
], 404);
|
|
}
|
|
|
|
if (! $pegawai) {
|
|
$pegawaiTubel = Pegawai::withoutGlobalScope('aktif')
|
|
->where(function ($q) use ($nip) {
|
|
$q->where('nip', $nip)->orWhere('nip_siakad', $nip);
|
|
})
|
|
->whereNotNull('tubel_berangkat')
|
|
->first();
|
|
|
|
if ($pegawaiTubel) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => $pegawaiTubel->nama.' sedang dalam Tugas Belajar ('.$pegawaiTubel->tubel_berangkat.' s.d. '.($pegawaiTubel->tubel_kembali ?? '???').')',
|
|
'periode' => $periodeModel?->nama ?? null,
|
|
'data' => [],
|
|
], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => 'Pegawai tidak ditemukan',
|
|
], 404);
|
|
}
|
|
|
|
if (is_null($pegawai->jabatan_fungsional_id)) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => 'Pegawai belum memenuhi syarat pembayaran P2 dikarenakan belum memiliki Jabatan Fungsional',
|
|
'periode' => $periodeModel?->nama ?? null,
|
|
'data' => [],
|
|
], 404);
|
|
}
|
|
|
|
$periode = $periodeModel ? $periodeModel->id_periode : env('PERIODE_VERIFIKATOR');
|
|
|
|
// Tentukan bulan berdasarkan periode (logika dari HitungRemunerasiCommand)
|
|
// Periode ganjil: bulan 1-6, Periode genap: bulan 7-12
|
|
$bulanArray = $request->input('bulan');
|
|
|
|
if (! $bulanArray) {
|
|
if ($periode % 2 === 1) {
|
|
$bulanArray = [1, 2, 3, 4, 5, 6];
|
|
} else {
|
|
$bulanArray = [7, 8, 9, 10, 11, 12];
|
|
}
|
|
}
|
|
|
|
// Pastikan bulan adalah array
|
|
if (! is_array($bulanArray)) {
|
|
$bulanArray = [$bulanArray];
|
|
}
|
|
|
|
$daftarKegiatan = $this->perhitunganKegiatanService->listKegiatan(
|
|
$pegawai->nip,
|
|
$periode,
|
|
$bulanArray
|
|
);
|
|
|
|
if (empty($daftarKegiatan)) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => 'Data tidak ditemukan di Periode ini',
|
|
'periode' => $periodeModel?->nama ?? $periode,
|
|
'data' => [],
|
|
]);
|
|
}
|
|
|
|
$dataRemunerasi = [];
|
|
|
|
foreach ($daftarKegiatan as $bulan => $kegiatan) {
|
|
// Hapus ratio dari p2
|
|
if (isset($kegiatan['p2']['p2']['ratio'])) {
|
|
unset($kegiatan['p2']['p2']['ratio']);
|
|
}
|
|
|
|
if (isset($kegiatan['p2']['total']['ratio'])) {
|
|
unset($kegiatan['p2']['total']['ratio']);
|
|
}
|
|
|
|
// Hitung ratio dari total units
|
|
$totalRatioUnits = collect($kegiatan['units'] ?? [])->sum('p2.ratio');
|
|
$kegiatan['p2']['total']['ratio'] = $totalRatioUnits;
|
|
|
|
// Transform tri_dharma_homebase to include poin_remunerasi for penelitian and other categories
|
|
$triDharmaHomebase = $kegiatan['tri_dharma_homebase'] ?? [];
|
|
$triDharmaHomebase = $this->transformTriDharmaData($triDharmaHomebase);
|
|
|
|
// Transform tri_dharma_luar_homebase to include poin_remunerasi
|
|
$triDharmaLuarHomebase = $kegiatan['tri_dharma_luar_homebase'] ?? [];
|
|
$triDharmaLuarHomebase = $this->transformTriDharmaData($triDharmaLuarHomebase);
|
|
|
|
$dataRemunerasi[] = [
|
|
'bulan' => month($bulan),
|
|
'kegiatan' => [
|
|
'grade_14_17' => $kegiatan['grade_14_17'] ?? [],
|
|
'skp' => $kegiatan['skp'] ?? [],
|
|
'presensi' => $kegiatan['presensi'] ?? [],
|
|
'tri_dharma_homebase' => $triDharmaHomebase,
|
|
'tri_dharma_luar_homebase' => $triDharmaLuarHomebase,
|
|
'penunjang_homebase' => isset($kegiatan['penunjang_homebase']) ? $kegiatan['penunjang_homebase']->values() : [],
|
|
'penunjang_luar_homebase_fakultas' => isset($kegiatan['penunjang_luar_homebase_fakultas']) ? $kegiatan['penunjang_luar_homebase_fakultas']->values() : [],
|
|
'penunjang_luar_homebase_universitas' => isset($kegiatan['penunjang_luar_homebase_universitas']) ? $kegiatan['penunjang_luar_homebase_universitas']->values() : [],
|
|
'semester_antara_homebase' => isset($kegiatan['semester_antara_homebase']) ? $kegiatan['semester_antara_homebase']->values() : [],
|
|
'semester_antara_luar_homebase' => $kegiatan['semester_antara_luar_homebase'] ?? [],
|
|
],
|
|
'detail_p2' => [
|
|
'total' => [
|
|
'bruto' => $kegiatan['p2']['total']['bruto'] ?? 0,
|
|
'ratio' => $kegiatan['p2']['total']['ratio'] ?? 0,
|
|
'tax' => $kegiatan['p2']['total']['tax'] ?? 0,
|
|
'netto' => $kegiatan['p2']['total']['netto'] ?? 0,
|
|
],
|
|
'detail' => $kegiatan['p2']['p2'] ?? [],
|
|
],
|
|
'p2_per_unit' => $kegiatan['units'] ?? [],
|
|
];
|
|
}
|
|
|
|
return response()->json([
|
|
'status' => 'success',
|
|
'message' => 'Berhasil mendapatkan data remunerasi '.$pegawai->nama,
|
|
'periode' => $periodeModel?->nama ?? $periode,
|
|
'data' => $dataRemunerasi,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Transform tri dharma data to include poin_remunerasi attribute
|
|
*/
|
|
private function transformTriDharmaData(array $triDharmaData): array
|
|
{
|
|
$categoriesToTransform = ['penelitian', 'pengabdian', 'mengajarLainnya', 'membimbingLainnya', 'mengujiLainnya'];
|
|
|
|
foreach ($categoriesToTransform as $category) {
|
|
if (isset($triDharmaData[$category])) {
|
|
$triDharmaData[$category] = collect($triDharmaData[$category])->map(function ($item) {
|
|
// Convert to array - toArray() will include dynamically added properties like poin_remunerasi
|
|
return is_array($item) ? $item : (is_object($item) ? $item->toArray() : $item);
|
|
})->toArray();
|
|
}
|
|
}
|
|
|
|
return $triDharmaData;
|
|
}
|
|
}
|