| Current Path : /var/www/html/crm/models/ |
| Current File : /var/www/html/crm/models/GrnSearch.php |
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Grn;
/**
* GrnSearch represents the model behind the search form of `app\models\Grn`.
*/
class GrnSearch extends Grn {
public $searchstring;
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['id', 'do_id', 'cust_id', 'com_id', 'product_id', 'quantity', 'created_by', 'updated_by'], 'integer'],
[['uuid', 'received_dt', 'remarks', 'created_dt', 'updated_dt', 'status_inspection'], '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 = Grn::find()
->leftJoin('company c', 'grn.com_id=c.id')
->leftJoin('product p', 'grn.product_id=p.id')
->leftJoin('delivery_order do', 'grn.do_id=do.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', 'do.doc_no', $this->searchstring])
->orFilterWhere(['like', 'grn.remarks', $this->searchstring])
->orFilterWhere(['like', 'do.customer_name', $this->searchstring])
->orFilterWhere(['like', 'c.name', $this->searchstring])
->orFilterWhere(['like', 'p.name', $this->searchstring]);
$query->groupBy(['grn.id']);
return $dataProvider;
}
public function searchreturn($params) {
$query = Grn::find()
->leftJoin('product p', 'grn.product_id=p.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->andFilterWhere(['like', 'p.name', $this->searchstring]);
$query->andFilterWhere(['=', 'grn.status_inspection', $this->status_inspection]);
$query->groupBy(['grn.id']);
return $dataProvider;
}
}