diff --git a/new_targets/procs/single_price_call.pg.sql b/new_targets/procs/single_price_call.pg.sql index 9823536..debe7e7 100644 --- a/new_targets/procs/single_price_call.pg.sql +++ b/new_targets/procs/single_price_call.pg.sql @@ -45,8 +45,10 @@ DECLARE _list_code TEXT; _hist JSONB := '{}'::jsonb; _expl JSONB := '{}'::jsonb; + _this JSONB := '{}'::jsonb; _guidance_price NUMERIC; _guidance_reason TEXT; + _partgroup TEXT; BEGIN ------------------------------------------------------------------ -- Step 1: Resolve customer metadata @@ -80,13 +82,16 @@ BEGIN ELSE bc.plevel END ELSE bc.plevel - END - INTO _pltq, _chan, _tier, _cust, _plevel + END, + i.partgroup + INTO _pltq, _chan, _tier, _cust, _plevel, _partgroup FROM rlarp.cust bc LEFT JOIN rlarp.cust sc ON sc.code = _ship LEFT JOIN "CMS.CUSLG".itemm i ON i.item = _part WHERE bc.code = _bill; + -- RAISE NOTICE 'Step 1: %', _expl; + ------------------------------------------------------------------ -- Step 2: Target price logic ------------------------------------------------------------------ @@ -102,7 +107,7 @@ BEGIN 'tier', TRIM(_tier), 'target math', tp.math ) - INTO _tprice, _expl + INTO _tprice, _this FROM pricequote.target_prices tp WHERE tp.stlc = _stlc AND tp.ds = _v1ds @@ -110,6 +115,12 @@ BEGIN AND tp.tier = _tier AND FLOOR(_vol / NULLIF(_pltq, 0))::int <@ tp.vol; + IF _this IS NOT NULL THEN + _expl := _expl || _this; + END IF; + + -- RAISE NOTICE 'Step 2: %', _expl; + ------------------------------------------------------------------ -- Step 3: Last sale data ------------------------------------------------------------------ @@ -123,7 +134,7 @@ BEGIN _last_price, _last_date, _last_order, _last_quote, _hist FROM pricequote.lastprice lp WHERE lp.customer = _cust - AND lp.partgroup = SUBSTRING(_part, 1, 8); + AND lp.partgroup = _partgroup; _expl := _expl || jsonb_build_object( 'last_price', _last_price, @@ -133,6 +144,8 @@ BEGIN -- 'full_history_________', _hist ); + -- RAISE NOTICE 'Step 3: %', _expl; + ------------------------------------------------------------------ -- Step 4: List price ------------------------------------------------------------------ @@ -157,6 +170,8 @@ BEGIN 'list_code', _list_code ); + -- RAISE NOTICE 'Step 4: %', _expl; + ------------------------------------------------------------------ -- Step 5: Compute guidance price and embed it ------------------------------------------------------------------ @@ -174,6 +189,9 @@ BEGIN 'guidance_reason', _guidance_reason ); + + -- RAISE NOTICE 'Step 5: %', _expl; + ------------------------------------------------------------------ -- Final: Return row ------------------------------------------------------------------ diff --git a/new_targets/scripts/matrix_guidance.pg.sql b/new_targets/scripts/matrix_guidance.pg.sql index 70a445d..176bbfd 100644 --- a/new_targets/scripts/matrix_guidance.pg.sql +++ b/new_targets/scripts/matrix_guidance.pg.sql @@ -22,7 +22,9 @@ CREATE TABLE pricequote.queue ( list_code TEXT, guidance_price NUMERIC, guidance_reason TEXT, - expl JSONB + expl JSONB, + this JSONB, + partgroup TEXT ); @@ -118,7 +120,8 @@ BEGIN ELSE bc.plevel END ELSE bc.plevel - END AS plevel + END AS plevel, + i.partgroup FROM pricequote.queue q JOIN rlarp.cust bc ON bc.code = q.bill LEFT JOIN rlarp.cust sc ON sc.code = q.ship @@ -131,7 +134,8 @@ BEGIN tier = src.tier, cust = src.cust, pltq = src.pltq, - plevel = src.plevel; + plevel = src.plevel, + partgroup = src.partgroup; ----------------------------------------------------------------------- -- Step 3: Apply target prices and embed target metadata