add method to fin reports by date

This commit is contained in:
iIronside
2022-02-15 12:42:56 +03:00
parent 40853b6167
commit e410a59c16
4 changed files with 182 additions and 2 deletions

View File

@ -18,6 +18,7 @@ class ReportSearchForm extends Model
* @var false
*/
public $byDate;
public $date;
public function __construct($config = [])
{
@ -27,6 +28,7 @@ class ReportSearchForm extends Model
$this->toDate = date('Y-m-d', time());
$this->fromDate = date('Y-m-01', time());
$this->date = date('Y-m-d');
$this->byDate = false;
parent::__construct($config);
@ -36,7 +38,7 @@ class ReportSearchForm extends Model
{
return [
[['byDate'], 'safe'],
[['fromDate', 'toDate'], 'date', 'format' => 'php:Y-m-d'],
[['fromDate', 'toDate', 'date'], 'date', 'format' => 'php:Y-m-d'],
[['limit', 'offset', 'user_id'], 'integer', 'min' => 0],
];
}
@ -47,7 +49,7 @@ class ReportSearchForm extends Model
->with('task');
if ($this->byDate) {
$queryBuilder->andWhere(['reports.created_at' => $this->byDate]);
$queryBuilder->andWhere(['reports.created_at' => $this->date]);
} else {
$queryBuilder->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]);
}