2020-02-12 10:21:06 +01:00
|
|
|
<?php
|
2020-02-15 10:01:15 +01:00
|
|
|
|
2020-02-12 10:21:06 +01:00
|
|
|
namespace App\Jobs\Quote;
|
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
use App\Events\Invoice\InvoiceWasEmailed;
|
|
|
|
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
|
2020-02-12 10:21:06 +01:00
|
|
|
use App\Events\Quote\QuoteWasEmailed;
|
|
|
|
use App\Events\Quote\QuoteWasEmailedAndFailed;
|
2020-02-15 10:01:15 +01:00
|
|
|
use App\Jobs\Utils\SystemLogger;
|
2020-02-12 10:21:06 +01:00
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Mail\TemplateEmail;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Quote;
|
2020-02-15 10:01:15 +01:00
|
|
|
use App\Models\QuoteInvitation;
|
2020-02-12 10:21:06 +01:00
|
|
|
use App\Models\SystemLog;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
|
|
|
class EmailQuote implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
public $quote_invitation;
|
2020-02-12 10:21:06 +01:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
public $email_builder;
|
2020-02-12 10:21:06 +01:00
|
|
|
|
|
|
|
/**
|
2020-02-15 10:01:15 +01:00
|
|
|
* EmailQuote constructor.
|
|
|
|
* @param BuildEmail $email_builder
|
|
|
|
* @param QuoteInvitation $quote_invitation
|
2020-02-12 10:21:06 +01:00
|
|
|
*/
|
2020-02-15 10:01:15 +01:00
|
|
|
public function __construct($email_builder, QuoteInvitation $quote_invitation)
|
2020-02-12 10:21:06 +01:00
|
|
|
{
|
2020-02-15 10:01:15 +01:00
|
|
|
$this->quote_invitation = $quote_invitation;
|
|
|
|
$this->email_builder = $email_builder;
|
2020-02-12 10:21:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2020-02-15 10:01:15 +01:00
|
|
|
Mail::to($this->quote_invitation->contact->email, $this->quote_invitation->contact->present()->name())
|
2020-03-21 06:37:30 +01:00
|
|
|
->send(
|
|
|
|
new TemplateEmail(
|
2020-03-26 04:23:57 +01:00
|
|
|
$this->email_builder,
|
|
|
|
$this->quote_invitation->contact->user,
|
|
|
|
$this->quote_invitation->contact->client
|
|
|
|
)
|
2020-02-15 10:01:15 +01:00
|
|
|
);
|
2020-02-12 10:21:06 +01:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
if (count(Mail::failures()) > 0) {
|
2020-02-15 12:49:31 +01:00
|
|
|
return $this->logMailError(Mail::failures());
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
2020-08-14 00:08:10 +02:00
|
|
|
|
2020-08-19 04:55:58 +02:00
|
|
|
$this->quote_invitation->quote->service()->markSent()->save();
|
2020-08-14 00:08:10 +02:00
|
|
|
|
2020-02-12 10:21:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function logMailError($errors)
|
|
|
|
{
|
|
|
|
SystemLogger::dispatch(
|
|
|
|
$errors,
|
|
|
|
SystemLog::CATEGORY_MAIL,
|
|
|
|
SystemLog::EVENT_MAIL_SEND,
|
|
|
|
SystemLog::TYPE_FAILURE,
|
|
|
|
$this->quote->client
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|