invoiceninja/app/Filters/PaymentFilters.php

113 lines
3 KiB
PHP
Raw Normal View History

2019-05-03 17:57:55 +10:00
<?php
2019-05-11 13:32:07 +10:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 13:32:07 +10:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 13:20:41 +10:00
* @copyright Copyright (c) 2022. 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 17:57:55 +10:00
namespace App\Filters;
use Illuminate\Database\Eloquent\Builder;
/**
* PaymentFilters.
2019-05-03 17:57:55 +10:00
*/
class PaymentFilters extends QueryFilters
{
/**
* Filter based on search text.
*
2020-10-28 21:10:49 +11:00
* @param string query filter
* @return Builder
2019-05-03 17:57:55 +10:00
* @deprecated
*/
2023-01-22 19:24:35 +11:00
public function filter(string $filter = ''): Builder
2019-09-11 13:46:23 +10:00
{
if (strlen($filter) == 0) {
2019-05-03 17:57:55 +10:00
return $this->builder;
}
2019-05-03 17:57:55 +10:00
return $this->builder->where(function ($query) use ($filter) {
2023-01-22 19:24:35 +11:00
$query->where('amount', 'like', '%'.$filter.'%')
->orWhere('date', 'like', '%'.$filter.'%')
->orWhere('custom_value1', 'like', '%'.$filter.'%')
->orWhere('custom_value2', 'like', '%'.$filter.'%')
->orWhere('custom_value3', 'like', '%'.$filter.'%')
->orWhere('custom_value4', 'like', '%'.$filter.'%');
});
2019-05-03 17:57:55 +10:00
}
/**
* Returns a list of payments that can be matched to bank transactions
*/
2023-01-22 19:24:35 +11:00
public function match_transactions($value = 'true'): Builder
{
2022-12-16 10:29:19 +11:00
if($value == 'true'){
2022-12-16 10:29:19 +11:00
return $this->builder
->where('is_deleted',0)
->where(function ($query){
$query->whereNull('transaction_id')
2023-01-16 10:05:44 +11:00
->orWhere("transaction_id","")
->company();
2022-12-16 10:29:19 +11:00
});
}
return $this->builder;
}
2019-05-03 17:57:55 +10:00
/**
* Sorts the list based on $sort.
*
2020-10-28 21:10:49 +11:00
* @param string sort formatted as column|asc
* @return Builder
2019-05-03 17:57:55 +10:00
*/
2023-01-22 19:24:35 +11:00
public function sort(string $sort): Builder
2019-05-03 17:57:55 +10:00
{
$sort_col = explode('|', $sort);
if(is_array($sort_col))
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
return true;
2019-05-03 17:57:55 +10:00
}
2023-01-22 19:24:35 +11:00
public function number(string $number = ''): Builder
2021-12-10 22:39:53 +11:00
{
return $this->builder->where('number', $number);
}
2019-05-03 17:57:55 +10:00
/**
* Filters the query by the users company ID.
*
2019-05-03 17:57:55 +10:00
* @return Illuminate\Database\Query\Builder
*/
2023-01-22 19:24:35 +11:00
public function entityFilter(): Builder
2019-05-03 17:57:55 +10:00
{
if (auth()->guard('contact')->user()) {
2019-08-16 15:20:28 +10:00
return $this->contactViewFilter();
} else {
return $this->builder->company();
}
2019-05-03 17:57:55 +10:00
}
2019-08-16 15:20:28 +10:00
/**
* We need additional filters when showing invoices for the
* client portal. Need to automatically exclude drafts and cancelled invoices.
*
2020-10-28 21:10:49 +11:00
* @return Builder
2019-08-16 15:20:28 +10:00
*/
2023-01-22 19:24:35 +11:00
private function contactViewFilter(): Builder
2019-08-16 15:20:28 +10:00
{
return $this->builder
->whereCompanyId(auth()->guard('contact')->user()->company->id)
2019-08-16 15:20:28 +10:00
->whereIsDeleted(false);
}
}