Bring date only from current year + previous year in the filter.

This commit is contained in:
Djonathan 2022-07-08 16:11:11 -03:00
parent 9ae172db78
commit ae5faf377a
2 changed files with 30 additions and 0 deletions

View File

@ -30,6 +30,12 @@ class FilterItem extends EntityJson
*/ */
protected bool $row = false; protected bool $row = false;
/**
* @var string
*/
protected string $interval;
/** /**
* @return bool * @return bool
*/ */
@ -75,4 +81,15 @@ class FilterItem extends EntityJson
{ {
$this->value = $value; $this->value = $value;
} }
public function getInterval(): string
{
return $this->interval;
}
public function setInterval(string $interval): void
{
$this->interval = $interval;
}
} }

View File

@ -36,6 +36,7 @@ class FilterType
"not_null" "not_null"
]; ];
public static function filter(Builder $builder, FilterItem $filter): Builder public static function filter(Builder $builder, FilterItem $filter): Builder
{ {
@ -61,7 +62,19 @@ class FilterType
if ($fType === 'not_like') { if ($fType === 'not_like') {
$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(); $field = ($filter->getRow()) ? DB::raw($filter->getField()) : $filter->getField();
return $builder->where($field, $fType, $filter->getValue()); return $builder->where($field, $fType, $filter->getValue());
} }