From aee13fcba91af89f59d7612df4e1c866a54fe78f Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 29 Jan 2025 19:43:36 +0700 Subject: [PATCH] feat(jobs): tambahkan job untuk memproses data detail tagihan - Membuat kelas ProcessBillDetailDataJob untuk memproses file CSV detail tagihan. - Menangani pembacaan file dan pemrosesan data dengan penanganan kesalahan. - Menggunakan model TempBillDetail untuk menyimpan data yang diproses. --- app/Jobs/ProcessBillDetailDataJob.php | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 app/Jobs/ProcessBillDetailDataJob.php diff --git a/app/Jobs/ProcessBillDetailDataJob.php b/app/Jobs/ProcessBillDetailDataJob.php new file mode 100644 index 0000000..2770fd7 --- /dev/null +++ b/app/Jobs/ProcessBillDetailDataJob.php @@ -0,0 +1,61 @@ +getFillable(); + while (($row = fgetcsv($handle, 0, ";")) !== false) { + if (count($headers) === count($row)) { + $data = array_combine($headers, $row); + + try { + TempBillDetail::upadteOrCreate(['_id',$data['_id']],$data); + } catch (Exception $e) { + \Log::error('Error processing bill detail: ' . $e->getMessage()); + } + } + } + fclose($handle); + } else { + throw new Exception("Unable to open file: {$filePath}"); + } + } catch (Exception $e) { + \Log::error('Error in ProcessBillDetailDataJob: ' . $e->getMessage()); + throw $e; + } + } +}