| Current Path : /var/www/html/crm/models/ |
| Current File : /var/www/html/crm/models/StockLogSearch.php |
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\StockLog;
/**
* StockLogSearch represents the model behind the search form of `app\models\StockLog`.
*/
class StockLogSearch extends StockLog {
public $searchkeyword;
public $searchdo;
public $searchdatestart;
public $searchdateend;
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['id', 'product_id', 'data_id', 'action_by'], 'integer'],
[['action_type', 'table_related', 'action_datetime'], 'safe'],
[['searchkeyword', 'searchdatestart', 'searchdateend', 'company_id', 'searchdo'], 'safe'],
];
}
public function attributeLabels() {
return [
'searchkeyword' => '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 getStockin() {
return $this->hasOne(StockIn::className(), ['data_id' => 'id']);
}
public function search($params) {
$query = StockLog::find();
$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;
}
$query->andFilterWhere(['IN', 'stock_log.table_related', $this->table_related]);
if (!empty($this->searchdatestart) && !empty($this->searchdateend))
$query->andFilterWhere(['BETWEEN', 'DATE(action_datetime)', $this->searchdatestart, $this->searchdateend]);
if (!empty($this->searchkeyword)) {
$query->innerJoin("product", "stock_log.product_id=product.id");
$query->andFilterWhere(['LIKE', 'product.name', $this->searchkeyword]);
}
$query->andFilterWhere(['=', 'stock_log.do_no', $this->searchdo]);
//$query->andFilterWhere(['=', 'stock_log.company_id', $this->company_id]);
$query->groupBy(['stock_log.id']);
return $dataProvider;
}
}