2015-03-24 09:21:12 +01:00
|
|
|
<?php namespace App\Ninja\Mailers;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
use Utils;
|
|
|
|
|
2015-03-31 20:50:58 +02:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\User;
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
class UserMailer extends Mailer
|
|
|
|
{
|
|
|
|
public function sendConfirmation(User $user, User $invitor = null)
|
|
|
|
{
|
|
|
|
if (!$user->email) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = 'confirm';
|
|
|
|
$subject = trans('texts.confirmation_subject');
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'user' => $user,
|
|
|
|
'invitationMessage' => $invitor ? trans('texts.invitation_message', ['invitor' => $invitor->getDisplayName()]) : '',
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($invitor) {
|
|
|
|
$fromEmail = $invitor->email;
|
|
|
|
$fromName = $invitor->getDisplayName();
|
|
|
|
} else {
|
|
|
|
$fromEmail = CONTACT_EMAIL;
|
|
|
|
$fromName = CONTACT_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->sendTo($user->email, $fromEmail, $fromName, $subject, $view, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sendNotification(User $user, Invoice $invoice, $notificationType, Payment $payment = null)
|
|
|
|
{
|
|
|
|
if (!$user->email) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-13 17:32:59 +02:00
|
|
|
$entityType = $notificationType == 'approved' ? ENTITY_QUOTE : ENTITY_INVOICE;
|
2015-04-13 14:00:31 +02:00
|
|
|
$view = "{$entityType}_{$notificationType}";
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'entityType' => $entityType,
|
|
|
|
'clientName' => $invoice->client->getDisplayName(),
|
|
|
|
'accountName' => $invoice->account->getDisplayName(),
|
|
|
|
'userName' => $user->getDisplayName(),
|
|
|
|
'invoiceAmount' => Utils::formatMoney($invoice->amount, $invoice->client->currency_id),
|
|
|
|
'invoiceNumber' => $invoice->invoice_number,
|
|
|
|
'invoiceLink' => SITE_URL."/{$entityType}s/{$invoice->public_id}",
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($payment) {
|
|
|
|
$data['paymentAmount'] = Utils::formatMoney($payment->amount, $invoice->client->currency_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = trans("texts.notification_{$entityType}_{$notificationType}_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->getDisplayName()]);
|
|
|
|
|
|
|
|
$this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
|
|
|
|
}
|
|
|
|
}
|