mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 10:44:29 -04:00
wrong implementation use each document for its own expense (or parse)
This commit is contained in:
parent
d0cad92fce
commit
46f3fd3866
@ -166,22 +166,29 @@ class InboundMailEngine
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepare data
|
||||||
|
$expense_vendor = $this->getVendor($company, $email);
|
||||||
|
$this->processHtmlBodyToDocument($email);
|
||||||
|
|
||||||
|
$parsed_expense_ids = []; // used to check if an expense was already matched within this job
|
||||||
|
|
||||||
|
// check documents => optimal when parsed from any source => else create an expense for each document
|
||||||
|
foreach ($email->documents as $document) {
|
||||||
|
|
||||||
/** @var \App\Models\Expense $expense */
|
/** @var \App\Models\Expense $expense */
|
||||||
$expense = null;
|
$expense = null;
|
||||||
|
|
||||||
// check documents for EDocument xml
|
|
||||||
foreach ($email->documents as $document) {
|
|
||||||
|
|
||||||
// check if document can be parsed to an expense
|
// check if document can be parsed to an expense
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$expense_obj = (new ParseEDocument($document->get(), $document->getFilename()))->run();
|
$expense = (new ParseEDocument($document->get(), $document->getFilename()))->run();
|
||||||
|
|
||||||
// throw error, when multiple parseable files are registered
|
// check if expense was already matched within this job and skip if true
|
||||||
if ($expense && $expense_obj)
|
if (array_search($expense->id, $parsed_expense_ids)) {
|
||||||
throw new \Exception('Multiple parseable Invoice documents found in email. Please use only one Invoice document per email.');
|
$this->saveDocument($document, $expense);
|
||||||
|
continue;
|
||||||
$expense = $expense_obj;
|
}
|
||||||
|
array_push($parsed_expenses, $expense->id);
|
||||||
|
|
||||||
} catch (\Exception $err) {
|
} catch (\Exception $err) {
|
||||||
// throw error, only, when its not expected
|
// throw error, only, when its not expected
|
||||||
@ -194,8 +201,6 @@ class InboundMailEngine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// populate missing data with data from email
|
// populate missing data with data from email
|
||||||
if (!$expense)
|
if (!$expense)
|
||||||
$expense = ExpenseFactory::create($company->id, $company->owner()->id);
|
$expense = ExpenseFactory::create($company->id, $company->owner()->id);
|
||||||
@ -209,19 +214,14 @@ class InboundMailEngine
|
|||||||
if (!$expense->date)
|
if (!$expense->date)
|
||||||
$expense->date = $email->date;
|
$expense->date = $email->date;
|
||||||
|
|
||||||
if (!$expense->vendor_id) {
|
if (!$expense->vendor_id && $expense_vendor)
|
||||||
$expense_vendor = $this->getVendor($company, $email);
|
|
||||||
|
|
||||||
if ($expense_vendor)
|
|
||||||
$expense->vendor_id = $expense_vendor->id;
|
$expense->vendor_id = $expense_vendor->id;
|
||||||
}
|
|
||||||
|
|
||||||
// handle documents
|
// handle documents
|
||||||
$documents = [];
|
$documents = [];
|
||||||
array_push($documents, $document);
|
array_push($documents, $document);
|
||||||
|
|
||||||
// handle email document
|
// handle email document
|
||||||
$this->processHtmlBodyToDocument($email);
|
|
||||||
if ($email->body_document !== null)
|
if ($email->body_document !== null)
|
||||||
array_push($documents, $email->body_document);
|
array_push($documents, $email->body_document);
|
||||||
|
|
||||||
@ -230,6 +230,7 @@ class InboundMailEngine
|
|||||||
$this->saveDocuments($documents, $expense);
|
$this->saveDocuments($documents, $expense);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HELPERS
|
// HELPERS
|
||||||
private function processHtmlBodyToDocument(InboundMail $email)
|
private function processHtmlBodyToDocument(InboundMail $email)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user