1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 15:42:51 +01:00
invoiceninja/app/ninja/mailers/ContactMailer.php

105 lines
3.8 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;
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
2015-01-11 12:56:58 +01:00
class ContactMailer extends Mailer
{
public function sendInvoice(Invoice $invoice)
{
$invoice->load('invitations', 'client', 'account');
$entityType = $invoice->getEntityType();
$view = 'invoice';
$subject = trans("texts.{$entityType}_subject", ['invoice' => $invoice->invoice_number, 'account' => $invoice->account->getDisplayName()]);
$accountName = $invoice->account->getDisplayName();
2015-02-12 21:50:05 +01:00
$emailTemplate = $invoice->account->getEmailTemplate($entityType);
$invoiceAmount = Utils::formatMoney($invoice->amount, $invoice->client->currency_id);
2015-01-11 12:56:58 +01:00
foreach ($invoice->invitations as $invitation) {
if (!$invitation->user || !$invitation->user->email) {
return false;
}
2015-01-27 19:38:51 +01:00
if (!$invitation->contact || !$invitation->contact->email) {
2015-01-11 12:56:58 +01:00
return false;
}
2015-01-11 13:30:08 +01:00
2015-01-11 12:56:58 +01:00
$invitation->sent_date = \Carbon::now()->toDateTimeString();
$invitation->save();
2015-02-12 21:50:05 +01:00
$variables = [
'$footer' => $invoice->account->getEmailFooter(),
'$link' => $invitation->getLink(),
'$client' => $invoice->client->getDisplayName(),
'$account' => $accountName,
'$contact' => $invitation->contact->getDisplayName(),
'$amount' => $invoiceAmount
2015-01-11 12:56:58 +01:00
];
2015-02-12 21:50:05 +01:00
$data['body'] = str_replace(array_keys($variables), array_values($variables), $emailTemplate);
$data['link'] = $invitation->getLink();
$data['entityType'] = $entityType;
2015-01-11 12:56:58 +01:00
$fromEmail = $invitation->user->email;
$this->sendTo($invitation->contact->email, $fromEmail, $accountName, $subject, $view, $data);
Activity::emailInvoice($invitation);
}
if (!$invoice->isSent()) {
$invoice->invoice_status_id = INVOICE_STATUS_SENT;
$invoice->save();
}
\Event::fire('invoice.sent', $invoice);
}
public function sendPaymentConfirmation(Payment $payment)
{
2015-02-12 21:50:05 +01:00
$invoice = $payment->invoice;
2015-01-11 12:56:58 +01:00
$view = 'payment_confirmation';
2015-02-12 21:50:05 +01:00
$subject = trans('texts.payment_subject', ['invoice' => $invoice->invoice_number]);
2015-01-11 12:56:58 +01:00
$accountName = $payment->account->getDisplayName();
2015-02-12 21:50:05 +01:00
$emailTemplate = $invoice->account->getEmailTemplate(ENTITY_PAYMENT);
2015-01-11 12:56:58 +01:00
2015-02-12 21:50:05 +01:00
$variables = [
'$footer' => $payment->account->getEmailFooter(),
'$client' => $payment->client->getDisplayName(),
'$account' => $accountName,
'$amount' => Utils::formatMoney($payment->amount, $payment->client->currency_id)
2015-01-11 12:56:58 +01:00
];
2015-02-12 21:50:05 +01:00
$data = ['body' => str_replace(array_keys($variables), array_values($variables), $emailTemplate)];
2015-01-11 12:56:58 +01:00
$user = $payment->invitation->user;
$this->sendTo($payment->contact->email, $user->email, $accountName, $subject, $view, $data);
}
public function sendLicensePaymentConfirmation($name, $email, $amount, $license, $productId)
{
2015-02-12 21:50:05 +01:00
$view = 'license_confirmation';
2015-01-11 12:56:58 +01:00
$subject = trans('texts.payment_subject');
2015-02-12 21:50:05 +01:00
2015-01-11 12:56:58 +01:00
if ($productId == PRODUCT_ONE_CLICK_INSTALL) {
2015-02-12 21:50:05 +01:00
$license = "Softaculous install license: $license";
2015-01-11 12:56:58 +01:00
} elseif ($productId == PRODUCT_INVOICE_DESIGNS) {
2015-02-12 21:50:05 +01:00
$license = "Invoice designs license: $license";
2015-01-11 12:56:58 +01:00
} elseif ($productId == PRODUCT_WHITE_LABEL) {
2015-02-12 21:50:05 +01:00
$license = "White label license: $license";
2015-01-11 12:56:58 +01:00
}
2015-02-12 21:50:05 +01:00
2015-01-11 12:56:58 +01:00
$data = [
2015-02-12 21:50:05 +01:00
'account' => trans('texts.email_from'),
'client' => $name,
'amount' => Utils::formatMoney($amount, 1),
'license' => $license
2015-01-11 12:56:58 +01:00
];
2015-02-12 21:50:05 +01:00
2015-01-11 12:56:58 +01:00
$this->sendTo($email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}
}