1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Ninja/Mailers/UserMailer.php

129 lines
3.8 KiB
PHP
Raw Normal View History

2016-07-21 14:35:23 +02:00
<?php namespace App\Ninja\Mailers;
2015-03-16 22:45:25 +01:00
2015-10-11 16:41:09 +02:00
use App\Models\Invitation;
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
{
/**
* @param User $user
* @param User|null $invitor
*/
2015-03-16 22:45:25 +01:00
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);
}
/**
* @param User $user
* @param Invoice $invoice
* @param $notificationType
* @param Payment|null $payment
*/
public function sendNotification(
User $user,
Invoice $invoice,
$notificationType,
Payment $payment = null
)
2015-03-16 22:45:25 +01:00
{
2016-06-07 13:39:53 +02:00
if (! $user->email || $user->cannot('view', $invoice)) {
2015-03-16 22:45:25 +01:00
return;
}
2016-06-07 13:39:53 +02:00
$entityType = $invoice->getEntityType();
$view = ($notificationType == 'approved' ? ENTITY_QUOTE : ENTITY_INVOICE) . "_{$notificationType}";
$account = $user->account;
$client = $invoice->client;
2015-03-16 22:45:25 +01:00
$data = [
'entityType' => $entityType,
'clientName' => $client->getDisplayName(),
'accountName' => $account->getDisplayName(),
2015-03-16 22:45:25 +01:00
'userName' => $user->getDisplayName(),
'invoiceAmount' => $account->formatMoney($invoice->getRequestedAmount(), $client),
2015-03-16 22:45:25 +01:00
'invoiceNumber' => $invoice->invoice_number,
'invoiceLink' => SITE_URL."/{$entityType}s/{$invoice->public_id}",
2015-12-16 12:49:26 +01:00
'account' => $account,
2015-03-16 22:45:25 +01:00
];
if ($payment) {
2016-04-30 23:54:56 +02:00
$data['payment'] = $payment;
$data['paymentAmount'] = $account->formatMoney($payment->amount, $client);
2015-03-16 22:45:25 +01:00
}
$subject = trans("texts.notification_{$entityType}_{$notificationType}_subject", [
'invoice' => $invoice->invoice_number,
'client' => $client->getDisplayName()
]);
2016-06-07 13:39:53 +02:00
2015-03-16 22:45:25 +01:00
$this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}
2015-10-11 16:41:09 +02:00
/**
* @param Invitation $invitation
*/
2015-10-11 16:41:09 +02:00
public function sendEmailBounced(Invitation $invitation)
{
$user = $invitation->user;
2015-12-16 12:49:26 +01:00
$account = $user->account;
2015-10-11 16:41:09 +02:00
$invoice = $invitation->invoice;
$entityType = $invoice->getEntityType();
if (!$user->email) {
return;
}
$subject = trans("texts.notification_{$entityType}_bounced_subject", ['invoice' => $invoice->invoice_number]);
$view = 'email_bounced';
$data = [
'userName' => $user->getDisplayName(),
'emailError' => $invitation->email_error,
'entityType' => $entityType,
'contactName' => $invitation->contact->getDisplayName(),
'invoiceNumber' => $invoice->invoice_number,
];
2016-06-07 13:39:53 +02:00
2015-10-11 16:41:09 +02:00
$this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}
2016-08-13 21:19:37 +02:00
public function sendSecurityCode($user, $code)
{
if (!$user->email) {
return;
}
$subject = trans('texts.security_code_email_subject');
$view = 'security_code';
$data = [
'userName' => $user->getDisplayName(),
'code' => $code,
];
$this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}
2015-03-16 22:45:25 +01:00
}