| Current Path : /var/www/html/dyna-crm/models/ |
| Current File : /var/www/html/dyna-crm/models/DebitnoteSearch.php |
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Debitnote;
/**
* DebitnoteSearch represents the model behind the search form of `app\models\Debitnote`.
*/
class DebitnoteSearch extends Debitnote {
public $searchstring;
public $searchcompany;
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['id', 'company_id', 'customer_id', 'created_by', 'updated_by'], 'integer'],
[['uuid', 'doc_no', 'doc_dt', 'ref', 'customer_name', 'customer_address1', 'customer_address2', 'customer_postcode', 'customer_city', 'customer_state', 'customer_pic', 'customer_phone', 'notes', '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 = Debitnote::find()->alias('dn')
->leftJoin('company c', 'dn.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', 'dn.doc_no', $this->searchstring])
->orFilterWhere(['like', 'dn.customer_name', $this->searchstring])
->orFilterWhere(['like', 'dn.customer_address1', $this->searchstring])
->orFilterWhere(['like', 'dn.customer_address2', $this->searchstring])
->orFilterWhere(['like', 'dn.customer_city', $this->searchstring])
->orFilterWhere(['like', 'dn.customer_pic', $this->searchstring])
->orFilterWhere(['like', 'dn.ref', $this->searchstring])
->orFilterWhere(['like', 'c.name', $this->searchstring]);
$query->andFilterWhere(['=', 'c.uuid', $this->searchcompany]);
$query->groupBy(['dn.id']);
return $dataProvider;
}
}