add inventory daily

This commit is contained in:
2017-03-25 22:18:27 +01:00
parent 2b5f5f60fd
commit b9c442fe22
13 changed files with 262 additions and 34 deletions

View File

@@ -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();
}