2020-03-12 14:20:09 -04:00
|
|
|
BEGIN;
|
|
|
|
|
|
|
|
--SELECT dsm, director, quota_rep_descr, billto_group, shipto_group, sum(value_usd ), count(*) from rlarp.osm_pool where order_season = 2021 group by dsm, director, quota_rep_descr, billto_group, shipto_group;
|
2020-03-12 14:19:46 -04:00
|
|
|
|
|
|
|
UPDATE
|
|
|
|
rlarp.osm_pool o
|
|
|
|
SET
|
|
|
|
chan = CASE SUBSTRING(b.bvclas,2,3)
|
|
|
|
--if the bill to class is ditsributor, then it's either warehouse or drop
|
|
|
|
WHEN 'DIS' THEN
|
|
|
|
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
|
|
|
CASE SUBSTRING(s.bvclas,2,3)
|
|
|
|
WHEN 'DIS' THEN 'WHS'
|
|
|
|
ELSE 'DRP'
|
|
|
|
END
|
|
|
|
--CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END
|
|
|
|
--everything else does not involve a distributor and is considered direct
|
|
|
|
ELSE 'DIR'
|
|
|
|
END,
|
|
|
|
chansub = CASE SUBSTRING(b.bvclas,2,3)
|
|
|
|
WHEN 'DIS' THEN
|
|
|
|
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
|
|
|
CASE SUBSTRING(s.bvclas,2,3)
|
|
|
|
WHEN 'DIS' THEN 'WHS'
|
|
|
|
ELSE CASE SUBSTRING(s.bvclas,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
|
|
|
|
END
|
|
|
|
WHEN 'MAS' THEN 'RMN'
|
|
|
|
WHEN 'NAT' THEN 'RMN'
|
|
|
|
ELSE CASE SUBSTRING(s.bvclas,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
|
|
|
|
END,
|
|
|
|
dsm = RTRIM(
|
|
|
|
--retail items go to currep, or if null go to 90005
|
|
|
|
CASE WHEN o.segm IN ('Retail') THEN
|
|
|
|
CASE WHEN b.bvctry = 'CAN' THEN
|
|
|
|
--Rachel Bowman
|
|
|
|
'50300'
|
|
|
|
ELSE
|
|
|
|
--select customers go to select reps
|
|
|
|
CASE CASE b.bvadr6 WHEN '' THEN b.bvname ELSE b.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 SUBSTRING(o.ming_descr,1,3) = 'B52' THEN
|
|
|
|
'PW'
|
|
|
|
--gdir, ndir go to bill-to rep
|
|
|
|
ELSE
|
|
|
|
CASE WHEN b.bvclas IN ('GDIR','NDIR') THEN
|
|
|
|
b.bvsalm
|
|
|
|
ELSE
|
|
|
|
s.bvsalm
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END
|
|
|
|
),
|
|
|
|
billto_group = CASE b.bvadr6 WHEN '' THEN b.bvname ELSE b.bvadr6 END,
|
|
|
|
shipto_group = CASE s.bvadr6 WHEN '' THEN s.bvname ELSE s.bvadr6 END
|
|
|
|
FROM
|
|
|
|
lgdat.cust b,
|
|
|
|
lgdat.cust s
|
|
|
|
WHERE
|
|
|
|
b.bvcust = rtrim(substring(o.bill_cust_descr,1,8))
|
|
|
|
AND s.bvcust = rtrim(substring(o.ship_cust_descr,1,8));
|
|
|
|
|
2020-03-12 14:20:09 -04:00
|
|
|
BEGIN;
|
|
|
|
|
|
|
|
UPDATE
|
|
|
|
rlarp.osm_pool o
|
|
|
|
SET
|
|
|
|
quota_rep_descr = c.a30
|
|
|
|
,director = COALESCE(Q.DIR,'Other')
|
|
|
|
FROM
|
|
|
|
lgdat.code c
|
|
|
|
,rlarp.qrh q
|
|
|
|
WHERE
|
|
|
|
LTRIM(RTRIM(c.a9)) = o.dsm
|
|
|
|
and c.a2 = 'MM'
|
|
|
|
AND q.qr = LTRIM(RTRIM(c.a9));
|
|
|
|
|
|
|
|
|
|
|
|
ROLLBACK;
|