first commit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user