link in cost, rounding, target for last price should be based on last price qty
This commit is contained in:
parent
23b3962313
commit
c46d4c25d7
@ -173,7 +173,7 @@ BEGIN
|
|||||||
WHEN 'DIS' THEN bc.dba
|
WHEN 'DIS' THEN bc.dba
|
||||||
ELSE sc.dba
|
ELSE sc.dba
|
||||||
END
|
END
|
||||||
ELSE q.bill
|
ELSE bc.dba
|
||||||
END,
|
END,
|
||||||
pltq = i.mpck,
|
pltq = i.mpck,
|
||||||
plevel =
|
plevel =
|
||||||
|
@ -289,32 +289,30 @@ BEGIN
|
|||||||
AND tp.ds = _last_dataseg
|
AND tp.ds = _last_dataseg
|
||||||
AND tp.chan = _chan
|
AND tp.chan = _chan
|
||||||
AND tp.tier = _tier
|
AND tp.tier = _tier
|
||||||
AND FLOOR(_vol / NULLIF(_pltq, 0))::int <@ tp.vol;
|
AND FLOOR(_last_qty / _pltq)::int <@ tp.vol;
|
||||||
|
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
-- Step 4: Cost data for normalization
|
-- Step 4: Cost data for normalization
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
-- Current/future standard for requested v1ds
|
|
||||||
SELECT
|
|
||||||
curstdus, futstdus
|
|
||||||
INTO
|
|
||||||
_curstd, _futstd
|
|
||||||
FROM
|
|
||||||
"CMS.CUSLG".itemm i
|
|
||||||
WHERE
|
|
||||||
i.item = _part
|
|
||||||
AND i.v1ds = _v1ds;
|
|
||||||
|
|
||||||
-- Current/future standard for last_dataseg
|
SELECT
|
||||||
SELECT
|
ROUND(CASE WHEN COALESCE(_customized,'') = '' THEN _curstd_orig ELSE COALESCE(v1.curstdus, v0.curstdus) END,5) AS curstd,
|
||||||
curstdus, futstdus
|
ROUND(CASE WHEN COALESCE(_customized,'') = '' THEN _futstd_orig ELSE COALESCE(v1.futstdus, v0.futstdus) END,5) AS futstd,
|
||||||
INTO
|
ROUND(CASE WHEN COALESCE(_last_isdiff,'') = '' THEN _curstd_orig ELSE COALESCE(v1l.curstdus, v0l.curstdus) END,5) AS curstd_last,
|
||||||
_curstd_last, _futstd_last
|
ROUND(CASE WHEN COALESCE(_last_isdiff,'') = '' THEN _futstd_orig ELSE COALESCE(v1l.futstdus, v0l.futstdus) END,5) AS futstd_last
|
||||||
FROM
|
INTO
|
||||||
"CMS.CUSLG".itemm i
|
_curstd, _futstd, _curstd_last, _futstd_last
|
||||||
WHERE
|
FROM (VALUES (1)) AS x(dummy)
|
||||||
i.item = _part
|
LEFT JOIN rlarp.cost_v1ds v1
|
||||||
AND i.v1ds = _last_dataseg;
|
ON v1.stlc = _stlc AND v1.v1ds = _v1ds
|
||||||
|
LEFT JOIN rlarp.cost_v0ds v0
|
||||||
|
ON v0.stlc = _stlc AND v0.v0ds = _v0ds
|
||||||
|
LEFT JOIN rlarp.cost_v1ds v1l
|
||||||
|
ON v1l.stlc = _stlc AND v1l.v1ds = _last_dataseg
|
||||||
|
LEFT JOIN rlarp.cost_v0ds v0l
|
||||||
|
ON v0l.stlc = _stlc AND v0l.v0ds = _last_v0ds
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
-- Step 5: Normalize last price if needed
|
-- Step 5: Normalize last price if needed
|
||||||
@ -325,7 +323,7 @@ BEGIN
|
|||||||
_last_price_norm := ROUND(_last_price * (_tprice / _tprice_last), 5);
|
_last_price_norm := ROUND(_last_price * (_tprice / _tprice_last), 5);
|
||||||
_last_premium_method := 'Target Price Ratio';
|
_last_premium_method := 'Target Price Ratio';
|
||||||
ELSIF _curstd_last IS NOT NULL AND _curstd IS NOT NULL AND _curstd_last <> 0 THEN
|
ELSIF _curstd_last IS NOT NULL AND _curstd IS NOT NULL AND _curstd_last <> 0 THEN
|
||||||
_last_premium := _curstd / _curstd_last;
|
_last_premium := ROUND(_curstd / _curstd_last, 5);
|
||||||
_last_price_norm := ROUND(_last_price * (_curstd / _curstd_last), 5);
|
_last_price_norm := ROUND(_last_price * (_curstd / _curstd_last), 5);
|
||||||
_last_premium_method := 'Cost Ratio';
|
_last_premium_method := 'Cost Ratio';
|
||||||
ELSE
|
ELSE
|
||||||
@ -425,7 +423,8 @@ BEGIN
|
|||||||
'targets',
|
'targets',
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'target_price', _tprice,
|
'target_price', _tprice,
|
||||||
'target_math', _tmath
|
'target_math', _tmath,
|
||||||
|
'volume_range', _volume_range
|
||||||
),
|
),
|
||||||
'list',
|
'list',
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
|
Loading…
Reference in New Issue
Block a user