Start working on recipes feature

This commit is contained in:
Bernd Bestel
2018-07-14 18:23:41 +02:00
parent 70e7e630c3
commit d9246b9b42
17 changed files with 624 additions and 4 deletions

38
migrations/0025.sql Normal file
View File

@@ -0,0 +1,38 @@
CREATE TABLE recipes (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT NOT NULL,
description TEXT,
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
);
CREATE TABLE recipes_pos (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
recipe_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
amount INTEGER NOT NULL DEFAULT 0,
note TEXT,
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
);
CREATE VIEW recipes_fulfillment
AS
SELECT
r.id AS recipe_id,
rp.id AS recipe_pos_id,
rp.product_id,
rp.amount AS recipe_amount,
sc.amount AS stock_amount,
CASE WHEN sc.amount >= rp.amount THEN 1 ELSE 0 END AS need_fullfiled
FROM recipes r
LEFT JOIN recipes_pos rp
ON r.id = rp.recipe_id
LEFT JOIN stock_current sc
ON rp.product_id = sc.product_id;
CREATE VIEW recipes_fulfillment_sum
AS
SELECT
rf.recipe_id,
MIN(rf.need_fullfiled) AS need_fullfiled
FROM recipes_fulfillment rf
GROUP BY rf.recipe_id;