| Current Path : /var/www/html/dyna-crm/models/ |
| Current File : /var/www/html/dyna-crm/models/InvoiceSearch.php |
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Invoice;
/**
* InvoiceSearch represents the model behind the search form of `app\models\Invoice`.
*/
class InvoiceSearch extends Invoice {
public $searchstring;
public $searchcompany;
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['id', 'com_id', 'created_by', 'updated_by'], 'integer'],
[['uuid', 'do_no', 'invoice_no', 'term', 'created_dt', 'updated_dt'], 'safe'],
[['searchstring', 'searchcompany', 'payment_status'], '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 = Invoice::find()->alias('i')
->leftJoin('company c', 'i.com_id=c.id')
->leftJoin('delivery_order do', 'do.id=i.do_no')
->leftJoin('delivery_order_item m', 'do.id=m.doc_id')
->leftJoin('product p', 'm.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->orFilterWhere(['like', 'i.invoice_no', $this->searchstring])
->orFilterWhere(['like', 'i.term', $this->searchstring])
->orFilterWhere(['like', 'do.doc_no', $this->searchstring])
->orFilterWhere(['like', 'do.customer_name', $this->searchstring])
->orFilterWhere(['like', 'p.name', $this->searchstring]);
$query->andFilterWhere(['=', 'i.type', 'do']);
$query->andFilterWhere(['=', 'i.payment_status', $this->payment_status]);
$query->andFilterWhere(['=', 'c.uuid', $this->searchcompany]);
$query->andFilterWhere(['=', 'i.deleted_status', '0']);
$query->groupBy(['i.id']);
return $dataProvider;
}
public function searchoverview($params) {
$query = Invoice2::find()->alias('i')
->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(['like', 'i.invoice_no', $this->searchstring])
->orFilterWhere(['like', 'i.term', $this->searchstring])
->orFilterWhere(['like', 'i.customer_name', $this->searchstring])
->orFilterWhere(['like', 'c.name', $this->searchstring]);
$query->andFilterWhere(['=', 'i.payment_status', $this->payment_status]);
$query->andFilterWhere(['=', 'c.uuid', $this->searchcompany]);
$query->andFilterWhere(['=', 'i.deleted_status', '0']);
$query->andWhere(['!=', 'i.type', 'transfer']);
$query->groupBy(['i.id']);
return $dataProvider;
}
public function searchtransfer($params) {
$query = Invoice2::find()->alias('i')
->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(['like', 'i.invoice_no', $this->searchstring])
->orFilterWhere(['like', 'i.term', $this->searchstring])
->orFilterWhere(['like', 'i.customer_name', $this->searchstring])
->orFilterWhere(['like', 'c.name', $this->searchstring]);
$query->andFilterWhere(['=', 'i.type', 'transfer']);
$query->andFilterWhere(['=', 'i.payment_status', $this->payment_status]);
$query->andFilterWhere(['=', 'c.uuid', $this->searchcompany]);
$query->andFilterWhere(['=', 'i.deleted_status', '0']);
$query->groupBy(['i.id']);
return $dataProvider;
}
}