update migration file, dan laporan
This commit is contained in:
@@ -19,7 +19,7 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MigrationDokumentJaminanSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/dokumen-dan-pemilik/mig_pemilik_dan_dokument_error.csv';
|
||||
protected $errorLogFile = __DIR__ . '/csv/dokumen-pemilik/mig_pemilik_dan_dokument_external_error_log.csv';
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
@@ -27,10 +27,10 @@ class MigrationDokumentJaminanSeeder extends Seeder
|
||||
{
|
||||
$this->initializeErrorLog();
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/dokumen-dan-pemilik/mig_pemilik_dan_dokument.csv');
|
||||
$filePath = realpath(__DIR__ . '/csv/dokumen-pemilik/mig_pemilik_dan_dokument_external.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/mig_pemilik_dan_dokument.csv');
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/dokumen-pemilik/mig_pemilik_dan_dokument_external.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
@@ -125,39 +125,45 @@ class MigrationDokumentJaminanSeeder extends Seeder
|
||||
DB::beginTransaction();
|
||||
|
||||
// Cari permohonan
|
||||
$permohonan = $this->getPermohonanId(
|
||||
$row['mig_kd_debitur_seq'],
|
||||
$row['mig_nomor_jaminan'],
|
||||
$permohonanCache
|
||||
);
|
||||
|
||||
if (empty($permohonan['debiture_id'])) {
|
||||
throw new \Exception('Missing debiture_id');
|
||||
$permohonan = Permohonan::where('nomor_registrasi', $row['mig_nomor_jaminan'])->first();
|
||||
|
||||
if (empty($permohonan)) {
|
||||
throw new \Exception('Missing debiture_id' . $row['mig_nomor_jaminan']);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Pastikan permohonan_id belum digunakan di dokumen_jaminan
|
||||
$existingDokumen = DokumenJaminan::where('permohonan_id', $permohonan['id'])->first();
|
||||
$existingDokumen = DokumenJaminan::where('permohonan_id', $permohonan->id)->first();
|
||||
if ($existingDokumen) {
|
||||
throw new \Exception("permohonan_id {$permohonan['id']} sudah digunakan di dokumen_jaminan");
|
||||
throw new \Exception("permohonan_id {$permohonan->id} sudah digunakan di dokumen_jaminan");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil lokasi
|
||||
|
||||
// jika external silahkan matikan ini
|
||||
|
||||
$proviceCode = $this->getProvinceCode($row['mig_province_name'], $provinceCache);
|
||||
$cityCode = $this->getCityCode($row['mig_city_name'], $cityCache);
|
||||
$districtCode = $this->getDistrictCode($row['mig_district_name'], $districtCache);
|
||||
$subdistrict = $this->getSubdistrictCode($row['mig_village_name'], $subdistrictCache, $districtCache);
|
||||
$hubunganPemilik = $this->getHubunganPemilikJaminanId($row['mig_hubungan_pemilik_jaminan'], $hubunganPemilikCache);
|
||||
// $hubunganPemilik = $this->getHubunganPemilikJaminanId($row['mig_hubungan_pemilik_jaminan'], $hubunganPemilikCache);
|
||||
|
||||
|
||||
$pemilik_jaminan_name = $this->getDebitureId($row['mig_kd_debitur_seq'], $pemilikJaminanCache);
|
||||
// Buat Pemilik Jaminan
|
||||
$pemilik_jaminan = PemilikJaminan::create([
|
||||
'debiture_id' => $permohonan['debiture_id'],
|
||||
'hubungan_pemilik_jaminan_id' => $hubunganPemilik,
|
||||
'name' => $row['name'],
|
||||
$pemilik_jaminan = PemilikJaminan::updateOrCreate([
|
||||
'debiture_id' => $permohonan->debiture_id,
|
||||
'hubungan_pemilik_jaminan_id' => 1,
|
||||
// 'name' => $row['name'],
|
||||
'name' => $pemilik_jaminan_name,
|
||||
'detail_sertifikat' => null,
|
||||
'npwp' => null,
|
||||
'nomor_id' => null,
|
||||
'email' => null,
|
||||
'phone' => null,
|
||||
// jika external silahkan matikan ini
|
||||
'province_code' => $proviceCode,
|
||||
'city_code' => $cityCode,
|
||||
'district_code' => $districtCode,
|
||||
@@ -172,16 +178,17 @@ class MigrationDokumentJaminanSeeder extends Seeder
|
||||
]);
|
||||
|
||||
// Buat Dokumen Jaminan
|
||||
DokumenJaminan::create([
|
||||
'debiture_id' => $permohonan['debiture_id'],
|
||||
'permohonan_id' => $permohonan['id'],
|
||||
'jenis_jaminan_id' => 17,
|
||||
DokumenJaminan::updateOrCreate([
|
||||
'debiture_id' => $permohonan->debiture_id,
|
||||
'permohonan_id' => $permohonan->id,
|
||||
'jenis_jaminan_id' => $this->getJaminanId($row['mig_jenis_seq']),
|
||||
'pemilik_jaminan_id' => $pemilik_jaminan->id,
|
||||
'province_code' => $proviceCode,
|
||||
'city_code' => $cityCode,
|
||||
'district_code' => $districtCode,
|
||||
'village_code' => $subdistrict['code'],
|
||||
'postal_code' => $subdistrict['postal_code'],
|
||||
// jika external silahkan matikan ini
|
||||
// 'province_code' => $proviceCode,
|
||||
// 'city_code' => $cityCode,
|
||||
// 'district_code' => $districtCode,
|
||||
// 'village_code' => $subdistrict['code'],
|
||||
// 'postal_code' => $subdistrict['postal_code'],
|
||||
'address' => $row['address'],
|
||||
'created_at' => $this->parseTimestamp($row['created_at']),
|
||||
'updated_at' => $this->parseTimestamp($row['updated_at']),
|
||||
@@ -201,50 +208,57 @@ class MigrationDokumentJaminanSeeder extends Seeder
|
||||
Log::error("Error pada baris: " . json_encode($row) . ". Pesan: " . $e->getMessage());
|
||||
$this->logError($row['mig_kd_debitur_seq'] ?? '-', $e->getMessage());
|
||||
$errorDebitureIds[] = $row['mig_kd_debitur_seq'] ?? '-';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->command->info("Batch {$batchCount} selesai. Total error: " . count($errorDebitureIds));
|
||||
}
|
||||
private function getPermohonanId(string $code, string $mig_nomor_jaminan, array &$cache): ?array
|
||||
// private function getPermohonanId($code,$cache)
|
||||
// {
|
||||
// if (isset($cache[$code])) {
|
||||
// return $cache[$code];
|
||||
// }
|
||||
|
||||
// $permohonan = Permohonan::where('mig_kd_debitur_seq', $code)->where('nomor_registrasi', $mig_nomor_jaminan)->first();
|
||||
|
||||
// if ($permohonan) {
|
||||
// $cache[$code] = $permohonan;
|
||||
// return $permohonan;
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
private function getJaminanId($code): ?int
|
||||
{
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$permohonan = Permohonan::where('mig_kd_debitur_seq', $code)->where('nomor_registrasi', $mig_nomor_jaminan)->first();
|
||||
|
||||
if ($permohonan) {
|
||||
$cache[$code] = [
|
||||
'id' => $permohonan->id,
|
||||
'debiture_id' => $permohonan->debiture_id,
|
||||
'mig_kd_debitur_seq' => $permohonan->mig_kd_debitur_seq
|
||||
];
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => null,
|
||||
'debiture_id' => null,
|
||||
'mig_kd_debitur_seq' => null
|
||||
$mapping = [
|
||||
7 => 17,
|
||||
8 => 13,
|
||||
6 => 32,
|
||||
1 => 17,
|
||||
2 => 26,
|
||||
3 => 27,
|
||||
4 => 50,
|
||||
5 => 21,
|
||||
138051314724 => 23,
|
||||
138027243057 => 34,
|
||||
138027664224 => 35,
|
||||
138027738489 => 10,
|
||||
138051485796 => 48,
|
||||
138051492883 => 47,
|
||||
138051515419 => 40,
|
||||
138051753311 => 41,
|
||||
138051754843 => 46,
|
||||
138051759078 => 42,
|
||||
138051480538 => 45,
|
||||
123382184742 => 18,
|
||||
138051483711 => 44,
|
||||
991 => 52
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function getJaminanId(string $code, array &$cache): ?int
|
||||
{
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$jaminan = JenisJaminan::whereRaw('LOWER(name) = ?', [strtolower($code)])->first();
|
||||
|
||||
if ($jaminan) {
|
||||
$cache[$code] = $jaminan->id;
|
||||
return $jaminan->id;
|
||||
}
|
||||
|
||||
return null;
|
||||
return $mapping[$code] ?? 17;
|
||||
}
|
||||
|
||||
private function getPemilikJaminanId(string $code, array &$cache): ?int
|
||||
@@ -263,7 +277,7 @@ class MigrationDokumentJaminanSeeder extends Seeder
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function getDebitureId(string $code, array &$cache): ?int
|
||||
private function getDebitureId(string $code, array &$cache): ?string
|
||||
{
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
@@ -272,8 +286,8 @@ class MigrationDokumentJaminanSeeder extends Seeder
|
||||
$debiture = Debiture::where('mig_kd_debitur_seq', $code)->first();
|
||||
|
||||
if ($debiture) {
|
||||
$cache[$code] = $debiture->id;
|
||||
return $debiture->id;
|
||||
$cache[$code] = $debiture->name;
|
||||
return $debiture->name;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user