refs #2543 Fixed: not equal year filter issue.
This commit is contained in:
parent
2ce7d7f651
commit
e5a68d8450
@ -132,6 +132,9 @@ abstract class Report
|
||||
$input = request('search');
|
||||
|
||||
// Remove year as it's handled based on financial start
|
||||
$search_not_year = 'not year:' . $this->getSearchStringValue('year', '', $input);
|
||||
$input = str_replace($search_not_year, '', $input);
|
||||
|
||||
$search_year = 'year:' . $this->getSearchStringValue('year', '', $input);
|
||||
$input = str_replace($search_year, '', $input);
|
||||
|
||||
|
@ -5,6 +5,7 @@ namespace App\Traits;
|
||||
use App\Traits\SearchString;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Date;
|
||||
use Lorisleiva\LaravelSearchString\SearchStringManager;
|
||||
|
||||
trait DateTime
|
||||
{
|
||||
@ -41,6 +42,7 @@ trait DateTime
|
||||
public function scopeMonthsOfYear($query, $field)
|
||||
{
|
||||
$now = Date::now();
|
||||
|
||||
$year = $this->getSearchStringValue('year', $now->year);
|
||||
|
||||
$financial_start = $this->getFinancialStart($year);
|
||||
@ -54,7 +56,31 @@ trait DateTime
|
||||
$end = $financial_start->addYear(1)->subDays(1)->endOfDay()->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
return $query->whereBetween($field, [$start, $end]);
|
||||
// Looking year or not year
|
||||
$query_type = 'whereBetween';
|
||||
|
||||
if (request('search')) {
|
||||
$search_string_manager = new SearchStringManager($query->getModel());
|
||||
$parse = $search_string_manager->parse(request('search'));
|
||||
|
||||
if (! empty($parse->expressions)) {
|
||||
foreach ($parse->expressions as $filter) {
|
||||
if (! $filter instanceof \Lorisleiva\LaravelSearchString\AST\NotSymbol) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($filter->expression->key != 'year') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$query_type = 'whereNotBetween';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $query->{$query_type}($field, [$start, $end]);
|
||||
}
|
||||
|
||||
public function getTimezones()
|
||||
|
Loading…
x
Reference in New Issue
Block a user