diff --git a/app/Jobs/ProcessTransactionDataJob.php b/app/Jobs/ProcessTransactionDataJob.php new file mode 100644 index 0000000..3601c9b --- /dev/null +++ b/app/Jobs/ProcessTransactionDataJob.php @@ -0,0 +1,68 @@ +getFillable(); + while (($row = fgetcsv($handle, 0, ";")) !== false) { + if (count($headers) === count($row)) { + $data = array_combine($headers, $row); + + try { + TempTransaction::updateOrCreate(['_id' => $data['_id']], $data); + } catch (Exception $e) { + Log::error('Error processing transactions: ' . $e->getMessage()); + } + } + } + fclose($handle); + } else { + throw new Exception("Unable to open file: {$filePath}"); + } + } catch (Exception $e) { + Log::error('Error in ProcessTransctionDataJob: ' . $e->getMessage()); + throw $e; + } + } + } diff --git a/app/Models/TempTransaction.php b/app/Models/TempTransaction.php new file mode 100644 index 0000000..72e3aa7 --- /dev/null +++ b/app/Models/TempTransaction.php @@ -0,0 +1,23 @@ +id(); + foreach ($fieldsArray as $field) { + $field = trim($field); + $table->text($field)->nullable(); + } + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('temp_transactions'); + } +};