1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00

renaming and minor changes

This commit is contained in:
paulwer 2023-12-18 17:24:59 +01:00
parent 7245de8c4c
commit 08662c1595

View File

@ -62,7 +62,7 @@ class IngresEmailEngine implements ShouldQueue
continue;
$this->isUnknownRecipent = false;
if (!$this->validateExpenseActive())
if (!$this->validateExpenseShouldProcess())
continue;
$this->createExpense();
@ -71,41 +71,6 @@ class IngresEmailEngine implements ShouldQueue
$this->saveMeta();
}
// MAIN-PROCESSORS
protected function createExpense()
{
if (!$this->validateExpenseSender()) {
nlog('invalid sender of an ingest email to company: ' . $this->company->id . ' from: ' . $this->email->from);
return;
}
$expense = ExpenseFactory::create($this->company->id, $this->company->owner()->id);
$expense->public_notes = $this->email->subject;
$expense->private_notes = $this->email->text_body;
$expense->date = $this->email->date;
// handle vendor assignment
$expense_vendor = $this->getExpenseVendor();
if ($expense_vendor)
$expense->vendor_id = $expense_vendor->id;
// handle documents
$this->processHtmlBodyToDocument();
$documents = [];
array_push($documents, ...$this->email->documents);
if ($this->email->body_document)
$documents[] = $this->email->body_document;
$this->saveDocuments($documents, $expense);
$expense->saveQuietly();
event(new ExpenseWasCreated($expense, $expense->company, Ninja::eventVars(null))); // @turbo124 please check, I copied from API
event('eloquent.created: App\Models\Expense', $expense); // @turbo124 please check, I copied from API
return $expense;
}
// SPAM Protection
private function isInvalidOrBlocked()
{
@ -166,7 +131,7 @@ class IngresEmailEngine implements ShouldQueue
Cache::add('ingresEmailBlockedSender:' . $this->email->from, true, now()->addHours(12));
$this->saveMeta();
// TODO: ignore, when known sender
// TODO: ignore, when known sender (for heavy email-usage mostly on isHosted())
// TODO: handle external blocking
}
private function saveMeta()
@ -185,15 +150,52 @@ class IngresEmailEngine implements ShouldQueue
}
}
}
// PARSING
// MAIL-PARSING
private function processHtmlBodyToDocument()
{
if (!$this->email->body_document && property_exists($this->email, "body")) {
$this->email->body_document = TempFile::UploadedFileFromRaw($this->email->body, "E-Mail.html", "text/html");
}
}
// MAIN-PROCESSORS
protected function createExpense()
{
if (!$this->validateExpenseSender()) {
nlog('invalid sender of an ingest email to company: ' . $this->company->id . ' from: ' . $this->email->from);
return;
}
$expense = ExpenseFactory::create($this->company->id, $this->company->owner()->id);
$expense->public_notes = $this->email->subject;
$expense->private_notes = $this->email->text_body;
$expense->date = $this->email->date;
// handle vendor assignment
$expense_vendor = $this->getExpenseVendor();
if ($expense_vendor)
$expense->vendor_id = $expense_vendor->id;
// handle documents
$this->processHtmlBodyToDocument();
$documents = [];
array_push($documents, ...$this->email->documents);
if ($this->email->body_document)
$documents[] = $this->email->body_document;
$this->saveDocuments($documents, $expense);
$expense->saveQuietly();
event(new ExpenseWasCreated($expense, $expense->company, Ninja::eventVars(null))); // @turbo124 please check, I copied from API
event('eloquent.created: App\Models\Expense', $expense); // @turbo124 please check, I copied from API
return $expense;
}
// HELPERS
private function validateExpenseActive()
private function validateExpenseShouldProcess()
{
return $this->company?->expense_mailbox_active ?: false;
}