From 5837d544eae91cddb8c0d82234505a2a47eeb26d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 21 Sep 2021 22:40:00 +1000 Subject: [PATCH 1/3] return early if no payments --- app/Services/PdfMaker/Design.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 8625585f0c31..069aaf6809be 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -428,7 +428,7 @@ class Design extends BaseDesign public function statementPaymentTableTotals(): array { - if (is_null($this->payments) && $this->type !== self::STATEMENT) { + if (!$this->payments->first() || $this->type !== self::STATEMENT) { return []; } From cdd6bee04605fb2270e965a9c6fe386e4f2dd2a2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 21 Sep 2021 22:45:28 +1000 Subject: [PATCH 2/3] Minor fixes --- app/Services/Client/Statement.php | 32 ++++++++++++++----------------- app/Services/PdfMaker/Design.php | 2 +- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index e18f9707618a..ea8f491e79dd 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -279,7 +279,7 @@ class Statement private function getAgingAmount($range) { $ranges = $this->calculateDateRanges($range); - +nlog($ranges); $from = $ranges[0]; $to = $ranges[1]; @@ -287,8 +287,10 @@ class Statement $amount = Invoice::where('company_id', $this->client->company->id) ->where('client_id', $client->id) + ->where('company_id', $this->client->company_id) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->where('balance', '>', 0) + ->where('is_deleted', 0) ->whereBetween('date', [$from, $to]) ->sum('balance'); @@ -307,35 +309,29 @@ class Statement switch ($range) { case '30': - $ranges[0] = now(); - $ranges[1] = now()->subDays(30); + $ranges[0] = now()->startOfDay(); + $ranges[1] = now()->startOfDay()->subDays(30); return $ranges; - break; case '60': - $ranges[0] = now()->subDays(30); - $ranges[1] = now()->subDays(60); + $ranges[0] = now()->startOfDay()->subDays(30); + $ranges[1] = now()->startOfDay()->subDays(60); return $ranges; - break; case '90': - $ranges[0] = now()->subDays(60); - $ranges[1] = now()->subDays(90); + $ranges[0] = now()->startOfDay()->subDays(60); + $ranges[1] = now()->startOfDay()->subDays(90); return $ranges; - break; case '120': - $ranges[0] = now()->subDays(90); - $ranges[1] = now()->subDays(120); + $ranges[0] = now()->startOfDay()->subDays(90); + $ranges[1] = now()->startOfDay()->subDays(120); return $ranges; - break; case '120+': - $ranges[0] = now()->subDays(120); - $ranges[1] = now()->subYears(40); + $ranges[0] = now()->startOfDay()->subDays(120); + $ranges[1] = now()->startOfDay()->subYears(40); return $ranges; - break; default: - $ranges[0] = now()->subDays(0); + $ranges[0] = now()->startOfDay()->subDays(0); $ranges[1] = now()->subDays(30); return $ranges; - break; } } diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 069aaf6809be..1ecab6b3ce22 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -428,7 +428,7 @@ class Design extends BaseDesign public function statementPaymentTableTotals(): array { - if (!$this->payments->first() || $this->type !== self::STATEMENT) { + if (is_null($this->payments) || !$this->payments->first() || $this->type !== self::STATEMENT) { return []; } From 6bcca461ef60546b5d464bcb74a648cf1f705e96 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 21 Sep 2021 22:50:44 +1000 Subject: [PATCH 3/3] Fixes for statements --- app/Services/Client/Statement.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index ea8f491e79dd..98cc4f798a99 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -279,10 +279,13 @@ class Statement private function getAgingAmount($range) { $ranges = $this->calculateDateRanges($range); -nlog($ranges); + $from = $ranges[0]; $to = $ranges[1]; +nlog("from ".$from->format("Y-m-d")); +nlog("to ".$to->format("Y-m-d")); + $client = Client::where('id', $this->client->id)->first(); $amount = Invoice::where('company_id', $this->client->company->id) @@ -291,7 +294,7 @@ nlog($ranges); ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->where('balance', '>', 0) ->where('is_deleted', 0) - ->whereBetween('date', [$from, $to]) + ->whereBetween('date', [$to, $from]) ->sum('balance'); return Number::formatMoney($amount, $client);