Bring date only from current year + previous year in the filter.
This commit is contained in:
parent
9ae172db78
commit
ae5faf377a
@ -30,6 +30,12 @@ class FilterItem extends EntityJson
|
||||
*/
|
||||
protected bool $row = false;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected string $interval;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@ -75,4 +81,15 @@ class FilterItem extends EntityJson
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getInterval(): string
|
||||
{
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
public function setInterval(string $interval): void
|
||||
{
|
||||
$this->interval = $interval;
|
||||
}
|
||||
|
||||
}
|
||||
@ -36,6 +36,7 @@ class FilterType
|
||||
"not_null"
|
||||
];
|
||||
|
||||
|
||||
public static function filter(Builder $builder, FilterItem $filter): Builder
|
||||
{
|
||||
|
||||
@ -61,7 +62,19 @@ class FilterType
|
||||
if ($fType === 'not_like') {
|
||||
$fType = 'not like';
|
||||
}
|
||||
|
||||
if ($filter->getInterval())
|
||||
{
|
||||
$filter->setField("TO_DATE({$filter->getField()}, 'YYMM')");
|
||||
$filter->setValue(DB::raw("TO_DATE(TO_CHAR(current_date , 'YYYY-01-01'), 'YYYY-MM-DD') - INTERVAL
|
||||
'{$filter->getValue()}' {$filter->getInterval()}"));
|
||||
$filter->setRow(true);
|
||||
|
||||
}
|
||||
|
||||
$field = ($filter->getRow()) ? DB::raw($filter->getField()) : $filter->getField();
|
||||
|
||||
|
||||
return $builder->where($field, $fType, $filter->getValue());
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user