add inventory changes
This commit is contained in:
@@ -20,7 +20,10 @@ use common\models\Inventory;
|
||||
class InventoryItemSearch extends InventoryItem
|
||||
{
|
||||
public $inventory;
|
||||
|
||||
public $output;
|
||||
public $item_name;
|
||||
public $item_type;
|
||||
public $item_id;
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -28,6 +31,10 @@ class InventoryItemSearch extends InventoryItem
|
||||
{
|
||||
return [
|
||||
[['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'],
|
||||
['output', 'string'],
|
||||
['item_name', 'string'],
|
||||
['item_type', 'string'],
|
||||
['item_id', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -50,6 +57,7 @@ class InventoryItemSearch extends InventoryItem
|
||||
public function search($params)
|
||||
{
|
||||
$query = new Query();
|
||||
|
||||
$query->select([
|
||||
'inventory_item.id_inventory_item as item_id_inventory_item',
|
||||
'inventory_item.created_at as item_created_at',
|
||||
@@ -65,6 +73,7 @@ class InventoryItemSearch extends InventoryItem
|
||||
'inventory_prev.name as inventory_prev_name',
|
||||
new Expression('(inventory_item.count - ( inventory_item.count_prev + inventory_item.count_in - inventory_item.count_sold )) as item_difference'),
|
||||
]);
|
||||
|
||||
$query->from(InventoryItem::tableName());
|
||||
|
||||
|
||||
@@ -78,9 +87,19 @@ class InventoryItemSearch extends InventoryItem
|
||||
|
||||
$query->andWhere( ['inventory_item.id_inventory' => $this->inventory->id_inventory] );
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$dataProvider = new ActiveDataProvider(
|
||||
['query' => $query ,
|
||||
'pagination' => ( empty($this->output) ? [] : false ),
|
||||
'sort' => [
|
||||
'defaultOrder' => ['item_name' => SORT_ASC],
|
||||
'attributes' => Helper::mkYiiSortItems([
|
||||
['item_created_at', 'item_created_at'],
|
||||
['item_name', 'item_name'],
|
||||
@@ -100,22 +119,16 @@ class InventoryItemSearch extends InventoryItem
|
||||
]
|
||||
]
|
||||
);
|
||||
$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([
|
||||
'inventory_item.id_inventory_item' => $this->id_inventory_item,
|
||||
'inventory_item.type' => $this->type,
|
||||
'inventory_item.id_product' => $this->id_product,
|
||||
'inventory_item.id_inventory_group' => $this->id_inventory_group,
|
||||
'inventory_item.id_user' => $this->id_user,
|
||||
'inventory_item.created_at' => $this->created_at,
|
||||
]);
|
||||
if ( !empty($this->item_type) && is_numeric($this->item_id) ){
|
||||
if ( $this->item_type == 'product'){
|
||||
$query->andFilterWhere(['product.id_product' => $this->item_id]);
|
||||
}else if ( $this->item_type == 'group' ){
|
||||
$query->andFilterWhere(['inventory_group.id_inventory_group' => $this->item_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user