<?php

namespace modules\cors\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use modules\cors\models\Vehiclebe;

/**
 * vehiclebeSearch represents the model behind the search form about `\modules\cors\models\Vehiclebe`.
 */
class VehiclebeSearch extends vehiclebe
{
    /**
     * @inheritdoc
     */
    public function rules(): array
    {
        return [
            [['id', 'reg', 'equipmentid', 'created_by', 'updated_by', 'category', 'name', 'description', 'make', 'model', 'status'], 'safe'],
            [['created_at', 'created_by2', 'updated_at', 'updated_by2', 'deleted', 'deleted_at', 'firstd', 'mileage'], 'integer'],
            [['weight', 'fueltanksize', 'loadedweight'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = vehiclebe::find()
        ->where(['!=','status','deleted']);

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'defaultOrder' => [
                    'status' => SORT_ASC,
                    'reg' => SORT_ASC,
                ],
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'created_at' => $this->created_at,
            'created_by2' => $this->created_by2,
            'updated_at' => $this->updated_at,
            'updated_by2' => $this->updated_by2,
            'deleted' => $this->deleted,
            'deleted_at' => $this->deleted_at,
            'weight' => $this->weight,
            'fueltanksize' => $this->fueltanksize,
            'firstd' => $this->firstd,
            'mileage' => $this->mileage,
            'loadedweight' => $this->loadedweight,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'reg', $this->reg])
            ->andFilterWhere(['like', 'equipmentid', $this->equipmentid])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by])
            ->andFilterWhere(['like', 'category', $this->category])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'description', $this->description])
            ->andFilterWhere(['like', 'make', $this->make])
            ->andFilterWhere(['like', 'model', $this->model]);

        return $dataProvider;
    }
    public function deleted($params)
    {
        $query = vehiclebe::find()
        ->where(['=','status','deleted']);

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'created_at' => $this->created_at,
            'created_by2' => $this->created_by2,
            'updated_at' => $this->updated_at,
            'updated_by2' => $this->updated_by2,
            'deleted' => $this->deleted,
            'deleted_at' => $this->deleted_at,
            'weight' => $this->weight,
            'fueltanksize' => $this->fueltanksize,
            'firstd' => $this->firstd,
            'mileage' => $this->mileage,
            'loadedweight' => $this->loadedweight,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'reg', $this->reg])
            ->andFilterWhere(['like', 'equipmentid', $this->equipmentid])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by])
            ->andFilterWhere(['like', 'category', $this->category])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'description', $this->description])
            ->andFilterWhere(['like', 'make', $this->make])
            ->andFilterWhere(['like', 'model', $this->model]);

        return $dataProvider;
    }
}
