2013-12-25 22:34:42 +01:00
|
|
|
<?php namespace ninja\mailers;
|
|
|
|
|
|
|
|
use Invoice;
|
2014-01-29 11:41:38 +01:00
|
|
|
use Payment;
|
2013-12-25 22:34:42 +01:00
|
|
|
use Contact;
|
|
|
|
use User;
|
2014-01-29 11:41:38 +01:00
|
|
|
use Utils;
|
2013-12-25 22:34:42 +01:00
|
|
|
|
|
|
|
class UserMailer extends Mailer {
|
|
|
|
|
2014-01-29 11:41:38 +01:00
|
|
|
public function sendNotification(User $user, Invoice $invoice, $type, Payment $payment = null)
|
2013-12-25 22:34:42 +01:00
|
|
|
{
|
|
|
|
if (!$user->email)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-29 11:41:38 +01:00
|
|
|
$view = 'invoice_' . $type;
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'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' => "http://www.invoiceninja.com/invoices/{$invoice->public_id}"
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($payment)
|
|
|
|
{
|
|
|
|
$data['paymentAmount'] = Utils::formatMoney($payment->amount, $invoice->client->currency_id);
|
|
|
|
}
|
|
|
|
|
2014-01-30 23:29:09 +01:00
|
|
|
if ($type == 'paid')
|
|
|
|
{
|
|
|
|
$action = 'paid by';
|
|
|
|
}
|
|
|
|
else if ($type == 'sent')
|
|
|
|
{
|
2014-02-02 15:33:08 +01:00
|
|
|
$action = 'sent to';
|
2014-01-30 23:29:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-02 15:33:08 +01:00
|
|
|
$action = 'viewed by';
|
2014-01-30 23:29:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$subject = "Invoice {$invoice->invoice_number} was $action {$invoice->client->getDisplayName()}";
|
2013-12-25 22:34:42 +01:00
|
|
|
|
2014-01-07 16:50:41 +01:00
|
|
|
$this->sendTo($user->email, CONTACT_EMAIL, $subject, $view, $data);
|
2013-12-25 22:34:42 +01:00
|
|
|
}
|
|
|
|
}
|