re-assign channel based for customer swaps

This commit is contained in:
Paul Trowbridge 2021-04-16 12:04:17 -04:00
parent 60b57263d0
commit d541ee16cc

View File

@ -140,8 +140,29 @@ target AS (SELECT $$swap_doc$$::jsonb swap)
,r.director ,r.director
,COALESCE(c.bill_dba,o.billto_group) billto_group ,COALESCE(c.bill_dba,o.billto_group) billto_group
,COALESCE(c.ship_dba,o.shipto_group) shipto_group ,COALESCE(c.ship_dba,o.shipto_group) shipto_group
,o.chan --master data ,CASE SUBSTRING(c.bill_class,2,3)
,o.chansub --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.chan_retail
,o.part ,o.part
,o.part_descr ,o.part_descr