<?php

namespace modules\cors\models;

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

/**
 * fueldatabeSearch represents the model behind the search form about `\modules\cors\models\Fueldatabe`.
 */
class FueldatabeSearch extends fueldatabe
{
    /**
     * @inheritdoc
     */
    public function rules(): array
    {
        return [
            [['id', 'created_by', 'updated_by', 'deleted_by', 'actid', 'status', 'padno', 'relatedid', 'driver', 'cardno', 'type'], 'safe'],
            [['created_at', 'updated_at', 'deleted_at', 'deleted', 'jobno', 'date', 'odometer'], 'integer'],
            [['quantity', 'ppl', 'price', 'vat', 'total'], '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 = fueldatabe::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,
            'deleted' => $this->deleted,
            'jobno' => $this->jobno,
            'date' => $this->date,
            'quantity' => $this->quantity,
            'odometer' => $this->odometer,
            'ppl' => $this->ppl,
            'price' => $this->price,
            'vat' => $this->vat,
            'total' => $this->total,
        ]);

        $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', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'relatedid', $this->relatedid])
            ->andFilterWhere(['like', 'driver', $this->driver])
            ->andFilterWhere(['like', 'cardno', $this->cardno])
            ->andFilterWhere(['like', 'type', $this->type]);

        return $dataProvider;
    }
    public function deleted($params)
    {
        $query = fueldatabe::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,
            'deleted' => $this->deleted,
            'jobno' => $this->jobno,
            'date' => $this->date,
            'quantity' => $this->quantity,
            'odometer' => $this->odometer,
            'ppl' => $this->ppl,
            'price' => $this->price,
            'vat' => $this->vat,
            'total' => $this->total,
        ]);

        $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', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'relatedid', $this->relatedid])
            ->andFilterWhere(['like', 'driver', $this->driver])
            ->andFilterWhere(['like', 'cardno', $this->cardno])
            ->andFilterWhere(['like', 'type', $this->type]);

        return $dataProvider;
    }
}
