From 038d5e0406815a7d0a713d97d4a09200fff5f941 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 25 Sep 2020 20:05:45 +1000 Subject: [PATCH 1/3] remove stripe omnipay driver --- app/Models/Gateway.php | 1 + composer.json | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 7e94fb839722..fe41ae3a476a 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -21,6 +21,7 @@ class Gateway extends StaticModel 'is_secure' => 'boolean', 'recommended' => 'boolean', //'visible' => 'boolean', + //'sort_order' => 'int', 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'default_gateway_type_id' => 'string', diff --git a/composer.json b/composer.json index 2b584ceebb40..b189ac1cd552 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,6 @@ "maennchen/zipstream-php": "^1.2", "nwidart/laravel-modules": "^6.0", "omnipay/paypal": "^3.0", - "omnipay/stripe": "^3.0", "predis/predis": "^1.1", "sentry/sentry-laravel": "^1.8", "spatie/browsershot": "^3.37", From 3c4bc4a51635b8f68806550b92e42d52d7305e6c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Sep 2020 09:48:42 +1000 Subject: [PATCH 2/3] Fixes for recurring scheduling --- app/Console/Commands/RecurringCommand.php | 53 +++++++++++++++++++++ app/Jobs/Cron/RecurringInvoicesCron.php | 22 +++++++-- app/Jobs/RecurringInvoice/SendRecurring.php | 11 ++++- 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 app/Console/Commands/RecurringCommand.php diff --git a/app/Console/Commands/RecurringCommand.php b/app/Console/Commands/RecurringCommand.php new file mode 100644 index 000000000000..df3e7caf5a20 --- /dev/null +++ b/app/Console/Commands/RecurringCommand.php @@ -0,0 +1,53 @@ +addMinutes(30))->cursor(); + $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now())->cursor(); - Log::info(Carbon::now()->addMinutes(30).' Sending Recurring Invoices. Count = '.$recurring_invoices->count()); + Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db); + + $recurring_invoices->each(function ($recurring_invoice, $key) { + + info("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date); - $recurring_invoices->each(function ($recurring_invoice, $key) { SendRecurring::dispatch($recurring_invoice, $recurring_invoice->company->db); + }); } else { //multiDB environment, need to foreach (MultiDB::$dbs as $db) { + MultiDB::setDB($db); - $recurring_invoices = RecurringInvoice::where('next_send_date', '<=', Carbon::now()->addMinutes(30))->cursor(); + $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now())->cursor(); - Log::info(Carbon::now()->addMinutes(30).' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db); + Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db); $recurring_invoices->each(function ($recurring_invoice, $key) { + + info("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date); + SendRecurring::dispatch($recurring_invoice, $recurring_invoice->company->db); + }); } } diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 850baef2a8ee..cb2d10f34a1c 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -54,15 +54,19 @@ class SendRecurring implements ShouldQueue */ public function handle() : void { + info(" in the handle "); // Generate Standard Invoice $invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client); + $invoice = $invoice->service() ->markSent() - ->applyRecurringNumber() + ->applyNumber() ->createInvitations() ->save(); + info("Invoice {$invoice->number} created"); + $invoice->invitations->each(function ($invitation) use ($invoice) { $email_builder = (new InvoiceEmail())->build($invitation); @@ -76,6 +80,7 @@ class SendRecurring implements ShouldQueue if($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled) $invoice->service()->autoBill()->save(); + info("updating recurring invoice dates"); /* Set next date here to prevent a recurring loop forming */ $this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate()->format('Y-m-d'); $this->recurring_invoice->remaining_cycles = $this->recurring_invoice->remainingCycles(); @@ -85,6 +90,10 @@ class SendRecurring implements ShouldQueue if ($this->recurring_invoice->remaining_cycles == 0) $this->recurring_invoice->setCompleted(); + info($this->recurring_invoice->next_send_date); + info($this->recurring_invoice->remaining_cycles); + info($this->recurring_invoice->last_sent_date); + $this->recurring_invoice->save(); if ($invoice->invitations->count() > 0) From c965e8d08bc5ff2479c40f2fb3f16349d9f303c6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 27 Sep 2020 19:22:34 +1000 Subject: [PATCH 3/3] Fixes for injecting settings object into email blade templates --- .../RecurringInvoice/StoreRecurringInvoiceRequest.php | 7 ++++++- app/Listeners/SendVerificationNotification.php | 2 +- app/Models/RecurringInvoice.php | 5 +++++ app/Notifications/Admin/EntitySentNotification.php | 1 + app/Notifications/Admin/EntityViewedNotification.php | 2 ++ app/Notifications/Admin/InvoiceSentNotification.php | 2 ++ app/Notifications/Admin/InvoiceViewedNotification.php | 2 ++ app/Notifications/Admin/NewPartialPaymentNotification.php | 1 + app/Notifications/Admin/NewPaymentNotification.php | 1 + app/Notifications/NewAccountCreated.php | 1 + app/Notifications/Ninja/NewAccountCreated.php | 1 + app/Notifications/Ninja/VerifyUser.php | 6 +++++- 12 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index e04a672c46d5..3e290847fed3 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -12,6 +12,7 @@ namespace App\Http\Requests\RecurringInvoice; use App\Http\Requests\Request; +use App\Models\Client; use App\Models\RecurringInvoice; use App\Utils\Traits\CleanLineItems; use App\Utils\Traits\MakesHash; @@ -98,7 +99,11 @@ class StoreRecurringInvoiceRequest extends Request if(isset($input['auto_bill'])) $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); - + else{ + $client = Client::find($this->decodePrimaryKey($input['client_id'])); + $input['auto_bill'] = $client->getSetting('auto_bill'); + } + $this->replace($input); } diff --git a/app/Listeners/SendVerificationNotification.php b/app/Listeners/SendVerificationNotification.php index b8205f7b7139..1ff54ed022b7 100644 --- a/app/Listeners/SendVerificationNotification.php +++ b/app/Listeners/SendVerificationNotification.php @@ -47,7 +47,7 @@ class SendVerificationNotification implements ShouldQueue MultiDB::setDB($event->company->db); try { - $event->user->notify(new VerifyUser($event->user)); + $event->user->notify(new VerifyUser($event->user, $event->company)); Ninja::registerNinjaUser($event->user); diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 0750e614f262..80ca04894b46 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -200,6 +200,11 @@ class RecurringInvoice extends BaseModel public function nextSendDate() :?Carbon { + if(!$this->next_send_date){ + return null; + // $this->next_send_date = now()->format('Y-m-d'); + } + switch ($this->frequency_id) { case self::FREQUENCY_WEEKLY: return Carbon::parse($this->next_send_date)->addWeek(); diff --git a/app/Notifications/Admin/EntitySentNotification.php b/app/Notifications/Admin/EntitySentNotification.php index dead3b4eae8f..eb649440434d 100644 --- a/app/Notifications/Admin/EntitySentNotification.php +++ b/app/Notifications/Admin/EntitySentNotification.php @@ -101,6 +101,7 @@ class EntitySentNotification extends Notification implements ShouldQueue 'button' => ctrans("texts.view_{$this->entity_name}"), 'signature' => $this->settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->settings, ]; return (new MailMessage) diff --git a/app/Notifications/Admin/EntityViewedNotification.php b/app/Notifications/Admin/EntityViewedNotification.php index d482d6d38989..13adb05d9201 100644 --- a/app/Notifications/Admin/EntityViewedNotification.php +++ b/app/Notifications/Admin/EntityViewedNotification.php @@ -146,6 +146,8 @@ class EntityViewedNotification extends Notification implements ShouldQueue 'button' => ctrans("texts.view_{$this->entity_name}"), 'signature' => $this->settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->settings, + ]; return $data; diff --git a/app/Notifications/Admin/InvoiceSentNotification.php b/app/Notifications/Admin/InvoiceSentNotification.php index 38c208f0a959..88cfe260768a 100644 --- a/app/Notifications/Admin/InvoiceSentNotification.php +++ b/app/Notifications/Admin/InvoiceSentNotification.php @@ -96,6 +96,8 @@ class InvoiceSentNotification extends Notification implements ShouldQueue 'button' => ctrans('texts.view_invoice'), 'signature' => $this->settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->settings, + ]; return (new MailMessage) diff --git a/app/Notifications/Admin/InvoiceViewedNotification.php b/app/Notifications/Admin/InvoiceViewedNotification.php index 9d468ea1d186..55e956ca441a 100644 --- a/app/Notifications/Admin/InvoiceViewedNotification.php +++ b/app/Notifications/Admin/InvoiceViewedNotification.php @@ -96,6 +96,8 @@ class InvoiceViewedNotification extends Notification implements ShouldQueue 'button' => ctrans('texts.view_invoice'), 'signature' => $this->settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->settings, + ]; return (new MailMessage) diff --git a/app/Notifications/Admin/NewPartialPaymentNotification.php b/app/Notifications/Admin/NewPartialPaymentNotification.php index acbaf9f402ef..55e0eef18189 100644 --- a/app/Notifications/Admin/NewPartialPaymentNotification.php +++ b/app/Notifications/Admin/NewPartialPaymentNotification.php @@ -94,6 +94,7 @@ class NewPartialPaymentNotification extends Notification implements ShouldQueue 'button' => ctrans('texts.view_payment'), 'signature' => $this->settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->settings, ]; return (new MailMessage) diff --git a/app/Notifications/Admin/NewPaymentNotification.php b/app/Notifications/Admin/NewPaymentNotification.php index d24267c1d519..5dab2f612e45 100644 --- a/app/Notifications/Admin/NewPaymentNotification.php +++ b/app/Notifications/Admin/NewPaymentNotification.php @@ -97,6 +97,7 @@ class NewPaymentNotification extends Notification implements ShouldQueue 'button' => ctrans('texts.view_payment'), 'signature' => $this->settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->settings, ]; return (new MailMessage) diff --git a/app/Notifications/NewAccountCreated.php b/app/Notifications/NewAccountCreated.php index f4d6ef5b4490..81f6230f20a3 100644 --- a/app/Notifications/NewAccountCreated.php +++ b/app/Notifications/NewAccountCreated.php @@ -73,6 +73,7 @@ class NewAccountCreated extends Notification implements ShouldQueue 'button' => ctrans('texts.account_login'), 'signature' => $this->company->settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->company->settings, ]; return (new MailMessage) diff --git a/app/Notifications/Ninja/NewAccountCreated.php b/app/Notifications/Ninja/NewAccountCreated.php index 580c0da32d98..13d586ec21d1 100644 --- a/app/Notifications/Ninja/NewAccountCreated.php +++ b/app/Notifications/Ninja/NewAccountCreated.php @@ -73,6 +73,7 @@ class NewAccountCreated extends Notification implements ShouldQueue 'button' => ctrans('texts.account_login'), 'signature' => $this->company->settings->email_signature, 'logo' => $this->company->present()->logo(), + 'settings' => $this->company->settings, ]; return (new MailMessage) diff --git a/app/Notifications/Ninja/VerifyUser.php b/app/Notifications/Ninja/VerifyUser.php index bef51b3e5009..74712d0697b5 100644 --- a/app/Notifications/Ninja/VerifyUser.php +++ b/app/Notifications/Ninja/VerifyUser.php @@ -32,9 +32,12 @@ class VerifyUser extends Notification implements ShouldQueue */ protected $user; - public function __construct($user) + private $company; + + public function __construct($user, $company) { $this->user = $user; + $this->company = $company; } /** @@ -63,6 +66,7 @@ class VerifyUser extends Notification implements ShouldQueue 'button' => ctrans('texts.button_confirmation_message'), 'signature' => '', 'logo' => 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png', + 'settings' => $this->company->settings, ]; return (new MailMessage)