vault backup: 2023-11-10 16:04:06
This commit is contained in:
parent
16be2ad264
commit
042a8abc0f
@ -123,13 +123,17 @@ export function apply_guidance(doc: any) {
|
|||||||
let anchorPrice = null;
|
let anchorPrice = null;
|
||||||
let anchorSource = null;
|
let anchorSource = null;
|
||||||
let bridgePremium = doc.bridgePremium ?? 1.00000;
|
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
|
// Determine the anchor price and source
|
||||||
if (earlyPrice) {
|
if (earlyPrice) {
|
||||||
// translate alternate product history to current product quoted
|
// translate alternate product history to current product quoted
|
||||||
anchorPrice = Number((earlyPrice * bridgePremium).toFixed(5));
|
anchorPrice = Number((earlyPrice * bridgePremium).toFixed(5));
|
||||||
// after the early price is translated see if target is still less
|
// after the early price is translated see if target is still less
|
||||||
if (targetPrice < anchorPrice) {
|
if (targetPrice < anchorPrice) {
|
||||||
anchorSource = 'Target Price';
|
anchorSource = `Target Price ${targetPrice}`;
|
||||||
anchorPrice = targetPrice;
|
anchorPrice = targetPrice;
|
||||||
} else {
|
} else {
|
||||||
anchorSource = doc.hist.cust.early_season + ' Similar (' + doc.hist.cust.ds + ') Customer Price ' + earlyPrice + ' x ' + doc.bridgePremium + ' = ' + anchorPrice;
|
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.finalReason = finalReason;
|
||||||
doc.bridgePremium = bridgePremium;
|
doc.bridgePremium = bridgePremium;
|
||||||
doc.targetPrice = targetPrice;
|
doc.targetPrice = targetPrice;
|
||||||
|
}
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ DECLARE
|
|||||||
_stlc text;
|
_stlc text;
|
||||||
_cust text;
|
_cust text;
|
||||||
_curr text;
|
_curr text;
|
||||||
|
_rate numeric;
|
||||||
_v1ds text;
|
_v1ds text;
|
||||||
_v0ds text;
|
_v0ds text;
|
||||||
_v1tp jsonb;
|
_v1tp jsonb;
|
||||||
@ -57,10 +58,29 @@ BEGIN
|
|||||||
--RAISE NOTICE '%', _chan;
|
--RAISE NOTICE '%', _chan;
|
||||||
|
|
||||||
----------------customer------------------------------------
|
----------------customer------------------------------------
|
||||||
|
----------------customer------------------------------------
|
||||||
SELECT dba INTO _cust FROM rlarp.cust WHERE code = CASE WHEN _chan = 'DRP' THEN _ship ELSE _bill END ;
|
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;
|
SELECT
|
||||||
_rslt = _rslt||jsonb_build_object('cust',_cust,'curr',_curr);
|
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;
|
--RAISE NOTICE 'cust %', _cust;
|
||||||
|
|
||||||
----------------price history-------------------------------
|
----------------price history-------------------------------
|
||||||
|
@ -15,6 +15,7 @@ DECLARE
|
|||||||
_item text;
|
_item text;
|
||||||
_cust text;
|
_cust text;
|
||||||
_curr text;
|
_curr text;
|
||||||
|
_rate numeric;
|
||||||
_v1ds text;
|
_v1ds text;
|
||||||
_v0ds text;
|
_v0ds text;
|
||||||
_v1tp jsonb;
|
_v1tp jsonb;
|
||||||
@ -25,6 +26,7 @@ DECLARE
|
|||||||
_targ jsonb;
|
_targ jsonb;
|
||||||
_list jsonb;
|
_list jsonb;
|
||||||
_iidx jsonb;
|
_iidx jsonb;
|
||||||
|
_itemr text;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
--_item := 'AMK06000G18B054';
|
--_item := 'AMK06000G18B054';
|
||||||
@ -33,24 +35,22 @@ BEGIN
|
|||||||
--_qty := 5000;
|
--_qty := 5000;
|
||||||
--_seas := 2024;
|
--_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--------------------------------
|
----------------base product--------------------------------
|
||||||
|
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
part_group
|
part_group
|
||||||
,item
|
,item
|
||||||
,stlc
|
,stlc
|
||||||
,v1ds
|
|
||||||
,v0ds
|
|
||||||
,idxk
|
,idxk
|
||||||
|
,prefer
|
||||||
INTO
|
INTO
|
||||||
_mold
|
_mold
|
||||||
,_item
|
,_item
|
||||||
,_stlc
|
,_stlc
|
||||||
,_v1ds
|
|
||||||
,_v0ds
|
|
||||||
,_iidx
|
,_iidx
|
||||||
|
,_itemr
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
@ -60,7 +60,7 @@ BEGIN
|
|||||||
,i.v1ds
|
,i.v1ds
|
||||||
,i.v0ds
|
,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
|
,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
|
FROM
|
||||||
"CMS.CUSLG".itemmv i
|
"CMS.CUSLG".itemmv i
|
||||||
INNER JOIN rlarp.molds m ON
|
INNER JOIN rlarp.molds m ON
|
||||||
@ -73,12 +73,12 @@ BEGIN
|
|||||||
,i.v1ds
|
,i.v1ds
|
||||||
,i.v0ds
|
,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))
|
,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
|
) best
|
||||||
ORDER BY
|
ORDER BY
|
||||||
prefer DESC
|
prefer DESC
|
||||||
LIMIT 1;
|
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;
|
RAISE NOTICE 'item data %', _iidx;
|
||||||
|
|
||||||
----------------channel-------------------------------------
|
----------------channel-------------------------------------
|
||||||
@ -88,10 +88,28 @@ BEGIN
|
|||||||
RAISE NOTICE 'chan %', _chan;
|
RAISE NOTICE 'chan %', _chan;
|
||||||
|
|
||||||
----------------customer------------------------------------
|
----------------customer------------------------------------
|
||||||
|
|
||||||
SELECT dba INTO _cust FROM rlarp.cust WHERE code = CASE WHEN _chan = 'DRP' THEN _ship ELSE _bill END ;
|
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;
|
SELECT
|
||||||
_rslt = _rslt||jsonb_build_object('cust',_cust,'curr',_curr);
|
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;
|
RAISE NOTICE 'cust %', _cust;
|
||||||
|
|
||||||
----------------price history-------------------------------
|
----------------price history-------------------------------
|
||||||
@ -131,7 +149,7 @@ BEGIN
|
|||||||
WHERE
|
WHERE
|
||||||
mold = _stlc
|
mold = _stlc
|
||||||
AND season = _seas
|
AND season = _seas
|
||||||
AND data_segment = _v1ds
|
AND data_segment = _dseg
|
||||||
AND region = 'ALL';
|
AND region = 'ALL';
|
||||||
--RAISE NOTICE 'target: %', jsonb_pretty(_targ);
|
--RAISE NOTICE 'target: %', jsonb_pretty(_targ);
|
||||||
_rslt := _rslt||COALESCE(_v1tp,'{}'::jsonb);
|
_rslt := _rslt||COALESCE(_v1tp,'{}'::jsonb);
|
||||||
|
Loading…
Reference in New Issue
Block a user