2020-02-15 09:01:15 +00:00
|
|
|
<?php
|
2020-07-01 11:06:40 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-07-01 11:06:40 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2023-01-29 09:21:40 +11:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-07-01 11:06:40 +10:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-07-01 11:06:40 +10:00
|
|
|
*/
|
|
|
|
|
|
2020-02-15 09:01:15 +00:00
|
|
|
namespace App\Services\Quote;
|
|
|
|
|
|
2020-10-28 10:02:32 +11:00
|
|
|
use App\Jobs\Entity\EmailEntity;
|
2020-05-09 08:35:49 +10:00
|
|
|
use App\Models\ClientContact;
|
2023-02-15 11:04:47 +11:00
|
|
|
use App\Services\Email\MailEntity;
|
|
|
|
|
use App\Services\Email\MailObject;
|
2020-02-15 09:01:15 +00:00
|
|
|
|
|
|
|
|
class SendEmail
|
|
|
|
|
{
|
|
|
|
|
public $quote;
|
|
|
|
|
|
2020-05-09 08:35:49 +10:00
|
|
|
protected $reminder_template;
|
|
|
|
|
|
|
|
|
|
protected $contact;
|
|
|
|
|
|
|
|
|
|
public function __construct($quote, $reminder_template = null, ClientContact $contact = null)
|
2020-02-15 09:01:15 +00:00
|
|
|
{
|
|
|
|
|
$this->quote = $quote;
|
2020-05-09 08:35:49 +10:00
|
|
|
|
|
|
|
|
$this->reminder_template = $reminder_template;
|
|
|
|
|
|
|
|
|
|
$this->contact = $contact;
|
2020-02-15 09:01:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Builds the correct template to send.
|
2020-10-28 21:10:49 +11:00
|
|
|
* @return void
|
2020-02-15 09:01:15 +00:00
|
|
|
*/
|
2020-08-19 12:55:58 +10:00
|
|
|
public function run()
|
2020-02-15 09:01:15 +00:00
|
|
|
{
|
2023-02-15 11:04:47 +11:00
|
|
|
nlog($this->reminder_template);
|
|
|
|
|
nlog("is there a template");
|
|
|
|
|
|
2020-09-06 19:38:10 +10:00
|
|
|
if (! $this->reminder_template) {
|
2020-10-27 22:57:12 +11:00
|
|
|
$this->reminder_template = $this->quote->calculateTemplate('quote');
|
2020-02-15 09:01:15 +00:00
|
|
|
}
|
2023-02-15 11:04:47 +11:00
|
|
|
|
|
|
|
|
$mo = new MailObject();
|
|
|
|
|
|
2022-07-27 15:39:43 +10:00
|
|
|
$this->quote->service()->markSent()->save();
|
2020-02-15 09:01:15 +00:00
|
|
|
|
2023-02-16 12:36:09 +11:00
|
|
|
$this->quote->invitations->each(function ($invitation) use ($mo) {
|
2022-06-21 09:57:17 +00:00
|
|
|
if (! $invitation->contact->trashed() && $invitation->contact->email) {
|
2023-02-15 22:31:02 +11:00
|
|
|
EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template);
|
2023-02-15 11:04:47 +11:00
|
|
|
|
2023-02-15 22:31:02 +11:00
|
|
|
// MailEntity::dispatch($invitation, $invitation->company->db, $mo);
|
2020-02-15 09:01:15 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|