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

Merge pull request #8227 from paulwer/v5-develop

adding additional filter methods
This commit is contained in:
David Bomba 2023-01-31 08:17:38 +11:00 committed by GitHub
commit 2dcdd4d72c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 312 additions and 96 deletions

View File

@ -26,12 +26,13 @@ class BankIntegrationFilters extends QueryFilters
*/
public function name(string $name = ''): Builder
{
if(strlen($name) >=1)
return $this->builder->where('bank_account_name', 'like', '%'.$name.'%');
if (strlen($name) == 0) {
return $this->builder;
}
return $this->builder->where('bank_account_name', 'like', '%'.$name.'%');
}
/**
* Filter based on search text.
*
@ -90,10 +91,14 @@ class BankIntegrationFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -27,12 +27,13 @@ class BankTransactionFilters extends QueryFilters
*/
public function name(string $name = ''): Builder
{
if(strlen($name) >=1)
return $this->builder->where('bank_account_name', 'like', '%'.$name.'%');
if (strlen($name) == 0) {
return $this->builder;
}
return $this->builder->where('bank_account_name', 'like', '%'.$name.'%');
}
/**
* Filter based on search text.
*
@ -123,12 +124,13 @@ class BankTransactionFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort) : Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if(!is_array($sort_col))
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
if($sort_col[0] == 'deposit')
return $this->builder->where('base_type', 'CREDIT')->orderBy('amount', $sort_col[1]);

View File

@ -30,12 +30,13 @@ class BankTransactionRuleFilters extends QueryFilters
*/
public function name(string $name = ''): Builder
{
if(strlen($name) >=1)
return $this->builder->where('name', 'like', '%'.$name.'%');
if (strlen($name) == 0) {
return $this->builder;
}
return $this->builder->where('name', 'like', '%'.$name.'%');
}
/**
* Filter based on search text.
*
@ -61,10 +62,14 @@ class BankTransactionRuleFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort) : Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -30,20 +30,25 @@ class ClientFilters extends QueryFilters
*/
public function name(string $name = ''): Builder
{
if(strlen($name) >=1)
return $this->builder->where('name', 'like', '%'.$name.'%');
if (strlen($name) == 0) {
return $this->builder;
}
return $this->builder->where('name', 'like', '%'.$name.'%');
}
/**
* Filter by balance.
*
* @param string $balance
* @return Builder
*/
public function balance(string $balance): Builder
public function balance(string $balance = ''): Builder
{
if (strlen($balance) == 0) {
return $this->builder;
}
$parts = $this->split($balance);
return $this->builder->where('balance', $parts->operator, $parts->value);
@ -55,11 +60,11 @@ class ClientFilters extends QueryFilters
* @param string balance
* @return Builder
*/
public function between_balance(string $balance): Builder
public function between_balance(string $balance = ''): Builder
{
$parts = explode(':', $balance);
if (! is_array($parts)) {
if (!is_array($parts) || count($parts) != 2) {
return $this->builder;
}
@ -68,9 +73,11 @@ class ClientFilters extends QueryFilters
public function email(string $email = ''): Builder
{
return
if (strlen($email) == 0) {
return $this->builder;
}
$this->builder->whereHas('contacts', function ($query) use ($email) {
return $this->builder->whereHas('contacts', function ($query) use ($email) {
$query->where('email', $email);
});
}
@ -86,11 +93,19 @@ class ClientFilters extends QueryFilters
public function id_number(string $id_number = ''): Builder
{
if (strlen($id_number) == 0) {
return $this->builder;
}
return $this->builder->where('id_number', $id_number);
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
@ -128,10 +143,14 @@ class ClientFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort) : Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
if($sort_col[0] == 'display_name')
$sort_col[0] = 'name';

View File

@ -43,10 +43,14 @@ class CompanyGatewayFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort) : Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -85,16 +85,29 @@ class CreditFilters extends QueryFilters
});
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort) : Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -44,16 +44,17 @@ class DesignFilters extends QueryFilters
*
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if(is_array($sort_col))
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}
/**
* Filters the query by the users company ID.
*

View File

@ -58,12 +58,13 @@ class DocumentFilters extends QueryFilters
{
$sort_col = explode('|', $sort);
if(is_array($sort_col))
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}
public function company_documents($value = 'false')
{

View File

@ -41,10 +41,14 @@ class ExpenseCategoryFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort) : Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['name']))
return $this->builder->orderBy($sort_col[0], $sort_col[1]);

View File

@ -132,16 +132,29 @@ class ExpenseFilters extends QueryFilters
return $this->builder;
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort) : Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
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]);
}

View File

@ -179,8 +179,7 @@ class InvoiceFilters extends QueryFilters
{
$sort_col = explode('|', $sort);
//catch invalid explode array count
if (count($sort_col) == 1) {
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}

View File

@ -62,25 +62,30 @@ class PaymentFilters extends QueryFilters
return $this->builder;
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if(is_array($sort_col))
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
return true;
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
public function number(string $number = ''): Builder
{
return $this->builder->where('number', $number);
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}
/**

View File

@ -42,10 +42,14 @@ class PaymentTermFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -58,12 +58,13 @@ class ProductFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if(!is_array($sort_col))
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -38,16 +38,29 @@ class ProjectFilters extends QueryFilters
});
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Illuminate\Eloquent\Query\Builder
*/
public function sort(string $sort) :Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
if(is_array($sort_col))
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -100,16 +100,29 @@ class PurchaseOrderFilters extends QueryFilters
});
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -113,7 +113,11 @@ class QuoteFilters extends QueryFilters
public function number($number = ''): Builder
{
return $this->builder->where('number', 'like', '%'.$number.'%');
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
@ -122,10 +126,14 @@ class QuoteFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
if($sort_col[0] == 'valid_until')
$sort_col[0] = 'due_date';

View File

@ -40,16 +40,29 @@ class RecurringExpenseFilters extends QueryFilters
});
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -83,16 +83,29 @@ class RecurringInvoiceFilters extends QueryFilters
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -39,16 +39,29 @@ class RecurringQuoteFilters extends QueryFilters
});
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Eloquent\Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -42,10 +42,14 @@ class SubscriptionFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -18,18 +18,30 @@ use Illuminate\Database\Eloquent\Builder;
*/
class SystemLogFilters extends QueryFilters
{
public function type_id(int $type_id) :Builder
public function type_id(string $type_id = ''): Builder
{
if (strlen($type_id) == 0) {
return $this->builder;
}
return $this->builder->where('type_id', $type_id);
}
public function category_id(int $category_id) :Builder
public function category_id(string $category_id = ''): Builder
{
if (strlen($category_id) == 0) {
return $this->builder;
}
return $this->builder->where('category_id', $category_id);
}
public function event_id(int $event_id) :Builder
public function event_id(string $event_id = ''): Builder
{
if (strlen($event_id) == 0) {
return $this->builder;
}
return $this->builder->where('event_id', $event_id);
}
@ -55,10 +67,14 @@ class SystemLogFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort) : Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -82,16 +82,29 @@ class TaskFilters extends QueryFilters
return $this->builder->where('project_id', $this->decodePrimaryKey($project));
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -42,10 +42,14 @@ class TaskStatusFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -42,10 +42,14 @@ class TaxRateFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -42,10 +42,14 @@ class TokenFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -46,10 +46,14 @@ class UserFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}
@ -76,8 +80,9 @@ class UserFilters extends QueryFilters
public function with(string $value = ''): Builder
{
if(strlen($value) == 0)
if(strlen($value) == 0) {
return $this->builder;
}
return $this->builder
->orWhere($this->with_property, $value)

View File

@ -46,16 +46,29 @@ class VendorFilters extends QueryFilters
});
}
public function number(string $number = ''): Builder
{
if (strlen($number) == 0) {
return $this->builder;
}
return $this->builder->where('number', $number);
}
/**
* Sorts the list based on $sort.
*
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}

View File

@ -42,10 +42,14 @@ class WebhookFilters extends QueryFilters
* @param string sort formatted as column|asc
* @return Builder
*/
public function sort(string $sort): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);
if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}