Updated resource

This commit is contained in:
David Bomba 2024-11-14 19:46:41 +11:00
parent 63c5aa861b
commit d3e12ba0bc
17 changed files with 25 additions and 27 deletions

View File

@ -83,7 +83,7 @@ class SendRemindersCron extends Command
//check if this reminder needs to be emailed
if (in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3']) && $invoice->client->getSetting('enable_'.$reminder_template)) {
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
EmailEntity::dispatch($invitation->withoutRelations(), $invitation->company->db, $reminder_template);
nlog("Firing reminder email for invoice {$invoice->number}");
});

View File

@ -641,7 +641,7 @@ class CreditController extends BaseController
case 'send_email':
$credit->invitations->load('contact.client.country', 'credit.client.country', 'credit.company')->each(function ($invitation) use ($credit) {
EmailEntity::dispatch($invitation, $credit->company, 'credit');
EmailEntity::dispatch($invitation->withoutRelations(), $credit->company->db, 'credit');
});
if (! $bulk) {

View File

@ -69,7 +69,7 @@ class AutoBill implements ShouldQueue
$invoice->invitations->each(function ($invitation) use ($invoice) {
if ($invitation->contact && ! $invitation->contact->trashed() && strlen($invitation->contact->email) >= 1 && $invoice->client->getSetting('auto_email_invoice')) {
try {
EmailEntity::dispatch($invitation, $invoice->company)->delay(rand(1, 2));
EmailEntity::dispatch($invitation->withoutRelations(), $invoice->company->db)->delay(rand(1, 2));
$invoice->entityEmailEvent($invitation, 'invoice', 'email_template_invoice');

View File

@ -59,18 +59,18 @@ class EmailEntity implements ShouldQueue
public $tries = 1;
public string $db;
/**
* EmailEntity constructor.
*
*
* @param mixed $invitation
* @param Company $company
* @param ?string $reminder_template
* @param array $template_data
*/
public function __construct($invitation, Company $company, ?string $reminder_template = null, $template_data = null)
{
$this->company = $company;
public function __construct($invitation, string $db, ?string $reminder_template = null, $template_data = null)
{
$this->db = $db;
$this->invitation = $invitation;
@ -95,16 +95,17 @@ class EmailEntity implements ShouldQueue
*/
public function handle(): void
{
/* Set DB */
MultiDB::setDB($this->db);
/* Don't fire emails if the company is disabled */
if ($this->company->is_disabled) {
if ($this->invitation->company->is_disabled) {
return;
}
$this->email_entity_builder = $this->resolveEmailBuilder();
/* Set DB */
MultiDB::setDB($this->company->db);
App::forgetInstance('translator');
$t = app('translator');
App::setLocale($this->invitation->contact->preferredLocale());
@ -115,7 +116,7 @@ class EmailEntity implements ShouldQueue
$nmo = new NinjaMailerObject();
$nmo->mailable = new TemplateEmail($this->email_entity_builder, $this->invitation->contact->withoutRelations(), $this->invitation->withoutRelations());
$nmo->company = $this->company->withoutRelations();
$nmo->company = $this->invitation->company->withoutRelations();
$nmo->settings = $this->settings;
$nmo->to_user = $this->invitation->contact->withoutRelations();
$nmo->entity_string = $this->entity_string;

View File

@ -60,8 +60,7 @@ class BulkInvoiceJob implements ShouldQueue
$this->invoice->service()->markSent()->save();
$this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) {
// EmailEntity::dispatch($invitation, $this->invoice->company, $this->reminder_template)->delay(now()->addSeconds(5));
//@refactor 2024-11-10 - move email into EmailObject/Email::class
$template = $this->resolveTemplateString($this->reminder_template);

View File

@ -218,7 +218,7 @@ class SendReminders implements ShouldQueue
if ($this->checkSendSetting($invoice, $template) && $invoice->company->account->hasFeature(Account::FEATURE_EMAIL_TEMPLATES_REMINDERS)) {
nlog('firing email');
EmailEntity::dispatch($invitation, $invitation->company, $template)->delay(10);
EmailEntity::dispatch($invitation->withoutRelations(), $invitation->company->db, $template)->delay(10);
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $template));
$invoice->sendEvent(Webhook::EVENT_REMIND_INVOICE, "client");
}

View File

@ -155,7 +155,7 @@ class SendRecurring implements ShouldQueue
$invoice->invitations->each(function ($invitation) use ($invoice) {
if ($invitation->contact && ! $invitation->contact->trashed() && strlen($invitation->contact->email) >= 1 && $invoice->client->getSetting('auto_email_invoice')) {
try {
EmailEntity::dispatch($invitation, $invoice->company)->delay(rand(1, 2));
EmailEntity::dispatch($invitation->withoutRelations(), $invoice->company->db)->delay(rand(1, 2));
} catch (\Exception $e) {
nlog($e->getMessage());
}

View File

@ -142,7 +142,7 @@ class QuoteReminderJob implements ShouldQueue
(Ninja::isSelfHost() || $quote->company->account->isPaidHostedClient())) {
$quote->invitations->each(function ($invitation) use ($quote, $reminder_template) {
if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
EmailEntity::dispatch($invitation->withoutRelations(), $invitation->company->db, $reminder_template);
nrlog("Firing reminder email for quote {$quote->number} - {$reminder_template}");
$quote->entityEmailEvent($invitation, $reminder_template);
$quote->sendEvent(Webhook::EVENT_REMIND_QUOTE, "client");

View File

@ -146,7 +146,7 @@ class ReminderJob implements ShouldQueue
(Ninja::isSelfHost() || $invoice->company->account->isPaidHostedClient())) {
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
EmailEntity::dispatch($invitation->withoutRelations(), $invitation->company->db, $reminder_template);
nrlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}");
$invoice->entityEmailEvent($invitation, $reminder_template);
$invoice->sendEvent(Webhook::EVENT_REMIND_INVOICE, "client");
@ -223,7 +223,7 @@ class ReminderJob implements ShouldQueue
(Ninja::isSelfHost() || $invoice->company->account->isPaidHostedClient())) {
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
EmailEntity::dispatch($invitation->withoutRelations(), $invitation->company->db, $reminder_template);
nrlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}");
$invoice->entityEmailEvent($invitation, $reminder_template);
$invoice->sendEvent(Webhook::EVENT_REMIND_INVOICE, "client");

View File

@ -67,7 +67,7 @@ class SendFailedEmails implements ShouldQueue
if ($invitation->invoice) {
if (! $invitation->contact->trashed() && $invitation->contact->send_email && $invitation->contact->email) {
EmailEntity::dispatch($invitation, $invitation->company, $job_meta_array['reminder_template']);
EmailEntity::dispatch($invitation->withoutRelations(), $invitation->company->db, $job_meta_array['reminder_template']);
}
}
});

View File

@ -47,7 +47,7 @@ class SendEmail
$this->credit->invitations->each(function ($invitation) {
if (! $invitation->contact->trashed() && $invitation->contact->email) {
EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template)->delay(2);
EmailEntity::dispatch($invitation->withoutRelations(), $invitation->company->db, $this->reminder_template)->delay(2);
}
});

View File

@ -74,7 +74,7 @@ class TriggeredActions extends AbstractService
$reminder_template = $this->credit->calculateTemplate('credit');
$this->credit->invitations->load('contact.client.country', 'credit.client.country', 'credit.company')->each(function ($invitation) use ($reminder_template) {
EmailEntity::dispatch($invitation, $this->credit->company, $reminder_template);
EmailEntity::dispatch($invitation->withoutRelations(), $this->credit->company->db, $reminder_template);
});
if ($this->credit->invitations->count() > 0) {

View File

@ -36,7 +36,7 @@ class SendEmail extends AbstractService
$this->invoice->invitations->each(function ($invitation) {
if (! $invitation->contact->trashed() && $invitation->contact->email) {
EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template)->delay(10);
EmailEntity::dispatch($invitation->withoutRelations(), $invitation->company->db, $this->reminder_template)->delay(10);
}
});

View File

@ -96,7 +96,7 @@ class TriggeredActions extends AbstractService
$reminder_template = $this->invoice->calculateTemplate('invoice');
$this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($reminder_template) {
EmailEntity::dispatch($invitation, $this->invoice->company, $reminder_template);
EmailEntity::dispatch($invitation->withoutRelations(), $this->invoice->company->db, $reminder_template);
});
if ($this->invoice->invitations->count() > 0) {

View File

@ -41,7 +41,6 @@ class SendEmail
$this->quote->invitations->each(function ($invitation) {
if (! $invitation->contact->trashed() && $invitation->contact->email) {
// EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template);
//@refactor 2024-11-10
$mo = new EmailObject();

View File

@ -86,7 +86,6 @@ class TriggeredActions extends AbstractService
$reminder_template = "email_template_{$reminder_template}";
$this->quote->invitations->load('contact.client.country', 'quote.client.country', 'quote.company')->each(function ($invitation) use ($reminder_template) {
// EmailEntity::dispatch($invitation, $this->quote->company, $reminder_template);
$mo = new EmailObject();
$mo->entity_id = $invitation->quote_id;

View File

@ -5468,7 +5468,7 @@ $lang = array(
'notification_credits_low_text' => 'Please add credits to your account to avoid interruption of services.',
'notification_no_credits' => 'Warning! Your credit balance is empty.',
'notification_no_credits_text' => 'Please add credits to your account to avoid interruption of services.',
'saved_comment', 'Comment Saved',
'saved_comment', => 'Comment Saved',
);
return $lang;