Your IP : 216.73.216.79


Current Path : /var/www/html/crm/models/
Upload File :
Current File : /var/www/html/crm/models/BankTransactionSearch.php

<?php

namespace app\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\BankTransaction;

/**
 * BankTransactionSearch represents the model behind the search form of `app\models\BankTransaction`.
 */
class BankTransactionSearch extends BankTransaction {

    public $searchstring;

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['id', 'from_id', 'receiver_id', 'created_by', 'updated_by'], 'integer'],
            [['uuid', 'from_type', 'receiver_type', 'descr', 'method', 'total', 'transaction_dt', 'ref_no', 'attachment', 'remarks', 'created_dt', 'updated_dt', 'related_table', 'related_id'], 'safe'],
            [['searchstring'], 'safe'],
        ];
    }

    public function attributeLabels() {
        return [
            'searchstring' => 'Keyword',
        ];
    }

    /**
     * {@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 = BankTransaction::find();

        // add conditions that should always apply here
        $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10,]]);
        $dataProvider->setSort(['defaultOrder' => ['transaction_dt' => 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->orFilterWhere(['like', 'descr', $this->descr]);
        $query->orFilterWhere(['=', 'method', $this->method]);
        
        $query->andFilterWhere(['=', 'related_id', $this->related_id]);
        $query->andFilterWhere(['=', 'related_table', $this->related_table]);

        return $dataProvider;
    }

}