commit: 2024-12-13 10:12:49

This commit is contained in:
Paul Trowbridge 2024-12-13 10:12:49 -05:00
parent 3e530e2729
commit 73cd1c3506

View File

@ -1,5 +1,5 @@
set work_mem TO '4GB'; -- set work_mem TO '4GB';
--
DROP VIEW IF EXISTS rlarp.quote_review; DROP VIEW IF EXISTS rlarp.quote_review;
CREATE VIEW rlarp.quote_review AS CREATE VIEW rlarp.quote_review AS
WITH WITH
@ -12,41 +12,57 @@ lq AS MATERIALIZED (
) )
,lqg AS ( ,lqg AS (
SELECT SELECT
lq.* lq.qid
,pricing->'product'->>'mold' part_group ,lq.qline
CASE SUBSTR(bc.cclass,2,3) ,lq.rep
--if the bill to class is ditsributor, then it's either warehouse or drop ,lq.touched
WHEN 'DIS' THEN ,lq.expires
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse ,lq.request
CASE SUBSTR(sc.cclass,2,3) ,lq.qtitle
WHEN 'DIS' THEN 'WHS' ,lq.qstatid
ELSE 'DRP' ,lq.qstat
END ,lq.quotenumber
--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 ,lq.billto
--everything else does not involve a distributor and is considered direct ,lq.shipto
ELSE 'DIR' ,lq.qchan
END qchan, ,lq.qcustomer
,CASE osm.chan WHEN 'DRP' THEN rtrim(osm.shipgrp) ELSE rtrim(osm.account) END customer ,lq.part
,pricing->'customer'->>'cust' qcust ,lq.qoptions
,pricing->'product'->>'itemrel' item_fit ,lq.partbuilt
,(pricing->'product'->>'pltq')::numeric pltq ,lq.colgrp
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance ,lq.colc
,pricing->'guidance'->'finalPrice'->>'Reason' reason ,lq.coltier
,(pricing->'product'->>'cstd_usd_ina')::numeric cstd_usd ,lq.brand
,(pricing->'product'->>'fstd_usd_ina')::numeric fstd_usd ,lq.dataseg
,(pricing->'guidance'->>'ltp')::numeric ltp ,lq.v1ds
,(pricing->'guidance'->>'optimization')::numeric optimization ,lq.comment
,(pricing->'guidance'->>'inflationFactor')::numeric inflation ,lq.units_each
,jsonb_pretty(pricing) pricing ,lq.price
,lq.sales
,lq.histprice
,lq.targetp
,lq.lastsalesprice
,lq.r_curr
,lq.qt_rate
,lq.qrn
,lq.url
,lq.tacticalmodifier
,lq.finalrecommendedprice
,i.partgroup part_group
-- ,pricing->'product'->>'itemrel' item_fit
,i.mpck pltq
-- ,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
-- ,pricing->'guidance'->'finalPrice'->>'Reason' reason
,i.curstdus cstd_usd
,i.futstdus fstd_usd
-- ,(pricing->'guidance'->>'ltp')::numeric ltp
-- ,(pricing->'guidance'->>'optimization')::numeric optimization
-- ,(pricing->'guidance'->>'inflationFactor')::numeric inflation
-- ,jsonb_pretty(pricing) pricing
FROM FROM
lq lq
LEFT OUTER JOIN rlarp.cust bc ON LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
bc.cust = lq.billto i.item = lq.part
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
WHERE WHERE
lq.qstat ~ 'Submitted' lq.qstat ~ 'Submitted'
) )