<?php

namespace api\modules\prolab\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\RiaFrmDVlab;

/**
 * RiaFrmDVlabSearch represents the model behind the search form of `common\models\RiaFrmDVlab`.
 */
class RiaFrmDVlabSearch extends RiaFrmDVlab
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'RiaDSeq', 'LabSetFlag', 'RiaDTubNbr', 'RiaDInOut', 'RiaDReEntryFlag', 'CustLabSpPriceFlag', 'LabDescFlag', 'LabAddResultFlag'], 'integer'],
            [['RiaHDocDate', 'RiaHDocID', 'LabID', 'LabName', 'SpecID', 'SpecName', 'LabTID', 'LabGrpID', 'LabSubID', 'UserIDEntry', 'UserDateEntry', 'UserIDReEntry', 'UserDateReEntry', 'LabAbbr', 'LabSubName'], 'safe'],
            [['RiaDUPrice', 'LabUPrice'], '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 = RiaFrmDVlab::find();

        // 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([
            'id' => $this->id,
            'RiaHDocDate' => $this->RiaHDocDate,
            'RiaDSeq' => $this->RiaDSeq,
            'LabSetFlag' => $this->LabSetFlag,
            'RiaDUPrice' => $this->RiaDUPrice,
            'RiaDTubNbr' => $this->RiaDTubNbr,
            'RiaDInOut' => $this->RiaDInOut,
            'UserDateEntry' => $this->UserDateEntry,
            'RiaDReEntryFlag' => $this->RiaDReEntryFlag,
            'UserDateReEntry' => $this->UserDateReEntry,
            'CustLabSpPriceFlag' => $this->CustLabSpPriceFlag,
            'LabUPrice' => $this->LabUPrice,
            'LabDescFlag' => $this->LabDescFlag,
            'LabAddResultFlag' => $this->LabAddResultFlag,
        ]);

        $query->andFilterWhere(['like', 'RiaHDocID', $this->RiaHDocID])
            ->andFilterWhere(['like', 'LabID', $this->LabID])
            ->andFilterWhere(['like', 'LabName', $this->LabName])
            ->andFilterWhere(['like', 'SpecID', $this->SpecID])
            ->andFilterWhere(['like', 'SpecName', $this->SpecName])
            ->andFilterWhere(['like', 'LabTID', $this->LabTID])
            ->andFilterWhere(['like', 'LabGrpID', $this->LabGrpID])
            ->andFilterWhere(['like', 'LabSubID', $this->LabSubID])
            ->andFilterWhere(['like', 'UserIDEntry', $this->UserIDEntry])
            ->andFilterWhere(['like', 'UserIDReEntry', $this->UserIDReEntry])
            ->andFilterWhere(['like', 'LabAbbr', $this->LabAbbr])
            ->andFilterWhere(['like', 'LabSubName', $this->LabSubName]);

        return $dataProvider;
    }
}
