diff --git a/app/Http/Controllers/ExpenseController.php b/app/Http/Controllers/ExpenseController.php index 091eb519ca..cc12786402 100644 --- a/app/Http/Controllers/ExpenseController.php +++ b/app/Http/Controllers/ExpenseController.php @@ -586,9 +586,17 @@ class ExpenseController extends BaseController public function edocument(EDocumentRequest $request): string { - if ($request->hasFile("documents")) { - return (new ImportEDocument($request->file("documents")->get(), $request->file("documents")->getClientOriginalName(), $request->file("documents")->getMimeType()))->handle(); - } + if ($request->hasFile("documents")) + try { + + return (new ImportEDocument($request->file("documents")->get(), $request->file("documents")->getClientOriginalName(), $request->file("documents")->getMimeType()))->handle(); + + } catch (\Exception $e) { + if ($e->getCode() == 409) + return $e->getMessage(); + + throw $e; + } return "No file found"; } diff --git a/app/Services/EDocument/Imports/MindeeEDocument.php b/app/Services/EDocument/Imports/MindeeEDocument.php index d73c7546c9..a37e0bf919 100644 --- a/app/Services/EDocument/Imports/MindeeEDocument.php +++ b/app/Services/EDocument/Imports/MindeeEDocument.php @@ -79,7 +79,7 @@ class MindeeEDocument extends AbstractService $expense->user_id = $user->id; $expense->company_id = $user->company->id; $expense->public_notes = $documentno; - $expense->currency_id = Currency::whereCode($invoiceCurrency)->first()->id; + $expense->currency_id = Currency::whereCode($invoiceCurrency)->first()?->id || $user->company->settings->currency_id; $expense->save(); $this->saveDocuments([ @@ -118,9 +118,11 @@ class MindeeEDocument extends AbstractService // $vendor->address2 = $address_2; // $vendor->city = $city; // $vendor->postal_code = $postcode; - $country = Country::where('iso_3166_2', $country)->first()?->id || Country::where('iso_3166_3', $country)->first()?->id || null; + $country = app('countries')->first(function ($c) use ($country) { + return $c->iso_3166_2 == $country || $c->iso_3166_3 == $country; + }); if ($country) - $vendor->country_id = Country::where('iso_3166_2', $country)->first()?->id || Country::where('iso_3166_3', $country)->first()?->id || null; // could be 2 or 3 length + $vendor->country_id = $country->id; $vendor->save(); diff --git a/app/Services/EDocument/Imports/ParseEDocument.php b/app/Services/EDocument/Imports/ParseEDocument.php index 40afcb8f31..aed13a9fda 100644 --- a/app/Services/EDocument/Imports/ParseEDocument.php +++ b/app/Services/EDocument/Imports/ParseEDocument.php @@ -71,7 +71,7 @@ class ParseEDocument extends AbstractService nlog("Zugferd Exception: " . $zugferd_exception->getMessage()); if ($mindee_exception) nlog("Mindee Exception: " . $mindee_exception->getMessage()); - throw new Exception("File type not supported or issue while parsing"); + throw new Exception("File type not supported or issue while parsing", 409); } } diff --git a/app/Services/EDocument/Imports/ZugferdEDocument.php b/app/Services/EDocument/Imports/ZugferdEDocument.php index 36fe1b77d1..e685cbe6ad 100644 --- a/app/Services/EDocument/Imports/ZugferdEDocument.php +++ b/app/Services/EDocument/Imports/ZugferdEDocument.php @@ -66,7 +66,7 @@ class ZugferdEDocument extends AbstractService $expense->user_id = $user->id; $expense->company_id = $user->company->id; $expense->public_notes = $documentno; - $expense->currency_id = Currency::whereCode($invoiceCurrency)->first()->id; + $expense->currency_id = Currency::whereCode($invoiceCurrency)->first()?->id || $user->company->settings->currency_id; $expense->save(); $documents = [$this->file]; @@ -114,7 +114,11 @@ class ZugferdEDocument extends AbstractService $vendor->address2 = $address_2; $vendor->city = $city; $vendor->postal_code = $postcode; - $vendor->country_id = Country::where('iso_3166_2', $country)->first()->id; + $country = app('countries')->first(function ($c) use ($country) { + return $c->iso_3166_2 == $country || $c->iso_3166_3 == $country; + }); + if ($country) + $vendor->country_id = $country->id; $vendor->save(); $expense->vendor_id = $vendor->id;