2017-01-11 11:32:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Ninja\Mailers\ContactMailer;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2017-01-30 20:40:43 +01:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2017-01-11 11:32:13 +01:00
|
|
|
use Monolog\Logger;
|
2017-04-25 14:05:41 +02:00
|
|
|
use Auth;
|
2017-01-11 11:32:13 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class SendInvoiceEmail.
|
2017-01-11 11:32:13 +01:00
|
|
|
*/
|
|
|
|
class SendInvoiceEmail extends Job implements ShouldQueue
|
|
|
|
{
|
|
|
|
use InteractsWithQueue, SerializesModels;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Invoice
|
|
|
|
*/
|
|
|
|
protected $invoice;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $reminder;
|
|
|
|
|
2017-02-05 22:29:11 +01:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $template;
|
|
|
|
|
2017-04-25 14:05:41 +02:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $userId;
|
|
|
|
|
2017-01-11 11:32:13 +01:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param Invoice $invoice
|
2017-01-30 20:40:43 +01:00
|
|
|
* @param string $pdf
|
|
|
|
* @param bool $reminder
|
2017-01-30 20:49:42 +01:00
|
|
|
* @param mixed $pdfString
|
2017-01-11 11:32:13 +01:00
|
|
|
*/
|
2017-04-25 14:05:41 +02:00
|
|
|
public function __construct(Invoice $invoice, $userId = false, $reminder = false, $template = false)
|
2017-01-11 11:32:13 +01:00
|
|
|
{
|
|
|
|
$this->invoice = $invoice;
|
2017-04-25 14:05:41 +02:00
|
|
|
$this->userId = $userId;
|
2017-01-11 11:32:13 +01:00
|
|
|
$this->reminder = $reminder;
|
2017-02-05 22:29:11 +01:00
|
|
|
$this->template = $template;
|
2017-01-11 11:32:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @param ContactMailer $mailer
|
|
|
|
*/
|
|
|
|
public function handle(ContactMailer $mailer)
|
|
|
|
{
|
2017-04-25 14:05:41 +02:00
|
|
|
// send email as user
|
|
|
|
if ($this->userId) {
|
|
|
|
Auth::loginUsingId($this->userId);
|
|
|
|
}
|
|
|
|
|
2017-03-09 15:09:52 +01:00
|
|
|
$mailer->sendInvoice($this->invoice, $this->reminder, $this->template);
|
2017-04-25 14:05:41 +02:00
|
|
|
|
|
|
|
if ($this->userId) {
|
|
|
|
Auth::logout();
|
|
|
|
}
|
2017-01-11 11:32:13 +01:00
|
|
|
}
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
/*
|
2017-01-11 11:32:13 +01:00
|
|
|
* Handle a job failure.
|
|
|
|
*
|
|
|
|
* @param ContactMailer $mailer
|
|
|
|
* @param Logger $logger
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
public function failed(ContactMailer $mailer, Logger $logger)
|
|
|
|
{
|
|
|
|
$this->jobName = $this->job->getName();
|
|
|
|
|
|
|
|
parent::failed($mailer, $logger);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|