From 2a51eec1c89a992e65df5f0b24a7282ada3a303b Mon Sep 17 00:00:00 2001 From: Paul Brinkmeier Date: Tue, 22 Aug 2023 01:58:50 +0200 Subject: [PATCH] Add unitsLeft field to SearchResult type --- frontend/Entry.elm | 2 ++ jon/db/add_views.sql | 1 + jon/db/search_items.sql | 9 ++++----- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/Entry.elm b/frontend/Entry.elm index bbd7a93..434f09b 100644 --- a/frontend/Entry.elm +++ b/frontend/Entry.elm @@ -38,6 +38,7 @@ type alias SearchResult = , groupName : String , groupId : Int , taxGroupId : Int + , unitsLeft : Int } searchResultDecoder = @@ -53,6 +54,7 @@ searchResultDecoder = |> P.required "group_name" D.string |> P.required "group_id" D.int |> P.required "tax_group_id" D.int + |> P.required "units_left" D.int type alias Location = { id : Int diff --git a/jon/db/add_views.sql b/jon/db/add_views.sql index 684fde9..a6c0834 100644 --- a/jon/db/add_views.sql +++ b/jon/db/add_views.sql @@ -11,6 +11,7 @@ SELECT inventory_items.available, inventory_items.item_group, inventory_items.location, + inventory_items.tax_group, inventory_item_groups.group_name, COALESCE(b.sales::numeric, 0::numeric) - COALESCE(cancel.count::numeric, 0::numeric) AS sales, inventory_items.sales_units::numeric - COALESCE(b.sales, 0::bigint)::numeric + COALESCE(c.delta, 0::numeric) + COALESCE(cancel.count::numeric, 0::numeric) AS units_left, diff --git a/jon/db/search_items.sql b/jon/db/search_items.sql index 62a8216..58da8d5 100644 --- a/jon/db/search_items.sql +++ b/jon/db/search_items.sql @@ -6,13 +6,12 @@ SELECT sales_units, available, location_name, - location_id, + location as location_id, group_name, item_group AS group_id, - tax_group AS tax_group_id -FROM garfield.inventory_items -LEFT JOIN garfield.locations ON location = location_id -LEFT JOIN garfield.inventory_item_groups ON item_group = group_id + tax_group AS tax_group_id, + units_left :: integer +FROM all_inventory_item_overview WHERE (%(location_id)s IS NULL OR location = %(location_id)s) AND (name ILIKE CONCAT('%%', %(search_term)s, '%%') OR item_barcode = %(search_term)s) ORDER BY bought DESC