1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/ninja/mailers/ContactMailer.php

101 lines
3.0 KiB
PHP
Raw Normal View History

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 {
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-11-11 09:29:43 +01:00
$accountName = $invoice->account->getDisplayName();
2014-04-06 11:21:59 +02: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();
$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(),
2014-11-11 09:29:43 +01:00
'accountName' => $accountName,
2014-01-29 11:41:38 +01:00
'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()
2014-01-29 11:41:38 +01:00
];
2014-11-11 09:29:43 +01:00
$fromEmail = $invitation->user->email;
$this->sendTo($invitation->contact->email, $fromEmail, $accountName, $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-11-11 09:29:43 +01:00
$accountName = $payment->account->getDisplayName();
2014-01-29 11:41:38 +01:00
$data = [
2014-11-11 09:29:43 +01:00
'accountName' => $accountName,
2014-01-29 11:41:38 +01:00
'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),
'showNinjaFooter' => !$payment->account->isPro()
2014-01-29 11:41:38 +01:00
];
2014-03-27 13:25:31 +01:00
$user = $payment->invitation->user;
2014-11-11 09:29:43 +01:00
$this->sendTo($payment->contact->email, $user->email, $accountName, $subject, $view, $data);
2014-01-29 11:41:38 +01:00
}
public function sendLicensePaymentConfirmation($name, $email, $amount, $license, $productId)
{
$view = 'payment_confirmation';
$subject = trans('texts.payment_subject');
if ($productId == PRODUCT_ONE_CLICK_INSTALL) {
$message = "Softaculous install license: $license";
} else if ($productId == PRODUCT_INVOICE_DESIGNS) {
$message = "Invoice designs license: $license";
} else if ($productId == PRODUCT_WHITE_LABEL) {
$message = "White label license: $license";
}
$data = [
'accountName' => trans('texts.email_from'),
'clientName' => $name,
'emailFooter' => false,
'paymentAmount' => Utils::formatMoney($amount, 1),
'showNinjaFooter' => false,
'emailMessage' => $message,
];
$this->sendTo($email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}
2013-12-10 18:18:35 +01:00
}