2019-05-03 08:33:32 +10:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2023-01-29 09:21:40 +11:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 13:32:07 +10:00
|
|
|
*/
|
2019-05-03 08:33:32 +10:00
|
|
|
|
|
|
|
|
namespace App\Filters;
|
|
|
|
|
|
2022-11-19 10:20:25 +11:00
|
|
|
use App\Models\RecurringInvoice;
|
2019-05-03 08:33:32 +10:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
|
|
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* RecurringInvoiceFilters.
|
2019-05-03 08:33:32 +10:00
|
|
|
*/
|
|
|
|
|
class RecurringInvoiceFilters extends QueryFilters
|
|
|
|
|
{
|
|
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Filter based on search text.
|
2019-12-31 08:59:12 +11:00
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @param string query filter
|
|
|
|
|
* @return Builder
|
2019-05-03 08:33:32 +10:00
|
|
|
* @deprecated
|
|
|
|
|
*/
|
2023-01-22 19:24:35 +11:00
|
|
|
public function filter(string $filter = ''): Builder
|
2019-05-03 08:33:32 +10:00
|
|
|
{
|
2019-12-31 08:59:12 +11:00
|
|
|
if (strlen($filter) == 0) {
|
2019-05-03 08:33:32 +10:00
|
|
|
return $this->builder;
|
2019-12-31 08:59:12 +11:00
|
|
|
}
|
2019-05-03 08:33:32 +10:00
|
|
|
|
|
|
|
|
return $this->builder->where(function ($query) use ($filter) {
|
2019-12-31 08:59:12 +11:00
|
|
|
$query->where('recurring_invoices.custom_value1', 'like', '%'.$filter.'%')
|
|
|
|
|
->orWhere('recurring_invoices.custom_value2', 'like', '%'.$filter.'%')
|
|
|
|
|
->orWhere('recurring_invoices.custom_value3', 'like', '%'.$filter.'%')
|
|
|
|
|
->orWhere('recurring_invoices.custom_value4', 'like', '%'.$filter.'%');
|
|
|
|
|
});
|
2019-05-03 08:33:32 +10:00
|
|
|
}
|
|
|
|
|
|
2022-11-19 10:20:25 +11:00
|
|
|
/**
|
|
|
|
|
* Filter based on client status.
|
|
|
|
|
*
|
|
|
|
|
* Statuses we need to handle
|
|
|
|
|
* - all
|
|
|
|
|
* - active
|
|
|
|
|
* - paused
|
|
|
|
|
* - completed
|
|
|
|
|
*
|
|
|
|
|
* @param string client_status The invoice status as seen by the client
|
|
|
|
|
* @return Builder
|
|
|
|
|
*/
|
2023-01-22 19:24:35 +11:00
|
|
|
public function client_status(string $value = ''): Builder
|
2022-11-19 10:20:25 +11:00
|
|
|
{
|
|
|
|
|
if (strlen($value) == 0) {
|
|
|
|
|
return $this->builder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$status_parameters = explode(',', $value);
|
|
|
|
|
|
|
|
|
|
if (in_array('all', $status_parameters)) {
|
|
|
|
|
return $this->builder;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 11:46:41 +11:00
|
|
|
$recurring_filters = [];
|
2022-11-19 10:20:25 +11:00
|
|
|
|
2023-02-16 12:36:09 +11:00
|
|
|
if (in_array('active', $status_parameters)) {
|
2023-01-16 11:46:41 +11:00
|
|
|
$recurring_filters[] = RecurringInvoice::STATUS_ACTIVE;
|
2023-02-16 12:36:09 +11:00
|
|
|
}
|
2022-11-19 10:20:25 +11:00
|
|
|
|
|
|
|
|
|
2023-02-16 12:36:09 +11:00
|
|
|
if (in_array('paused', $status_parameters)) {
|
2023-01-16 11:46:41 +11:00
|
|
|
$recurring_filters[] = RecurringInvoice::STATUS_PAUSED;
|
2023-02-16 12:36:09 +11:00
|
|
|
}
|
2022-11-19 10:20:25 +11:00
|
|
|
|
2023-02-16 12:36:09 +11:00
|
|
|
if (in_array('completed', $status_parameters)) {
|
2023-01-16 11:46:41 +11:00
|
|
|
$recurring_filters[] = RecurringInvoice::STATUS_COMPLETED;
|
2023-02-16 12:36:09 +11:00
|
|
|
}
|
2019-05-03 08:33:32 +10:00
|
|
|
|
2023-02-16 12:36:09 +11:00
|
|
|
if (count($recurring_filters) >= 1) {
|
2023-01-19 11:52:07 +11:00
|
|
|
return $this->builder->whereIn('status_id', $recurring_filters);
|
2023-02-16 12:36:09 +11:00
|
|
|
}
|
2019-05-03 08:33:32 +10:00
|
|
|
|
2023-01-19 11:52:07 +11:00
|
|
|
return $this->builder;
|
2019-05-03 08:33:32 +10:00
|
|
|
}
|
|
|
|
|
|
2023-01-30 07:08:26 +01:00
|
|
|
public function number(string $number = ''): Builder
|
2023-01-29 09:52:40 +01:00
|
|
|
{
|
2023-01-30 10:36:13 +01:00
|
|
|
if (strlen($number) == 0) {
|
|
|
|
|
return $this->builder;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-29 09:52:40 +01:00
|
|
|
return $this->builder->where('number', $number);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 08:33:32 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Sorts the list based on $sort.
|
2019-12-31 08:59:12 +11:00
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @param string sort formatted as column|asc
|
|
|
|
|
* @return Builder
|
2019-05-03 08:33:32 +10:00
|
|
|
*/
|
2023-01-30 12:08:39 +01:00
|
|
|
public function sort(string $sort = ''): Builder
|
2019-05-03 08:33:32 +10:00
|
|
|
{
|
2020-09-06 19:38:10 +10:00
|
|
|
$sort_col = explode('|', $sort);
|
|
|
|
|
|
2023-01-30 11:04:55 +01:00
|
|
|
if (!is_array($sort_col) || count($sort_col) != 2) {
|
|
|
|
|
return $this->builder;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 08:33:32 +10:00
|
|
|
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Filters the query by the users company ID.
|
2019-12-31 08:59:12 +11:00
|
|
|
*
|
2023-01-22 19:24:35 +11:00
|
|
|
* @return Illuminate\Eloquent\Builder
|
2019-05-03 08:33:32 +10:00
|
|
|
*/
|
2019-12-31 08:59:12 +11:00
|
|
|
public function entityFilter()
|
2019-05-03 08:33:32 +10:00
|
|
|
{
|
2019-12-31 08:59:12 +11:00
|
|
|
return $this->builder->company();
|
2019-05-03 08:33:32 +10:00
|
|
|
}
|
2019-12-31 08:59:12 +11:00
|
|
|
}
|