mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add cast ABS when sorting lists by number
This commit is contained in:
parent
2a33bb31e2
commit
169c1074f2
@ -165,6 +165,11 @@ class ClientFilters extends QueryFilters
|
|||||||
|
|
||||||
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
|
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number')
|
||||||
|
{
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->builder->orderBy($sort_col[0], $dir);
|
return $this->builder->orderBy($sort_col[0], $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,6 +146,11 @@ class CreditFilters extends QueryFilters
|
|||||||
->whereColumn('clients.id', 'credits.client_id'), $dir);
|
->whereColumn('clients.id', 'credits.client_id'), $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->builder->orderBy($sort_col[0], $dir);
|
return $this->builder->orderBy($sort_col[0], $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +172,8 @@ class ExpenseFilters extends QueryFilters
|
|||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
|
||||||
|
|
||||||
if ($sort_col[0] == 'client_id' && in_array($sort_col[1], ['asc', 'desc'])) {
|
if ($sort_col[0] == 'client_id' && in_array($sort_col[1], ['asc', 'desc'])) {
|
||||||
return $this->builder
|
return $this->builder
|
||||||
->orderByRaw('ISNULL(client_id), client_id '. $sort_col[1])
|
->orderByRaw('ISNULL(client_id), client_id '. $sort_col[1])
|
||||||
@ -194,6 +196,10 @@ class ExpenseFilters extends QueryFilters
|
|||||||
->whereColumn('expense_categories.id', 'expenses.category_id'), $sort_col[1]);
|
->whereColumn('expense_categories.id', 'expenses.category_id'), $sort_col[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['public_notes', 'date', 'id_number', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4'])) {
|
if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['public_notes', 'date', 'id_number', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4'])) {
|
||||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||||
}
|
}
|
||||||
|
@ -318,11 +318,16 @@ class InvoiceFilters extends QueryFilters
|
|||||||
|
|
||||||
if ($sort_col[0] == 'client_id') {
|
if ($sort_col[0] == 'client_id') {
|
||||||
|
|
||||||
return $this->builder->orderBy(\App\Models\Client::select('name')
|
return $this->builder->orderBy(\App\Models\Client::select ('name')
|
||||||
->whereColumn('clients.id', 'invoices.client_id'), $dir);
|
->whereColumn('clients.id', 'invoices.client_id'), $dir);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number')
|
||||||
|
{
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->builder->orderBy($sort_col[0], $dir);
|
return $this->builder->orderBy($sort_col[0], $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,14 +167,18 @@ class PaymentFilters extends QueryFilters
|
|||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
|
||||||
|
|
||||||
if ($sort_col[0] == 'client_id') {
|
if ($sort_col[0] == 'client_id') {
|
||||||
return $this->builder->orderBy(\App\Models\Client::select('name')
|
return $this->builder->orderBy(\App\Models\Client::select('name')
|
||||||
->whereColumn('clients.id', 'payments.client_id'), $sort_col[1]);
|
->whereColumn('clients.id', 'payments.client_id'), $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
return $this->builder->orderBy($sort_col[0], $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function date_range(string $date_range = ''): Builder
|
public function date_range(string $date_range = ''): Builder
|
||||||
|
@ -59,21 +59,24 @@ class ProjectFilters extends QueryFilters
|
|||||||
public function sort(string $sort = ''): Builder
|
public function sort(string $sort = ''): Builder
|
||||||
{
|
{
|
||||||
$sort_col = explode('|', $sort);
|
$sort_col = explode('|', $sort);
|
||||||
|
|
||||||
if ($sort_col[0] == 'client_id') {
|
|
||||||
return $this->builder->orderBy(\App\Models\Client::select('name')
|
|
||||||
->whereColumn('clients.id', 'projects.client_id'), $sort_col[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_array($sort_col) || count($sort_col) != 2) {
|
if (!is_array($sort_col) || count($sort_col) != 2) {
|
||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($sort_col) && in_array($sort_col[1], ['asc','desc'])) {
|
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
|
||||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
|
||||||
|
if ($sort_col[0] == 'client_id') {
|
||||||
|
return $this->builder->orderBy(\App\Models\Client::select('name')
|
||||||
|
->whereColumn('clients.id', 'projects.client_id'), $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->builder;
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->builder->orderBy($sort_col[0], $dir);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,6 +130,10 @@ class PurchaseOrderFilters extends QueryFilters
|
|||||||
->whereColumn('vendors.id', 'purchase_orders.vendor_id'), $dir);
|
->whereColumn('vendors.id', 'purchase_orders.vendor_id'), $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->builder->orderBy($sort_col[0], $dir);
|
return $this->builder->orderBy($sort_col[0], $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +155,10 @@ class QuoteFilters extends QueryFilters
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
if ($sort_col[0] == 'valid_until') {
|
if ($sort_col[0] == 'valid_until') {
|
||||||
$sort_col[0] = 'due_date';
|
$sort_col[0] = 'due_date';
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,8 @@ class RecurringExpenseFilters extends QueryFilters
|
|||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
|
||||||
|
|
||||||
if ($sort_col[0] == 'client_id' && in_array($sort_col[1], ['asc', 'desc'])) {
|
if ($sort_col[0] == 'client_id' && in_array($sort_col[1], ['asc', 'desc'])) {
|
||||||
return $this->builder
|
return $this->builder
|
||||||
->orderByRaw('ISNULL(client_id), client_id '. $sort_col[1])
|
->orderByRaw('ISNULL(client_id), client_id '. $sort_col[1])
|
||||||
@ -162,6 +164,10 @@ class RecurringExpenseFilters extends QueryFilters
|
|||||||
->whereColumn('expense_categories.id', 'expenses.category_id'), $sort_col[1]);
|
->whereColumn('expense_categories.id', 'expenses.category_id'), $sort_col[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['public_notes', 'date', 'id_number', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4'])) {
|
if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['public_notes', 'date', 'id_number', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4'])) {
|
||||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,10 @@ class TaskFilters extends QueryFilters
|
|||||||
->whereColumn('users.id', 'tasks.user_id'), $dir);
|
->whereColumn('users.id', 'tasks.user_id'), $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->builder->orderBy($sort_col[0], $dir);
|
return $this->builder->orderBy($sort_col[0], $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,10 @@ class VendorFilters extends QueryFilters
|
|||||||
|
|
||||||
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
|
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
|
||||||
|
|
||||||
|
if($sort_col[0] == 'number') {
|
||||||
|
return $this->builder->orderByRaw('ABS(number) ' . $dir);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->builder->orderBy($sort_col[0], $dir);
|
return $this->builder->orderBy($sort_col[0], $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user