update migration file, dan laporan
This commit is contained in:
@@ -10,21 +10,19 @@ use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
|
||||
|
||||
|
||||
class MigrationPermohonanSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/permohonan/error_permohonan.csv';
|
||||
protected $errorLogFile = __DIR__ . '/csv/permohonan/mig_permohonan_extenal_error.csv';
|
||||
|
||||
public function run()
|
||||
{
|
||||
// Bersihkan file error sebelum mulai
|
||||
$this->initializeErrorLog();
|
||||
|
||||
$filePath = realpath(__DIR__ . '/csv/permohonan/mig_permohonan.csv');
|
||||
$filePath = realpath(__DIR__ . '/csv/permohonan/mig_permohonan_external.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File CSV tidak ditemukan: ' . __DIR__ . '/csv/permohonan/mig_permohonan.csv');
|
||||
Log::error('File CSV tidak ditemukan: ' . __DIR__ . '/csv/permohonan/mig_permohonan_external.csv');
|
||||
$this->command->error('File CSV tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
@@ -61,7 +59,7 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
// print_r($rows);
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
@@ -70,7 +68,7 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
}
|
||||
}
|
||||
|
||||
print_r($rows[0]);
|
||||
// print_r($rows);
|
||||
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
@@ -97,12 +95,12 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil branch_id
|
||||
$branchId = $this->getBranchId($row['mig_mst_jaminan_kd_cabang'] ?? null, $branchCache);
|
||||
if (!$branchId) {
|
||||
$this->logError($branchId, 'Cabang tidak ditemukan');
|
||||
continue;
|
||||
}
|
||||
// Ambil branch_id
|
||||
$branchId = $this->getBranchId($row['mig_mst_jaminan_kd_cabang'] ?? null, $branchCache);
|
||||
// if (!$branchId) {
|
||||
// $this->logError($branchId, 'Cabang tidak ditemukan');
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Ambil Debitur ID
|
||||
$debitureId = $this->getDebiturId($row['mig_mst_jaminan_kd_debitur_seq'], $debitureCache);
|
||||
@@ -113,37 +111,45 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
|
||||
// Ambil User IDs
|
||||
$userId = $this->getUserId($row['mig_mst_jaminan_nama_ao'], $branchCache, true);
|
||||
$approved1Id = $this->getUserId($row['mig_mst_lpj_user_approved_1'], $branchCache, false);
|
||||
$approved2Id = $this->getUserId($row['mig_mst_lpj_user_approved_2'], $branchCache, false);
|
||||
|
||||
// Ambil user IDs berdasarkan NIK
|
||||
$userIdUpdate = $this->getUserIdData($row['mig_mst_jaminan_user_create'] ?? null, $userData)['id'];
|
||||
$userIdOtorisasi = $this->getUserIdData($row['mig_mst_jaminan_user_oto'] ?? null, $userData)['id'];
|
||||
// jika external matikan
|
||||
// $approved1Id = $this->getUserId($row['mig_mst_lpj_user_approved_1'], $branchCache, false);
|
||||
// $approved2Id = $this->getUserId($row['mig_mst_lpj_user_approved_2'], $branchCache, false);
|
||||
|
||||
if (!$userIdUpdate || !$userIdOtorisasi) {
|
||||
$this->logError($userIdUpdate, 'Salah satu user tidak ditemukan');
|
||||
continue;
|
||||
}
|
||||
// // Ambil user IDs berdasarkan NIK
|
||||
$userIdUpdate = $this->getUserIdData($row['mig_mst_jaminan_user_create'] ?? null, $userData)['id'];
|
||||
$userIdOtorisasi = $this->getUserIdData($row['mig_mst_jaminan_user_oto'] ?? null, $userData)['id'];
|
||||
|
||||
// Mapping field user
|
||||
$mapUser = [
|
||||
'created_by' => $userIdUpdate,
|
||||
'updated_by' => $userIdUpdate,
|
||||
'authorized_by' => $userIdOtorisasi,
|
||||
];
|
||||
// jika external matikan
|
||||
// if (!$userIdUpdate || !$userIdOtorisasi) {
|
||||
// $this->logError($userIdUpdate, 'Salah satu user tidak ditemukan');
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Mapping field user
|
||||
$mapUser = [
|
||||
'created_by' => $userIdUpdate,
|
||||
'updated_by' => $userIdUpdate,
|
||||
'authorized_by' => $userIdOtorisasi,
|
||||
];
|
||||
|
||||
|
||||
if (!$userId || !$approved1Id || !$approved2Id) {
|
||||
$this->logError($userId, 'Salah satu user tidak ditemukan');
|
||||
continue;
|
||||
}
|
||||
// jika external matikan
|
||||
// if (!$userId || !$approved1Id || !$approved2Id) {
|
||||
// $this->logError($userId, 'Salah satu user tidak ditemukan');
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Mapping data
|
||||
$jenisFasilitas = $this->checkJenisFasilitas($row['mig_mst_jaminan_kd_jenis_fas_seq']);
|
||||
$tujuanPenilaian = $this->checkTujuanPenilaian($row['mig_mst_jaminan_kd_tujuan_seq']);
|
||||
$regionId = $this->checkRegion($row['mig_mst_kode_kelompok_region']);
|
||||
|
||||
|
||||
$nomor_lpj = isset($row['mig_mst_lpj_nomor_lpj']) ? $row['mig_mst_lpj_nomor_lpj'] : '';
|
||||
$nomor_lpj = is_numeric($nomor_lpj) ? (int)$nomor_lpj : 0;
|
||||
|
||||
$jenisPenilaian = $row['mig_internal_or_external'] == 1 ? 2 : 1;
|
||||
|
||||
// Simpan data
|
||||
Permohonan::create([
|
||||
'nomor_registrasi' => $nomorJaminan,
|
||||
@@ -155,25 +161,26 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
'jenis_fasilitas_kredit_id' => $jenisFasilitas,
|
||||
'nilai_plafond_id' => 2,
|
||||
'status' => 'done',
|
||||
'approval_eo' => $approved2Id['id'] ?? 0,
|
||||
'approval_eo_at' => $this->parseTimestamp($row['mig_mst_lpj_tgl_approved_2']),
|
||||
'approval_dd' => 0,
|
||||
'approval_dd_at' => null,
|
||||
'approval_so' => $approved1Id['id'] ?? 0,
|
||||
'approval_so_at' => $this->parseTimestamp($row['mig_mst_lpj_tgl_approved_1']),
|
||||
// jika external matikan
|
||||
// 'approval_eo' => $approved2Id['id'] ?? 0,
|
||||
// 'approval_eo_at' => $this->parseTimestamp($row['mig_mst_lpj_tgl_approved_2']),
|
||||
// 'approval_dd' => 0,
|
||||
// 'approval_dd_at' => null,
|
||||
// 'approval_so' => $approved1Id['id'] ?? 0,
|
||||
// 'approval_so_at' => $this->parseTimestamp($row['mig_mst_lpj_tgl_approved_1']),
|
||||
// end external matikan
|
||||
'keterangan' => $row['mig_mst_jaminan_catatan'] ?? null,
|
||||
'status_bayar' => 'sudah_bayar',
|
||||
'created_at' => $this->parseTimestamp($row['mig_mst_jaminan_tgl_create']),
|
||||
'updated_at' => $this->parseTimestamp($row['mig_mst_jaminan_tgl_update']),
|
||||
'mig_kd_debitur_seq' => $row['mig_mst_jaminan_kd_debitur_seq'],
|
||||
'nomor_lpj' => $row['mig_mst_lpj_nomor_lpj'],
|
||||
'nomor_lpj' => $nomor_lpj,
|
||||
'region_id' => $regionId,
|
||||
|
||||
'jenis_penilaian_id' => $jenisPenilaian,
|
||||
'authorized_by' => $mapUser['authorized_by'],
|
||||
'created_by' => $mapUser['created_by'],
|
||||
'updated_by' => $mapUser['updated_by'],
|
||||
|
||||
'processed_at' => now(),
|
||||
'mig_nama_ao' => $row['mig_mst_jaminan_nama_ao'],
|
||||
'is_mig' => 1
|
||||
]);
|
||||
|
||||
@@ -190,7 +197,9 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
|
||||
private function getUserIdData(?string $code, array &$cache): array
|
||||
{
|
||||
if (!$code) return ['id' => null, 'branch_id' => null];
|
||||
if (!$code) {
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
@@ -249,7 +258,9 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
}
|
||||
private function getBranchId(?string $code, array &$cache): ?int
|
||||
{
|
||||
if (!$code) return null;
|
||||
if (!$code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
@@ -268,7 +279,7 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
{
|
||||
$mapping = [
|
||||
161337594516 => 1,
|
||||
161337598118 => 2,
|
||||
161337598118 => 14,
|
||||
155739382483 => 7,
|
||||
2 => 9,
|
||||
153568936592 => 10,
|
||||
@@ -353,7 +364,7 @@ class MigrationPermohonanSeeder extends Seeder
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError( $nomorJaminan, string $message)
|
||||
private function logError($nomorJaminan, string $message)
|
||||
{
|
||||
Log::error("Error migrasi permohonan [$nomorJaminan]: $message");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user