mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
wip: adding mindee
This commit is contained in:
parent
2a7eb83965
commit
f480108c25
@ -13,7 +13,6 @@ namespace App\Services\EDocument\Imports;
|
|||||||
|
|
||||||
use App\Factory\ExpenseFactory;
|
use App\Factory\ExpenseFactory;
|
||||||
use App\Factory\VendorFactory;
|
use App\Factory\VendorFactory;
|
||||||
use App\Jobs\Util\UploadFile;
|
|
||||||
use App\Models\Country;
|
use App\Models\Country;
|
||||||
use App\Models\Currency;
|
use App\Models\Currency;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
@ -29,7 +28,6 @@ use Illuminate\Http\UploadedFile;
|
|||||||
class MindeeEDocument extends AbstractService
|
class MindeeEDocument extends AbstractService
|
||||||
{
|
{
|
||||||
use SavesDocuments;
|
use SavesDocuments;
|
||||||
public ZugferdDocumentReader|string $document;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@ -62,19 +60,21 @@ class MindeeEDocument extends AbstractService
|
|||||||
$inputSource = $mindeeClient->sourceFromFile($this->file);
|
$inputSource = $mindeeClient->sourceFromFile($this->file);
|
||||||
|
|
||||||
// Parse the file
|
// Parse the file
|
||||||
$apiResponse = $mindeeClient->parse(InvoiceV4::class, $inputSource);
|
$result = $mindeeClient->parse(InvoiceV4::class, $inputSource);
|
||||||
|
|
||||||
|
/** @var \Mindee\Product\Invoice\InvoiceV4Document $prediction */
|
||||||
|
$prediction = $result->document->inference->prediction;
|
||||||
|
|
||||||
|
$grandTotalAmount = $prediction->totalAmount->value;
|
||||||
|
$documentno = $prediction->invoiceNumber->value;
|
||||||
|
$documentdate = $prediction->date->value;
|
||||||
|
$invoiceCurrency = $prediction->locale->currency;
|
||||||
|
$country = $prediction->locale->country;
|
||||||
|
|
||||||
$expense = Expense::where('amount', $grandTotalAmount)->where("transaction_reference", $documentno)->whereDate("date", $documentdate)->first();
|
$expense = Expense::where('amount', $grandTotalAmount)->where("transaction_reference", $documentno)->whereDate("date", $documentdate)->first();
|
||||||
if (empty($expense)) {
|
if (empty($expense)) {
|
||||||
// The document does not exist as an expense
|
// The document does not exist as an expense
|
||||||
// Handle accordingly
|
// Handle accordingly
|
||||||
$visualizer = new ZugferdVisualizer($this->document);
|
|
||||||
$visualizer->setDefaultTemplate();
|
|
||||||
$visualizer->setRenderer(app(ZugferdVisualizerLaravelRenderer::class));
|
|
||||||
$visualizer->setPdfFontDefault("arial");
|
|
||||||
$visualizer->setPdfPaperSize('A4-P');
|
|
||||||
$visualizer->setTemplate('edocument.xinvoice');
|
|
||||||
|
|
||||||
$expense = ExpenseFactory::create($user->company()->id, $user->id);
|
$expense = ExpenseFactory::create($user->company()->id, $user->id);
|
||||||
$expense->date = $documentdate;
|
$expense->date = $documentdate;
|
||||||
$expense->user_id = $user->id;
|
$expense->user_id = $user->id;
|
||||||
@ -83,11 +83,7 @@ class MindeeEDocument extends AbstractService
|
|||||||
$expense->currency_id = Currency::whereCode($invoiceCurrency)->first()->id;
|
$expense->currency_id = Currency::whereCode($invoiceCurrency)->first()->id;
|
||||||
$expense->save();
|
$expense->save();
|
||||||
|
|
||||||
$documents = [];
|
$this->saveDocument($this->file, $expense);
|
||||||
array_push($documents, $this->file);
|
|
||||||
if ($this->file->getExtension() == "xml")
|
|
||||||
array_push($documents, TempFile::UploadedFileFromRaw($visualizer->renderPdf(), $documentno . "_visualiser.pdf", "application/pdf"));
|
|
||||||
$this->saveDocuments($documents, $expense);
|
|
||||||
$expense->saveQuietly();
|
$expense->saveQuietly();
|
||||||
|
|
||||||
if ($taxCurrency && $taxCurrency != $invoiceCurrency) {
|
if ($taxCurrency && $taxCurrency != $invoiceCurrency) {
|
||||||
@ -104,10 +100,6 @@ class MindeeEDocument extends AbstractService
|
|||||||
$counter++;
|
$counter++;
|
||||||
} while ($this->document->nextDocumentTax());
|
} while ($this->document->nextDocumentTax());
|
||||||
}
|
}
|
||||||
$this->document->getDocumentSeller($name, $buyer_id, $buyer_description);
|
|
||||||
$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;
|
$taxid = null;
|
||||||
if (array_key_exists("VA", $taxtype)) {
|
if (array_key_exists("VA", $taxtype)) {
|
||||||
$taxid = $taxtype["VA"];
|
$taxid = $taxtype["VA"];
|
||||||
@ -124,12 +116,12 @@ class MindeeEDocument extends AbstractService
|
|||||||
$vendor->vat_number = $taxid;
|
$vendor->vat_number = $taxid;
|
||||||
}
|
}
|
||||||
$vendor->currency_id = Currency::whereCode($invoiceCurrency)->first()->id;
|
$vendor->currency_id = Currency::whereCode($invoiceCurrency)->first()->id;
|
||||||
$vendor->phone = $contact_phone;
|
$vendor->phone = $prediction->supplierPhoneNumber;
|
||||||
$vendor->address1 = $address_1;
|
$vendor->address1 = $address_1; // TODO: we only have the full address string
|
||||||
$vendor->address2 = $address_2;
|
$vendor->address2 = $address_2;
|
||||||
$vendor->city = $city;
|
$vendor->city = $city;
|
||||||
$vendor->postal_code = $postcode;
|
$vendor->postal_code = $postcode;
|
||||||
$vendor->country_id = Country::where('iso_3166_2', $country)->first()->id;
|
$vendor->country_id = Country::where('iso_3166_2', $country)->first()->id; // could be 2 or 3 length
|
||||||
|
|
||||||
$vendor->save();
|
$vendor->save();
|
||||||
$expense->vendor_id = $vendor->id;
|
$expense->vendor_id = $vendor->id;
|
||||||
|
@ -206,11 +206,11 @@ class InboundMailEngine
|
|||||||
if (!$expense)
|
if (!$expense)
|
||||||
$expense = ExpenseFactory::create($company->id, $company->owner()->id);
|
$expense = ExpenseFactory::create($company->id, $company->owner()->id);
|
||||||
|
|
||||||
if (!$expense->public_notes)
|
if ($is_imported_by_parser)
|
||||||
$expense->public_notes = $email->subject;
|
$expense->public_notes = $expense->public_notes . $email->subject;
|
||||||
|
|
||||||
if (!$expense->private_notes)
|
if ($is_imported_by_parser)
|
||||||
$expense->private_notes = $email->text_body;
|
$expense->private_notes = $expense->private_notes . $email->text_body;
|
||||||
|
|
||||||
if (!$expense->date)
|
if (!$expense->date)
|
||||||
$expense->date = $email->date;
|
$expense->date = $email->date;
|
||||||
|
@ -32,10 +32,10 @@
|
|||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
|
"ext-curl": "*",
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-libxml": "*",
|
"ext-libxml": "*",
|
||||||
"ext-curl": "*",
|
|
||||||
"afosto/yaac": "^1.4",
|
"afosto/yaac": "^1.4",
|
||||||
"asm/php-ansible": "dev-main",
|
"asm/php-ansible": "dev-main",
|
||||||
"authorizenet/authorizenet": "^2.0",
|
"authorizenet/authorizenet": "^2.0",
|
||||||
@ -57,12 +57,12 @@
|
|||||||
"hedii/laravel-gelf-logger": "^9",
|
"hedii/laravel-gelf-logger": "^9",
|
||||||
"horstoeko/orderx": "dev-master",
|
"horstoeko/orderx": "dev-master",
|
||||||
"horstoeko/zugferd": "^1",
|
"horstoeko/zugferd": "^1",
|
||||||
"horstoeko/zugferdvisualizer":"^1",
|
"horstoeko/zugferdvisualizer": "^1",
|
||||||
"hyvor/php-json-exporter": "^0.0.3",
|
"hyvor/php-json-exporter": "^0.0.3",
|
||||||
"imdhemy/laravel-purchases": "^1.7",
|
"imdhemy/laravel-purchases": "^1.7",
|
||||||
"intervention/image": "^2.5",
|
"intervention/image": "^2.5",
|
||||||
"invoiceninja/inspector": "^3.0",
|
|
||||||
"invoiceninja/einvoice": "dev-main",
|
"invoiceninja/einvoice": "dev-main",
|
||||||
|
"invoiceninja/inspector": "^3.0",
|
||||||
"invoiceninja/ubl_invoice": "^2",
|
"invoiceninja/ubl_invoice": "^2",
|
||||||
"josemmo/facturae-php": "^1.7",
|
"josemmo/facturae-php": "^1.7",
|
||||||
"laracasts/presenter": "^0.2.1",
|
"laracasts/presenter": "^0.2.1",
|
||||||
@ -78,6 +78,7 @@
|
|||||||
"livewire/livewire": "^3.0",
|
"livewire/livewire": "^3.0",
|
||||||
"mailgun/mailgun-php": "^3.6",
|
"mailgun/mailgun-php": "^3.6",
|
||||||
"microsoft/microsoft-graph": "^1.69",
|
"microsoft/microsoft-graph": "^1.69",
|
||||||
|
"mindee/mindee": "^1.8",
|
||||||
"mollie/mollie-api-php": "^2.36",
|
"mollie/mollie-api-php": "^2.36",
|
||||||
"nelexa/zip": "^4.0",
|
"nelexa/zip": "^4.0",
|
||||||
"nordigen/nordigen-php": "^1.1",
|
"nordigen/nordigen-php": "^1.1",
|
||||||
|
52
composer.lock
generated
52
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "f0c032698a2cafaf6d112d0fb27cb010",
|
"content-hash": "bea0d5e6d14872ba2000632b2b8d287d",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "adrienrn/php-mimetyper",
|
"name": "adrienrn/php-mimetyper",
|
||||||
@ -6572,6 +6572,52 @@
|
|||||||
},
|
},
|
||||||
"time": "2024-01-15T18:49:30+00:00"
|
"time": "2024-01-15T18:49:30+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "mindee/mindee",
|
||||||
|
"version": "v1.8.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mindee/mindee-api-php.git",
|
||||||
|
"reference": "cf7de6c6e23fa81372f1f1d314bbf93e1f811953"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/mindee/mindee-api-php/zipball/cf7de6c6e23fa81372f1f1d314bbf93e1f811953",
|
||||||
|
"reference": "cf7de6c6e23fa81372f1f1d314bbf93e1f811953",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-curl": "*",
|
||||||
|
"ext-fileinfo": "*",
|
||||||
|
"ext-json": "*",
|
||||||
|
"php": ">=7.4",
|
||||||
|
"symfony/console": ">=5.4"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"friendsofphp/php-cs-fixer": "^3.38",
|
||||||
|
"phpunit/phpunit": "^9.6",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7"
|
||||||
|
},
|
||||||
|
"bin": [
|
||||||
|
"bin/mindee"
|
||||||
|
],
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Mindee\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "Mindee Client Library for PHP",
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/mindee/mindee-api-php/issues",
|
||||||
|
"source": "https://github.com/mindee/mindee-api-php/tree/v1.8.0"
|
||||||
|
},
|
||||||
|
"time": "2024-05-31T15:24:47+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "mollie/mollie-api-php",
|
"name": "mollie/mollie-api-php",
|
||||||
"version": "v2.68.0",
|
"version": "v2.68.0",
|
||||||
@ -19770,10 +19816,10 @@
|
|||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
|
"ext-curl": "*",
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-libxml": "*",
|
"ext-libxml": "*"
|
||||||
"ext-curl": "*"
|
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.6.0"
|
"plugin-api-version": "2.6.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user