From e1406f70abeb3ba96fb4bca5f78c23d429e2f635 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 8 Dec 2023 11:37:07 -0500 Subject: [PATCH] pull target based on modified channel --- sql/get_cust.pg.sql | 10 ++++++++++ sql/get_guidance_dseg.pg.sql | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sql/get_cust.pg.sql b/sql/get_cust.pg.sql index e214da3..a194a2b 100644 --- a/sql/get_cust.pg.sql +++ b/sql/get_cust.pg.sql @@ -5,6 +5,7 @@ LANGUAGE plpgsql AS $func$ DECLARE _chan text; + _chantp text; _bill_class text; _ship_class text; _bill_dba text; @@ -47,6 +48,14 @@ BEGIN INTO _chan; + SELECT + CASE WHEN SUBSTRING(_bill_class,2,3) = 'DIS' + THEN CASE WHEN SUBSTRING(_ship_class,2,3) = 'DIS' THEN 'DISTRIBUTOR' ELSE 'DISTRIB DROP SHIP' END + ELSE 'DIRECT' + END + INTO + _chantp; + SELECT CASE WHEN _chan = 'DRP' THEN _ship_dba ELSE _bill_dba END INTO @@ -56,6 +65,7 @@ BEGIN jsonb_build_object( 'cust',_cust, 'chan',_chan, + 'chantp',_chantp, 'curr',_bill_curr, 'fxrate',_bill_rate, 'bill_dba',_bill_dba, diff --git a/sql/get_guidance_dseg.pg.sql b/sql/get_guidance_dseg.pg.sql index 572b7c3..55f59f8 100644 --- a/sql/get_guidance_dseg.pg.sql +++ b/sql/get_guidance_dseg.pg.sql @@ -181,7 +181,8 @@ BEGIN mold = _stlc AND season = _seas AND data_segment = _v0ds - AND region = 'ALL'; + AND region = 'ALL' + AND chan = _customer->'customer'->>'chantp'; ----------------target pricing------------------------------ SELECT jsonb_build_object( @@ -198,7 +199,8 @@ BEGIN mold = _stlc AND season = _seas AND data_segment = _dseg - AND region = 'ALL'; + AND region = 'ALL' + AND chan = _customer->'customer'->>'chantp'; --RAISE NOTICE 'target: %', jsonb_pretty(_targ); _pricing := (COALESCE(_v0tp,'{}'::jsonb)||COALESCE(_v1tp,'{}'::jsonb));