diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index a3feeb040047..08a6e5c6923f 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -147,15 +147,22 @@ class InvoiceFilters extends QueryFilters public function upcoming(): Builder { return $this->builder->whereIn('status_id', [Invoice::STATUS_PARTIAL, Invoice::STATUS_SENT]) - ->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'); + ->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'); + } /**