mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 20:04:31 -04:00
wip mindee
This commit is contained in:
parent
f480108c25
commit
aa12fe3976
@ -65,6 +65,9 @@ class MindeeEDocument extends AbstractService
|
|||||||
/** @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')
|
||||||
|
throw new Exception('Unsupported document type');
|
||||||
|
|
||||||
$grandTotalAmount = $prediction->totalAmount->value;
|
$grandTotalAmount = $prediction->totalAmount->value;
|
||||||
$documentno = $prediction->invoiceNumber->value;
|
$documentno = $prediction->invoiceNumber->value;
|
||||||
$documentdate = $prediction->date->value;
|
$documentdate = $prediction->date->value;
|
||||||
@ -86,42 +89,38 @@ class MindeeEDocument extends AbstractService
|
|||||||
$this->saveDocument($this->file, $expense);
|
$this->saveDocument($this->file, $expense);
|
||||||
$expense->saveQuietly();
|
$expense->saveQuietly();
|
||||||
|
|
||||||
if ($taxCurrency && $taxCurrency != $invoiceCurrency) {
|
// if ($taxCurrency && $taxCurrency != $invoiceCurrency) {
|
||||||
$expense->private_notes = ctrans("texts.tax_currency_mismatch");
|
// $expense->private_notes = ctrans("texts.tax_currency_mismatch");
|
||||||
}
|
// }
|
||||||
$expense->uses_inclusive_taxes = True;
|
$expense->uses_inclusive_taxes = True;
|
||||||
$expense->amount = $grandTotalAmount;
|
$expense->amount = $grandTotalAmount;
|
||||||
$counter = 1;
|
$counter = 1;
|
||||||
if ($this->document->firstDocumentTax()) {
|
foreach ($prediction->taxes as $taxesElem) {
|
||||||
do {
|
$expense->{"tax_amount$counter"} = $taxesElem->amount;
|
||||||
$this->document->getDocumentTax($categoryCode, $typeCode, $basisAmount, $calculatedAmount, $rateApplicablePercent, $exemptionReason, $exemptionReasonCode, $lineTotalBasisAmount, $allowanceChargeBasisAmount, $taxPointDate, $dueDateTypeCode);
|
$expense->{"tax_rate$counter"} = $taxesElem->rate;
|
||||||
$expense->{"tax_amount$counter"} = $calculatedAmount;
|
$counter++;
|
||||||
$expense->{"tax_rate$counter"} = $rateApplicablePercent;
|
|
||||||
$counter++;
|
|
||||||
} while ($this->document->nextDocumentTax());
|
|
||||||
}
|
}
|
||||||
$taxid = null;
|
$taxid = null;
|
||||||
if (array_key_exists("VA", $taxtype)) {
|
if (array_key_exists("VA", $taxtype)) {
|
||||||
$taxid = $taxtype["VA"];
|
$taxid = $taxtype["VA"];
|
||||||
}
|
}
|
||||||
$vendor = Vendor::where('vat_number', $taxid)->first();
|
$vendor = Vendor::where('email', $prediction->supplierEmail)->first();
|
||||||
|
|
||||||
if (!empty($vendor)) {
|
if (!empty($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 = $name;
|
$vendor->name = $prediction->supplierName;
|
||||||
if ($taxid != null) {
|
$vendor->email = $prediction->supplierEmail;
|
||||||
$vendor->vat_number = $taxid;
|
|
||||||
}
|
|
||||||
$vendor->currency_id = Currency::whereCode($invoiceCurrency)->first()->id;
|
$vendor->currency_id = Currency::whereCode($invoiceCurrency)->first()->id;
|
||||||
$vendor->phone = $prediction->supplierPhoneNumber;
|
$vendor->phone = $prediction->supplierPhoneNumber;
|
||||||
$vendor->address1 = $address_1; // TODO: we only have the full address string
|
// $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; // 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; // could be 2 or 3 length
|
||||||
|
|
||||||
$vendor->save();
|
$vendor->save();
|
||||||
$expense->vendor_id = $vendor->id;
|
$expense->vendor_id = $vendor->id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user