From 56fe16e5a8bbff1c533555898c06b5ef0bd01183 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 9 Dec 2023 11:27:24 +1100 Subject: [PATCH] Improvements for upcoming filters --- app/Filters/InvoiceFilters.php | 40 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index f0ef5257bf..df04af1d07 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -146,22 +146,25 @@ class InvoiceFilters extends QueryFilters */ public function upcoming(): Builder { - return $this->builder->whereIn('status_id', [Invoice::STATUS_PARTIAL, Invoice::STATUS_SENT]) - ->where('is_deleted', 0) - ->where('balance', '>', 0) - ->where(function ($query) { - - $query->whereNull('due_date') - ->orWhere(function ($q) { - $q->where('due_date', '>=', now()->startOfDay()->subSecond())->where('partial', 0)->company(); - }) - ->orWhere(function ($q) { - $q->where('partial_due_date', '>=', now()->startOfDay()->subSecond())->where('partial', '>', 0)->company(); - }); - }) - ->orderByRaw('ISNULL(due_date), due_date '. 'desc') - ->orderByRaw('ISNULL(partial_due_date), partial_due_date '. 'desc'); + return $this->builder->where(function ($query) { + $query->whereIn('status_id', [Invoice::STATUS_PARTIAL, Invoice::STATUS_SENT]) + ->where('is_deleted', 0) + ->where('balance', '>', 0) + ->where(function ($query) { + + $query->whereNull('due_date') + ->orWhere(function ($q) { + $q->where('due_date', '>=', now()->startOfDay()->subSecond())->where('partial', 0); + }) + ->orWhere(function ($q) { + $q->where('partial_due_date', '>=', now()->startOfDay()->subSecond())->where('partial', '>', 0); + }); + + }) + ->orderByRaw('ISNULL(due_date), due_date ' . 'desc') + ->orderByRaw('ISNULL(partial_due_date), partial_due_date ' . 'desc'); + }); } @@ -172,13 +175,18 @@ class InvoiceFilters extends QueryFilters */ public function overdue(): Builder { - return $this->builder->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) + return $this->builder->where(function ($query) { + + $query->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->where('is_deleted', 0) + ->where('balance', '>', 0) ->where(function ($query) { $query->where('due_date', '<', now()) ->orWhere('partial_due_date', '<', now()); }) ->orderBy('due_date', 'ASC'); + }); + } /**