From a5acb798b46bc29aaa05c3d678ac0a73cbda5585 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 13 Nov 2023 12:59:45 -0500 Subject: [PATCH] include pallet quantity in product info --- sql/get_guidance_dseg.pg.sql | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/sql/get_guidance_dseg.pg.sql b/sql/get_guidance_dseg.pg.sql index c33d535..a1b0a9b 100644 --- a/sql/get_guidance_dseg.pg.sql +++ b/sql/get_guidance_dseg.pg.sql @@ -13,6 +13,8 @@ DECLARE _prem jsonb; _mold text; _item text; + _unti text; + _pltq numeric; _cust text; _curr text; _rate numeric; @@ -62,11 +64,13 @@ BEGIN ,item ,idxk ,prefer + ,(SELECT unti FROM "CMS.CUSLG".itemm WHERE item = best.item) INTO _mold ,_item ,_iidx ,_itemr + ,_unti FROM ( SELECT @@ -94,17 +98,37 @@ BEGIN ORDER BY prefer DESC LIMIT 1; - _product := jsonb_build_object( - 'product', + _product := jsonb_build_object( 'mold',_mold ,'item',_item ,'itemrel',_itemr ,'iidx',_iidx - ) - ); + ,'unti',_unti + ); --RAISE NOTICE 'item data %', jsonb_pretty(_product||_input); + ----------------pallet quantity----------------------------- + SELECT + ROUND(uom.nm/uom.dm,1) pltq + INTO + _pltq + FROM + ( + SELECT + jsonb_agg(row_to_json(d)::jsonb) jdoc + FROM + ( + select distinct + _item partn + ,'PLT' fu + ,_unti tu + ) d + ) c + JOIN LATERAL rlarp.uom_array(c.jdoc) uom ON TRUE; + + _product := jsonb_build_object('product',_product||jsonb_build_object('pltq',_pltq)); + ----------------channel------------------------------------- SELECT rlarp.channel_code(_bill, _ship) INTO _chan;