mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 12:26:15 +02:00
migrations/0095: add factor_purchase_amount to stock_current and stock_current_location_content
This commit is contained in:
parent
1967b6e449
commit
dcaad3557f
|
|
@ -5,6 +5,7 @@ SELECT
|
|||
IFNULL(s.location_id, p.location_id) AS location_id,
|
||||
s.product_id,
|
||||
SUM(s.amount) AS amount,
|
||||
SUM(s.amount / p.qu_factor_purchase_to_stock) as factor_purchase_amount,
|
||||
SUM(IFNULL(s.price, 0) * s.amount) AS value,
|
||||
MIN(s.best_before_date) AS best_before_date,
|
||||
IFNULL((SELECT SUM(amount) FROM stock WHERE product_id = s.product_id AND location_id = s.location_id AND open = 1), 0) AS amount_opened
|
||||
|
|
@ -19,6 +20,7 @@ AS
|
|||
SELECT
|
||||
pr.parent_product_id AS product_id,
|
||||
IFNULL((SELECT SUM(amount) FROM stock WHERE product_id = pr.parent_product_id), 0) AS amount,
|
||||
IFNULL((SELECT SUM(amount / p.qu_factor_purchase_to_stock) FROM stock s join products p on s.product_id = p.id WHERE s.product_id = pr.parent_product_id), 0) AS factor_purchase_amount,
|
||||
SUM(s.amount) AS amount_aggregated,
|
||||
IFNULL((SELECT SUM(IFNULL(s.price,0) * IFNULL(amount,0)) FROM stock WHERE product_id = pr.parent_product_id),0) AS value,
|
||||
MIN(s.best_before_date) AS best_before_date,
|
||||
|
|
@ -39,6 +41,7 @@ UNION
|
|||
SELECT
|
||||
pr.sub_product_id AS product_id,
|
||||
SUM(s.amount) AS amount,
|
||||
SUM(s.amount / p.qu_factor_purchase_to_stock) as factor_purchase_amount,
|
||||
SUM(s.amount) AS amount_aggregated,
|
||||
SUM(IFNULL(s.price, 0) * s.amount) AS value,
|
||||
MIN(s.best_before_date) AS best_before_date,
|
||||
|
|
@ -48,6 +51,8 @@ SELECT
|
|||
FROM products_resolved pr
|
||||
JOIN stock s
|
||||
ON pr.sub_product_id = s.product_id
|
||||
JOIN products p
|
||||
ON p.id = s.product_id
|
||||
WHERE pr.parent_product_id != pr.sub_product_id
|
||||
GROUP BY pr.sub_product_id
|
||||
HAVING SUM(s.amount) > 0;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class StockService extends BaseService
|
|||
$missingProductsView = 'stock_missing_products';
|
||||
}
|
||||
|
||||
$sql = 'SELECT * FROM stock_current WHERE best_before_date IS NOT NULL UNION SELECT id, 0, 0, 0, null, 0, 0, 0 FROM ' . $missingProductsView . ' WHERE id NOT IN (SELECT product_id FROM stock_current)';
|
||||
$sql = 'SELECT * FROM stock_current WHERE best_before_date IS NOT NULL UNION SELECT id, 0, 0, 0, 0, null, 0, 0, 0 FROM ' . $missingProductsView . ' WHERE id NOT IN (SELECT product_id FROM stock_current)';
|
||||
}
|
||||
|
||||
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user