vault backup: 2023-11-20 15:46:59
This commit is contained in:
parent
aaa62afb5d
commit
14ee797b91
@ -81,6 +81,7 @@ AS $function$
|
|||||||
const inflationFactor = iidx ? iidx[inflation] : 0;
|
const inflationFactor = iidx ? iidx[inflation] : 0;
|
||||||
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
|
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
|
||||||
const listUSD = list ? list * fxrate :null;
|
const listUSD = list ? list * fxrate :null;
|
||||||
|
const fstdUSD = doc.product?.std;
|
||||||
|
|
||||||
// ------------------calculate price adders------------------------------------------------------
|
// ------------------calculate price adders------------------------------------------------------
|
||||||
let ltp = qty < pltq ? 0.15 : null;
|
let ltp = qty < pltq ? 0.15 : null;
|
||||||
@ -121,6 +122,9 @@ AS $function$
|
|||||||
let guidance = {
|
let guidance = {
|
||||||
prices
|
prices
|
||||||
,finalPrice
|
,finalPrice
|
||||||
|
,targetPrice
|
||||||
|
,listUSD
|
||||||
|
,fstdUSD
|
||||||
}
|
}
|
||||||
doc.guidance = guidance;
|
doc.guidance = guidance;
|
||||||
return doc;
|
return doc;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
DROP FUNCTION rlarp.get_guidance_dseg;
|
DROP FUNCTION rlarp.get_guidance_dseg CASCADE;
|
||||||
CREATE OR REPLACE FUNCTION rlarp.get_guidance_dseg(_bill text, _ship text, _stlc text, _dseg text, _qty numeric, _seas int)
|
CREATE OR REPLACE FUNCTION rlarp.get_guidance_dseg(_bill text, _ship text, _stlc text, _dseg text, _qty numeric, _seas int)
|
||||||
RETURNS jsonb
|
RETURNS jsonb
|
||||||
LANGUAGE plpgsql AS
|
LANGUAGE plpgsql AS
|
||||||
@ -15,6 +15,7 @@ DECLARE
|
|||||||
_item text;
|
_item text;
|
||||||
_unti text;
|
_unti text;
|
||||||
_pltq numeric;
|
_pltq numeric;
|
||||||
|
_fstd numeric;
|
||||||
_cust text;
|
_cust text;
|
||||||
_curr text;
|
_curr text;
|
||||||
_rate numeric;
|
_rate numeric;
|
||||||
@ -65,12 +66,14 @@ BEGIN
|
|||||||
,idxk
|
,idxk
|
||||||
,prefer
|
,prefer
|
||||||
,pltq
|
,pltq
|
||||||
|
,fstd_usd
|
||||||
INTO
|
INTO
|
||||||
_mold
|
_mold
|
||||||
,_item
|
,_item
|
||||||
,_iidx
|
,_iidx
|
||||||
,_itemr
|
,_itemr
|
||||||
,_pltq
|
,_pltq
|
||||||
|
,_fstd
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
@ -80,6 +83,7 @@ BEGIN
|
|||||||
,i.v1ds
|
,i.v1ds
|
||||||
,i.v0ds
|
,i.v0ds
|
||||||
,i.pltq
|
,i.pltq
|
||||||
|
,avg(i.fstd_usd) FILTER (WHERE aplnt <> 'I') fstd_usd
|
||||||
,jsonb_strip_nulls(jsonb_build_object('assc',CASE WHEN i.assc <> '' THEN i.assc ELSE null::text END,'majg',i.majg::int,'coltier',i.coltier)) idxk
|
,jsonb_strip_nulls(jsonb_build_object('assc',CASE WHEN i.assc <> '' THEN i.assc ELSE null::text END,'majg',i.majg::int,'coltier',i.coltier)) idxk
|
||||||
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END prefer
|
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END prefer
|
||||||
FROM
|
FROM
|
||||||
@ -109,6 +113,7 @@ BEGIN
|
|||||||
,'itemrel',_itemr
|
,'itemrel',_itemr
|
||||||
,'iidx',_iidx
|
,'iidx',_iidx
|
||||||
,'pltq',_pltq
|
,'pltq',_pltq
|
||||||
|
,'fstd_usd',_fstd
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
--RAISE NOTICE 'item data %', jsonb_pretty(_product||_input);
|
--RAISE NOTICE 'item data %', jsonb_pretty(_product||_input);
|
||||||
|
@ -11,20 +11,18 @@ lq AS MATERIALIZED (
|
|||||||
,lqg AS (
|
,lqg AS (
|
||||||
SELECT
|
SELECT
|
||||||
lq.*
|
lq.*
|
||||||
,m.part_group
|
,pricing->'product'->>'mold' part_group
|
||||||
,i.pltq
|
,pricing->'product'->>'itemrel' item_fit
|
||||||
|
,(pricing->'product'->>'pltq')::numeric pltq
|
||||||
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
|
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
|
||||||
,pricing->'guidance'->'finalPrice'->>'Reason' reason
|
,pricing->'guidance'->'finalPrice'->>'Reason' reason
|
||||||
|
,(pricing->'product'->>'fstd_usd')::numeric fstd_usd
|
||||||
,jsonb_pretty(pricing) pricing
|
,jsonb_pretty(pricing) pricing
|
||||||
FROM
|
FROM
|
||||||
lq
|
lq
|
||||||
JOIN LATERAL rlarp.guidance_r1(
|
JOIN LATERAL rlarp.guidance_r1(
|
||||||
rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2024)
|
rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2024)
|
||||||
) pricing ON TRUE
|
) pricing ON TRUE
|
||||||
LEFT OUTER JOIN rlarp.molds m ON
|
|
||||||
m.stlc = lq.mold
|
|
||||||
LEFT OUTER JOIN "CMS.CUSLG".itemmv i ON
|
|
||||||
i.item = lq.part
|
|
||||||
WHERE
|
WHERE
|
||||||
lq.qstat ~ 'Submitted'
|
lq.qstat ~ 'Submitted'
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user