diff --git a/route_sql/swap_cust.sql b/route_sql/swap_cust.sql index 4bbb2d7..ae52d1c 100644 --- a/route_sql/swap_cust.sql +++ b/route_sql/swap_cust.sql @@ -140,8 +140,29 @@ target AS (SELECT $$swap_doc$$::jsonb swap) ,r.director ,COALESCE(c.bill_dba,o.billto_group) billto_group ,COALESCE(c.ship_dba,o.shipto_group) shipto_group - ,o.chan --master data - ,o.chansub + ,CASE SUBSTRING(c.bill_class,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(c.ship_class,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 chan + ,CASE SUBSTRING(c.bill_class,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(c.ship_class,2,3) + WHEN 'DIS' THEN 'WHS' + ELSE CASE SUBSTRING(c.ship_class,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END + END + WHEN 'MAS' THEN 'RMN' + WHEN 'NAT' THEN 'RMN' + ELSE CASE SUBSTRING(c.ship_class,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END + END chansub ,o.chan_retail ,o.part ,o.part_descr