From 4b00d3a82a1308f3d3c1e7a607514163222bdfd7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 19 Sep 2020 20:05:29 +1000 Subject: [PATCH 1/6] Improve eager loading --- app/Http/Controllers/BaseController.php | 6 ++++-- app/Jobs/Util/SendFailedEmails.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 8801eda1a129..81772a8beed4 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -71,6 +71,7 @@ class BaseController extends Controller 'company.clients.gateway_tokens', 'company.clients.documents', 'company.products', + 'company.products.documents', 'company.recurring_invoices', 'company.invoices.invitations.contact', 'company.invoices.invitations.company', @@ -92,6 +93,7 @@ class BaseController extends Controller 'company.tasks', 'company.projects', 'company.designs', + 'company.documents', 'company.webhooks', 'company.tokens_hashed', ]; @@ -202,7 +204,7 @@ class BaseController extends Controller $query->with( [ 'company' => function ($query) use ($updated_at) { - $query->whereNotNull('updated_at'); + $query->whereNotNull('updated_at')->with('documents'); }, 'company.clients' => function ($query) use ($updated_at) { $query->where('clients.updated_at', '>=', $updated_at)->with('contacts', 'gateway_tokens','documents'); @@ -217,7 +219,7 @@ class BaseController extends Controller $query->whereNotNull('updated_at'); }, 'company.products' => function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at); + $query->where('updated_at', '>=', $updated_at)->with('documents'); }, 'company.recurring_invoices'=> function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at)->with('company'); diff --git a/app/Jobs/Util/SendFailedEmails.php b/app/Jobs/Util/SendFailedEmails.php index e9975213e0ef..329ed566c00b 100644 --- a/app/Jobs/Util/SendFailedEmails.php +++ b/app/Jobs/Util/SendFailedEmails.php @@ -56,7 +56,7 @@ class SendFailedEmails implements ShouldQueue private function processEmails() { - \Log::error('processing emails'); + //\Log::error('processing emails'); //info("process emails"); //@todo check that the quota is available for the job From 624f8db66136988f7716c9867ddae974ee633f5f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 19 Sep 2020 20:33:59 +1000 Subject: [PATCH 2/6] Improve payments page for client portal and fix invoice status after payment made --- app/Services/Invoice/InvoiceService.php | 3 +++ app/Services/Payment/UpdateInvoicePayment.php | 4 ++++ .../gateways/stripe/credit_card.blade.php | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 9e027a98f381..a7e52f7d63ce 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -206,6 +206,9 @@ class InvoiceService if($this->invoice->balance == 0) $this->setStatus(Invoice::STATUS_PAID); + if($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) + $this->setStatus(Invoice::STATUS_PARTIAL); + return $this; } diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index ed6c69d316c2..341e3c746595 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -73,6 +73,8 @@ class UpdateInvoicePayment $pivot_invoice->pivot->amount = $paid_amount; $pivot_invoice->pivot->save(); + $this->payment->applied += $paid_amount; + $invoice->service() //caution what if we amount paid was less than partial - we wipe it! ->clearPartial() ->updateBalance($paid_amount * -1) @@ -82,6 +84,8 @@ class UpdateInvoicePayment event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars())); }); + + $this->payment->save(); return $this->payment; } diff --git a/resources/views/portal/ninja2020/gateways/stripe/credit_card.blade.php b/resources/views/portal/ninja2020/gateways/stripe/credit_card.blade.php index 77c91ba8e5c3..5169466ee6d3 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/credit_card.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/credit_card.blade.php @@ -31,6 +31,28 @@
+ +
+
+ {{ ctrans('texts.subtotal') }} +
+
+ {{ App\Utils\Number::formatMoney($total['invoice_totals'], $client) }} +
+
+ {{ ctrans('texts.gateway_fees') }} +
+
+ {{ App\Utils\Number::formatMoney($total['fee_total'], $client) }} +
+
+ {{ ctrans('texts.total') }} +
+
+ {{ App\Utils\Number::formatMoney($total['amount_with_fee'], $client) }} +
+
+ @if($token)
From 0338a30a48c60a6c2be54d4d235ff9efe17b5e6f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 21 Sep 2020 08:17:57 +1000 Subject: [PATCH 3/6] Fixes for generic email templates --- app/Jobs/User/UserEmailChanged.php | 1 + app/Mail/Admin/EntitySentObject.php | 2 ++ app/Mail/Admin/EntityViewedObject.php | 2 ++ app/Mail/Admin/PaymentFailureObject.php | 2 ++ 4 files changed, 7 insertions(+) diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php index 6c3cb939b036..8043d4e2232c 100644 --- a/app/Jobs/User/UserEmailChanged.php +++ b/app/Jobs/User/UserEmailChanged.php @@ -92,6 +92,7 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue 'button' => ctrans('texts.account_login'), 'signature' => $this->company->owner()->signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->settings, ]; } } diff --git a/app/Mail/Admin/EntitySentObject.php b/app/Mail/Admin/EntitySentObject.php index 5ebcf6a19c64..4367acda86c7 100644 --- a/app/Mail/Admin/EntitySentObject.php +++ b/app/Mail/Admin/EntitySentObject.php @@ -84,6 +84,8 @@ class EntitySentObject 'button' => ctrans("texts.view_{$this->entity_type}"), 'signature' => $settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $settings, + ]; } } diff --git a/app/Mail/Admin/EntityViewedObject.php b/app/Mail/Admin/EntityViewedObject.php index e491e1566696..367c3f2de2a2 100644 --- a/app/Mail/Admin/EntityViewedObject.php +++ b/app/Mail/Admin/EntityViewedObject.php @@ -84,6 +84,8 @@ class EntityViewedObject 'button' => ctrans("texts.view_{$this->entity_type}"), 'signature' => $settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $settings, + ]; return $data; diff --git a/app/Mail/Admin/PaymentFailureObject.php b/app/Mail/Admin/PaymentFailureObject.php index 08077206bfdd..12e041740f05 100644 --- a/app/Mail/Admin/PaymentFailureObject.php +++ b/app/Mail/Admin/PaymentFailureObject.php @@ -76,6 +76,8 @@ class PaymentFailureObject ), 'signature' => $signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->client->getMergedSettings(), + ]; return $data; From 3f62ff941e4b3f5de4a41b3c5e9381b94c0996aa Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 21 Sep 2020 12:26:10 +1000 Subject: [PATCH 4/6] Add more events when a PDF must be updated --- app/Providers/EventServiceProvider.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 8215fb1dc87c..75ff36321ea5 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -225,6 +225,7 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasPaid::class => [ InvoicePaidActivity::class, + CreateInvoicePdf::class, ], InvoiceWasViewed::class => [ InvoiceViewedActivity::class, @@ -238,6 +239,7 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasDeleted::class => [ InvoiceDeletedActivity::class, + CreateInvoicePdf::class, ], InvoiceWasArchived::class => [ InvoiceArchivedActivity::class, @@ -247,6 +249,7 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasReversed::class => [ InvoiceReversedActivity::class, + CreateInvoicePdf::class, ], InvoiceWasCancelled::class => [ InvoiceCancelledActivity::class, From 78848fff4f271ff4d5a53b8b3abcdf3d11f6d22e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 21 Sep 2020 16:27:02 +1000 Subject: [PATCH 5/6] fixes --- app/Http/Controllers/InvoiceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 97cdf2b47193..32302359ad29 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -700,7 +700,7 @@ class InvoiceController extends BaseController } break; case 'email': - //check query paramater for email_type and set the template else use calculateTemplate + //check query parameter for email_type and set the template else use calculateTemplate if (request()->has('email_type') && property_exists($invoice->company->settings, request()->input('email_type'))) { $this->reminder_template = $invoice->client->getSetting(request()->input('email_type')); } else { From 617a923894ff8467f86a53c847326acc4315461d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 21 Sep 2020 20:54:58 +1000 Subject: [PATCH 6/6] Fixes for notifications: --- app/Notifications/Admin/EntitySentNotification.php | 9 +++++++++ app/Notifications/Admin/EntityViewedNotification.php | 9 +++++++++ app/Notifications/Admin/InvoiceSentNotification.php | 9 +++++++++ app/Notifications/Admin/InvoiceViewedNotification.php | 9 +++++++++ .../Admin/NewPartialPaymentNotification.php | 9 +++++++++ app/Notifications/Admin/NewPaymentNotification.php | 9 +++++++++ app/Notifications/BaseNotification.php | 10 ++++++++++ app/Notifications/ClientContactRequestCancellation.php | 9 +++++++++ app/Notifications/ClientContactResetPassword.php | 9 +++++++++ app/Notifications/GmailTestNotification.php | 9 +++++++++ app/Notifications/NewAccountCreated.php | 9 +++++++++ app/Notifications/Ninja/NewAccountCreated.php | 9 +++++++++ app/Notifications/Ninja/VerifyUser.php | 9 +++++++++ app/Notifications/SendGenericNotification.php | 9 +++++++++ app/Utils/ClientPortal/CustomMessage/CustomMessage.php | 9 +++++++++ .../ClientPortal/CustomMessage/CustomMessageFacade.php | 9 +++++++++ 16 files changed, 145 insertions(+) diff --git a/app/Notifications/Admin/EntitySentNotification.php b/app/Notifications/Admin/EntitySentNotification.php index ec5680a4582a..dead3b4eae8f 100644 --- a/app/Notifications/Admin/EntitySentNotification.php +++ b/app/Notifications/Admin/EntitySentNotification.php @@ -1,4 +1,13 @@ ctrans('texts.view_'.$this->entity_string), 'logo' => $this->entity->company->present()->logo(), 'signature' => $this->settings->email_signature, + 'settings' => $this->settings, ]; diff --git a/app/Notifications/ClientContactRequestCancellation.php b/app/Notifications/ClientContactRequestCancellation.php index 25c2fcce0ddc..927b07e25802 100644 --- a/app/Notifications/ClientContactRequestCancellation.php +++ b/app/Notifications/ClientContactRequestCancellation.php @@ -1,4 +1,13 @@