vault backup: 2023-11-20 15:46:59

This commit is contained in:
Paul Trowbridge 2023-11-20 15:46:59 -05:00
parent aaa62afb5d
commit 14ee797b91
3 changed files with 14 additions and 7 deletions

View File

@ -81,6 +81,7 @@ AS $function$
const inflationFactor = iidx ? iidx[inflation] : 0;
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
const listUSD = list ? list * fxrate :null;
const fstdUSD = doc.product?.std;
// ------------------calculate price adders------------------------------------------------------
let ltp = qty < pltq ? 0.15 : null;
@ -121,6 +122,9 @@ AS $function$
let guidance = {
prices
,finalPrice
,targetPrice
,listUSD
,fstdUSD
}
doc.guidance = guidance;
return doc;

View File

@ -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)
RETURNS jsonb
LANGUAGE plpgsql AS
@ -15,6 +15,7 @@ DECLARE
_item text;
_unti text;
_pltq numeric;
_fstd numeric;
_cust text;
_curr text;
_rate numeric;
@ -65,12 +66,14 @@ BEGIN
,idxk
,prefer
,pltq
,fstd_usd
INTO
_mold
,_item
,_iidx
,_itemr
,_pltq
,_fstd
FROM
(
SELECT
@ -80,6 +83,7 @@ BEGIN
,i.v1ds
,i.v0ds
,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
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END prefer
FROM
@ -109,6 +113,7 @@ BEGIN
,'itemrel',_itemr
,'iidx',_iidx
,'pltq',_pltq
,'fstd_usd',_fstd
)
);
--RAISE NOTICE 'item data %', jsonb_pretty(_product||_input);

View File

@ -11,20 +11,18 @@ lq AS MATERIALIZED (
,lqg AS (
SELECT
lq.*
,m.part_group
,i.pltq
,pricing->'product'->>'mold' part_group
,pricing->'product'->>'itemrel' item_fit
,(pricing->'product'->>'pltq')::numeric pltq
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
,pricing->'guidance'->'finalPrice'->>'Reason' reason
,(pricing->'product'->>'fstd_usd')::numeric fstd_usd
,jsonb_pretty(pricing) pricing
FROM
lq
JOIN LATERAL rlarp.guidance_r1(
rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2024)
) 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
lq.qstat ~ 'Submitted'
)