vault backup: 2023-11-10 16:04:06

This commit is contained in:
Paul Trowbridge 2023-11-10 16:04:06 -05:00
parent 16be2ad264
commit 042a8abc0f
3 changed files with 89 additions and 46 deletions

View File

@ -123,13 +123,17 @@ export function apply_guidance(doc: any) {
let anchorPrice = null;
let anchorSource = null;
let bridgePremium = doc.bridgePremium ?? 1.00000;
if (!targetPrice) {
anchorSource = "No target pricing setup";
doc.finalReason = "No target pricing setup";
} else {
// Determine the anchor price and source
if (earlyPrice) {
// translate alternate product history to current product quoted
anchorPrice = Number((earlyPrice * bridgePremium).toFixed(5));
// after the early price is translated see if target is still less
if (targetPrice < anchorPrice) {
anchorSource = 'Target Price';
anchorSource = `Target Price ${targetPrice}`;
anchorPrice = targetPrice;
} else {
anchorSource = doc.hist.cust.early_season + ' Similar (' + doc.hist.cust.ds + ') Customer Price ' + earlyPrice + ' x ' + doc.bridgePremium + ' = ' + anchorPrice;
@ -157,6 +161,7 @@ export function apply_guidance(doc: any) {
doc.finalReason = finalReason;
doc.bridgePremium = bridgePremium;
doc.targetPrice = targetPrice;
}
return doc;
}

View File

@ -14,6 +14,7 @@ DECLARE
_stlc text;
_cust text;
_curr text;
_rate numeric;
_v1ds text;
_v0ds text;
_v1tp jsonb;
@ -57,10 +58,29 @@ BEGIN
--RAISE NOTICE '%', _chan;
----------------customer------------------------------------
----------------customer------------------------------------
SELECT dba INTO _cust FROM rlarp.cust WHERE code = CASE WHEN _chan = 'DRP' THEN _ship ELSE _bill END ;
SELECT currency INTO _curr FROM rlarp.cust WHERE code = _bill;
_rslt = _rslt||jsonb_build_object('cust',_cust,'curr',_curr);
SELECT
currency,
(SELECT
x.rate
FROM
rlarp.ffcret x
WHERE
x.perd = (select fspr from rlarp.gld where drange @> current_date)
AND x.rtyp = 'MA'
and x.fcur = currency
AND x.tcur = 'US'
)
INTO
_curr
,_rate
FROM
rlarp.cust
WHERE
code = _bill;
_rslt = _rslt||jsonb_build_object('cust',_cust,'curr',_curr,'fxrate',_rate);
--RAISE NOTICE 'cust %', _cust;
----------------price history-------------------------------

View File

@ -15,6 +15,7 @@ DECLARE
_item text;
_cust text;
_curr text;
_rate numeric;
_v1ds text;
_v0ds text;
_v1tp jsonb;
@ -25,6 +26,7 @@ DECLARE
_targ jsonb;
_list jsonb;
_iidx jsonb;
_itemr text;
BEGIN
--_item := 'AMK06000G18B054';
@ -33,24 +35,22 @@ BEGIN
--_qty := 5000;
--_seas := 2024;
_v0ds := CASE split_part(substring(_dseg,4,100), '.',1) WHEN 'B' THEN 'BASE' ELSE 'COLOR' END || CASE split_part(substring(_dseg,4,100), '.',2) WHEN 'L' THEN ' LABELED' WHEN 'P' THEN ' PRINTED' ELSE '' END;
_v1ds := _dseg;
----------------base product--------------------------------
SELECT
part_group
,item
,stlc
,v1ds
,v0ds
,idxk
,prefer
INTO
_mold
,_item
,_stlc
,_v1ds
,_v0ds
,_iidx
,_itemr
FROM
(
SELECT
@ -60,7 +60,7 @@ BEGIN
,i.v1ds
,i.v0ds
,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 1 ELSE 0 END prefer
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END prefer
FROM
"CMS.CUSLG".itemmv i
INNER JOIN rlarp.molds m ON
@ -73,12 +73,12 @@ BEGIN
,i.v1ds
,i.v0ds
,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))
,CASE WHEN i.v1ds = _v1ds THEN 1 ELSE 0 END
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END
) best
ORDER BY
prefer DESC
LIMIT 1;
_rslt := jsonb_build_object('mold',_mold,'v1ds',_v1ds,'v0ds',_v0ds,'stlc',_stlc,'item',_item,'desg',_dseg)||_iidx;
_rslt := jsonb_build_object('mold',_mold,'v1ds',_v1ds,'v0ds',_v0ds,'stlc',_stlc,'item',_item,'item rel',_itemr,'desg',_dseg)||_iidx;
RAISE NOTICE 'item data %', _iidx;
----------------channel-------------------------------------
@ -88,10 +88,28 @@ BEGIN
RAISE NOTICE 'chan %', _chan;
----------------customer------------------------------------
SELECT dba INTO _cust FROM rlarp.cust WHERE code = CASE WHEN _chan = 'DRP' THEN _ship ELSE _bill END ;
SELECT currency INTO _curr FROM rlarp.cust WHERE code = _bill;
_rslt = _rslt||jsonb_build_object('cust',_cust,'curr',_curr);
SELECT
currency,
(SELECT
x.rate
FROM
rlarp.ffcret x
WHERE
x.perd = (select fspr from rlarp.gld where drange @> current_date)
AND x.rtyp = 'MA'
and x.fcur = currency
AND x.tcur = 'US'
)
INTO
_curr
,_rate
FROM
rlarp.cust
WHERE
code = _bill;
_rslt = _rslt||jsonb_build_object('cust',_cust,'curr',_curr,'fxrate',_rate);
RAISE NOTICE 'cust %', _cust;
----------------price history-------------------------------
@ -131,7 +149,7 @@ BEGIN
WHERE
mold = _stlc
AND season = _seas
AND data_segment = _v1ds
AND data_segment = _dseg
AND region = 'ALL';
--RAISE NOTICE 'target: %', jsonb_pretty(_targ);
_rslt := _rslt||COALESCE(_v1tp,'{}'::jsonb);