add wate to inventory
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use common\models\Waste;
|
||||
use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
|
||||
Yii;
|
||||
use yii\base\Model;
|
||||
@@ -47,6 +48,7 @@ class InventoryItemForm extends Model{
|
||||
|
||||
/** internal stuff*/
|
||||
public $product_in;
|
||||
public $product_waste;
|
||||
public $product_out;
|
||||
public $product_stock;
|
||||
public $last_inventory_item;
|
||||
@@ -94,19 +96,18 @@ class InventoryItemForm extends Model{
|
||||
|
||||
public function save(){
|
||||
|
||||
|
||||
$this->loadLastInventory();
|
||||
|
||||
$this->loadLastInventoryItem();
|
||||
$this->loadProductIn();
|
||||
$this->loadProductSold();
|
||||
$this->loadProductStock();
|
||||
$this->loadProductWaste();
|
||||
|
||||
$item = new InventoryItem();
|
||||
$item->count_in = $this->product_in;
|
||||
$item->count_sold = $this->product_out;
|
||||
$item->count_system = $this->product_stock;
|
||||
|
||||
$item->count_waste = $this->product_waste;
|
||||
|
||||
if ( isset($this->inventory )){
|
||||
if ( $this->inventory->type == Inventory::$TYPE_DAILY){
|
||||
@@ -125,7 +126,6 @@ class InventoryItemForm extends Model{
|
||||
}else{
|
||||
$item->count_prev = 0;
|
||||
}
|
||||
|
||||
|
||||
if ( isset(\Yii::$app->user )){
|
||||
$item->id_user = \Yii::$app->user->id;
|
||||
@@ -157,7 +157,7 @@ class InventoryItemForm extends Model{
|
||||
$query->select(['coalesce(sum(procurement.count),0) as total_in']);
|
||||
$query->from(Procurement::tableName());
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = procurement.id_product");
|
||||
|
||||
|
||||
if ( isset($this->last_inventory_item ) ){
|
||||
$query->andWhere([ '>', 'procurement.created_at' ,$this->last_inventory_item->created_at]);
|
||||
}
|
||||
@@ -170,10 +170,31 @@ class InventoryItemForm extends Model{
|
||||
}else{
|
||||
$query->andWhere(['product.id_inventory_group' => $this->inventoryGroup->id_inventory_group]);
|
||||
}
|
||||
|
||||
|
||||
$this->product_in = $query->scalar();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function loadProductWaste(){
|
||||
$query = new Query();
|
||||
$query->select(['coalesce(sum(waste.count),0) as total_waste']);
|
||||
$query->from(Waste::tableName());
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = waste.id_product");
|
||||
|
||||
if ( isset($this->last_inventory_item ) ){
|
||||
$query->andWhere([ '>', 'waste.created_at' ,$this->last_inventory_item->created_at]);
|
||||
}
|
||||
|
||||
|
||||
if ( $this->type == 'product') {
|
||||
$query->andWhere(['product.id_product' => $this->product->id_product]);
|
||||
}else{
|
||||
$query->andWhere(['product.id_inventory_group' => $this->inventoryGroup->id_inventory_group]);
|
||||
}
|
||||
|
||||
$this->product_waste = $query->scalar();
|
||||
|
||||
}
|
||||
|
||||
protected function loadProductSold(){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user