/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $filter)
 {
     $query = Journal::find();
     $query->joinWith(['company', 'kind', 'type']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['N_year' => SORT_ASC]]]);
     // Add extended sorts for related tables
     $dataProvider->sort->attributes['company.nazva'] = ['asc' => [Leshoz::tableName() . '.nazva' => SORT_ASC], 'desc' => [Leshoz::tableName() . '.nazva' => SORT_DESC]];
     $dataProvider->sort->attributes['kind.nazva_short'] = ['asc' => [Poroda::tableName() . '.nazva_short' => SORT_ASC], 'desc' => [Poroda::tableName() . '.nazva_short' => SORT_DESC]];
     $dataProvider->sort->attributes['type.type'] = ['asc' => [TestType::tableName() . '.type' => SORT_ASC], 'desc' => [TestType::tableName() . '.type' => SORT_DESC]];
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'N_total' => $this->N_total, 'N_year' => $this->N_year, 'id_leshoz' => $this->id_leshoz, 'id_poroda' => $this->id_poroda, 'date_start' => $this->date_start, 'date_end' => $this->date_end, 'date_pasport' => $this->date_pasport, 'masa' => $this->masa, 'masa_zrazka' => $this->masa_zrazka, 'energy' => $this->energy, 'shozh' => $this->shozh, 'chistota' => $this->chistota, 'masa_1000' => $this->masa_1000, 'klass' => $this->klass, 'date_doc' => $this->date_doc, 'id_type' => $this->id_type, 'N_prev' => $this->N_prev, 'v_rahunok' => $this->v_rahunok, 'id_bill' => $this->id_bill, 'id_koef' => $this->id_koef]);
     $query->andFilterWhere(['like', 'N_pasport', $this->N_pasport])->andFilterWhere(['like', 'zagotiv', $this->zagotiv]);
     if (empty($params['date_start']) && isset($filter['year'])) {
         $query->andFilterWhere(['between', 'date_start', $filter['year'] . '-01-01', $filter['year'] . '-12-31']);
     }
     return $dataProvider;
 }
 public function down()
 {
     $this->dropColumn(TestType::tableName(), 'order');
 }