<?php

namespace backend\modules\administrator\models;

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

/**
 * RiaFrmHVLABSearch represents the model behind the search form of `common\models\RiaFrmHVLAB`.
 */
class RiaFrmHVLABSearch extends RiaFrmHVLAB
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'RiaHPaySts', 'RiaHDataFlag', 'RiaHReEntryFlag', 'RiaLHGRFlag', 'CustLabQty', 'RiaLHPreExpFlag', 'RiaLHExpFlag', 'RiaHRepType', 'RiaHMsightFlag'], 'integer'],
            [['RiaHDocDate', 'RiaHDocID', 'PatName', 'PatHN', 'PatWard', 'CustID', 'CustTitle', 'CustName', 'CustFax', 'RiaHReqBy', 'RiaHRemark', 'CsHDocID', 'UserIDEntry', 'UserDateEntry', 'UserIDReEntry', 'UserDateReEntry', 'PatAgeType', 'PatAgeDesc', 'Sex'], 'safe'],
            [['PatAge', 'RiaHCrDay', 'RiaHSUPrice'], '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 = RiaFrmHVLAB::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,
            'PatAge' => $this->PatAge,
            'RiaHPaySts' => $this->RiaHPaySts,
            'RiaHCrDay' => $this->RiaHCrDay,
            'RiaHSUPrice' => $this->RiaHSUPrice,
            'RiaHDataFlag' => $this->RiaHDataFlag,
            'RiaHReEntryFlag' => $this->RiaHReEntryFlag,
            'UserDateEntry' => $this->UserDateEntry,
            'UserDateReEntry' => $this->UserDateReEntry,
            'RiaLHGRFlag' => $this->RiaLHGRFlag,
            'CustLabQty' => $this->CustLabQty,
            'RiaLHPreExpFlag' => $this->RiaLHPreExpFlag,
            'RiaLHExpFlag' => $this->RiaLHExpFlag,
            'RiaHRepType' => $this->RiaHRepType,
            'RiaHMsightFlag' => $this->RiaHMsightFlag,
        ]);

        $query->andFilterWhere(['like', 'RiaHDocID', $this->RiaHDocID])
            ->andFilterWhere(['like', 'PatName', $this->PatName])
            ->andFilterWhere(['like', 'PatHN', $this->PatHN])
            ->andFilterWhere(['like', 'PatWard', $this->PatWard])
            ->andFilterWhere(['like', 'CustID', $this->CustID])
            ->andFilterWhere(['like', 'CustTitle', $this->CustTitle])
            ->andFilterWhere(['like', 'CustName', $this->CustName])
            ->andFilterWhere(['like', 'CustFax', $this->CustFax])
            ->andFilterWhere(['like', 'RiaHReqBy', $this->RiaHReqBy])
            ->andFilterWhere(['like', 'RiaHRemark', $this->RiaHRemark])
            ->andFilterWhere(['like', 'CsHDocID', $this->CsHDocID])
            ->andFilterWhere(['like', 'UserIDEntry', $this->UserIDEntry])
            ->andFilterWhere(['like', 'UserIDReEntry', $this->UserIDReEntry])
            ->andFilterWhere(['like', 'PatAgeType', $this->PatAgeType])
            ->andFilterWhere(['like', 'PatAgeDesc', $this->PatAgeDesc])
            ->andFilterWhere(['like', 'Sex', $this->Sex]);

        return $dataProvider;
    }
}
