<?php

namespace myresto\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use myresto\models\SyncToJurnal;

/**
 * SyncToJurnalSearch represents the model behind the search form of `myresto\models\SyncToJurnal`.
 */
class SyncToJurnalSearch extends SyncToJurnal
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['last_update', 'tipe_tabel', 'status_sinkron', 'keterangan', 'tipe_proses'], 'safe'],
            [['id', 'id_record'], 'integer'],
            [['id_jurnal'], '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 = SyncToJurnal::find()->where(['type_con' => 'resto']);

        // 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([
            'last_update' => $this->last_update,
            'id' => $this->id,
            'id_record' => $this->id_record,
            'id_jurnal' => $this->id_jurnal,
        ]);

        $query->andFilterWhere(['like', 'tipe_tabel', $this->tipe_tabel])
            ->andFilterWhere(['!=', 'tipe_tabel', 'rst_fc_payment'])
            ->andFilterWhere(['like', 'status_sinkron', $this->status_sinkron])
            ->andFilterWhere(['like', 'keterangan', $this->keterangan])
            ->andFilterWhere(['like', 'tipe_proses', $this->tipe_proses]);

        return $dataProvider;
    }
}
