mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
fix: mindee taxation transform issue
This commit is contained in:
parent
5c0f228cb7
commit
3f0f5663a9
@ -273,8 +273,6 @@ class PostMarkController extends BaseController
|
|||||||
|
|
||||||
$input = $request->all();
|
$input = $request->all();
|
||||||
|
|
||||||
nlog($input);
|
|
||||||
|
|
||||||
if (!$request->has('token') || $request->token != config('ninja.inbound_mailbox.inbound_webhook_token'))
|
if (!$request->has('token') || $request->token != config('ninja.inbound_mailbox.inbound_webhook_token'))
|
||||||
return response()->json(['message' => 'Unauthorized'], 403);
|
return response()->json(['message' => 'Unauthorized'], 403);
|
||||||
|
|
||||||
@ -282,7 +280,7 @@ class PostMarkController extends BaseController
|
|||||||
nlog('Failed: Message could not be parsed, because required parameters are missing.');
|
nlog('Failed: Message could not be parsed, because required parameters are missing.');
|
||||||
return response()->json(['message' => 'Failed. Missing/Invalid Parameters.'], 400);
|
return response()->json(['message' => 'Failed. Missing/Invalid Parameters.'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$company = MultiDB::findAndSetDbByExpenseMailbox($input["ToFull"][0]["Email"]);
|
$company = MultiDB::findAndSetDbByExpenseMailbox($input["ToFull"][0]["Email"]);
|
||||||
|
|
||||||
if (!$company) {
|
if (!$company) {
|
||||||
|
@ -47,7 +47,7 @@ class MindeeEDocument extends AbstractService
|
|||||||
public function run(): Expense
|
public function run(): Expense
|
||||||
{
|
{
|
||||||
$api_key = config('services.mindee.api_key');
|
$api_key = config('services.mindee.api_key');
|
||||||
|
|
||||||
if (!$api_key)
|
if (!$api_key)
|
||||||
throw new Exception('Mindee API key not configured');
|
throw new Exception('Mindee API key not configured');
|
||||||
|
|
||||||
@ -72,22 +72,22 @@ class MindeeEDocument extends AbstractService
|
|||||||
$country = $prediction->locale->country;
|
$country = $prediction->locale->country;
|
||||||
|
|
||||||
$expense = Expense::query()
|
$expense = Expense::query()
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
->where('amount', $grandTotalAmount)
|
->where('amount', $grandTotalAmount)
|
||||||
->where("transaction_reference", $documentno)
|
->where("transaction_reference", $documentno)
|
||||||
->whereDate("date", $documentdate)
|
->whereDate("date", $documentdate)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (!$expense) {
|
if (!$expense) {
|
||||||
// The document does not exist as an expense
|
// The document does not exist as an expense
|
||||||
// Handle accordingly
|
// Handle accordingly
|
||||||
|
|
||||||
/** @var \App\Models\Currency $currency */
|
/** @var \App\Models\Currency $currency */
|
||||||
$currency = app('currencies')->first(function ($c) use ($invoiceCurrency){
|
$currency = app('currencies')->first(function ($c) use ($invoiceCurrency) {
|
||||||
/** @var \App\Models\Currency $c */
|
/** @var \App\Models\Currency $c */
|
||||||
return $c->code == $invoiceCurrency;
|
return $c->code == $invoiceCurrency;
|
||||||
});
|
});
|
||||||
|
|
||||||
$expense = ExpenseFactory::create($this->company->id, $this->company->owner()->id);
|
$expense = ExpenseFactory::create($this->company->id, $this->company->owner()->id);
|
||||||
$expense->date = $documentdate;
|
$expense->date = $documentdate;
|
||||||
$expense->public_notes = $documentno;
|
$expense->public_notes = $documentno;
|
||||||
@ -105,14 +105,14 @@ class MindeeEDocument extends AbstractService
|
|||||||
$counter = 1;
|
$counter = 1;
|
||||||
|
|
||||||
foreach ($prediction->taxes as $taxesElem) {
|
foreach ($prediction->taxes as $taxesElem) {
|
||||||
$expense->{"tax_amount{$counter}"} = $taxesElem->amount;
|
$expense->{"tax_amount{$counter}"} = $taxesElem->value;
|
||||||
$expense->{"tax_rate{$counter}"} = $taxesElem->rate;
|
$expense->{"tax_rate{$counter}"} = $taxesElem->rate;
|
||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \App\Models\VendorContact $vendor_contact */
|
/** @var \App\Models\VendorContact $vendor_contact */
|
||||||
$vendor_contact = VendorContact::query()->where("company_id", $this->company->id)->where("email", $prediction->supplierEmail)->first();
|
$vendor_contact = VendorContact::query()->where("company_id", $this->company->id)->where("email", $prediction->supplierEmail)->first();
|
||||||
|
|
||||||
/** @var \App\Models\Vendor|null $vendor */
|
/** @var \App\Models\Vendor|null $vendor */
|
||||||
$vendor = $vendor_contact ? $vendor_contact->vendor : Vendor::query()->where("company_id", $this->company->id)->where("name", $prediction->supplierName)->first();
|
$vendor = $vendor_contact ? $vendor_contact->vendor : Vendor::query()->where("company_id", $this->company->id)->where("name", $prediction->supplierName)->first();
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ class ParseEDocument extends AbstractService
|
|||||||
try {
|
try {
|
||||||
return (new ZugferdEDocument($this->file, $this->company))->run();
|
return (new ZugferdEDocument($this->file, $this->company))->run();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
nlog($this->file->get());
|
|
||||||
nlog("Zugferd Exception: " . $e->getMessage());
|
nlog("Zugferd Exception: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user