From 98706698d290c4868a66bfadf52d3c65588a969d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 15 Jun 2023 16:23:08 +1000 Subject: [PATCH 1/7] Localize payment dates --- app/Http/Requests/Payment/StorePaymentRequest.php | 2 +- app/PaymentDrivers/BaseDriver.php | 2 +- app/Services/Credit/CreditService.php | 2 +- app/Services/Invoice/AutoBillInvoice.php | 2 +- app/Services/Invoice/MarkPaid.php | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 196c302e57a7..9fd353d39323 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -88,7 +88,7 @@ class StorePaymentRequest extends Request // $input['is_manual'] = true; if (! isset($input['date'])) { - $input['date'] = now()->format('Y-m-d'); + $input['date'] = now()->addSeconds(auth()->user()->company->timezone()->utc_offset)->format('Y-m-d'); } $this->replace($input); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index fcc36d4b698a..4bad13f054a3 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -320,7 +320,7 @@ class BaseDriver extends AbstractPaymentDriver $payment->company_gateway_id = $this->company_gateway->id; $payment->status_id = $status; $payment->currency_id = $this->client->getSetting('currency_id'); - $payment->date = Carbon::now(); + $payment->date = Carbon::now()->addSeconds($this->client->company->timezone()->utc_offset)->format('Y-m-d'); $payment->gateway_type_id = $data['gateway_type_id']; $client_contact = $this->getContact(); diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 4adc71cd290c..26c9228e3804 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -119,7 +119,7 @@ class CreditService $payment->type_id = PaymentType::CREDIT; $payment->is_manual = true; $payment->currency_id = $this->credit->client->getSetting('currency_id'); - $payment->date = now(); + $payment->date = now()->addSeconds($this->credit->company->timezone()->utc_offset)->format('Y-m-d'); $payment->saveQuietly(); $payment->number = $payment->client->getNextPaymentNumber($payment->client, $payment); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index de76290a75e0..d67b4fa8607f 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -179,7 +179,7 @@ class AutoBillInvoice extends AbstractService $payment->applied = $amount; $payment->client_id = $this->invoice->client_id; $payment->currency_id = $this->invoice->client->getSetting('currency_id'); - $payment->date = now(); + $payment->date = now()->addSeconds($this->invoice->company->timezone()->utc_offset)->format('Y-m-d'); $payment->status_id = Payment::STATUS_COMPLETED; $payment->type_id = PaymentType::CREDIT; $payment->service()->applyNumber()->save(); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index a056da4b6038..333c84eb1524 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -71,6 +71,7 @@ class MarkPaid extends AbstractService $payment->is_manual = true; if ($this->invoice->company->timezone()) { + nlog($this->invoice->company->timezone()->utc_offset); $payment->date = now()->addSeconds($this->invoice->company->timezone()->utc_offset)->format('Y-m-d'); } From e54525658b7321c969ac7498935c5095c9cca390 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 15 Jun 2023 16:29:40 +1000 Subject: [PATCH 2/7] Minor fixes for timezone --- app/Http/Requests/Payment/StorePaymentRequest.php | 2 +- app/Services/Invoice/MarkPaid.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 9fd353d39323..b178717caa1e 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -88,7 +88,7 @@ class StorePaymentRequest extends Request // $input['is_manual'] = true; if (! isset($input['date'])) { - $input['date'] = now()->addSeconds(auth()->user()->company->timezone()->utc_offset)->format('Y-m-d'); + $input['date'] = now()->addSeconds(auth()->user()->company()->timezone()->utc_offset)->format('Y-m-d'); } $this->replace($input); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 333c84eb1524..a056da4b6038 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -71,7 +71,6 @@ class MarkPaid extends AbstractService $payment->is_manual = true; if ($this->invoice->company->timezone()) { - nlog($this->invoice->company->timezone()->utc_offset); $payment->date = now()->addSeconds($this->invoice->company->timezone()->utc_offset)->format('Y-m-d'); } From 06edbe3f0679739a0216df3cc512c108cd919b36 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 16 Jun 2023 14:44:43 +1000 Subject: [PATCH 3/7] Revert for query --- app/Services/Scheduler/EmailStatementService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/Scheduler/EmailStatementService.php b/app/Services/Scheduler/EmailStatementService.php index 3ce5d5f7f7bf..e795f83b1b32 100644 --- a/app/Services/Scheduler/EmailStatementService.php +++ b/app/Services/Scheduler/EmailStatementService.php @@ -95,7 +95,7 @@ class EmailStatementService EmailStatement::THIS_YEAR => [now()->startOfDay()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->lastOfYear()->format('Y-m-d')], EmailStatement::LAST_YEAR => [now()->startOfDay()->subYearNoOverflow()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->subYearNoOverflow()->lastOfYear()->format('Y-m-d')], EmailStatement::ALL_TIME => [ - Invoice::withTrashed()->where('client_id', $client->id)->selectRaw('MIN(invoices.date) as start_date')->pluck('start_date')->first() + $client->invoices()->selectRaw('MIN(invoices.date) as start_date')->pluck('start_date')->first() ?: Carbon::now()->format('Y-m-d'), Carbon::now()->format('Y-m-d') ], From 89d68c5d460807fac97324673fd6fa100ba19827 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 16 Jun 2023 15:23:59 +1000 Subject: [PATCH 4/7] Minor fixes --- app/Services/Scheduler/EmailStatementService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Services/Scheduler/EmailStatementService.php b/app/Services/Scheduler/EmailStatementService.php index e795f83b1b32..c701913f5cc2 100644 --- a/app/Services/Scheduler/EmailStatementService.php +++ b/app/Services/Scheduler/EmailStatementService.php @@ -11,11 +11,11 @@ namespace App\Services\Scheduler; +use App\DataMapper\Schedule\EmailStatement; use App\Models\Client; use App\Models\Scheduler; -use App\Utils\Traits\MakesHash; -use App\DataMapper\Schedule\EmailStatement; use App\Utils\Traits\MakesDates; +use App\Utils\Traits\MakesHash; use Carbon\Carbon; class EmailStatementService @@ -38,7 +38,7 @@ class EmailStatementService //Email only the selected clients if (count($this->scheduler->parameters['clients']) >= 1) { $query->whereIn('id', $this->transformKeys($this->scheduler->parameters['clients'])); - }else { + } else { $query->where('balance', '>', 0); } From 1dda57c1fd698c336b61305d0a6367e67d4bc6f0 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 16 Jun 2023 16:12:37 +1000 Subject: [PATCH 5/7] Fixes for tests --- tests/Feature/Scheduler/SchedulerTest.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/Feature/Scheduler/SchedulerTest.php b/tests/Feature/Scheduler/SchedulerTest.php index c4f58e235ff5..6cafea26ef54 100644 --- a/tests/Feature/Scheduler/SchedulerTest.php +++ b/tests/Feature/Scheduler/SchedulerTest.php @@ -40,6 +40,8 @@ class SchedulerTest extends TestCase use WithoutEvents; use DatabaseTransactions; + protected $faker; + protected function setUp(): void { parent::setUp(); @@ -594,12 +596,6 @@ class SchedulerTest extends TestCase $scheduler->save(); $scheduler->calculateNextRun(); - // $service_object = new SchedulerService($scheduler); - - // $reflectionMethod = new \ReflectionMethod(SchedulerService::class, 'calculateNextRun'); - // $reflectionMethod->setAccessible(true); - // $method = $reflectionMethod->invoke(new SchedulerService($scheduler)); - $scheduler->fresh(); $offset = $this->company->timezone_offset(); @@ -634,7 +630,7 @@ class SchedulerTest extends TestCase $reflectionMethod = new \ReflectionMethod(EmailStatementService::class, 'calculateStartAndEndDates'); $reflectionMethod->setAccessible(true); - $method = $reflectionMethod->invoke(new EmailStatementService($scheduler)); + $method = $reflectionMethod->invoke(new EmailStatementService($scheduler), $this->client); $this->assertIsArray($method); @@ -668,7 +664,7 @@ class SchedulerTest extends TestCase $reflectionMethod = new \ReflectionMethod(EmailStatementService::class, 'calculateStatementProperties'); $reflectionMethod->setAccessible(true); - $method = $reflectionMethod->invoke(new EmailStatementService($scheduler)); // 'baz' + $method = $reflectionMethod->invoke(new EmailStatementService($scheduler), $this->client); $this->assertIsArray($method); From af502e9757b9c91c57d26f06d9c3119c6f7b23f9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 17 Jun 2023 12:13:41 +1000 Subject: [PATCH 6/7] Add notifications for send emails for recurring --- app/Jobs/Cron/AutoBill.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Jobs/Cron/AutoBill.php b/app/Jobs/Cron/AutoBill.php index 824f9463f29a..5376571d7ced 100644 --- a/app/Jobs/Cron/AutoBill.php +++ b/app/Jobs/Cron/AutoBill.php @@ -67,6 +67,9 @@ class AutoBill implements ShouldQueue if ($invitation->contact && ! $invitation->contact->trashed() && strlen($invitation->contact->email) >= 1 && $invoice->client->getSetting('auto_email_invoice')) { try { EmailEntity::dispatch($invitation, $invoice->company)->delay(rand(1, 2)); + + $invoice->entityEmailEvent($invitation, 'invoice', 'email_template_invoice'); + } catch (\Exception $e) { nlog($e->getMessage()); } From 3ef7f06421cbef0322ab94518d64dea48d5c699c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 17 Jun 2023 14:42:10 +1000 Subject: [PATCH 7/7] v5.6.3 --- VERSION.txt | 2 +- app/Utils/Traits/Inviteable.php | 2 +- config/ninja.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 475e18429482..25c1b355a168 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.6.2 \ No newline at end of file +5.6.3 \ No newline at end of file diff --git a/app/Utils/Traits/Inviteable.php b/app/Utils/Traits/Inviteable.php index 530c3f92c229..98584eed484a 100644 --- a/app/Utils/Traits/Inviteable.php +++ b/app/Utils/Traits/Inviteable.php @@ -69,7 +69,7 @@ trait Inviteable $qr = $writer->writeString($this->getPaymentLink(), 'utf-8'); return " - {$qr}"; + {$qr}"; } public function getUnsubscribeLink() diff --git a/config/ninja.php b/config/ninja.php index 75f811bc12a6..77cf14b0d32d 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -15,8 +15,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.6.2', - 'app_tag' => '5.6.2', + 'app_version' => '5.6.3', + 'app_tag' => '5.6.3', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),