add inventory daily
This commit is contained in:
@@ -19,6 +19,9 @@ use common\models\Sale;
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
* @property \Yii\web\UploadedFile $file
|
||||
* @property \common\models\Inventory $inventory
|
||||
* @property \common\models\Inventory $last_inventory
|
||||
* @property number $id_inventory
|
||||
*/
|
||||
class InventoryItemForm extends Model{
|
||||
|
||||
@@ -102,10 +105,17 @@ class InventoryItemForm extends Model{
|
||||
$item = new InventoryItem();
|
||||
$item->count_in = $this->product_in;
|
||||
$item->count_sold = $this->product_out;
|
||||
$item->count = $this->count;
|
||||
$item->count_system = $this->product_stock;
|
||||
|
||||
|
||||
|
||||
|
||||
if ( isset($this->inventory )){
|
||||
if ( $this->inventory->type == Inventory::$TYPE_DAILY){
|
||||
$item->count = $this->product_stock;
|
||||
}else{
|
||||
$item->count = $this->count;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $this->last_inventory_item ) ){
|
||||
$item->id_inventory_item_prev = $this->last_inventory_item->id_inventory_item;
|
||||
$item->count_prev = $this->last_inventory_item->count;
|
||||
@@ -116,9 +126,11 @@ class InventoryItemForm extends Model{
|
||||
$item->count_prev = 0;
|
||||
}
|
||||
|
||||
|
||||
$item->id_user = \Yii::$app->user->id;
|
||||
|
||||
|
||||
if ( isset(\Yii::$app->user )){
|
||||
$item->id_user = \Yii::$app->user->id;
|
||||
}
|
||||
|
||||
if ( $this->type == 'product'){
|
||||
$item->price_brutto = $this->product->sale_price;
|
||||
$item->type = InventoryItem::$TYPE_PRODUCT;
|
||||
@@ -201,17 +213,7 @@ class InventoryItemForm extends Model{
|
||||
$this->product_stock = $query->scalar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function addProductItem(){
|
||||
|
||||
}
|
||||
|
||||
public function addGroupItem(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load previous inventory item, if exists
|
||||
* */
|
||||
@@ -259,6 +261,7 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
|
||||
$query->andWhere(['<', 'inventory.created_at' , $this->inventory->created_at]);
|
||||
$query->andWhere(['=', 'inventory.type' , $this->inventory->type]);
|
||||
$query->orderBy(['created_at' => SORT_DESC ]);
|
||||
$this->last_inventory =$query->limit(1)->one();
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ class InventoryItemSearch extends InventoryItem
|
||||
$query->from(InventoryItem::tableName());
|
||||
|
||||
|
||||
$query->innerJoin(User::tableName(), "user.id = inventory_item.id_user");
|
||||
$query->leftJoin(User::tableName(), "user.id = inventory_item.id_user");
|
||||
$query->leftJoin(Product::tableName(), "product.id_product = inventory_item.id_product");
|
||||
$query->leftJoin(InventoryGroup::tableName(), "inventory_group.id_inventory_group = inventory_item.id_inventory_group");
|
||||
$query->leftJoin(Inventory::tableName(), "inventory.id_inventory = inventory_item.id_inventory");
|
||||
|
||||
@@ -42,11 +42,12 @@ class InventorySearch extends Inventory
|
||||
public function search($params)
|
||||
{
|
||||
$query = Inventory::find();
|
||||
$query->andWhere(['=','type',Inventory::$TYPE_MANUAL]);
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' => [
|
||||
'defaultOrder' => ['created_at' => SORT_DESC]
|
||||
'defaultOrder' => ['created_at' => SORT_DESC]
|
||||
]
|
||||
]);
|
||||
|
||||
@@ -65,6 +66,7 @@ class InventorySearch extends Inventory
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
|
||||
72
backend/models/InventorySearchAuto.php
Normal file
72
backend/models/InventorySearchAuto.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Inventory;
|
||||
|
||||
/**
|
||||
* InventorySearch represents the model behind the search form about `common\models\Inventory`.
|
||||
*/
|
||||
class InventorySearchAuto extends Inventory
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_inventory', 'id_user'], 'integer'],
|
||||
[['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 = Inventory::find();
|
||||
$query->andWhere(['=','type',Inventory::$TYPE_DAILY]);
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' => [
|
||||
'defaultOrder' => ['created_at' => 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([
|
||||
'id_inventory' => $this->id_inventory,
|
||||
'id_user' => $this->id_user,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user