mirror of
https://github.com/grocy/grocy.git
synced 2026-04-07 05:16:15 +02:00
Review
This commit is contained in:
parent
0872de5ff3
commit
cd6cbca07e
|
|
@ -1,77 +1,65 @@
|
||||||
DROP VIEW IF EXISTS stock_current_overview_opened;
|
CREATE VIEW uihelper_stock_current_overview_including_opened
|
||||||
CREATE VIEW IF NOT EXISTS stock_current_overview_opened
|
|
||||||
AS
|
AS
|
||||||
SELECT id,
|
SELECT
|
||||||
stock_current.amount_opened AS amount_opened,
|
p.id,
|
||||||
p.tare_weight AS tare_weight,
|
sc.amount_opened AS amount_opened,
|
||||||
p.enable_tare_weight_handling AS enable_tare_weight_handling,
|
p.tare_weight AS tare_weight,
|
||||||
stock_current.amount AS amount,
|
p.enable_tare_weight_handling AS enable_tare_weight_handling,
|
||||||
stock_current.product_id AS product_id,
|
sc.amount AS amount,
|
||||||
stock_current.best_before_date AS best_before_date,
|
sc.product_id AS product_id,
|
||||||
EXISTS(SELECT id
|
sc.best_before_date AS best_before_date,
|
||||||
FROM (stock_missing_products_including_opened)
|
EXISTS(SELECT id FROM stock_missing_products_including_opened WHERE id = sc.product_id) AS product_missing,
|
||||||
WHERE id = stock_current.product_id) AS product_missing,
|
(SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name,
|
||||||
(SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name,
|
(SELECT name_plural FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name_plural,
|
||||||
(SELECT name_plural
|
p.name AS product_name,
|
||||||
FROM quantity_units
|
(SELECT name FROM product_groups WHERE product_groups.id = product_group_id) AS product_group_name,
|
||||||
WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name_plural,
|
EXISTS(SELECT * FROM shopping_list WHERE shopping_list.product_id = sc.product_id) AS on_shopping_list,
|
||||||
p.name AS product_name,
|
sc.factor_purchase_amount AS factor_purchase_amount,
|
||||||
(SELECT name
|
(SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name,
|
||||||
FROM product_groups
|
(SELECT name_plural FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name_plural,
|
||||||
WHERE product_groups.id = product_group_id) AS product_group_name,
|
sc.is_aggregated_amount,
|
||||||
EXISTS(SELECT * FROM shopping_list WHERE shopping_list.product_id = stock_current.product_id) AS on_shopping_list,
|
sc.amount_opened_aggregated
|
||||||
stock_current.factor_purchase_amount AS factor_purchase_amount,
|
|
||||||
(SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name,
|
|
||||||
(SELECT name_plural
|
|
||||||
FROM quantity_units
|
|
||||||
WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name_plural,
|
|
||||||
is_aggregated_amount,
|
|
||||||
amount_opened_aggregated
|
|
||||||
FROM (
|
FROM (
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM stock_current
|
FROM stock_current
|
||||||
WHERE best_before_date IS NOT NULL
|
WHERE best_before_date IS NOT NULL
|
||||||
UNION
|
UNION
|
||||||
SELECT id, 0, 0, 0, 0, null, 0, 0, 0
|
SELECT id, 0, 0, 0, 0, null, 0, 0, 0
|
||||||
FROM stock_missing_products_including_opened
|
FROM stock_missing_products_including_opened
|
||||||
WHERE id NOT IN (SELECT product_id FROM stock_current)
|
WHERE id NOT IN (SELECT product_id FROM stock_current)
|
||||||
) AS stock_current
|
) sc
|
||||||
LEFT JOIN products p ON stock_current.product_id = p.id;
|
LEFT JOIN products p
|
||||||
DROP VIEW IF EXISTS stock_current_overview;
|
ON sc.product_id = p.id;
|
||||||
|
|
||||||
CREATE VIEW IF NOT EXISTS stock_current_overview
|
CREATE VIEW uihelper_stock_current_overview
|
||||||
AS
|
AS
|
||||||
SELECT id,
|
SELECT
|
||||||
stock_current.amount_opened AS amount_opened,
|
p.id,
|
||||||
p.tare_weight AS tare_weight,
|
sc.amount_opened AS amount_opened,
|
||||||
p.enable_tare_weight_handling AS enable_tare_weight_handling,
|
p.tare_weight AS tare_weight,
|
||||||
stock_current.amount AS amount,
|
p.enable_tare_weight_handling AS enable_tare_weight_handling,
|
||||||
stock_current.product_id AS product_id,
|
sc.amount AS amount,
|
||||||
stock_current.best_before_date AS best_before_date,
|
sc.product_id AS product_id,
|
||||||
EXISTS(SELECT id FROM (stock_missing_products) WHERE id = stock_current.product_id) AS product_missing,
|
sc.best_before_date AS best_before_date,
|
||||||
(SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name,
|
EXISTS(SELECT id FROM stock_missing_products_including_opened WHERE id = sc.product_id) AS product_missing,
|
||||||
(SELECT name_plural
|
(SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name,
|
||||||
FROM quantity_units
|
(SELECT name_plural FROM quantity_units WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name_plural,
|
||||||
WHERE quantity_units.id = p.qu_id_stock) AS qu_unit_name_plural,
|
p.name AS product_name,
|
||||||
p.name AS product_name,
|
(SELECT name FROM product_groups WHERE product_groups.id = product_group_id) AS product_group_name,
|
||||||
(SELECT name
|
EXISTS(SELECT * FROM shopping_list WHERE shopping_list.product_id = sc.product_id) AS on_shopping_list,
|
||||||
FROM product_groups
|
sc.factor_purchase_amount AS factor_purchase_amount,
|
||||||
WHERE product_groups.id = product_group_id) AS product_group_name,
|
(SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name,
|
||||||
EXISTS(SELECT * FROM shopping_list WHERE shopping_list.product_id = stock_current.product_id) AS on_shopping_list,
|
(SELECT name_plural FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name_plural,
|
||||||
stock_current.factor_purchase_amount AS factor_purchase_amount,
|
sc.is_aggregated_amount,
|
||||||
(SELECT name FROM quantity_units WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name,
|
sc.amount_opened_aggregated
|
||||||
(SELECT name_plural
|
|
||||||
FROM quantity_units
|
|
||||||
WHERE quantity_units.id = p.qu_id_purchase) AS qu_purchase_unit_name_plural,
|
|
||||||
is_aggregated_amount,
|
|
||||||
amount_opened_aggregated
|
|
||||||
FROM (
|
FROM (
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM stock_current
|
FROM stock_current
|
||||||
WHERE best_before_date IS NOT NULL
|
WHERE best_before_date IS NOT NULL
|
||||||
UNION
|
UNION
|
||||||
SELECT id, 0, 0, 0, 0, null, 0, 0, 0
|
SELECT id, 0, 0, 0, 0, null, 0, 0, 0
|
||||||
FROM stock_missing_products
|
FROM stock_missing_products
|
||||||
WHERE id NOT IN (SELECT product_id FROM stock_current)
|
WHERE id NOT IN (SELECT product_id FROM stock_current)
|
||||||
) AS stock_current
|
) sc
|
||||||
LEFT JOIN products p ON stock_current.product_id = p.id;
|
LEFT JOIN products p
|
||||||
|
ON sc.product_id = p.id;
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,29 @@
|
||||||
DROP INDEX IF EXISTS _index_products_parents;
|
CREATE INDEX ix_products_performance1 ON products (
|
||||||
DROP INDEX IF EXISTS _index_stock_products_amount;
|
parent_product_id
|
||||||
|
);
|
||||||
|
|
||||||
CREATE INDEX _index_products_parents ON products (parent_product_id);
|
CREATE INDEX ix_products_performance2 ON products (
|
||||||
CREATE INDEX _index_stock_products_amount ON stock (product_id, open, best_before_date, amount);
|
CASE WHEN parent_product_id IS NULL THEN id ELSE parent_product_id END,
|
||||||
|
active
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX ix_stock_performance1 ON stock (
|
||||||
|
product_id,
|
||||||
|
open,
|
||||||
|
best_before_date,
|
||||||
|
amount
|
||||||
|
);
|
||||||
|
|
||||||
DROP INDEX IF EXISTS _index_product_parents_2;
|
|
||||||
CREATE INDEX _index_product_parents_2
|
|
||||||
ON products (
|
|
||||||
/* see products_resolved */
|
|
||||||
CASE WHEN parent_product_id IS NULL THEN id ELSE parent_product_id END,
|
|
||||||
active
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Old version is in 0103.sql
|
|
||||||
*/
|
|
||||||
DROP VIEW products_resolved;
|
DROP VIEW products_resolved;
|
||||||
CREATE VIEW products_resolved
|
CREATE VIEW products_resolved
|
||||||
AS
|
AS
|
||||||
SELECT CASE
|
SELECT
|
||||||
WHEN p.parent_product_id IS NULL
|
CASE
|
||||||
THEN p.id
|
WHEN p.parent_product_id IS NULL THEN
|
||||||
ELSE
|
p.id
|
||||||
p.parent_product_id
|
ELSE
|
||||||
END
|
p.parent_product_id
|
||||||
AS parent_product_id,
|
END AS parent_product_id,
|
||||||
p.id as sub_product_id
|
p.id as sub_product_id
|
||||||
FROM products p WHERE active = 1;
|
FROM products p
|
||||||
|
WHERE p.active = 1;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ class StockService extends BaseService
|
||||||
public function GetCurrentStockOverview()
|
public function GetCurrentStockOverview()
|
||||||
{
|
{
|
||||||
if (!GROCY_FEATURE_SETTING_STOCK_COUNT_OPENED_PRODUCTS_AGAINST_MINIMUM_STOCK_AMOUNT) {
|
if (!GROCY_FEATURE_SETTING_STOCK_COUNT_OPENED_PRODUCTS_AGAINST_MINIMUM_STOCK_AMOUNT) {
|
||||||
return $this->getDatabase()->stock_current_overview();
|
return $this->getDatabase()->uihelper_stock_current_overview();
|
||||||
} else {
|
} else {
|
||||||
return $this->getDatabase()->stock_current_overview_opened();
|
return $this->getDatabase()->uihelper_stock_current_overview_including_opened();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user