mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Entity mail failure email
This commit is contained in:
parent
d8c8901aa0
commit
92e5465679
@ -12,7 +12,7 @@
|
||||
namespace App\Events\Invoice;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
@ -22,36 +22,34 @@ class InvoiceWasEmailedAndFailed
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Invoice
|
||||
*/
|
||||
public $invoice;
|
||||
public $invitation;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $errors;
|
||||
public $message;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
public $template;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @param InvoiceInvitation $invitation
|
||||
* @param Company $company
|
||||
* @param string $errors
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(Invoice $invoice, Company $company, string $errors, array $event_vars)
|
||||
public function __construct(InvoiceInvitation $invitation, Company $company, string $message, string $template, array $event_vars)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
$this->invitation = $invitation;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
$this->errors = $errors;
|
||||
$this->message = $message;
|
||||
|
||||
$this->event_vars = $event_vars;
|
||||
|
||||
$this->template = $template;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ function nlog($output, $context = []): void
|
||||
}
|
||||
|
||||
$trace = debug_backtrace();
|
||||
\Illuminate\Support\Facades\Log::channel('invoiceninja')->info(print_r($trace[1]['class'],1), []);
|
||||
// \Illuminate\Support\Facades\Log::channel('invoiceninja')->info(print_r($trace[1]['class'],1), []);
|
||||
\Illuminate\Support\Facades\Log::channel('invoiceninja')->info($output, $context);
|
||||
|
||||
}
|
||||
|
@ -129,9 +129,6 @@ class EmailController extends BaseController
|
||||
];
|
||||
|
||||
$entity_obj->service()->markSent()->save();
|
||||
|
||||
//@TODO why is this dispatchNow instead of just dispatch?
|
||||
//update - changing to dispatch and see if something breaks.
|
||||
EmailEntity::dispatch($invitation, $invitation->company, $template, $data)->delay(now()->addSeconds(5));
|
||||
}
|
||||
});
|
||||
|
@ -711,6 +711,7 @@ class InvoiceController extends BaseController
|
||||
break;
|
||||
case 'email':
|
||||
//check query parameter for email_type and set the template else use calculateTemplate
|
||||
|
||||
if (request()->has('email_type') && property_exists($invoice->company->settings, request()->input('email_type'))) {
|
||||
$this->reminder_template = $invoice->client->getSetting(request()->input('email_type'));
|
||||
} else {
|
||||
@ -725,7 +726,7 @@ class InvoiceController extends BaseController
|
||||
});
|
||||
|
||||
if ($invoice->invitations->count() >= 1) {
|
||||
$invoice->entityEmailEvent($invoice->invitations->first(), $this->reminder_template);
|
||||
$invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', $this->reminder_template);
|
||||
}
|
||||
|
||||
if (! $bulk) {
|
||||
|
@ -15,6 +15,7 @@ use App\Events\Invoice\InvoiceReminderWasEmailed;
|
||||
use App\Events\Invoice\InvoiceWasEmailed;
|
||||
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
|
||||
use App\Jobs\Mail\BaseMailerJob;
|
||||
use App\Jobs\Mail\EntityFailedSendMailer;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\TemplateEmail;
|
||||
use App\Models\Activity;
|
||||
@ -110,7 +111,6 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$this->entityEmailFailed($e->getMessage());
|
||||
$this->logMailError($e->getMessage(), $this->entity->client);
|
||||
}
|
||||
@ -136,7 +136,7 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
switch ($this->entity_string) {
|
||||
case 'invoice':
|
||||
event(new InvoiceWasEmailedAndFailed($this->invitation->invoice, $this->company, $message, Ninja::eventVars()));
|
||||
event(new InvoiceWasEmailedAndFailed($this->invitation, $this->company, $message, $this->reminder_template, Ninja::eventVars()));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntityFailedSendObject;
|
||||
use App\Mail\Admin\EntityNotificationMailer;
|
||||
use App\Mail\Admin\EntitySentObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@ -40,6 +41,8 @@ class EntityFailedSendMailer extends BaseMailerJob implements ShouldQueue
|
||||
public $settings;
|
||||
|
||||
public $template;
|
||||
|
||||
public $message;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -48,7 +51,7 @@ class EntityFailedSendMailer extends BaseMailerJob implements ShouldQueue
|
||||
* @param $user
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct($invitation, $entity_type, $user, $company, $template)
|
||||
public function __construct($invitation, $entity_type, $user, $company, $template, $message)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
@ -63,6 +66,8 @@ class EntityFailedSendMailer extends BaseMailerJob implements ShouldQueue
|
||||
$this->settings = $invitation->contact->client->getMergedSettings();
|
||||
|
||||
$this->template = $template;
|
||||
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,12 +77,11 @@ class EntityFailedSendMailer extends BaseMailerJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
nlog("entity sent mailer");
|
||||
nlog("failed entity sent mailer");
|
||||
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled) {
|
||||
if ($this->company->is_disabled)
|
||||
return true;
|
||||
}
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
@ -85,13 +89,14 @@ class EntityFailedSendMailer extends BaseMailerJob implements ShouldQueue
|
||||
//if we need to set an email driver do it now
|
||||
$this->setMailDriver();
|
||||
|
||||
$mail_obj = (new EntitySentObject($this->invitation, $this->entity_type, $this->template))->build();
|
||||
$mail_obj = (new EntityFailedSendObject($this->invitation, $this->entity_type, $this->template, $this->message))->build();
|
||||
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
||||
|
||||
try {
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
} catch (\Exception $e) {
|
||||
nlog("failing in EntityFailedSendMailer");
|
||||
$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->entity->client);
|
||||
}
|
||||
|
@ -39,17 +39,19 @@ class InvoiceEmailFailedActivity implements ShouldQueue
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
nlog("inside activity_repo");
|
||||
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$fields->invoice_id = $event->invoice->id;
|
||||
$fields->client_id = $event->invoice->client_id;
|
||||
$fields->user_id = $event->invoice->user_id;
|
||||
$fields->company_id = $event->invoice->company_id;
|
||||
$fields->invoice_id = $event->invitation->invoice->id;
|
||||
$fields->client_id = $event->invitation->invoice->client_id;
|
||||
$fields->user_id = $event->invitation->invoice->user_id;
|
||||
$fields->company_id = $event->invitation->invoice->company_id;
|
||||
$fields->activity_type_id = Activity::EMAIL_INVOICE_FAILED;
|
||||
$fields->notes = $event->errors;
|
||||
$fields->notes = $event->message;
|
||||
|
||||
$this->activity_repo->save($fields, $event->invoice, $event->event_vars);
|
||||
$this->activity_repo->save($fields, $event->invitation->invoice, $event->event_vars);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Listeners\Invoice;
|
||||
|
||||
use App\Jobs\Mail\EntityFailedSendMailer;
|
||||
use App\Jobs\Mail\EntitySentMailer;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Notifications\Admin\EntitySentNotification;
|
||||
@ -33,6 +34,8 @@ class InvoiceFailedEmailNotification implements ShouldQueue
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
nlog("inside a failed notification");
|
||||
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
$first_notification_sent = true;
|
||||
@ -51,7 +54,7 @@ class InvoiceFailedEmailNotification implements ShouldQueue
|
||||
if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) {
|
||||
unset($methods[$key]);
|
||||
|
||||
EntitySentMailer::dispatch($event->invitation, 'invoice', $user, $event->invitation->company, $event->template);
|
||||
EntityFailedSendMailer::dispatch($event->invitation, 'invoice', $user, $event->invitation->company, $event->template, $event->message);
|
||||
$first_notification_sent = false;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,9 @@ class EntityFailedSendObject
|
||||
|
||||
private $template_body;
|
||||
|
||||
public function __construct($invitation, $entity_type, $template)
|
||||
private $message;
|
||||
|
||||
public function __construct($invitation, $entity_type, $template, $message)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->entity_type = $entity_type;
|
||||
@ -42,6 +44,7 @@ class EntityFailedSendObject
|
||||
$this->contact = $invitation->contact;
|
||||
$this->company = $invitation->company;
|
||||
$this->template = $template;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
public function build()
|
||||
@ -127,6 +130,7 @@ class EntityFailedSendObject
|
||||
'amount' => $this->getAmount(),
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->entity->number,
|
||||
'error' => $this->message,
|
||||
]
|
||||
),
|
||||
'url' => $this->invitation->getAdminLink(),
|
||||
|
@ -34,6 +34,7 @@ class EntityNotificationMailer extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
|
||||
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||
->subject($this->mail_obj->subject)
|
||||
->markdown($this->mail_obj->markdown, $this->mail_obj->data)
|
||||
|
@ -14,7 +14,7 @@ namespace App\Mail\Admin;
|
||||
use App\Utils\Number;
|
||||
use stdClass;
|
||||
|
||||
class EntityFailedSendObject
|
||||
class EntitySentObject
|
||||
{
|
||||
public $invitation;
|
||||
|
||||
@ -91,6 +91,7 @@ class EntityFailedSendObject
|
||||
$this->template_subject = "texts.notification_credit_sent_subject";
|
||||
$this->template_body = "texts.notification_credit_sent";
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->template_subject = "texts.notification_invoice_sent_subject";
|
||||
$this->template_body = "texts.notification_invoice_sent";
|
||||
@ -115,20 +116,25 @@ class EntityFailedSendObject
|
||||
);
|
||||
}
|
||||
|
||||
private function getData()
|
||||
private function getMessage()
|
||||
{
|
||||
$settings = $this->entity->client->getMergedSettings();
|
||||
|
||||
return [
|
||||
'title' => $this->getSubject(),
|
||||
'message' => ctrans(
|
||||
return ctrans(
|
||||
$this->template_body,
|
||||
[
|
||||
'amount' => $this->getAmount(),
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->entity->number,
|
||||
]
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private function getData()
|
||||
{
|
||||
$settings = $this->entity->client->getMergedSettings();
|
||||
|
||||
return [
|
||||
'title' => $this->getSubject(),
|
||||
'message' => $this->getMessage(),
|
||||
'url' => $this->invitation->getAdminLink(),
|
||||
'button' => ctrans("texts.view_{$this->entity_type}"),
|
||||
'signature' => $settings->email_signature,
|
||||
|
@ -42,6 +42,7 @@ use App\Events\Invoice\InvoiceWasCancelled;
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Events\Invoice\InvoiceWasDeleted;
|
||||
use App\Events\Invoice\InvoiceWasEmailed;
|
||||
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
|
||||
use App\Events\Invoice\InvoiceWasMarkedSent;
|
||||
use App\Events\Invoice\InvoiceWasPaid;
|
||||
use App\Events\Invoice\InvoiceWasRestored;
|
||||
@ -128,6 +129,7 @@ use App\Listeners\Invoice\InvoiceDeletedActivity;
|
||||
use App\Listeners\Invoice\InvoiceEmailActivity;
|
||||
use App\Listeners\Invoice\InvoiceEmailFailedActivity;
|
||||
use App\Listeners\Invoice\InvoiceEmailedNotification;
|
||||
use App\Listeners\Invoice\InvoiceFailedEmailNotification;
|
||||
use App\Listeners\Invoice\InvoicePaidActivity;
|
||||
use App\Listeners\Invoice\InvoiceReminderEmailActivity;
|
||||
use App\Listeners\Invoice\InvoiceRestoredActivity;
|
||||
@ -310,6 +312,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
],
|
||||
InvoiceWasEmailedAndFailed::class => [
|
||||
InvoiceEmailFailedActivity::class,
|
||||
InvoiceFailedEmailNotification::class,
|
||||
],
|
||||
InvoiceReminderWasEmailed::class => [
|
||||
InvoiceReminderEmailActivity::class,
|
||||
|
@ -728,9 +728,9 @@ return [
|
||||
'disable' => 'Disable',
|
||||
'invoice_quote_number' => 'Invoice and Quote Numbers',
|
||||
'invoice_charges' => 'Invoice Surcharges',
|
||||
'notification_invoice_bounced' => 'We were unable to deliver Invoice :invoice to :contact.',
|
||||
'notification_invoice_bounced' => 'We were unable to deliver Invoice :invoice to :contact. \n :error',
|
||||
'notification_invoice_bounced_subject' => 'Unable to deliver Invoice :invoice',
|
||||
'notification_quote_bounced' => 'We were unable to deliver Quote :invoice to :contact.',
|
||||
'notification_quote_bounced' => 'We were unable to deliver Quote :invoice to :contact. \n :error',
|
||||
'notification_quote_bounced_subject' => 'Unable to deliver Quote :invoice',
|
||||
'custom_invoice_link' => 'Custom Invoice Link',
|
||||
'total_invoiced' => 'Total Invoiced',
|
||||
@ -3372,6 +3372,6 @@ return [
|
||||
'required_payment_information_more' => 'To complete a payment we need more details about you.',
|
||||
|
||||
'required_client_info_save_label' => 'We will save this, so you don\'t have to enter it next time.',
|
||||
'notification_credit_bounced' => 'We were unable to deliver Credit :invoice to :contact.',
|
||||
'notification_credit_bounced' => 'We were unable to deliver Credit :invoice to :contact. \n :error',
|
||||
'notification_credit_bounced_subject' => 'Unable to deliver Credit :invoice',
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user