From 1de91c9e3357f4c847b47dcb6abbad43bc084f58 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Feb 2023 19:58:30 +1100 Subject: [PATCH] Reducing the quantity of jobs dispatched --- VERSION.txt | 2 +- app/Jobs/Entity/CreateEntityPdf.php | 4 --- app/Jobs/Ledger/ClientLedgerBalanceUpdate.php | 22 ++++++------ app/Jobs/Quote/QuoteWorkflowSettings.php | 4 --- .../Credit/CreditCreatedNotification.php | 6 ++-- .../Credit/CreditEmailedNotification.php | 6 +--- .../Invoice/InvoiceCreatedNotification.php | 4 +-- .../Invoice/InvoiceEmailedNotification.php | 4 +-- .../InvoiceFailedEmailNotification.php | 4 ++- app/Listeners/Invoice/InvoicePaidActivity.php | 5 --- .../Misc/InvitationViewedListener.php | 2 +- .../Payment/PaymentEmailedActivity.php | 1 - app/Listeners/Payment/PaymentNotification.php | 4 +-- .../PurchaseOrderAcceptedListener.php | 2 +- .../PurchaseOrderCreatedListener.php | 4 ++- .../PurchaseOrderEmailedNotification.php | 2 +- .../Quote/QuoteApprovedNotification.php | 4 +-- .../Quote/QuoteCreatedNotification.php | 2 +- .../Quote/QuoteEmailedNotification.php | 8 +---- app/Mail/Admin/EntityPaidObject.php | 3 +- app/Mail/Engine/PaymentEmailEngine.php | 2 +- app/Models/CompanyGateway.php | 4 +++ app/Models/CreditInvitation.php | 34 ------------------- app/Models/QuoteInvitation.php | 1 - app/Providers/EventServiceProvider.php | 4 +-- app/Services/Bank/BankMatchingService.php | 1 - app/Services/Credit/ApplyPayment.php | 1 + config/ninja.php | 4 +-- 28 files changed, 45 insertions(+), 99 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index f4a6c60233..dd7e5a287c 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.5.70 \ No newline at end of file +5.5.71 \ No newline at end of file diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index b59e3529fd..9217bdce59 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -73,19 +73,15 @@ class CreateEntityPdf implements ShouldQueue $this->invitation = $invitation; if ($invitation instanceof InvoiceInvitation) { - // $invitation->load('contact.client.company','invoice.client','invoice.user.account'); $this->entity = $invitation->invoice; $this->entity_string = 'invoice'; } elseif ($invitation instanceof QuoteInvitation) { - // $invitation->load('contact.client.company','quote.client','quote.user.account'); $this->entity = $invitation->quote; $this->entity_string = 'quote'; } elseif ($invitation instanceof CreditInvitation) { - // $invitation->load('contact.client.company','credit.client','credit.user.account'); $this->entity = $invitation->credit; $this->entity_string = 'credit'; } elseif ($invitation instanceof RecurringInvoiceInvitation) { - // $invitation->load('contact.client.company','recurring_invoice'); $this->entity = $invitation->recurring_invoice; $this->entity_string = 'recurring_invoice'; } diff --git a/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php b/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php index 731ec0872a..8dc45cf74f 100644 --- a/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php +++ b/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php @@ -19,25 +19,16 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; class ClientLedgerBalanceUpdate implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public $tries = 1; - - public $company; - - public $client; - public $deleteWhenMissingModels = true; - - public function __construct(Company $company, Client $client) - { - $this->company = $company; - $this->client = $client; - } + public function __construct(public Company $company, public Client $client) + {} /** * Execute the job. @@ -71,4 +62,11 @@ class ClientLedgerBalanceUpdate implements ShouldQueue $company_ledger->save(); }); } + + + public function middleware() + { + return [(new WithoutOverlapping($this->client->id))->dontRelease()]; + } + } diff --git a/app/Jobs/Quote/QuoteWorkflowSettings.php b/app/Jobs/Quote/QuoteWorkflowSettings.php index ec95340a70..9090dc2b9c 100644 --- a/app/Jobs/Quote/QuoteWorkflowSettings.php +++ b/app/Jobs/Quote/QuoteWorkflowSettings.php @@ -56,9 +56,5 @@ class QuoteWorkflowSettings implements ShouldQueue $this->quote->service()->sendEmail($invitation->contact); }); } - - // if ($this->client->getSetting('auto_archive_quote')) { - // $this->base_repository->archive($this->quote); - // } } } diff --git a/app/Listeners/Credit/CreditCreatedNotification.php b/app/Listeners/Credit/CreditCreatedNotification.php index 79dfa23d53..19aca5a7c7 100644 --- a/app/Listeners/Credit/CreditCreatedNotification.php +++ b/app/Listeners/Credit/CreditCreatedNotification.php @@ -24,6 +24,8 @@ class CreditCreatedNotification implements ShouldQueue { use UserNotifies; + public $delay = 10; + public function __construct() { } @@ -64,10 +66,8 @@ class CreditCreatedNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); - /* This prevents more than one notification being sent */ - // $first_notification_sent = false; } /* Override the methods in the Notification Class */ diff --git a/app/Listeners/Credit/CreditEmailedNotification.php b/app/Listeners/Credit/CreditEmailedNotification.php index a983fc6f73..db09b5a6ae 100644 --- a/app/Listeners/Credit/CreditEmailedNotification.php +++ b/app/Listeners/Credit/CreditEmailedNotification.php @@ -62,14 +62,10 @@ class CreditEmailedNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); - // $first_notification_sent = false; } - // $notification->method = $methods; - - // $user->notify($notification); } } } diff --git a/app/Listeners/Invoice/InvoiceCreatedNotification.php b/app/Listeners/Invoice/InvoiceCreatedNotification.php index 92f5074901..1022a2f507 100644 --- a/app/Listeners/Invoice/InvoiceCreatedNotification.php +++ b/app/Listeners/Invoice/InvoiceCreatedNotification.php @@ -24,7 +24,7 @@ class InvoiceCreatedNotification implements ShouldQueue { use UserNotifies; - public $delay = 5; + public $delay = 7; public function __construct() { @@ -70,7 +70,7 @@ class InvoiceCreatedNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); /* This prevents more than one notification being sent */ $first_notification_sent = false; diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index 66cb02145c..e9012e0a8f 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -24,7 +24,7 @@ class InvoiceEmailedNotification implements ShouldQueue { use UserNotifies; - public $delay = 5; + public $delay = 10; public function __construct() { @@ -68,7 +68,7 @@ class InvoiceEmailedNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); /* This prevents more than one notification being sent */ $first_notification_sent = false; diff --git a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php index 09d28f1870..85005e4503 100644 --- a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php +++ b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php @@ -26,6 +26,8 @@ class InvoiceFailedEmailNotification { use UserNotifies, Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public $delay = 7; + public function __construct() { } @@ -60,7 +62,7 @@ class InvoiceFailedEmailNotification $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); $first_notification_sent = false; } diff --git a/app/Listeners/Invoice/InvoicePaidActivity.php b/app/Listeners/Invoice/InvoicePaidActivity.php index e33c837bce..f2d64a0c81 100644 --- a/app/Listeners/Invoice/InvoicePaidActivity.php +++ b/app/Listeners/Invoice/InvoicePaidActivity.php @@ -57,10 +57,5 @@ class InvoicePaidActivity implements ShouldQueue $event->invoice->subscription->service()->planPaid($event->invoice); } - // try { - // $event->invoice->service()->touchPdf(); - // } catch (\Exception $e) { - // nlog(print_r($e->getMessage(), 1)); - // } } } diff --git a/app/Listeners/Misc/InvitationViewedListener.php b/app/Listeners/Misc/InvitationViewedListener.php index fb8d28afee..885b4c9c7b 100644 --- a/app/Listeners/Misc/InvitationViewedListener.php +++ b/app/Listeners/Misc/InvitationViewedListener.php @@ -74,7 +74,7 @@ class InvitationViewedListener implements ShouldQueue unset($methods[$key]); $nmo->to_user = $company_user->user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); } } } diff --git a/app/Listeners/Payment/PaymentEmailedActivity.php b/app/Listeners/Payment/PaymentEmailedActivity.php index b4d75181fa..52ee83b3fe 100644 --- a/app/Listeners/Payment/PaymentEmailedActivity.php +++ b/app/Listeners/Payment/PaymentEmailedActivity.php @@ -39,7 +39,6 @@ class PaymentEmailedActivity implements ShouldQueue public function handle($event) { MultiDB::setDb($event->company->db); - $payment = $event->payment; } } diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index 1899c9ed35..5dbe0374e5 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -24,7 +24,7 @@ class PaymentNotification implements ShouldQueue { use UserNotifies; - public $delay = 5; + public $delay = 20; /** * Create the event listener. @@ -75,7 +75,7 @@ class PaymentNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); } } diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderAcceptedListener.php b/app/Listeners/PurchaseOrder/PurchaseOrderAcceptedListener.php index d83b7223d5..2803f82379 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderAcceptedListener.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderAcceptedListener.php @@ -64,7 +64,7 @@ class PurchaseOrderAcceptedListener implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); /* This prevents more than one notification being sent */ $first_notification_sent = false; diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php index 6b7e146def..6117881557 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php @@ -25,6 +25,8 @@ class PurchaseOrderCreatedListener implements ShouldQueue { use UserNotifies; + public $delay = 7; + public function __construct() { } @@ -69,7 +71,7 @@ class PurchaseOrderCreatedListener implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); /* This prevents more than one notification being sent */ $first_notification_sent = false; diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderEmailedNotification.php b/app/Listeners/PurchaseOrder/PurchaseOrderEmailedNotification.php index 2254138076..82c3b3b0cf 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderEmailedNotification.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderEmailedNotification.php @@ -68,7 +68,7 @@ class PurchaseOrderEmailedNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); /* This prevents more than one notification being sent */ $first_notification_sent = false; diff --git a/app/Listeners/Quote/QuoteApprovedNotification.php b/app/Listeners/Quote/QuoteApprovedNotification.php index eae4d21e41..adedab41f9 100644 --- a/app/Listeners/Quote/QuoteApprovedNotification.php +++ b/app/Listeners/Quote/QuoteApprovedNotification.php @@ -23,7 +23,7 @@ class QuoteApprovedNotification implements ShouldQueue { use UserNotifies; - public $delay = 5; + public $delay = 8; public function __construct() { @@ -66,7 +66,7 @@ class QuoteApprovedNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); /* This prevents more than one notification being sent */ $first_notification_sent = false; diff --git a/app/Listeners/Quote/QuoteCreatedNotification.php b/app/Listeners/Quote/QuoteCreatedNotification.php index 6c636605f1..5af1a1943e 100644 --- a/app/Listeners/Quote/QuoteCreatedNotification.php +++ b/app/Listeners/Quote/QuoteCreatedNotification.php @@ -70,7 +70,7 @@ class QuoteCreatedNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); /* This prevents more than one notification being sent */ $first_notification_sent = false; diff --git a/app/Listeners/Quote/QuoteEmailedNotification.php b/app/Listeners/Quote/QuoteEmailedNotification.php index 8c67b1e84e..296e7df119 100644 --- a/app/Listeners/Quote/QuoteEmailedNotification.php +++ b/app/Listeners/Quote/QuoteEmailedNotification.php @@ -54,8 +54,6 @@ class QuoteEmailedNotification implements ShouldQueue foreach ($event->invitation->company->company_users as $company_user) { $user = $company_user->user; - // $notification = new EntitySentNotification($event->invitation, 'quote'); - $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'quote', ['all_notifications', 'quote_sent', 'quote_sent_all', 'quote_sent_user']); if (($key = array_search('mail', $methods)) !== false) { @@ -63,14 +61,10 @@ class QuoteEmailedNotification implements ShouldQueue $nmo->to_user = $user; - NinjaMailerJob::dispatch($nmo); + (new NinjaMailerJob($nmo))->handle(); - // $first_notification_sent = false; } - // $notification->method = $methods; - - // $user->notify($notification); } } } diff --git a/app/Mail/Admin/EntityPaidObject.php b/app/Mail/Admin/EntityPaidObject.php index eb3c8153d0..aa806d66e4 100644 --- a/app/Mail/Admin/EntityPaidObject.php +++ b/app/Mail/Admin/EntityPaidObject.php @@ -16,6 +16,7 @@ use App\Utils\Ninja; use App\Utils\Number; use Illuminate\Support\Facades\App; use stdClass; +use App\Models\Payment; class EntityPaidObject { @@ -29,7 +30,7 @@ class EntityPaidObject public $settings; - public function __construct($payment) + public function __construct(public Payment $payment) { $this->payment = $payment; $this->company = $payment->company; diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index cae4251c57..a8f7d44f46 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -323,7 +323,7 @@ class PaymentEmailEngine extends BaseEmailEngine $invoice_list = '

'; foreach ($this->payment->invoices as $invoice) { - $invoice_list .= ctrans('texts.invoice_number_short')." {$invoice->number} - ".Number::formatMoney($invoice->pivot->amount, $this->client).'
'; + $invoice_list .= ctrans('texts.invoice_number_short')." {$invoice->number} ".Number::formatMoney($invoice->pivot->amount, $this->client).'
'; } return $invoice_list; diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 9dc1f03c24..7bded57017 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -74,6 +74,8 @@ class CompanyGateway extends BaseModel // const TYPE_WEPAY = 309; // const TYPE_PAYFAST = 310; // const TYPE_PAYTRACE = 311; + // const TYPE_MOLLIE = 312; + // const TYPE_EWAY = 313; // const TYPE_FORTE = 314; public $gateway_consts = [ @@ -87,6 +89,8 @@ class CompanyGateway extends BaseModel '8fdeed552015b3c7b44ed6c8ebd9e992' => 309, 'd6814fc83f45d2935e7777071e629ef9' => 310, 'bbd736b3254b0aabed6ad7fda1298c88' => 311, + '1bd651fb213ca0c9d66ae3c336dc77e7' => 312, + '944c20175bbe6b9972c05bcfe294c2c7' => 313, 'kivcvjexxvdiyqtj3mju5d6yhpeht2xs' => 314, '65faab2ab6e3223dbe848b1686490baz' => 320, 'b9886f9257f0c6ee7c302f1c74475f6c' => 321, diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index d029f915ed..1f600e19af 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -11,7 +11,6 @@ namespace App\Models; -use App\Events\Credit\CreditWasUpdated; use App\Jobs\Entity\CreateEntityPdf; use App\Utils\Ninja; use App\Utils\Traits\Inviteable; @@ -44,38 +43,6 @@ class CreditInvitation extends BaseModel return self::class; } - // public function getSignatureDateAttribute($value) - // { - // if (!$value) { - // return (new Carbon($value))->format('Y-m-d'); - // } - // return $value; - // } - - // public function getSentDateAttribute($value) - // { - // if (!$value) { - // return (new Carbon($value))->format('Y-m-d'); - // } - // return $value; - // } - - // public function getViewedDateAttribute($value) - // { - // if (!$value) { - // return (new Carbon($value))->format('Y-m-d'); - // } - // return $value; - // } - - // public function getOpenedDateAttribute($value) - // { - // if (!$value) { - // return (new Carbon($value))->format('Y-m-d'); - // } - // return $value; - // } - public function entityType() { return Credit::class; @@ -129,7 +96,6 @@ class CreditInvitation extends BaseModel $storage_path = Storage::url($this->credit->client->quote_filepath($this).$this->credit->numberFormatter().'.pdf'); if (! Storage::exists($this->credit->client->credit_filepath($this).$this->credit->numberFormatter().'.pdf')) { - event(new CreditWasUpdated($this->credit, $this->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); (new CreateEntityPdf($this))->handle(); } diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index c3508b23fa..d5cb22710a 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -101,7 +101,6 @@ class QuoteInvitation extends BaseModel $storage_path = Storage::url($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf'); if (! Storage::exists($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf')) { - event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); (new CreateEntityPdf($this))->handle(); } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index b0949dc593..a9434ea7f9 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -407,12 +407,10 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasUpdated::class => [ UpdateInvoiceActivity::class, - CreateInvoicePdf::class, ], InvoiceWasCreated::class => [ CreateInvoiceActivity::class, InvoiceCreatedNotification::class, - // CreateInvoicePdf::class, ], InvoiceWasPaid::class => [ InvoicePaidActivity::class, @@ -451,7 +449,7 @@ class EventServiceProvider extends ServiceProvider InvitationViewedListener::class, ], PaymentWasEmailed::class => [ - PaymentEmailedActivity::class, + // PaymentEmailedActivity::class, ], PaymentWasEmailedAndFailed::class => [ // PaymentEmailFailureActivity::class, diff --git a/app/Services/Bank/BankMatchingService.php b/app/Services/Bank/BankMatchingService.php index 906e21fe91..df013e77cc 100644 --- a/app/Services/Bank/BankMatchingService.php +++ b/app/Services/Bank/BankMatchingService.php @@ -23,7 +23,6 @@ use Illuminate\Queue\SerializesModels; class BankMatchingService implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public function __construct(public $company_id, public $db) { } diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index f9eeb7ec46..0f8af8b4ae 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -137,6 +137,7 @@ class ApplyPayment ->updateBalance($this->amount_applied * -1) ->updatePaidToDate($this->amount_applied) ->updateStatus() + ->touchPdf() ->save(); $this->credit diff --git a/config/ninja.php b/config/ninja.php index 54370ef714..6cfd2e5814 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.5.70', - 'app_tag' => '5.5.70', + 'app_version' => '5.5.71', + 'app_tag' => '5.5.71', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),