wip: adding mindee

This commit is contained in:
paulwer 2024-06-22 19:58:55 +02:00
parent 2a7eb83965
commit f480108c25
4 changed files with 71 additions and 32 deletions

View File

@ -13,7 +13,6 @@ namespace App\Services\EDocument\Imports;
use App\Factory\ExpenseFactory;
use App\Factory\VendorFactory;
use App\Jobs\Util\UploadFile;
use App\Models\Country;
use App\Models\Currency;
use App\Models\Expense;
@ -29,7 +28,6 @@ use Illuminate\Http\UploadedFile;
class MindeeEDocument extends AbstractService
{
use SavesDocuments;
public ZugferdDocumentReader|string $document;
/**
* @throws Exception
@ -62,19 +60,21 @@ class MindeeEDocument extends AbstractService
$inputSource = $mindeeClient->sourceFromFile($this->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();
if (empty($expense)) {
// The document does not exist as an expense
// 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->date = $documentdate;
$expense->user_id = $user->id;
@ -83,11 +83,7 @@ class MindeeEDocument extends AbstractService
$expense->currency_id = Currency::whereCode($invoiceCurrency)->first()->id;
$expense->save();
$documents = [];
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);
$this->saveDocument($this->file, $expense);
$expense->saveQuietly();
if ($taxCurrency && $taxCurrency != $invoiceCurrency) {
@ -104,10 +100,6 @@ class MindeeEDocument extends AbstractService
$counter++;
} 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;
if (array_key_exists("VA", $taxtype)) {
$taxid = $taxtype["VA"];
@ -124,12 +116,12 @@ class MindeeEDocument extends AbstractService
$vendor->vat_number = $taxid;
}
$vendor->currency_id = Currency::whereCode($invoiceCurrency)->first()->id;
$vendor->phone = $contact_phone;
$vendor->address1 = $address_1;
$vendor->phone = $prediction->supplierPhoneNumber;
$vendor->address1 = $address_1; // TODO: we only have the full address string
$vendor->address2 = $address_2;
$vendor->city = $city;
$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();
$expense->vendor_id = $vendor->id;

View File

@ -206,11 +206,11 @@ class InboundMailEngine
if (!$expense)
$expense = ExpenseFactory::create($company->id, $company->owner()->id);
if (!$expense->public_notes)
$expense->public_notes = $email->subject;
if ($is_imported_by_parser)
$expense->public_notes = $expense->public_notes . $email->subject;
if (!$expense->private_notes)
$expense->private_notes = $email->text_body;
if ($is_imported_by_parser)
$expense->private_notes = $expense->private_notes . $email->text_body;
if (!$expense->date)
$expense->date = $email->date;

View File

@ -32,10 +32,10 @@
"type": "project",
"require": {
"php": "^8.2",
"ext-curl": "*",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-curl": "*",
"afosto/yaac": "^1.4",
"asm/php-ansible": "dev-main",
"authorizenet/authorizenet": "^2.0",
@ -57,12 +57,12 @@
"hedii/laravel-gelf-logger": "^9",
"horstoeko/orderx": "dev-master",
"horstoeko/zugferd": "^1",
"horstoeko/zugferdvisualizer":"^1",
"horstoeko/zugferdvisualizer": "^1",
"hyvor/php-json-exporter": "^0.0.3",
"imdhemy/laravel-purchases": "^1.7",
"intervention/image": "^2.5",
"invoiceninja/inspector": "^3.0",
"invoiceninja/einvoice": "dev-main",
"invoiceninja/inspector": "^3.0",
"invoiceninja/ubl_invoice": "^2",
"josemmo/facturae-php": "^1.7",
"laracasts/presenter": "^0.2.1",
@ -78,6 +78,7 @@
"livewire/livewire": "^3.0",
"mailgun/mailgun-php": "^3.6",
"microsoft/microsoft-graph": "^1.69",
"mindee/mindee": "^1.8",
"mollie/mollie-api-php": "^2.36",
"nelexa/zip": "^4.0",
"nordigen/nordigen-php": "^1.1",

52
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f0c032698a2cafaf6d112d0fb27cb010",
"content-hash": "bea0d5e6d14872ba2000632b2b8d287d",
"packages": [
{
"name": "adrienrn/php-mimetyper",
@ -6572,6 +6572,52 @@
},
"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",
"version": "v2.68.0",
@ -19770,10 +19816,10 @@
"prefer-lowest": false,
"platform": {
"php": "^8.2",
"ext-curl": "*",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-curl": "*"
"ext-libxml": "*"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"