add inventory to frontend
This commit is contained in:
@@ -108,10 +108,14 @@ class InventoryItemForm extends Model{
|
||||
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;
|
||||
if ( !isset($item->count_prev)){
|
||||
$item->count_prev = 0;
|
||||
}
|
||||
}else{
|
||||
$item->count_prev = 0;
|
||||
}
|
||||
|
||||
|
||||
$item->id_user = \Yii::$app->user->id;
|
||||
|
||||
if ( $this->type == 'product'){
|
||||
@@ -121,7 +125,7 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
$item->id_inventory = $this->inventory->id_inventory;
|
||||
|
||||
if ( !$item->save() ){
|
||||
if ( !$item->save(false) ){
|
||||
throw new \Exception("Nem sikerült a leltár végrehajtása");
|
||||
}
|
||||
$this->inventory_item = $item;
|
||||
@@ -132,7 +136,7 @@ class InventoryItemForm extends Model{
|
||||
|
||||
protected function loadProductIn(){
|
||||
$query = new Query();
|
||||
$query->select(['sum(procurement.count) as total_in']);
|
||||
$query->select(['coalesce(sum(procurement.count),0) as total_in']);
|
||||
$query->from(Procurement::tableName());
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = procurement.id_product");
|
||||
|
||||
@@ -153,7 +157,7 @@ class InventoryItemForm extends Model{
|
||||
protected function loadProductSold(){
|
||||
|
||||
$query = new Query();
|
||||
$query->select(['sum(transfer.count) as total_sold']);
|
||||
$query->select(['coalesce(sum(transfer.count),0) as total_sold']);
|
||||
$query->from(Transfer::tableName());
|
||||
$query->innerJoin(Sale::tableName(),"sale.id_sale = transfer.id_object and transfer.type = " .Transfer::TYPE_PRODUCT);
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = sale.id_product ");
|
||||
@@ -172,7 +176,7 @@ class InventoryItemForm extends Model{
|
||||
protected function loadProductStock(){
|
||||
|
||||
$query = new Query();
|
||||
$query->select(['sum(product.stock) as total_stock']);
|
||||
$query->select(['coalesce(sum(product.stock),0) as total_stock']);
|
||||
$query->from(Product::tableName());
|
||||
|
||||
if ( $this->type == 'product') {
|
||||
|
||||
Reference in New Issue
Block a user