77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace backend\models;
|
|
|
|
use Yii;
|
|
use yii\base\Model;
|
|
use yii\data\ActiveDataProvider;
|
|
use common\models\Product;
|
|
|
|
/**
|
|
* ProductSearch represents the model behind the search form about `common\models\Product`.
|
|
*/
|
|
class ProductSearch extends Product
|
|
{
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['id_product', 'id_product_type', 'id_account', 'purchase_price', 'sale_price', 'profit_margins', 'status'], 'integer'],
|
|
[['product_number', 'barcode', 'description', 'created_at', 'updated_at'], 'safe'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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 = Product::find();
|
|
|
|
$dataProvider = new ActiveDataProvider([
|
|
'query' => $query,
|
|
]);
|
|
|
|
$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([
|
|
'id_product' => $this->id_product,
|
|
'id_product_type' => $this->id_product_type,
|
|
'id_account' => $this->id_account,
|
|
'purchase_price' => $this->purchase_price,
|
|
'sale_price' => $this->sale_price,
|
|
'profit_margins' => $this->profit_margins,
|
|
'status' => $this->status,
|
|
'created_at' => $this->created_at,
|
|
'updated_at' => $this->updated_at,
|
|
]);
|
|
|
|
$query->andFilterWhere(['like', 'product_number', $this->product_number])
|
|
->andFilterWhere(['like', 'barcode', $this->barcode])
|
|
->andFilterWhere(['like', 'description', $this->description]);
|
|
|
|
return $dataProvider;
|
|
}
|
|
}
|