adjust rep source to rlarp.repc, adjust join logic to match current osm definition
This commit is contained in:
parent
480adef789
commit
12c17b0be6
@ -47,10 +47,10 @@ target AS (select $$replace_request$$::json def)
|
|||||||
,('12 - May',12,5,0)
|
,('12 - May',12,5,0)
|
||||||
) x(m,s,cal,yr)
|
) x(m,s,cal,yr)
|
||||||
)
|
)
|
||||||
,SEG AS (
|
,seg AS (
|
||||||
SELECT
|
SELECT
|
||||||
x.GLEC
|
x.GLEC glec
|
||||||
,x.SEGM
|
,x.SEGM segm
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
VALUES
|
VALUES
|
||||||
@ -71,19 +71,6 @@ target AS (select $$replace_request$$::json def)
|
|||||||
('9TO','Other')
|
('9TO','Other')
|
||||||
) X(GLEC, SEGM)
|
) X(GLEC, SEGM)
|
||||||
)
|
)
|
||||||
,REPC AS (
|
|
||||||
SELECT
|
|
||||||
LTRIM(RTRIM(C.A9)) RCODE
|
|
||||||
,c.a30 rname
|
|
||||||
,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP
|
|
||||||
,COALESCE(Q.DIR,'Other') DIRECTOR
|
|
||||||
FROM
|
|
||||||
LGDAT.CODE C
|
|
||||||
LEFT OUTER JOIN RLARP.QRH Q ON
|
|
||||||
Q.QR = LTRIM(RTRIM(C.A9))
|
|
||||||
WHERE
|
|
||||||
C.A2 = 'MM'
|
|
||||||
)
|
|
||||||
,copr AS (
|
,copr AS (
|
||||||
SELECT
|
SELECT
|
||||||
LTRIM(RTRIM(A9)) AS COMP,
|
LTRIM(RTRIM(A9)) AS COMP,
|
||||||
@ -286,9 +273,9 @@ SELECT
|
|||||||
,COALESCE(b.terms,bc.bvterm) terms
|
,COALESCE(b.terms,bc.bvterm) terms
|
||||||
,b.bill_cust_descr
|
,b.bill_cust_descr
|
||||||
,b.ship_cust_descr
|
,b.ship_cust_descr
|
||||||
,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm
|
,(SELECT max(rcode) FROM rlarp.repc WHERE repp ~ (log.doc->'scenario'->>'quota_rep_descr')) dsm
|
||||||
,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr
|
,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr
|
||||||
,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director
|
,(SELECT max(director) FROM rlarp.repc WHERE repp ~ (log.doc->'scenario'->>'quota_rep_descr')) director
|
||||||
,COALESCE(CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END,b.bill_cust_descr) billto_group
|
,COALESCE(CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END,b.bill_cust_descr) billto_group
|
||||||
,COALESCE(CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE sc.BVADR6 END,b.ship_cust_descr) shipto_group
|
,COALESCE(CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE sc.BVADR6 END,b.ship_cust_descr) shipto_group
|
||||||
,CASE SUBSTRING(bc.bvclas,2,3)
|
,CASE SUBSTRING(bc.bvclas,2,3)
|
||||||
@ -364,52 +351,20 @@ FROM
|
|||||||
BC.BVCUST = rtrim(substring(b.bill_cust_descr,1,8))
|
BC.BVCUST = rtrim(substring(b.bill_cust_descr,1,8))
|
||||||
LEFT OUTER JOIN LGDAT.CUST SC ON
|
LEFT OUTER JOIN LGDAT.CUST SC ON
|
||||||
SC.BVCUST = rtrim(substring(b.ship_cust_descr,1,8))
|
SC.BVCUST = rtrim(substring(b.ship_cust_descr,1,8))
|
||||||
LEFT OUTER JOIN REPC ON
|
LEFT OUTER JOIN rlarp.repc r ON
|
||||||
REPC.RCODE = RTRIM(
|
r.rcode = CASE WHEN i.ming = 'B52' THEN 'PW' ELSE
|
||||||
--retail items go to currep, or if null go to 90005
|
--if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available
|
||||||
CASE WHEN i.glec IN ('1RE','1CU') THEN
|
CASE WHEN COALESCE(seg.segm,'') = 'Retail' AND COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = bc.bvcust),'') <> ''
|
||||||
CASE WHEN bc.bvctry = 'CAN' THEN
|
THEN
|
||||||
--Rachel Bowman
|
(SELECT currep FROM lgpgm.usrcust where cucust = bc.bvcust)
|
||||||
'50300'
|
--default logic
|
||||||
ELSE
|
|
||||||
--select customers go to select reps
|
|
||||||
CASE CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END
|
|
||||||
------Alecia Latini-------------------------------
|
|
||||||
WHEN 'DO IT BEST' THEN '90006'
|
|
||||||
WHEN 'ACE HARDWARE' THEN '90006'
|
|
||||||
WHEN 'ALDI' THEN '90006'
|
|
||||||
WHEN 'AMAZON.COM' THEN '90006'
|
|
||||||
WHEN 'GARDEN RIDGE CORP' THEN '90006' --AKA "At Home"
|
|
||||||
WHEN 'TRUE VALUE' THEN '90006'
|
|
||||||
WHEN 'WAYFAIR' THEN '90006'
|
|
||||||
WHEN 'GRIFFIN' THEN '90006'
|
|
||||||
WHEN 'WAL-MART' THEN '90006'
|
|
||||||
------Tony Landino--------------------------------
|
|
||||||
WHEN 'THE HOME DEPOT' THEN '50802'
|
|
||||||
WHEN 'FRED MEYER' THEN '50802'
|
|
||||||
WHEN 'MENARDS' THEN '50802'
|
|
||||||
WHEN 'KROGER' THEN '50802'
|
|
||||||
WHEN 'OCEAN STATE JOBBERS' THEN '50802'
|
|
||||||
WHEN 'AURORA WHOLESALE' THEN '50802'
|
|
||||||
WHEN 'LEON KORRAL' THEN '50802'
|
|
||||||
--all other retail goes to Doran Marable-----------
|
|
||||||
ELSE '50200'
|
|
||||||
END
|
|
||||||
END
|
|
||||||
--minor group b52 goes to dedicated rep
|
|
||||||
ELSE
|
|
||||||
CASE WHEN i.MING = 'B52' THEN
|
|
||||||
'PW'
|
|
||||||
--gdir, ndir go to bill-to rep
|
|
||||||
ELSE
|
|
||||||
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
|
|
||||||
bc.bvsalm
|
|
||||||
ELSE
|
ELSE
|
||||||
sc.bvsalm
|
CASE SUBSTR(bc.bvclas,2,3)
|
||||||
END
|
WHEN 'DIS' THEN sc.bvsalm
|
||||||
|
ELSE bc.bvsalm
|
||||||
|
END
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
)
|
|
||||||
LEFT OUTER JOIN lgdat.icstm im ON
|
LEFT OUTER JOIN lgdat.icstm im ON
|
||||||
im.cgpart = b.part
|
im.cgpart = b.part
|
||||||
AND im.cgplnt = i.dplt
|
AND im.cgplnt = i.dplt
|
||||||
|
Loading…
Reference in New Issue
Block a user