Your IP : 216.73.216.79


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

<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Quotation;

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

    public $searchstring;
    public $searchcompany;

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['id', 'company_id', 'customer_id', 'created_by', 'updated_by'], 'integer'],
            [['uuid', 'doc_no', 'customer_name', 'customer_address1', 'customer_address2', 'customer_postcode', 'customer_city', 'customer_state', 'customer_pic', 'customer_phone', 'doc_date', 'valid_dt', 'grandtotal', 'created_dt', 'updated_dt'], 'safe'],
            [['searchstring','searchcompany'], '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 = Quotation::find()->alias('q')
                ->leftJoin('company c', 'q.company_id=c.id');

        // add conditions that should always apply here
        $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10,]]);
        $dataProvider->setSort(['defaultOrder' => ['id' => 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;
        }

        // grid filtering conditions
        $query->orFilterWhere(['like', 'q.doc_no', $this->searchstring])
                ->orFilterWhere(['like', 'q.customer_name', $this->searchstring])
                ->orFilterWhere(['like', 'q.customer_address1', $this->searchstring])
                ->orFilterWhere(['like', 'q.customer_address2', $this->searchstring])
                ->orFilterWhere(['like', 'q.customer_city', $this->searchstring])
                ->orFilterWhere(['like', 'q.customer_pic', $this->searchstring])
                ->orFilterWhere(['like', 'q.customer_phone', $this->searchstring])
                ->orFilterWhere(['like', 'c.name', $this->searchstring]);
        $query->andFilterWhere(['=', 'c.uuid', $this->searchcompany]);
        $query->groupBy(['q.id']);

        return $dataProvider;
    }

}