| Current Path : /var/www/html/crm/models/ |
| Current File : /var/www/html/crm/models/InvoiceInboundSearch.php |
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\InvoiceInbound;
/**
* InvoiceInboundSearch represents the model behind the search form of `app\models\InvoiceInbound`.
*/
class InvoiceInboundSearch extends InvoiceInbound {
public $searchstring;
public $searchcompany;
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['id', 'vendor_id', 'com_id', 'created_by', 'updated_by'], 'integer'],
[['searchstring', 'searchcompany', 'uuid', 'doc_url', 'amount', 'invoice_dt', 'payment_status', 'payment_dt', 'created_dt', 'updated_dt'], '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 = InvoiceInbound::find()->alias('i')
->leftJoin('company_access a', 'a.com_id=i.com_id')
->leftJoin('company c', 'i.com_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(['OR', ['like', 'i.invoice_no', $this->searchstring], ['like', 'i.remarks', $this->searchstring]]);
$query->andFilterWhere(['=', 'i.payment_status', $this->payment_status]);
$query->andFilterWhere(['=', 'a.user_id', Yii::$app->user->identity->id]);
$query->andFilterWhere(['=', 'c.uuid', $this->searchcompany]);
$query->andFilterWhere(['=', 'i.deleted_status', '0']);
$query->groupBy(['i.id']);
return $dataProvider;
}
}