diff --git a/jon/db/add_views.sql b/jon/db/add_views.sql index a6c0834..63b898c 100644 --- a/jon/db/add_views.sql +++ b/jon/db/add_views.sql @@ -58,3 +58,19 @@ FROM garfield.inventory_items ) m USING (item_id) ORDER BY inventory_items.name; +-- How many *other* active inventory lines exist with the same barcode in the same location that are newer? + +CREATE TEMPORARY VIEW more_recent_inventory_lines_with_same_barcode AS +SELECT + a.item_id, + -- It's important not to count(*) here because item_id is NULL + -- when no other inventory lines exist. + count(b.item_id) AS other_lines_count +FROM garfield.inventory_items AS a +LEFT JOIN garfield.inventory_items AS b + ON a.item_barcode = b.item_barcode + AND a.item_id != b.item_id + AND a.location = b.location + AND b.available + AND b.bought > a.bought +GROUP BY a.item_id; diff --git a/jon/db/get_inventory_overview.sql b/jon/db/get_inventory_overview.sql index fe2a44f..6c03a21 100644 --- a/jon/db/get_inventory_overview.sql +++ b/jon/db/get_inventory_overview.sql @@ -1,6 +1,7 @@ SELECT * FROM all_inventory_item_overview +LEFT JOIN more_recent_inventory_lines_with_same_barcode USING (item_id) WHERE (%(location_id)s IS NULL OR location = %(location_id)s) AND available ORDER BY diff --git a/jon/templates/inventory/index.html b/jon/templates/inventory/index.html index f87e979..ce6164e 100644 --- a/jon/templates/inventory/index.html +++ b/jon/templates/inventory/index.html @@ -3,6 +3,7 @@ {% block content %} + @@ -17,6 +18,10 @@ {% for item in items %} +
Stat ID Barcode Name
+ {% if item.units_left == 0 %}🅾️{% endif %} + {% if item.other_lines_count != 0 %}🔄{% endif %} + {{ item.item_id }} {{ item.item_barcode }} {{ item.name }}