commit: 2024-12-13 09:46:50

This commit is contained in:
Paul Trowbridge 2024-12-13 09:46:50 -05:00
parent b38cc02ef5
commit 3e530e2729
2 changed files with 18 additions and 2 deletions

View File

@ -14,7 +14,7 @@ lq AS MATERIALIZED (
SELECT
lq.*
,pricing->'product'->>'mold' part_group
,substring(pricing->'customer'->>'chan',1,1) qchan
-- ,substring(pricing->'customer'->>'chan',1,1) qchan
,pricing->'customer'->>'cust' qcust
,pricing->'product'->>'itemrel' item_fit
,(pricing->'product'->>'pltq')::numeric pltq

View File

@ -14,7 +14,19 @@ lq AS MATERIALIZED (
SELECT
lq.*
,pricing->'product'->>'mold' part_group
,substring(pricing->'customer'->>'chan',1,1) qchan
CASE SUBSTR(bc.cclass,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 SUBSTR(sc.cclass,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE 'DRP'
END
--CASE WHEN RTRIM(SUBSTR(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTR(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 qchan,
,CASE osm.chan WHEN 'DRP' THEN rtrim(osm.shipgrp) ELSE rtrim(osm.account) END customer
,pricing->'customer'->>'cust' qcust
,pricing->'product'->>'itemrel' item_fit
,(pricing->'product'->>'pltq')::numeric pltq
@ -28,6 +40,10 @@ lq AS MATERIALIZED (
,jsonb_pretty(pricing) pricing
FROM
lq
LEFT OUTER JOIN rlarp.cust bc ON
bc.cust = lq.billto
LEFT OUTER JOIN rlarp.cust sc ON
bc.cust = lq.shipto
LEFT JOIN LATERAL rlarp.guidance_r1(
rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2025)
) pricing ON TRUE