mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
log error in all cases for better debugging experience + minor find vendor improvements
This commit is contained in:
parent
f44559869a
commit
ec0df164ce
@ -100,9 +100,8 @@ class MindeeEDocument extends AbstractService
|
||||
$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 ($vendor)
|
||||
$vendor = $vendor_contact->vendor;
|
||||
if (!$vendor)
|
||||
$vendor = Vendor::where("company_id", $user->company()->id)->where("name", $prediction->supplierName)->first();
|
||||
|
||||
if ($vendor) {
|
||||
|
@ -44,35 +44,29 @@ class ParseEDocument extends AbstractService
|
||||
$account = auth()->user()->account;
|
||||
|
||||
// ZUGFERD - try to parse via Zugferd lib
|
||||
$zugferd_exception = null;
|
||||
try {
|
||||
switch (true) {
|
||||
case $this->file->getExtension() == 'pdf':
|
||||
case $this->file->getExtension() == 'xml' && stristr($this->file->get(), "urn:cen.eu:en16931:2017"):
|
||||
case $this->file->getExtension() == 'xml' && stristr($this->file->get(), "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0"):
|
||||
case $this->file->getExtension() == 'xml' && stristr($this->file->get(), "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_2.1"):
|
||||
case $this->file->getExtension() == 'xml' && stristr($this->file->get(), "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_2.0"):
|
||||
switch (true) {
|
||||
case $this->file->getExtension() == 'pdf':
|
||||
case $this->file->getExtension() == 'xml' && stristr($this->file->get(), "urn:cen.eu:en16931:2017"):
|
||||
case $this->file->getExtension() == 'xml' && stristr($this->file->get(), "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0"):
|
||||
case $this->file->getExtension() == 'xml' && stristr($this->file->get(), "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_2.1"):
|
||||
case $this->file->getExtension() == 'xml' && stristr($this->file->get(), "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_2.0"):
|
||||
try {
|
||||
return (new ZugferdEDocument($this->file))->run();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$zugferd_exception = $e;
|
||||
} catch (Exception $e) {
|
||||
nlog("Zugferd Exception: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// MINDEE OCR - try to parse via mindee external service
|
||||
$mindee_exception = null;
|
||||
if (config('services.mindee.api_key') && (Ninja::isSelfHost() || (Ninja::isHosted() && $account->isPaid() && $account->plan == 'enterprise')))
|
||||
try {
|
||||
return (new MindeeEDocument($this->file))->run();
|
||||
} catch (Exception $e) {
|
||||
// ignore not available exceptions
|
||||
$mindee_exception = $e;
|
||||
if (!($e->getMessage() == 'Unsupported document type'))
|
||||
nlog("Mindee Exception: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// log exceptions and throw error
|
||||
if ($zugferd_exception)
|
||||
nlog("Zugferd Exception: " . $zugferd_exception->getMessage());
|
||||
if ($mindee_exception)
|
||||
nlog("Mindee Exception: " . $mindee_exception->getMessage());
|
||||
// NO PARSER OR ERROR
|
||||
throw new Exception("File type not supported or issue while parsing", 409);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ use App\Models\Country;
|
||||
use App\Models\Currency;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\VendorContact;
|
||||
use App\Services\AbstractService;
|
||||
use App\Utils\TempFile;
|
||||
use App\Utils\Traits\SavesDocuments;
|
||||
@ -46,6 +47,7 @@ class ZugferdEDocument extends AbstractService
|
||||
public function run(): Expense
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$this->document = ZugferdDocumentReader::readAndGuessFromContent($this->file->get());
|
||||
$this->document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $invoiceCurrency, $taxCurrency, $documentname, $documentlanguage, $effectiveSpecifiedPeriod);
|
||||
$this->document->getDocumentSummation($grandTotalAmount, $duePayableAmount, $lineTotalAmount, $chargeTotalAmount, $allowanceTotalAmount, $taxBasisTotalAmount, $taxTotalAmount, $roundingAmount, $totalPrepaidAmount);
|
||||
@ -93,11 +95,19 @@ class ZugferdEDocument extends AbstractService
|
||||
$this->document->getDocumentSellerContact($person_name, $person_department, $contact_phone, $contact_fax, $contact_email);
|
||||
$this->document->getDocumentSellerAddress($address_1, $address_2, $address_3, $postcode, $city, $country, $subdivision);
|
||||
$this->document->getDocumentSellerTaxRegistration($taxtype);
|
||||
|
||||
$taxid = null;
|
||||
if (array_key_exists("VA", $taxtype)) {
|
||||
$taxid = $taxtype["VA"];
|
||||
}
|
||||
$vendor = Vendor::where('vat_number', $taxid)->first();
|
||||
$vendor = Vendor::where("company_id", $user->company()->id)->where('vat_number', $taxid)->first();
|
||||
if (!$vendor) {
|
||||
$vendor_contact = VendorContact::where("company_id", $user->company()->id)->where("email", $contact_email)->first();
|
||||
if ($vendor_contact)
|
||||
$vendor = $vendor_contact->vendor;
|
||||
}
|
||||
if (!$vendor)
|
||||
$vendor = Vendor::where("company_id", $user->company()->id)->where("name", $person_name)->first();
|
||||
|
||||
if (!empty($vendor)) {
|
||||
// Vendor found
|
||||
|
Loading…
x
Reference in New Issue
Block a user