diff --git a/application/__pycache__/postsqldb.cpython-313.pyc b/application/__pycache__/postsqldb.cpython-313.pyc index 8c75ecb..6664be4 100644 Binary files a/application/__pycache__/postsqldb.cpython-313.pyc and b/application/__pycache__/postsqldb.cpython-313.pyc differ diff --git a/application/postsqldb.py b/application/postsqldb.py index dae0f88..ea0fbde 100644 --- a/application/postsqldb.py +++ b/application/postsqldb.py @@ -560,7 +560,7 @@ class RecipesTable: @dataclass class ItemPayload: - uuid: str + item_uuid: str rp_id: int item_type: str item_name:str @@ -571,7 +571,7 @@ class RecipesTable: def payload(self): return ( - self.uuid, + self.item_uuid, self.rp_id, self.item_type, self.item_name, diff --git a/application/recipes/__pycache__/recipes_api.cpython-313.pyc b/application/recipes/__pycache__/recipes_api.cpython-313.pyc index b1810c3..ee5a6fa 100644 Binary files a/application/recipes/__pycache__/recipes_api.cpython-313.pyc and b/application/recipes/__pycache__/recipes_api.cpython-313.pyc differ diff --git a/application/recipes/recipes_api.py b/application/recipes/recipes_api.py index e1ee10e..8157925 100644 --- a/application/recipes/recipes_api.py +++ b/application/recipes/recipes_api.py @@ -110,7 +110,7 @@ def postCustomItem(): site_name = session['selected_site'] rp_id = int(request.get_json()['rp_id']) recipe_item = db.RecipesTable.ItemPayload( - uuid=f"%{int(request.get_json()['rp_id'])}{database_recipes.getUUID(6)}%", + item_uuid=None, rp_id=rp_id, item_type=request.get_json()['item_type'], item_name=request.get_json()['item_name'], @@ -133,7 +133,7 @@ def postSKUItem(): site_name = session['selected_site'] item = database_recipes.getItemData(site_name, (item_id, )) recipe_item = db.RecipesTable.ItemPayload( - uuid=item['barcode'], + item_uuid=item['item_uuid'], rp_id=recipe_id, item_type='sku', item_name=item['item_name'], diff --git a/application/recipes/sql/getItemData.sql b/application/recipes/sql/getItemData.sql index ca66227..94029c3 100644 --- a/application/recipes/sql/getItemData.sql +++ b/application/recipes/sql/getItemData.sql @@ -1,4 +1,4 @@ -SELECT item.id, item.barcode, item.item_name, item.links, item_info.uom_quantity, item_info.uom +SELECT item.id, item.barcode, item.item_name, item.links, item_info.uom_quantity, item_info.uom, item.item_uuid FROM %%site_name%%_items item LEFT JOIN %%site_name%%_item_info item_info ON item_info.id = item.item_info_id WHERE item.id = %s; \ No newline at end of file diff --git a/application/recipes/sql/getRecipes.sql b/application/recipes/sql/getRecipes.sql index 1703d1e..30cc811 100644 --- a/application/recipes/sql/getRecipes.sql +++ b/application/recipes/sql/getRecipes.sql @@ -1,3 +1,17 @@ +WITH sum_cte AS ( + SELECT mi.item_uuid, SUM(mil.quantity_on_hand)::FLOAT8 AS total_sum + FROM %%site_name%%_item_locations mil + JOIN %%site_name%%_items mi ON mil.part_id = mi.id + GROUP BY mi.id + ), + cte_recipe_items AS ( + SELECT rp_item.*, COALESCE(sum_cte.total_sum, 0) as quantity_on_hand FROM %%site_name%%_recipe_items rp_item + LEFT JOIN sum_cte ON sum_cte.item_uuid = rp_item.item_uuid + ) + + + SELECT *, - (SELECT COALESCE(array_agg(row_to_json(g)), '{}') FROM %%site_name%%_recipe_items g WHERE rp_id = %%site_name%%_recipes.id) AS rp_items - FROM %%site_name%%_recipes LIMIT %s OFFSET %s; \ No newline at end of file + (SELECT COALESCE(array_agg(row_to_json(g)), '{}') FROM cte_recipe_items g WHERE g.rp_id = recipes.id) AS rp_items +FROM %%site_name%%_recipes recipes +LIMIT %s OFFSET %s; \ No newline at end of file diff --git a/application/recipes/static/js/recipesListHandler.js b/application/recipes/static/js/recipesListHandler.js index 4bc06a2..cda669f 100644 --- a/application/recipes/static/js/recipesListHandler.js +++ b/application/recipes/static/js/recipesListHandler.js @@ -70,10 +70,27 @@ async function replenishRecipesTable() { let table_body = document.createElement('tbody') for(let i = 0; i < recipes.length; i++){ + console.log(recipes[i]) + + + + let rp_items = recipes[i].rp_items + let rp_items_count = 0 + let rp_items_availble = 0 + + for(let y = 0; y < rp_items.length; y++){ + if (rp_items[y].quantity_on_hand >= rp_items[y].qty && rp_items[y].item_type == "sku"){ + rp_items_availble = rp_items_availble + 1 + } + if (rp_items[y].item_type == "sku"){ + rp_items_count = rp_items_count + 1 + } + } + let table_row = document.createElement('tr') let nameCell = document.createElement('td') - nameCell.innerHTML = recipes[i].name + nameCell.innerHTML = `${recipes[i].name} ${rp_items_availble}/${rp_items_count}` nameCell.setAttribute('class', 'uk-width-1-4') let descriptionCell = document.createElement('td') descriptionCell.innerHTML = recipes[i].description @@ -113,6 +130,25 @@ async function replenishRecipesCards() { console.log('cards') for(let i=0; i < recipes.length; i++){ + + let rp_items = recipes[i].rp_items + let rp_items_count = 0 + let rp_items_availble = 0 + let badge_color = 'uk-label-success' + + for(let y = 0; y < rp_items.length; y++){ + if (rp_items[y].quantity_on_hand >= rp_items[y].qty && rp_items[y].item_type == "sku"){ + rp_items_availble = rp_items_availble + 1 + } + if (rp_items[y].item_type == "sku"){ + rp_items_count = rp_items_count + 1 + } + } + + if (rp_items_availble < rp_items_count){ + badge_color = 'uk-label-danger' + } + let main_div = document.createElement('div') main_div.setAttribute('class', 'uk-card uk-card-default uk-card-small uk-margin') @@ -125,7 +161,7 @@ async function replenishRecipesCards() { let title_div = document.createElement('div') title_div.setAttribute('class', '') - title_div.innerHTML = ` + title_div.innerHTML = `