<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\Billing;

/**
 * BillingSearch represents the model behind the search form of `backend\models\Billing`.
 */
class BillingSearch extends Billing
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['BILLING_UUID', 'BILLING_PROFILE_UUID', 'BILLING_SKEMA_UUID', 'BILLING_BAYAR_BUKTI', 'BILLING_BAYAR_TGL', 'BILLING_VERIFIKASI', 'BILLING_VERIFIKASI_LSP', 'BILLING_VERIFIKASI_USERNAME', 'BILLING_VERIFIKASI_TGL', 'BILLING_PENAGIHAN', 'BILLING_PENAGIHAN_TGL', 'CREATED', 'USERNAME'], 'safe'],
            [['BILLING_SKEMA_BIAYA'], '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
     * @param string|null $formName Form name to be used into `->load()` method.
     *
     * @return ActiveDataProvider
     */
    public function search($params, $formName = null)
    {
        $query = Billing::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params, $formName);

        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([
            'BILLING_SKEMA_BIAYA' => $this->BILLING_SKEMA_BIAYA,
            'BILLING_BAYAR_TGL' => $this->BILLING_BAYAR_TGL,
            'BILLING_VERIFIKASI_TGL' => $this->BILLING_VERIFIKASI_TGL,
            'BILLING_PENAGIHAN_TGL' => $this->BILLING_PENAGIHAN_TGL,
            'CREATED' => $this->CREATED,
        ]);

        $query->andFilterWhere(['like', 'BILLING_UUID', $this->BILLING_UUID])
            ->andFilterWhere(['like', 'BILLING_PROFILE_UUID', $this->BILLING_PROFILE_UUID])
            ->andFilterWhere(['like', 'BILLING_SKEMA_UUID', $this->BILLING_SKEMA_UUID])
            ->andFilterWhere(['like', 'BILLING_BAYAR_BUKTI', $this->BILLING_BAYAR_BUKTI])
            ->andFilterWhere(['like', 'BILLING_VERIFIKASI', $this->BILLING_VERIFIKASI])
            ->andFilterWhere(['like', 'BILLING_VERIFIKASI_LSP', $this->BILLING_VERIFIKASI_LSP])
            ->andFilterWhere(['like', 'BILLING_VERIFIKASI_USERNAME', $this->BILLING_VERIFIKASI_USERNAME])
            ->andFilterWhere(['like', 'BILLING_PENAGIHAN', $this->BILLING_PENAGIHAN])
            ->andFilterWhere(['like', 'USERNAME', $this->USERNAME]);

        return $dataProvider;
    }
}
