mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 05:32:39 +01:00
3d31f810c0
* Working on importing company gateways * Fix for companyuser settings object * Migrate client_gateway_tokens * Working on Notificaitons * Working on notifications * Failsafe for user-company * unlink files * Set DB for jobs * Always have a fallback for company_id * Fixes for user model * Formatting for MultiDB * Working on Company Ledger Tests * Fixes for contact request * Set Invitations as a default include for invoices
82 lines
2.1 KiB
PHP
82 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Invoice;
|
|
|
|
use App\Events\Invoice\InvoiceWasEmailed;
|
|
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
|
|
use App\Helpers\Email\InvoiceEmail;
|
|
use App\Jobs\Utils\SystemLogger;
|
|
use App\Libraries\MultiDB;
|
|
use App\Mail\TemplateEmail;
|
|
use App\Models\Company;
|
|
use App\Models\Invoice;
|
|
use App\Models\InvoiceInvitation;
|
|
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;
|
|
use Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains;
|
|
|
|
class EmailInvoice implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $invoice_invitation;
|
|
|
|
public $email_builder;
|
|
|
|
public $company;
|
|
/**
|
|
*
|
|
* EmailQuote constructor.
|
|
* @param BuildEmail $email_builder
|
|
* @param QuoteInvitation $quote_invitation
|
|
*/
|
|
|
|
public function __construct(InvoiceEmail $email_builder, InvoiceInvitation $invoice_invitation, Company $company)
|
|
{
|
|
$this->company = $company;
|
|
|
|
$this->invoice_invitation = $invoice_invitation;
|
|
|
|
$this->email_builder = $email_builder;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
*
|
|
* @return void
|
|
*/
|
|
|
|
public function handle()
|
|
{
|
|
|
|
Mail::to($this->invoice_invitation->contact->email, $this->invoice_invitation->contact->present()->name())
|
|
->send(new TemplateEmail($this->email_builder,
|
|
$this->invoice_invitation->contact->user,
|
|
$this->invoice_invitation->contact->client
|
|
)
|
|
);
|
|
|
|
if (count(Mail::failures()) > 0) {
|
|
return $this->logMailError(Mail::failures());
|
|
}
|
|
|
|
}
|
|
|
|
private function logMailError($errors)
|
|
{
|
|
SystemLogger::dispatch(
|
|
$errors,
|
|
SystemLog::CATEGORY_MAIL,
|
|
SystemLog::EVENT_MAIL_SEND,
|
|
SystemLog::TYPE_FAILURE,
|
|
$this->invoice->client
|
|
);
|
|
}
|
|
}
|