mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
fixes from tests
This commit is contained in:
parent
4a56c114d0
commit
a31e810ec9
@ -587,10 +587,9 @@ class ExpenseController extends BaseController
|
|||||||
public function edocument(EDocumentRequest $request): string
|
public function edocument(EDocumentRequest $request): string
|
||||||
{
|
{
|
||||||
if ($request->hasFile("documents")) {
|
if ($request->hasFile("documents")) {
|
||||||
return (new ImportEDocument($request->file("documents")[0]->get(), $request->file("documents")[0]->getClientOriginalName(), $request->file("documents")[0]->getMimeType()))->handle();
|
return (new ImportEDocument($request->file("documents")->get(), $request->file("documents")->getClientOriginalName(), $request->file("documents")->getMimeType()))->handle();
|
||||||
} else {
|
|
||||||
return "No file found";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "No file found";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,13 @@
|
|||||||
namespace App\Services\EDocument\Imports;
|
namespace App\Services\EDocument\Imports;
|
||||||
|
|
||||||
use App\Factory\ExpenseFactory;
|
use App\Factory\ExpenseFactory;
|
||||||
|
use App\Factory\VendorContactFactory;
|
||||||
use App\Factory\VendorFactory;
|
use App\Factory\VendorFactory;
|
||||||
use App\Models\Country;
|
use App\Models\Country;
|
||||||
use App\Models\Currency;
|
use App\Models\Currency;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use App\Models\Vendor;
|
use App\Models\Vendor;
|
||||||
|
use App\Models\VendorContact;
|
||||||
use App\Services\AbstractService;
|
use App\Services\AbstractService;
|
||||||
use App\Utils\TempFile;
|
use App\Utils\TempFile;
|
||||||
use App\Utils\Traits\SavesDocuments;
|
use App\Utils\Traits\SavesDocuments;
|
||||||
@ -52,14 +54,14 @@ class MindeeEDocument extends AbstractService
|
|||||||
|
|
||||||
// perform parsing
|
// perform parsing
|
||||||
$mindeeClient = new Client($api_key);
|
$mindeeClient = new Client($api_key);
|
||||||
$inputSource = $mindeeClient->sourceFromFile($this->file);
|
$inputSource = $mindeeClient->sourceFromBytes($this->file->get(), $this->file->getClientOriginalName());
|
||||||
$result = $mindeeClient->parse(InvoiceV4::class, $inputSource);
|
$result = $mindeeClient->parse(InvoiceV4::class, $inputSource);
|
||||||
$this->incrementRequestCounts();
|
$this->incrementRequestCounts();
|
||||||
|
|
||||||
/** @var \Mindee\Product\Invoice\InvoiceV4Document $prediction */
|
/** @var \Mindee\Product\Invoice\InvoiceV4Document $prediction */
|
||||||
$prediction = $result->document->inference->prediction;
|
$prediction = $result->document->inference->prediction;
|
||||||
|
|
||||||
if ($prediction->documentType !== 'INVOICE')
|
if ($prediction->documentType->value !== 'INVOICE')
|
||||||
throw new Exception('Unsupported document type');
|
throw new Exception('Unsupported document type');
|
||||||
|
|
||||||
$grandTotalAmount = $prediction->totalAmount->value;
|
$grandTotalAmount = $prediction->totalAmount->value;
|
||||||
@ -95,15 +97,20 @@ class MindeeEDocument extends AbstractService
|
|||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$vendor = Vendor::where('email', $prediction->supplierEmail)->first();
|
$vendor = null;
|
||||||
|
$vendor_contact = VendorContact::where("company_id", $user->company()->id)->where("email", $prediction->supplierEmail)->first();
|
||||||
|
if ($vendor_contact)
|
||||||
|
return $vendor = $vendor_contact->vendor;
|
||||||
|
|
||||||
if (!empty($vendor)) {
|
if ($vendor)
|
||||||
|
$vendor = Vendor::where("company_id", $user->company()->id)->where("name", $prediction->supplierName)->first();
|
||||||
|
|
||||||
|
if ($vendor) {
|
||||||
// Vendor found
|
// Vendor found
|
||||||
$expense->vendor_id = $vendor->id;
|
$expense->vendor_id = $vendor->id;
|
||||||
} else {
|
} else {
|
||||||
$vendor = VendorFactory::create($user->company()->id, $user->id);
|
$vendor = VendorFactory::create($user->company()->id, $user->id);
|
||||||
$vendor->name = $prediction->supplierName;
|
$vendor->name = $prediction->supplierName;
|
||||||
$vendor->email = $prediction->supplierEmail;
|
|
||||||
|
|
||||||
$vendor->currency_id = Currency::whereCode($invoiceCurrency)->first()?->id;
|
$vendor->currency_id = Currency::whereCode($invoiceCurrency)->first()?->id;
|
||||||
$vendor->phone = $prediction->supplierPhoneNumber;
|
$vendor->phone = $prediction->supplierPhoneNumber;
|
||||||
@ -111,9 +118,19 @@ class MindeeEDocument extends AbstractService
|
|||||||
// $vendor->address2 = $address_2;
|
// $vendor->address2 = $address_2;
|
||||||
// $vendor->city = $city;
|
// $vendor->city = $city;
|
||||||
// $vendor->postal_code = $postcode;
|
// $vendor->postal_code = $postcode;
|
||||||
|
$country = Country::where('iso_3166_2', $country)->first()?->id || Country::where('iso_3166_3', $country)->first()?->id || null;
|
||||||
|
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::where('iso_3166_2', $country)->first()?->id || Country::where('iso_3166_3', $country)->first()?->id || null; // could be 2 or 3 length
|
||||||
|
|
||||||
$vendor->save();
|
$vendor->save();
|
||||||
|
|
||||||
|
if ($prediction->supplierEmail) {
|
||||||
|
$vendor_contact = VendorContactFactory::create($user->company()->id, $user->id);
|
||||||
|
$vendor_contact->vendor_id = $vendor->id;
|
||||||
|
$vendor_contact->email = $prediction->supplierEmail;
|
||||||
|
$vendor_contact->save();
|
||||||
|
}
|
||||||
|
|
||||||
$expense->vendor_id = $vendor->id;
|
$expense->vendor_id = $vendor->id;
|
||||||
}
|
}
|
||||||
$expense->transaction_reference = $documentno;
|
$expense->transaction_reference = $documentno;
|
||||||
|
@ -71,7 +71,7 @@ class ParseEDocument extends AbstractService
|
|||||||
if ($zugferd_exception)
|
if ($zugferd_exception)
|
||||||
nlog("Zugferd Exception: " . $zugferd_exception->getMessage());
|
nlog("Zugferd Exception: " . $zugferd_exception->getMessage());
|
||||||
if ($mindee_exception)
|
if ($mindee_exception)
|
||||||
nlog("Mindee Exception: " . $zugferd_exception->getMessage());
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user