feat(job): perbarui jalur file dan pemisah CSV pada ProcessStmtNarrFormatDataJob

- Memperbarui pemisah CSV dari ';' menjadi '~'.
- Menambahkan pengecekan untuk memastikan '_id' tidak sama dengan 'id' sebelum melakukan update atau create.
This commit is contained in:
Daeng Deni Mardaeni
2025-04-09 13:50:56 +07:00
parent 8d3e6a21f2
commit 225ec85bad

View File

@@ -29,7 +29,7 @@
public function handle()
: void
{
$filePath = storage_path('app/20240901.ST.STMT.NARR.FORMAT.csv'); // Adjust this path as needed
$filePath = storage_path('app/20250207.ST.STMT.NARR.FORMAT.csv'); // Adjust this path as needed
try {
if (!file_exists($filePath)) {
throw new Exception("File not found: $filePath");
@@ -45,11 +45,13 @@
if ($handle !== false) {
$headers = (new TempStmtNarrFormat())->getFillable();
while (($row = fgetcsv($handle, 0, ";")) !== false) {
while (($row = fgetcsv($handle, 0, "~")) !== false) {
if (count($headers) === count($row)) {
$data = array_combine($headers, $row);
try {
TempStmtNarrFormat::updateOrCreate(['_id' => $data['_id']], $data);
if($data['_id'] !== 'id') {
TempStmtNarrFormat::updateOrCreate(['_id' => $data['_id']], $data);
}
} catch (Exception $e) {
Log::error('Error processing stmt narr format: ' . $e->getMessage());
}