diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index 57b71e4..a788cd8 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -443,18 +443,53 @@ SELECT ,b.ship_cust --history cust mix ,sc.bvsalm ship_rep --master data ,sc.bvterr ship_terr --master data - ,b.quota_rep --master data - ,b.account --master data - ,b.shipgrp --master data - ,b.geo --master data - ,b.chan --master data + --quota rep-------------------------------------------- + ,RTRIM( + COALESCE( + --retail items go to currep, or if null go to 90005 + CASE WHEN COALESCE(avgled,awgled) IN ('1RE','1CU') THEN + CASE WHEN bc.bvctry = 'CAN' THEN + --Rachel Bowman + '50300' + ELSE + --retail chain got to Mark Wilkinson + CASE COALESCE(cg.cgrp,bc.bvname) + WHEN 'THE HOME DEPOT' THEN '90005' + WHEN 'DO IT BEST' THEN '90005' + WHEN 'ACE HARDWARE' THEN '90005' + WHEN 'ALDI' THEN '90005' + WHEN 'AMAZON.COM' THEN '90005' + WHEN 'GARDEN RIDGE CORP' THEN '90005' + --all other retail goes to Doran Marable + ELSE '50200' + END + END + ELSE + CASE WHEN COALESCE(avming,awming) = 'B52' THEN + 'PW' + --gdir, ndir go to bill-to rep + ELSE + CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN + bc.bvsalm + ELSE + sc.bvsalm + END + END + END + ,'' + ) + ) quota_rep + ,coalesce(cg.cgrp,bc.bvname) account + ,coalesce(sg.cgrp,sc.bvname) shipgrp + ,coalesce(t.geo,'UNDEFINED') geo + ,coalesce(c.chan,'UNDEFINED') chan ,ad.qzcryc orig_ctry ,ad.qzprov orig_prov ,ad.qzpost orig_post ,sc.bvctry dest_ctry ,sc.bvprcd dest_prov ,sc.bvpost dest_post - ,(SELECT (regexp_match(def->>'newpart','(.*) - '::text))[1] FROM target) part --history part mix + ,b.part --history part mix ,COALESCE(m.avglcd, p.awgldc) ord_gldc --master data ,COALESCE(m.avmajg,p.awmajg) majg --master data ,COALESCE(m.avming,p.awming) ming --master data @@ -500,8 +535,8 @@ SELECT ,b.ship_month ,b.request_season ,b.request_month - ,b.part ||' - '|| RTRIM(COALESCE(m.AVDES1, p.AWDES1)) part_descr - ,F.F3||' - '||F.DESCR part_family + ,b.part_descr + ,SUBSTR(b.part,1,3)||' - '||F.DESCR part_family ,SUBSTRING(b.part,1,8)||' - '||MD.DESCR part_group ,COALESCE(MG.GRP,'Unbranded') branding ,CASE WHEN substring(COALESCE(m.avgled, p.awgled),1,1) <= '2' THEN SUBSTRING(b.part,9,3) ELSE '' END color @@ -515,11 +550,11 @@ SELECT ,COALESCE(m.avmajs,p.awmajs)||COALESCE(' - '||SJ.BSDES1,'') majs_descr ,COALESCE(m.avmins,p.awmins)||COALESCE(' - '||SI.BSDES1,'') mins_descr ,CASE COALESCE(SEG.SEGM,'Other') - WHEN 'Retail' THEN L.RETAIL + WHEN 'Retail' THEN c.RETAIL ELSE b.CHAN END mod_chan ,CASE COALESCE(SEG.SEGM,'Other') - WHEN 'Retail' THEN L.RETAILSUB + WHEN 'Retail' THEN c.RETAILSUB ELSE '' END mod_chansub ,b.quota_rep_descr @@ -548,13 +583,20 @@ FROM F.F3 = SUBSTR(b.PART,1,3) LEFT OUTER JOIN MD ON MD.MOLD = SUBSTR(b.PART,1,8) - LEFT OUTER JOIN RLARP.FFCHNL L ON - L.BILL = b.BILL_CLASS - AND L.SHIP = b.SHIP_CLASS LEFT OUTER JOIN LGDAT.CUST BC ON BC.BVCUST = b.BILL_CUST LEFT OUTER JOIN LGDAT.CUST SC ON SC.BVCUST = b.BILL_CUST + LEFT OUTER JOIN RLARP.FFCHNL c ON + c.BILL = bc.bvclas + AND c.SHIP = sc.bvclas + LEFT OUTER JOIN rlarp.ffterr t ON + t.prov = sc.bvprcd AND + t.ctry = sc.bvctry + LEFT OUTER JOIN RLARP.FFCUST CG ON + CG.CUSTN = BC.BVCUST + LEFT OUTER JOIN RLARP.FFCUST SG ON + SG.CUSTN = SC.BVCUST LEFT OUTER JOIN REPC ON REPC.RCODE = b.QUOTA_REP LEFT OUTER JOIN SI ON