<?php

namespace modules\custom\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use modules\custom\models\Complaintsbe;

/**
 * complaintsbeSearch represents the model behind the search form about `\modules\custom\models\Complaintsbe`.
 */
class ComplaintsbeSearch extends complaintsbe
{
    /**
     * @inheritdoc
     */
    public function rules(): array
    {
        return [
            [['id', 'created_by', 'updated_by', 'deleted_by', 'actid', 'relatedid', 'employee', 'vehicle', 'status', 'padno', 'comname', 'comphone', 'type', 'relatedto', 'overview', 'comaddress'], 'safe'],
            [['created_at', 'updated_at', 'deleted_at', 'jobno', 'step1', 'step2', 'step3', 'step4', 'step5', 'step6'], 'integer'],
        ];
    }

    /**
     * @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 = complaintsbe::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([
        	'employee' => $this->employee,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'deleted_at' => $this->deleted_at,
            'jobno' => $this->jobno,
            'step1' => $this->step1,
            'step2' => $this->step2,
            'step3' => $this->step3,
            'step4' => $this->step4,
            'step5' => $this->step5,
            'step6' => $this->step6,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by])
            ->andFilterWhere(['like', 'deleted_by', $this->deleted_by])
            ->andFilterWhere(['like', 'actid', $this->actid])
            ->andFilterWhere(['like', 'relatedid', $this->relatedid])
            ->andFilterWhere(['like', 'employee', $this->employee])
            ->andFilterWhere(['like', 'vehicle', $this->vehicle])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'comname', $this->comname])
            ->andFilterWhere(['like', 'comphone', $this->comphone])
            ->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 'relatedto', $this->relatedto])
            ->andFilterWhere(['like', 'overview', $this->overview])
            ->andFilterWhere(['like', 'comaddress', $this->comaddress]);

        return $dataProvider;
    }
    public function deleted($params)
    {
        $query = complaintsbe::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,
            'updated_at' => $this->updated_at,
            'deleted_at' => $this->deleted_at,
            'jobno' => $this->jobno,
            'step1' => $this->step1,
            'step2' => $this->step2,
            'step3' => $this->step3,
            'step4' => $this->step4,
            'step5' => $this->step5,
            'step6' => $this->step6,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by])
            ->andFilterWhere(['like', 'deleted_by', $this->deleted_by])
            ->andFilterWhere(['like', 'actid', $this->actid])
            ->andFilterWhere(['like', 'relatedid', $this->relatedid])
            ->andFilterWhere(['like', 'employee', $this->employee])
            ->andFilterWhere(['like', 'vehicle', $this->vehicle])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'comname', $this->comname])
            ->andFilterWhere(['like', 'comphone', $this->comphone])
            ->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 'relatedto', $this->relatedto])
            ->andFilterWhere(['like', 'overview', $this->overview])
            ->andFilterWhere(['like', 'comaddress', $this->comaddress]);

        return $dataProvider;
    }
}
