2013-12-25 22:34:42 +01:00
|
|
|
<?php namespace ninja\mailers;
|
2013-12-10 18:18:35 +01:00
|
|
|
|
|
|
|
use Invoice;
|
2014-01-29 11:41:38 +01:00
|
|
|
use Payment;
|
2013-12-10 18:18:35 +01:00
|
|
|
use Contact;
|
|
|
|
use Invitation;
|
|
|
|
use URL;
|
|
|
|
use Auth;
|
2013-12-30 21:17:45 +01:00
|
|
|
use Activity;
|
2014-01-29 11:41:38 +01:00
|
|
|
use Utils;
|
2013-12-10 18:18:35 +01:00
|
|
|
|
|
|
|
class ContactMailer extends Mailer {
|
|
|
|
|
2013-12-13 10:13:57 +01:00
|
|
|
public function sendInvoice(Invoice $invoice)
|
2013-12-10 18:18:35 +01:00
|
|
|
{
|
2014-01-29 11:41:38 +01:00
|
|
|
$invoice->load('invitations', 'client', 'account');
|
2014-05-20 23:40:09 +02:00
|
|
|
$entityType = $invoice->getEntityType();
|
2014-01-09 11:05:35 +01:00
|
|
|
|
2014-04-06 11:21:59 +02:00
|
|
|
$view = 'invoice';
|
2014-05-20 23:40:09 +02:00
|
|
|
$subject = trans("texts.{$entityType}_subject", ['invoice' => $invoice->invoice_number, 'account' => $invoice->account->getDisplayName()]);
|
2014-04-06 11:21:59 +02:00
|
|
|
|
2013-12-13 10:13:57 +01:00
|
|
|
foreach ($invoice->invitations as $invitation)
|
|
|
|
{
|
2014-01-08 00:59:06 +01:00
|
|
|
if (!$invitation->user->email)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-06 19:03:00 +01:00
|
|
|
$invitation->sent_date = \Carbon::now()->toDateTimeString();
|
2013-12-13 10:13:57 +01:00
|
|
|
$invitation->save();
|
2014-01-06 07:48:11 +01:00
|
|
|
|
2014-01-29 11:41:38 +01:00
|
|
|
$data = [
|
2014-05-20 23:40:09 +02:00
|
|
|
'entityType' => $entityType,
|
2014-04-23 09:20:01 +02:00
|
|
|
'link' => $invitation->getLink(),
|
2014-01-29 11:41:38 +01:00
|
|
|
'clientName' => $invoice->client->getDisplayName(),
|
|
|
|
'accountName' => $invoice->account->getDisplayName(),
|
|
|
|
'contactName' => $invitation->contact->getDisplayName(),
|
|
|
|
'invoiceAmount' => Utils::formatMoney($invoice->amount, $invoice->client->currency_id),
|
2014-05-25 15:40:09 +02:00
|
|
|
'emailFooter' => $invoice->account->email_footer,
|
|
|
|
'showNinjaFooter' => !$invoice->account->isPro() || !Utils::isNinjaProd()
|
2014-01-29 11:41:38 +01:00
|
|
|
];
|
|
|
|
|
2014-03-27 13:25:31 +01:00
|
|
|
$fromEmail = $invitation->user->email;
|
|
|
|
$fromName = $invitation->user->getDisplayName();
|
|
|
|
|
|
|
|
$this->sendTo($invitation->contact->email, $fromEmail, $fromName, $subject, $view, $data);
|
2013-12-10 18:18:35 +01:00
|
|
|
|
2013-12-30 21:17:45 +01:00
|
|
|
Activity::emailInvoice($invitation);
|
|
|
|
}
|
|
|
|
|
2013-12-11 12:11:59 +01:00
|
|
|
if (!$invoice->isSent())
|
|
|
|
{
|
|
|
|
$invoice->invoice_status_id = INVOICE_STATUS_SENT;
|
|
|
|
$invoice->save();
|
|
|
|
}
|
2013-12-25 22:34:42 +01:00
|
|
|
|
|
|
|
\Event::fire('invoice.sent', $invoice);
|
2013-12-10 18:18:35 +01:00
|
|
|
}
|
2014-01-29 11:41:38 +01:00
|
|
|
|
|
|
|
public function sendPaymentConfirmation(Payment $payment)
|
|
|
|
{
|
|
|
|
$view = 'payment_confirmation';
|
2014-04-02 14:28:23 +02:00
|
|
|
$subject = trans('texts.payment_subject', ['invoice' => $payment->invoice->invoice_number]);
|
2014-01-29 11:41:38 +01:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'accountName' => $payment->account->getDisplayName(),
|
|
|
|
'clientName' => $payment->client->getDisplayName(),
|
|
|
|
'emailFooter' => $payment->account->email_footer,
|
2014-05-25 15:40:09 +02:00
|
|
|
'paymentAmount' => Utils::formatMoney($payment->amount, $payment->client->currency_id),
|
2014-05-25 16:25:58 +02:00
|
|
|
'showNinjaFooter' => !$payment->account->isPro() || !Utils::isNinjaProd()
|
2014-01-29 11:41:38 +01:00
|
|
|
];
|
|
|
|
|
2014-03-27 13:25:31 +01:00
|
|
|
$user = $payment->invitation->user;
|
|
|
|
$this->sendTo($payment->contact->email, $user->email, $user->getDisplayName(), $subject, $view, $data);
|
2014-01-29 11:41:38 +01:00
|
|
|
}
|
2013-12-10 18:18:35 +01:00
|
|
|
}
|