From 3675b8541f1ad22d8cd4658344d85cbef61b0f73 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 25 Aug 2025 21:05:13 -0400 Subject: [PATCH] introduce a new key-value pair in the ui json that indicates level of visibility to various roles --- example_usage.pg.sql | 38 +++++++++++++++++----------------- procs/single_price_call.ms.sql | 15 +++++++++++++- procs/single_price_call.pg.sql | 11 ++++++++++ 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/example_usage.pg.sql b/example_usage.pg.sql index 9bccc47..4063aae 100644 --- a/example_usage.pg.sql +++ b/example_usage.pg.sql @@ -1,12 +1,12 @@ --- SELECT --- ui_json->'details' --- FROM pricequote.single_price_call( --- 'FARM0001', --- 'KEYB0001', --- 'HCA10000B661100', --- 'v1:T..CSE..D', --- 50000 --- ) f; + SELECT + ui_json->'details' + FROM pricequote.single_price_call( + 'FARM0001', + 'KEYB0001', + 'HCA10000B661100', + 'v1:T..CSE..D', + 50000 + ) f; -- -- SELECT -- ui_json->'details' @@ -30,16 +30,16 @@ -- -- SELECT * FROM pricequote.lastpricedetail l WHERE customer = 'HYBELS' AND l.partgroup = 'HZP3E100'; -- --- SELECT --- pc.expl --- FROM --- pricequote.live_quotes --- LEFT JOIN LATERAL pricequote.single_price_call( --- billto, shipto, part, v1ds, units_each --- ) pc ON TRUE --- WHERE --- qid = 113173 --- AND qrn = 32; + SELECT + pc.expl, pc.hist + FROM + pricequote.live_quotes + LEFT JOIN LATERAL pricequote.single_price_call( + billto, shipto, part, v1ds, units_each + ) pc ON TRUE + WHERE + qid = 113800 + AND qrn = 4; create table pricequote.target_prices_base as ( with diff --git a/procs/single_price_call.ms.sql b/procs/single_price_call.ms.sql index 5a996ab..b572d3f 100644 --- a/procs/single_price_call.ms.sql +++ b/procs/single_price_call.ms.sql @@ -445,11 +445,13 @@ BEGIN ( SELECT panel.label, + panel.detailLevel, JSON_QUERY(panel.details) AS details FROM ( -- History Panel SELECT 'History' AS label, + 10 as detailLevel, ( SELECT ----------------------label------------------------------------------------ @@ -465,6 +467,8 @@ BEGIN END ELSE 'No Recent' END AS label, + ----------------------detail----------------------------------------------- + 10 AS detailLevel, ----------------------value------------------------------------------------ ISNULL(q.last_price, 0) AS value, ----------------------type------------------------------------------------- @@ -505,25 +509,30 @@ BEGIN -- List Panel SELECT 'List' AS label, + 10 AS detailLevel, ( SELECT COALESCE('Code: ' + q.listcode,'No List') AS label, + 10 AS detailLevel, COALESCE(q.listprice,0) AS value, 'currency' AS type, COALESCE('List Min Qty: ' + format(q.list_from,'#,###'),'') + CASE WHEN q.list_relevance = '' THEN '' ELSE ' (' + q.list_relevance + ')' END AS note FOR JSON PATH - ) + ) AS details UNION ALL -- Target Support Panel SELECT 'Target Calculation' AS label, + 10 AS detailLevel, ( SELECT * FROM ( SELECT ----------------------label------------------------------------------------ CASE WHEN value <> '' THEN replace(RTRIM(SUBSTRING(value,1,18)),'Anchor:', '') ELSE 'No Target' END AS label, + ----------------------detailLevel------------------------------------------ + 10 AS detailLevel, ----------------------value------------------------------------------------ CASE WHEN value <> '' THEN TRY_CAST(SUBSTRING(value,23,7) AS NUMERIC(20,5)) @@ -548,6 +557,8 @@ BEGIN SELECT ----------------------label------------------------------------------------ 'Target' AS label, + ----------------------detailLevel------------------------------------------ + 10 AS detailLevel, ----------------------value------------------------------------------------ tprice AS value, ----------------------type------------------------------------------------- @@ -564,9 +575,11 @@ BEGIN -- Guidance Panel SELECT 'Guidance' AS label, + 10 AS detailLevel, ( SELECT 'Price' AS label, + 10 AS detailLevel, COALESCE(q.guidance_price,0) AS value, 'currency' AS type, q.guidance_reason AS note diff --git a/procs/single_price_call.pg.sql b/procs/single_price_call.pg.sql index 0161be2..c3d7d54 100644 --- a/procs/single_price_call.pg.sql +++ b/procs/single_price_call.pg.sql @@ -447,9 +447,11 @@ BEGIN ------------------------------------------ jsonb_build_object( 'label', 'History', + 10, 'detailLevel', 'details', jsonb_build_array( jsonb_build_object( 'label', CASE WHEN _last_price IS NOT NULL THEN 'Last Sale: ' || _last_date ELSE 'No Recent' END, + 'detailLevel', 10, 'value', COALESCE(_last_price,0), 'type', 'currency', 'note', CASE WHEN _last_price IS NOT NULL THEN @@ -467,6 +469,7 @@ BEGIN ||CASE WHEN COALESCE(_last_premium,1) <> 1 THEN COALESCE(jsonb_build_array(jsonb_build_object( 'label','Price Difference', + 'detailLevel',10, 'value', _last_premium, 'type','percent', 'note', _last_premium_method @@ -477,6 +480,7 @@ BEGIN ||CASE WHEN COALESCE(_last_premium,1) <> 1 THEN COALESCE(jsonb_build_array(jsonb_build_object( 'label','Adjusted Price', + 'detailLevel',10, 'value', _last_price_norm, 'type','currency', 'note','normalized to ' || _v1ds @@ -490,9 +494,11 @@ BEGIN ------------------------------------------ jsonb_build_object( 'label', 'List', + 'detailLevel',10, 'details', jsonb_build_array( jsonb_build_object( 'label', 'List:' || COALESCE(_list_code, ''), + 'detailLevel',10, 'value', _list_price, 'type', 'currency', 'note', _list_relevance @@ -504,6 +510,7 @@ BEGIN ------------------------------------------ jsonb_build_object( 'label', 'Target Calculation', + 'detailLevel',10, 'details', -- jsonb_build_array( ( @@ -512,6 +519,8 @@ BEGIN jsonb_build_object( ----------------------label------------------------------------------------ 'label',CASE WHEN value <> '' THEN RTRIM(SUBSTRING(value,1,18)) ELSE 'No Target' END, + ----------------------detailLevel------------------------------------------ + 'detailLevel',10, ----------------------value------------------------------------------------ 'value',CASE WHEN value <> '' THEN SUBSTRING(value,23,7)::NUMERIC(20,5) + @@ -545,9 +554,11 @@ BEGIN ------------------------------------------ jsonb_build_object( 'label', 'Guidance', + 'detailLevel',10, 'details', jsonb_build_array( jsonb_build_object( 'label', 'Price', + 'detailLevel',10, 'value', COALESCE(_guidance_price,0), 'type', 'currency', 'note', COALESCE(_guidance_reason,'')