First draft for printable location content sheets (references #341)

This commit is contained in:
Bernd Bestel
2019-08-10 16:34:29 +02:00
parent d6e9dc1b59
commit 28716ed96c
6 changed files with 91 additions and 0 deletions

12
migrations/0079.sql Normal file
View File

@@ -0,0 +1,12 @@
CREATE VIEW stock_current_location_content
AS
SELECT
IFNULL(s.location_id, p.location_id) AS location_id,
s.product_id,
SUM(s.amount) AS amount,
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
FROM stock s
JOIN products p
ON s.product_id = p.id
GROUP BY IFNULL(s.location_id, p.location_id), s.product_id;