1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00

fix for api error and requested changes

This commit is contained in:
paulwer 2024-06-26 17:34:32 +02:00
parent 7e9e33b846
commit 96b60f4ee2
4 changed files with 23 additions and 9 deletions

View File

@ -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";
}

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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;