From b90fb4515f27026b07757eb0e9ccb4a05612d9be Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 17 Oct 2024 08:56:21 +1100 Subject: [PATCH] Fixes for expense imports --- app/Jobs/EDocument/ImportEDocument.php | 3 +-- app/Services/EDocument/Imports/ParseEDocument.php | 2 ++ app/Services/EDocument/Imports/ZugferdEDocument.php | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Jobs/EDocument/ImportEDocument.php b/app/Jobs/EDocument/ImportEDocument.php index e403caa704..d1f3ce41a6 100644 --- a/app/Jobs/EDocument/ImportEDocument.php +++ b/app/Jobs/EDocument/ImportEDocument.php @@ -53,7 +53,7 @@ public function handle(): Expense public function middleware() { - return [new WithoutOverlapping($this->company->company_key)]; + return [new WithoutOverlapping($this->company->company_key."_expense_import")]; } public function failed($exception = null) @@ -63,7 +63,6 @@ public function failed($exception = null) } $this->fail($exception); //manually fail - prevents future jobs with the same name from being discarded - config(['queue.failed.driver' => null]); } } diff --git a/app/Services/EDocument/Imports/ParseEDocument.php b/app/Services/EDocument/Imports/ParseEDocument.php index 913e293950..f48ab1e697 100644 --- a/app/Services/EDocument/Imports/ParseEDocument.php +++ b/app/Services/EDocument/Imports/ParseEDocument.php @@ -60,6 +60,7 @@ public function run(): Expense return (new ZugferdEDocument($this->file, $this->company))->run(); } catch (\Throwable $e) { nlog("Zugferd Exception: " . $e->getMessage()); + break; } case ($extension == 'xml' || $mimetype == 'application/xml') && stristr($this->file->get(), "urn:cen.eu:en16931:2017"): case ($extension == 'xml' || $mimetype == 'application/xml') && stristr($this->file->get(), "urn:oasis:names:specification:ubl"): @@ -68,6 +69,7 @@ public function run(): Expense } catch(\Throwable $e){ nlog("UBL Import Exception: " . $e->getMessage()); + break; } } diff --git a/app/Services/EDocument/Imports/ZugferdEDocument.php b/app/Services/EDocument/Imports/ZugferdEDocument.php index 9863b6900d..b6118b5922 100644 --- a/app/Services/EDocument/Imports/ZugferdEDocument.php +++ b/app/Services/EDocument/Imports/ZugferdEDocument.php @@ -25,6 +25,8 @@ use Exception; use App\Models\Company; use App\Repositories\ExpenseRepository; +use App\Repositories\VendorContactRepository; +use App\Repositories\VendorRepository; use horstoeko\zugferd\ZugferdDocumentReader; use horstoeko\zugferdvisualizer\ZugferdVisualizer; use horstoeko\zugferdvisualizer\renderer\ZugferdVisualizerLaravelRenderer; @@ -139,7 +141,9 @@ public function run(): Expense if ($country) $vendor->country_id = $country->id; - $vendor->save(); + $vendor_repo = new VendorRepository(new VendorContactRepository()); + $vendor = $vendor_repo->save([], $vendor); + $expense->vendor_id = $vendor->id; } $expense->transaction_reference = $documentno;