feat(job): perbarui jalur file dan pemisah CSV pada ProcessTransactionDataJob
- Memperbarui pemisah CSV dari ';' menjadi '~'. - Menambahkan pengecekan untuk memastikan '_id' tidak sama dengan 'id' sebelum memperbarui atau membuat entri baru.
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
public function handle()
|
||||
: void
|
||||
{
|
||||
$filePath = storage_path('app/20240901.ST.TRANSACTION.csv'); // Adjust this path as needed
|
||||
$filePath = storage_path('app/20250207.ST.TRANSACTION.csv'); // Adjust this path as needed
|
||||
try {
|
||||
if (!file_exists($filePath)) {
|
||||
throw new Exception("File not found: $filePath");
|
||||
@@ -45,12 +45,14 @@
|
||||
|
||||
if ($handle !== false) {
|
||||
$headers = (new TempTransaction())->getFillable();
|
||||
while (($row = fgetcsv($handle, 0, ";")) !== false) {
|
||||
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||
if (count($headers) === count($row)) {
|
||||
$data = array_combine($headers, $row);
|
||||
|
||||
try {
|
||||
TempTransaction::updateOrCreate(['_id' => $data['_id']], $data);
|
||||
if($data['_id'] !== 'id') {
|
||||
TempTransaction::updateOrCreate(['_id' => $data['_id']], $data);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::error('Error processing transactions: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user