From d541ee16ccb32e5cf17ac677312cd8a74c30a555 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 16 Apr 2021 12:04:17 -0400 Subject: [PATCH] re-assign channel based for customer swaps --- route_sql/swap_cust.sql | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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