From 4dc7a8d5f1a24b4923bd281103563018f1a5a866 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 16 Dec 2015 13:49:26 +0200 Subject: [PATCH] Working on email markup --- app/Events/QuoteInvitationWasApproved.php | 4 +++- app/Http/Middleware/StartupCheck.php | 1 - app/Http/routes.php | 2 +- app/Models/Invoice.php | 9 +++++++++ app/Ninja/Mailers/ContactMailer.php | 5 +++++ app/Ninja/Mailers/UserMailer.php | 2 ++ app/Ninja/Presenters/InvoicePresenter.php | 12 +++++++++++ app/Ninja/Repositories/InvoiceRepository.php | 2 ++ app/Services/InvoiceService.php | 2 +- .../views/accounts/email_settings.blade.php | 20 +++++++++++-------- .../views/emails/email_bounced_html.blade.php | 3 --- resources/views/emails/invoice_html.blade.php | 2 +- .../views/emails/invoice_paid_html.blade.php | 4 ++-- .../views/emails/invoice_sent_html.blade.php | 4 ++-- .../emails/invoice_viewed_html.blade.php | 4 ++-- resources/views/emails/master.blade.php | 2 +- .../client_view_action.blade.php} | 4 ++-- .../partials/user_view_action.blade.php | 13 ++++++++++++ .../payment_confirmation_html.blade.php | 7 ++++++- .../emails/quote_approved_html.blade.php | 6 +++--- 20 files changed, 79 insertions(+), 29 deletions(-) rename resources/views/emails/{view_action.blade.php => partials/client_view_action.blade.php} (81%) create mode 100644 resources/views/emails/partials/user_view_action.blade.php diff --git a/app/Events/QuoteInvitationWasApproved.php b/app/Events/QuoteInvitationWasApproved.php index 954aa83b4c..5e69fe9c78 100644 --- a/app/Events/QuoteInvitationWasApproved.php +++ b/app/Events/QuoteInvitationWasApproved.php @@ -9,6 +9,7 @@ class QuoteInvitationWasApproved extends Event { use SerializesModels; public $quote; + public $invoice; public $invitation; /** @@ -16,9 +17,10 @@ class QuoteInvitationWasApproved extends Event { * * @return void */ - public function __construct($quote, $invitation) + public function __construct($quote, $invoice, $invitation) { $this->quote = $quote; + $this->invoice = $invoice; $this->invitation = $invitation; } diff --git a/app/Http/Middleware/StartupCheck.php b/app/Http/Middleware/StartupCheck.php index c95b411019..bf730af09e 100644 --- a/app/Http/Middleware/StartupCheck.php +++ b/app/Http/Middleware/StartupCheck.php @@ -34,7 +34,6 @@ class StartupCheck // Ensure all request are over HTTPS in production if (Utils::requireHTTPS() && !Request::secure()) { - //return Redirect::secure(Request::getRequestUri()); return Redirect::secure(Request::path()); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 71989afbd8..7c8fd031fa 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -445,7 +445,7 @@ if (!defined('CONTACT_EMAIL')) { define('PHANTOMJS_CLOUD', 'http://api.phantomjscloud.com/api/browser/v2/'); define('PHP_DATE_FORMATS', 'http://php.net/manual/en/function.date.php'); define('REFERRAL_PROGRAM_URL', 'https://www.invoiceninja.com/referral-program/'); - define('EMAIL_MARKUP_URL', 'https://developers.google.com/gmail/markup/overview'); + define('EMAIL_MARKUP_URL', 'https://developers.google.com/gmail/markup'); define('COUNT_FREE_DESIGNS', 4); define('COUNT_FREE_DESIGNS_SELF_HOST', 5); // include the custom design diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index e097ce4477..9e10021ab8 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -313,6 +313,15 @@ class Invoice extends EntityModel implements BalanceAffecting return $this->invoice_status_id >= INVOICE_STATUS_PAID; } + public function isOverdue() + { + if ( ! $this->due_date) { + return false; + } + + return time() > strtotime($this->due_date); + } + public function getRequestedAmount() { return $this->partial > 0 ? $this->partial : $this->balance; diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 1d95593564..36dcc6fb6c 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -172,7 +172,12 @@ class ContactMailer extends Mailer $data = [ 'body' => $this->processVariables($emailTemplate, $variables), + 'link' => $invitation->getLink(), + 'invoice' => $invoice, + 'client' => $client, 'account' => $account, + 'payment' => $payment, + 'entityType' => ENTITY_INVOICE, ]; if ($account->attatchPDF()) { diff --git a/app/Ninja/Mailers/UserMailer.php b/app/Ninja/Mailers/UserMailer.php index 21e8b05286..ce0c538341 100644 --- a/app/Ninja/Mailers/UserMailer.php +++ b/app/Ninja/Mailers/UserMailer.php @@ -53,6 +53,7 @@ class UserMailer extends Mailer 'invoiceAmount' => $account->formatMoney($invoice->getRequestedAmount(), $client), 'invoiceNumber' => $invoice->invoice_number, 'invoiceLink' => SITE_URL."/{$entityType}s/{$invoice->public_id}", + 'account' => $account, ]; if ($payment) { @@ -70,6 +71,7 @@ class UserMailer extends Mailer public function sendEmailBounced(Invitation $invitation) { $user = $invitation->user; + $account = $user->account; $invoice = $invitation->invoice; $entityType = $invoice->getEntityType(); diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index 73a2483554..fb292a8859 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -26,6 +26,18 @@ class InvoicePresenter extends Presenter { } } + // https://schema.org/PaymentStatusType + public function paymentStatus() + { + if ( ! $this->entity->balance) { + return 'PaymentComplete'; + } elseif ($this->entity->isOverdue()) { + return 'PaymentPastDue'; + } else { + return 'PaymentDue'; + } + } + public function status() { $status = $this->entity->invoice_status ? $this->entity->invoice_status->name : 'draft'; diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index d1e4f3914d..2142588ec9 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -627,6 +627,8 @@ class InvoiceRepository extends BaseRepository if ($recurInvoice->auto_bill) { if ($this->paymentService->autoBillInvoice($invoice)) { + // update the invoice reference to match its actual state + // this is to ensure a 'payment received' email is sent $invoice->invoice_status_id = INVOICE_STATUS_PAID; } } diff --git a/app/Services/InvoiceService.php b/app/Services/InvoiceService.php index d2f73f58f6..664180e5a9 100644 --- a/app/Services/InvoiceService.php +++ b/app/Services/InvoiceService.php @@ -74,7 +74,7 @@ class InvoiceService extends BaseService return $invoice; } - event(new QuoteInvitationWasApproved($invoice, $invitation)); + event(new QuoteInvitationWasApproved($quote, $invoice, $invitation)); foreach ($invoice->invitations as $invoiceInvitation) { if ($invitation->contact_id == $invoiceInvitation->contact_id) { diff --git a/resources/views/accounts/email_settings.blade.php b/resources/views/accounts/email_settings.blade.php index 2bc11b45bb..01269a4bb8 100644 --- a/resources/views/accounts/email_settings.blade.php +++ b/resources/views/accounts/email_settings.blade.php @@ -15,9 +15,20 @@
{!! Former::checkbox('pdf_email_attachment')->text(trans('texts.enable')) !!} +   + {{-- Former::select('recurring_hour')->options($recurringHours) --}} + + {!! Former::select('email_design_id') + ->style('width: 200px') + ->addOption(trans('texts.plain'), 1) + ->addOption(trans('texts.light'), 2) + ->addOption(trans('texts.dark'), 3) + ->help(trans('texts.email_design_help')) !!} +   + {!! Former::inline_radios('custom_invoice_link') ->onchange('onCustomLinkChange()') ->label(trans('texts.invoice_link')) @@ -26,7 +37,7 @@ trans('texts.website') => ['value' => 'website', 'name' => 'custom_link'], ])->check($account->iframe_url ? 'website' : 'subdomain') !!} {{ Former::setOption('capitalize_translations', false) }} - + {!! Former::text('subdomain') ->placeholder(trans('texts.www')) ->onchange('onSubdomainChange()') @@ -41,13 +52,6 @@ ->label(' ') ->help(trans('texts.subdomain_help')) !!}   - {!! Former::select('email_design_id') - ->style('width: 200px') - ->addOption(trans('texts.plain'), 1) - ->addOption(trans('texts.light'), 2) - ->addOption(trans('texts.dark'), 3) - ->help(trans('texts.email_design_help')) !!} -   @if (Utils::isNinja()) {!! Former::checkbox('enable_email_markup') ->text(trans('texts.enable') . diff --git a/resources/views/emails/email_bounced_html.blade.php b/resources/views/emails/email_bounced_html.blade.php index b80c35dbf7..81dbbebf09 100644 --- a/resources/views/emails/email_bounced_html.blade.php +++ b/resources/views/emails/email_bounced_html.blade.php @@ -4,9 +4,6 @@ - @if (false) - @include('emails.view_action', ['link' => $invoiceLink, 'entityType' => $entityType]) - @endif {{ trans('texts.email_salutation', ['name' => $userName]) }}

{{ trans("texts.notification_{$entityType}_bounced", ['contact' => $contactName, 'invoice' => $invoiceNumber]) }}

diff --git a/resources/views/emails/invoice_html.blade.php b/resources/views/emails/invoice_html.blade.php index 86a799dc1d..762726e95d 100644 --- a/resources/views/emails/invoice_html.blade.php +++ b/resources/views/emails/invoice_html.blade.php @@ -5,7 +5,7 @@ @if ($account->enable_email_markup) - @include('emails.view_action', ['link' => $link, 'entityType' => $entityType]) + @include('emails.partials.client_view_action') @endif {!! $body !!} diff --git a/resources/views/emails/invoice_paid_html.blade.php b/resources/views/emails/invoice_paid_html.blade.php index 07e478b033..98fdce5b63 100644 --- a/resources/views/emails/invoice_paid_html.blade.php +++ b/resources/views/emails/invoice_paid_html.blade.php @@ -4,8 +4,8 @@ - @if (false) - @include('emails.view_action', ['link' => $invoiceLink, 'entityType' => $entityType]) + @if ($account->enable_email_markup) + @include('emails.partials.user_view_action') @endif {{ trans('texts.email_salutation', ['name' => $userName]) }}

diff --git a/resources/views/emails/invoice_sent_html.blade.php b/resources/views/emails/invoice_sent_html.blade.php index 3426820e1d..420f4260aa 100644 --- a/resources/views/emails/invoice_sent_html.blade.php +++ b/resources/views/emails/invoice_sent_html.blade.php @@ -4,8 +4,8 @@ - @if (false) - @include('emails.view_action', ['link' => $invoiceLink, 'entityType' => $entityType]) + @if ($account->enable_email_markup) + @include('emails.partials.user_view_action') @endif {{ trans('texts.email_salutation', ['name' => $userName]) }}

diff --git a/resources/views/emails/invoice_viewed_html.blade.php b/resources/views/emails/invoice_viewed_html.blade.php index 60fd6faaae..e38a635500 100644 --- a/resources/views/emails/invoice_viewed_html.blade.php +++ b/resources/views/emails/invoice_viewed_html.blade.php @@ -4,8 +4,8 @@ - @if (false) - @include('emails.view_action', ['link' => $invoiceLink, 'entityType' => $entityType]) + @if ($account->enable_email_markup) + @include('emails.partials.user_view_action') @endif {{ trans('texts.email_salutation', ['name' => $userName]) }}

diff --git a/resources/views/emails/master.blade.php b/resources/views/emails/master.blade.php index f12bf04c96..77da414231 100644 --- a/resources/views/emails/master.blade.php +++ b/resources/views/emails/master.blade.php @@ -7,7 +7,7 @@ @if ($account->enable_email_markup) - @include('emails.view_action', ['link' => $link, 'entityType' => $entityType]) + @include('emails.partials.client_view_action') @endif