1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Improvements for upcoming filters

This commit is contained in:
David Bomba 2023-12-09 11:27:24 +11:00
parent 1f2d608742
commit 56fe16e5a8

View File

@ -146,22 +146,25 @@ class InvoiceFilters extends QueryFilters
*/ */
public function upcoming(): Builder 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') return $this->builder->where(function ($query) {
->orWhere(function ($q) { $query->whereIn('status_id', [Invoice::STATUS_PARTIAL, Invoice::STATUS_SENT])
$q->where('due_date', '>=', now()->startOfDay()->subSecond())->where('partial', 0)->company(); ->where('is_deleted', 0)
}) ->where('balance', '>', 0)
->orWhere(function ($q) { ->where(function ($query) {
$q->where('partial_due_date', '>=', now()->startOfDay()->subSecond())->where('partial', '>', 0)->company();
});
}) $query->whereNull('due_date')
->orderByRaw('ISNULL(due_date), due_date '. 'desc') ->orWhere(function ($q) {
->orderByRaw('ISNULL(partial_due_date), partial_due_date '. 'desc'); $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 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('is_deleted', 0)
->where('balance', '>', 0)
->where(function ($query) { ->where(function ($query) {
$query->where('due_date', '<', now()) $query->where('due_date', '<', now())
->orWhere('partial_due_date', '<', now()); ->orWhere('partial_due_date', '<', now());
}) })
->orderBy('due_date', 'ASC'); ->orderBy('due_date', 'ASC');
});
} }
/** /**