From 89a271e59c39e718c2b2f9a14d0039c6a6b207a9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 31 Mar 2021 12:55:33 +1100 Subject: [PATCH 1/5] Improve custom label replacements in emails --- app/Jobs/Payment/EmailPayment.php | 7 ++++++- app/Mail/Admin/AutoBillingFailureObject.php | 3 +++ app/Mail/Admin/ClientPaymentFailureObject.php | 3 +++ app/Mail/Admin/EntityFailedSendObject.php | 7 ++++++- app/Mail/Admin/EntityPaidObject.php | 13 ++++++++++++- app/Mail/Engine/BaseEmailEngine.php | 1 + app/Mail/Engine/PaymentEmailEngine.php | 2 +- app/Mail/TemplateEmail.php | 13 +++++++++---- 8 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index 134b0673eac6..2abdfd802af6 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -77,8 +77,13 @@ class EmailPayment implements ShouldQueue $email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build(); + $invitation = null; + + if($this->payment->invoices()->exists()) + $invitation = $this->payment->invoices()->first()->invitations()->first(); + $nmo = new NinjaMailerObject; - $nmo->mailable = new TemplateEmail($email_builder, $this->contact); + $nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation); $nmo->to_user = $this->contact; $nmo->settings = $this->settings; $nmo->company = $this->company; diff --git a/app/Mail/Admin/AutoBillingFailureObject.php b/app/Mail/Admin/AutoBillingFailureObject.php index bd30395f67de..e9064506164e 100644 --- a/app/Mail/Admin/AutoBillingFailureObject.php +++ b/app/Mail/Admin/AutoBillingFailureObject.php @@ -12,6 +12,7 @@ namespace App\Mail\Admin; use App\Models\Invoice; +use App\Utils\HtmlEngine; use App\Utils\Number; use App\Utils\Traits\MakesHash; use stdClass; @@ -84,6 +85,8 @@ class AutoBillingFailureObject private function getData() { $signature = $this->client->getSetting('email_signature'); + $html_variables = (new HtmlEngine($this->invoices->first()->invitations->first()))->makeValues(); + $signature = str_replace(array_keys($html_variables), array_values($html_variables), $signature); $data = [ 'title' => ctrans( diff --git a/app/Mail/Admin/ClientPaymentFailureObject.php b/app/Mail/Admin/ClientPaymentFailureObject.php index 0135a2dad1ab..4debf5a37c69 100644 --- a/app/Mail/Admin/ClientPaymentFailureObject.php +++ b/app/Mail/Admin/ClientPaymentFailureObject.php @@ -12,6 +12,7 @@ namespace App\Mail\Admin; use App\Models\Invoice; +use App\Utils\HtmlEngine; use App\Utils\Number; use App\Utils\Traits\MakesHash; use stdClass; @@ -88,6 +89,8 @@ class ClientPaymentFailureObject private function getData() { $signature = $this->client->getSetting('email_signature'); + $html_variables = (new HtmlEngine($this->invoices->first()->invitations->first()))->makeValues(); + $signature = str_replace(array_keys($html_variables), array_values($html_variables), $signature); $data = [ 'title' => ctrans( diff --git a/app/Mail/Admin/EntityFailedSendObject.php b/app/Mail/Admin/EntityFailedSendObject.php index bc7d228fba48..0b937e731647 100644 --- a/app/Mail/Admin/EntityFailedSendObject.php +++ b/app/Mail/Admin/EntityFailedSendObject.php @@ -11,6 +11,7 @@ namespace App\Mail\Admin; +use App\Utils\HtmlEngine; use App\Utils\Number; use stdClass; @@ -121,6 +122,10 @@ class EntityFailedSendObject private function getData() { $settings = $this->entity->client->getMergedSettings(); + $signature = $settings->email_signature; + + $html_variables = (new HtmlEngine($this->invitation)->makeValues(); + $signature = str_replace(array_keys($html_variables), array_values($html_variables), $signature); return [ 'title' => $this->getSubject(), @@ -136,7 +141,7 @@ class EntityFailedSendObject ), 'url' => $this->invitation->getAdminLink(), 'button' => ctrans("texts.view_{$this->entity_type}"), - 'signature' => $settings->email_signature, + 'signature' => $signature, 'logo' => $this->company->present()->logo(), 'settings' => $settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, diff --git a/app/Mail/Admin/EntityPaidObject.php b/app/Mail/Admin/EntityPaidObject.php index 25046f7af5f5..df9c7fa8c654 100644 --- a/app/Mail/Admin/EntityPaidObject.php +++ b/app/Mail/Admin/EntityPaidObject.php @@ -11,6 +11,7 @@ namespace App\Mail\Admin; +use App\Mail\Engine\PaymentEmailEngine; use App\Utils\Number; use stdClass; @@ -62,6 +63,8 @@ class EntityPaidObject { $settings = $this->payment->client->getMergedSettings(); + $signature = $this->generateSignature($settings); + $amount = Number::formatMoney($this->payment->amount, $this->payment->client); $invoice_texts = ctrans('texts.invoice_number_short'); @@ -85,7 +88,6 @@ class EntityPaidObject ] ), 'url' => config('ninja.app_url'), - // 'url' => config('ninja.app_url') . '/payments/' . $this->payment->hashed_id, //because we have no deep linking we cannot use this 'button' => ctrans('texts.view_payment'), 'signature' => $settings->email_signature, 'logo' => $this->company->present()->logo(), @@ -95,4 +97,13 @@ class EntityPaidObject return $data; } + + private function generateSignature($settings) + { + $html_variables = (new PaymentEmailEngine($this->payment, $this->payment->client->primary_contact()->first()))->makeValues(); + + $signature = str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature); + + return $signature; + } } diff --git a/app/Mail/Engine/BaseEmailEngine.php b/app/Mail/Engine/BaseEmailEngine.php index 01727dfd8aef..2f7bfa49da63 100644 --- a/app/Mail/Engine/BaseEmailEngine.php +++ b/app/Mail/Engine/BaseEmailEngine.php @@ -69,6 +69,7 @@ class BaseEmailEngine implements EngineInterface { if (! empty($this->variables)) { $body = str_replace(array_keys($this->variables), array_values($this->variables), $body); + $body = str_replace(array_keys($this->variables), array_values($this->variables), $body); } $this->body = $body; diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index 8e12d7280895..94c925843675 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -76,7 +76,7 @@ class PaymentEmailEngine extends BaseEmailEngine } - private function makePaymentVariables() + public function makePaymentVariables() { $data = []; diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index ea47aab1487b..7598a54c4ea2 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -53,9 +53,14 @@ class TemplateEmail extends Mailable $company = $this->client->company; - $html_variables = (new HtmlEngine($this->invitation))->makeValues(); - -//str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature) + if($this->invitation) + { + $html_variables = (new HtmlEngine($this->invitation))->makeValues(); + $signature = str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature); + } + else + $signature = $settings->email_signature; + $this->from(config('mail.from.address'), $this->company->present()->name()); if (strlen($settings->bcc_email) > 1) @@ -75,7 +80,7 @@ class TemplateEmail extends Mailable 'view_link' => $this->build_email->getViewLink(), 'view_text' => $this->build_email->getViewText(), 'title' => '', - 'signature' => str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature), + 'signature' => $signature, 'settings' => $settings, 'company' => $company, 'whitelabel' => $this->client->user->account->isPaid() ? true : false, From 9c4a2239237d477a9c5185de34a4c095805870f5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 31 Mar 2021 13:28:03 +1100 Subject: [PATCH 2/5] Fixes for notification gates --- app/Listeners/Payment/PaymentNotification.php | 2 +- app/Utils/Traits/Notifications/UserNotifies.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index 1876074ba1ca..97861e362750 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -59,7 +59,7 @@ class PaymentNotification implements ShouldQueue foreach ($payment->company->company_users as $company_user) { $user = $company_user->user; - $methods = $this->findUserEntityNotificationType($payment, $company_user, ['payment_success_all', 'all_notifications']); + $methods = $this->findUserEntityNotificationType($payment, $company_user, ['payment_success', 'payment_success_all', 'all_notifications']); if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); diff --git a/app/Utils/Traits/Notifications/UserNotifies.php b/app/Utils/Traits/Notifications/UserNotifies.php index efff7001004f..857ad2eb1418 100644 --- a/app/Utils/Traits/Notifications/UserNotifies.php +++ b/app/Utils/Traits/Notifications/UserNotifies.php @@ -38,8 +38,6 @@ trait UserNotifies array_push($notifiable_methods, 'mail'); } -nlog($notifiable_methods); - // if(count(array_intersect($required_permissions, $notifications->slack)) >=1) // array_push($notifiable_methods, 'slack'); @@ -63,10 +61,11 @@ nlog($notifiable_methods); array_push($required_permissions, 'all_user_notifications'); } - if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, ['all_user_notifications'])) >= 1 || count(array_intersect($required_permissions, ['all_notifications'])) >= 1) { + if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_user_notifications'], $notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) { array_push($notifiable_methods, 'mail'); } + return $notifiable_methods; } From b9e56a271dff737cf78b5d0e16845fab2e781a83 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 31 Mar 2021 21:41:17 +1100 Subject: [PATCH 3/5] Add expense type id for invoice items --- app/DataMapper/InvoiceItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/DataMapper/InvoiceItem.php b/app/DataMapper/InvoiceItem.php index 35328227bdb3..acf261094522 100644 --- a/app/DataMapper/InvoiceItem.php +++ b/app/DataMapper/InvoiceItem.php @@ -51,7 +51,7 @@ class InvoiceItem public $custom_value4 = ''; - public $type_id = '1'; //1 = product, 2 = service, 3 unpaid gateway fee, 4 paid gateway fee, 5 late fee, 6 promo code + public $type_id = '1'; //1 = product, 2 = service, 3 unpaid gateway fee, 4 paid gateway fee, 5 late fee, 6 expense public static $casts = [ 'type_id' => 'string', From c279cf013ee3bee96bbac198c8d64ff463f7dc13 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 1 Apr 2021 07:04:53 +1100 Subject: [PATCH 4/5] add per_seat_enabled to fillable --- app/Models/Subscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index 3b7beb19d156..d0778797c9e9 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -29,7 +29,7 @@ class Subscription extends BaseModel 'promo_discount', 'is_amount_discount', 'allow_cancellation', - 'per_set_enabled', + 'per_seat_enabled', 'min_seats_limit', 'max_seats_limit', 'trial_enabled', From c78feb80e8a8c2a92c72b69a76f741cd3b6e8c48 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 1 Apr 2021 08:28:51 +1100 Subject: [PATCH 5/5] Fixes for payment mailer --- app/Console/Commands/SendRemindersCron.php | 4 ++++ app/Mail/Engine/PaymentEmailEngine.php | 6 +++--- app/Transformers/SubscriptionTransformer.php | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/SendRemindersCron.php b/app/Console/Commands/SendRemindersCron.php index a41a7e9b25f1..54d00824d2f4 100644 --- a/app/Console/Commands/SendRemindersCron.php +++ b/app/Console/Commands/SendRemindersCron.php @@ -75,6 +75,10 @@ class SendRemindersCron extends Command } + private function webHookExpiredQuotes() + { + + } private function executeWebhooks() { diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index 94c925843675..cac95765180f 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -132,9 +132,9 @@ class PaymentEmailEngine extends BaseEmailEngine $data['$client_balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')]; $data['$paid_to_date'] = ['value' => Number::formatMoney($this->client->paid_to_date, $this->client), 'label' => ctrans('texts.paid_to_date')]; - $data['$contact.full_name'] = ['value' => $this->contact->present()->name(), 'label' => ctrans('texts.name')]; - $data['$contact.email'] = ['value' => $this->contact->email, 'label' => ctrans('texts.email')]; - $data['$contact.phone'] = ['value' => $this->contact->phone, 'label' => ctrans('texts.phone')]; + $data['$contact.full_name'] = ['value' => isset($this->contact) ? $this->contact->present()->name() : '', 'label' => ctrans('texts.name')]; + $data['$contact.email'] = ['value' => isset($this->contact) ? $this->contact->email : '', 'label' => ctrans('texts.email')]; + $data['$contact.phone'] = ['value' => isset($this->contact) ? $this->contact->phone: '', 'label' => ctrans('texts.phone')]; $data['$contact.name'] = ['value' => isset($this->contact) ? $this->contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')]; $data['$contact.first_name'] = ['value' => isset($this->contact) ? $this->contact->first_name : '', 'label' => ctrans('texts.first_name')]; diff --git a/app/Transformers/SubscriptionTransformer.php b/app/Transformers/SubscriptionTransformer.php index c9ca170104e5..47b337bf718d 100644 --- a/app/Transformers/SubscriptionTransformer.php +++ b/app/Transformers/SubscriptionTransformer.php @@ -44,6 +44,7 @@ class SubscriptionTransformer extends EntityTransformer 'assigned_user_id' => $this->encodePrimaryKey($subscription->assigned_user_id), 'company_id' => $this->encodePrimaryKey($subscription->company_id), 'price' => (float) $subscription->price, + 'promo_price' => (float) $subscription->promo_price, 'frequency_id' => (string)$subscription->frequency_id, 'auto_bill' => (string)$subscription->auto_bill, 'promo_code' => (string)$subscription->promo_code,