Compare commits
5 Commits
new_guidan
...
master
Author | SHA1 | Date | |
---|---|---|---|
619539eac9 | |||
5ec3f1d9c1 | |||
581224dad8 | |||
af4c7c4853 | |||
abac006970 |
@ -548,7 +548,7 @@ BEGIN
|
|||||||
-- Target Support Panel
|
-- Target Support Panel
|
||||||
SELECT
|
SELECT
|
||||||
'Target Calculation' AS label,
|
'Target Calculation' AS label,
|
||||||
10 AS detailLevel,
|
5 AS detailLevel,
|
||||||
(
|
(
|
||||||
SELECT * FROM (
|
SELECT * FROM (
|
||||||
SELECT
|
SELECT
|
||||||
@ -581,7 +581,7 @@ BEGIN
|
|||||||
----------------------label------------------------------------------------
|
----------------------label------------------------------------------------
|
||||||
'Target' AS label,
|
'Target' AS label,
|
||||||
----------------------detailLevel------------------------------------------
|
----------------------detailLevel------------------------------------------
|
||||||
10 AS detailLevel,
|
5 AS detailLevel,
|
||||||
----------------------value------------------------------------------------
|
----------------------value------------------------------------------------
|
||||||
tprice AS value,
|
tprice AS value,
|
||||||
----------------------type-------------------------------------------------
|
----------------------type-------------------------------------------------
|
||||||
|
@ -384,8 +384,8 @@ BEGIN
|
|||||||
,_approval_price
|
,_approval_price
|
||||||
,_approval_reason
|
,_approval_reason
|
||||||
FROM
|
FROM
|
||||||
pricequote.guidance_logic(_tprice, _last_price_norm, _listprice_eff, _last_date, .95, 1.0, 1.0) gl
|
pricequote.guidance_logic(_tprice, _last_price_norm, _listprice_eff, _last_date, 1.0, 1.0, 1.0) gl
|
||||||
CROSS JOIN pricequote.approval_logic(_tprice, _last_price_norm, _listprice_eff, _last_date, .95, 1.0, 1.0) al;
|
CROSS JOIN pricequote.approval_logic(_tprice, _last_price_norm, _listprice_eff, _last_date, 1.0, 1.0, 1.0) al;
|
||||||
|
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
-- Step 8: Build explanation JSON
|
-- Step 8: Build explanation JSON
|
||||||
|
@ -51,42 +51,50 @@ WITH base AS (
|
|||||||
ranked AS (
|
ranked AS (
|
||||||
SELECT
|
SELECT
|
||||||
b.*
|
b.*
|
||||||
-- Most recent sale
|
-- Most recent sale (Actuals only)
|
||||||
,ROW_NUMBER() OVER (
|
,CASE WHEN b.version = 'Actual' THEN
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
PARTITION BY b.customer, b.partgroup
|
PARTITION BY b.customer, b.partgroup
|
||||||
ORDER BY CASE WHEN b.version = 'Actual' THEN b.odate ELSE NULL END DESC
|
ORDER BY b.odate DESC
|
||||||
) AS rn_mrs
|
)
|
||||||
-- Most recent quote
|
END AS rn_mrs
|
||||||
,ROW_NUMBER() OVER (
|
-- Most recent quote (Quotes only)
|
||||||
|
,CASE WHEN b.version = 'Quotes' THEN
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
PARTITION BY b.customer, b.partgroup
|
PARTITION BY b.customer, b.partgroup
|
||||||
ORDER BY CASE WHEN b.version = 'Quotes' THEN b.odate ELSE NULL END DESC
|
ORDER BY b.odate DESC
|
||||||
) AS rn_mrq
|
)
|
||||||
-- Largest volume sale (last 12 months)
|
END AS rn_mrq
|
||||||
,ROW_NUMBER() OVER (
|
-- Largest volume sale (Actuals only; last 12 months prioritized)
|
||||||
|
,CASE WHEN b.version = 'Actual' THEN
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
PARTITION BY b.customer, b.partgroup
|
PARTITION BY b.customer, b.partgroup
|
||||||
ORDER BY CASE
|
ORDER BY
|
||||||
WHEN b.version = 'Actual' AND b.odate >= DATEADD(YEAR, -1, GETDATE())
|
CASE WHEN b.version = 'Actual' AND b.odate >= DATEADD(YEAR, -1, GETDATE()) THEN 1 ELSE 0 END DESC,
|
||||||
THEN b.qty ELSE NULL
|
b.qty DESC
|
||||||
END DESC
|
)
|
||||||
) AS rn_lvs
|
END AS rn_lvs
|
||||||
-- Largest volume quote (last 12 months)
|
-- Largest volume quote (Quotes only; last 12 months prioritized)
|
||||||
,ROW_NUMBER() OVER (
|
,CASE WHEN b.version = 'Quotes' THEN
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
PARTITION BY b.customer, b.partgroup
|
PARTITION BY b.customer, b.partgroup
|
||||||
ORDER BY CASE
|
ORDER BY
|
||||||
WHEN b.version = 'Quotes' AND b.odate >= DATEADD(YEAR, -1, GETDATE())
|
CASE WHEN b.version = 'Quotes' AND b.odate >= DATEADD(YEAR, -1, GETDATE()) THEN 1 ELSE 0 END DESC,
|
||||||
THEN b.qty ELSE NULL
|
b.qty DESC
|
||||||
END DESC
|
)
|
||||||
) AS rn_lvq
|
END AS rn_lvq
|
||||||
-- Most recent sale per data segment
|
,CASE WHEN b.version = 'Actual' THEN
|
||||||
,ROW_NUMBER() OVER (
|
ROW_NUMBER() OVER (
|
||||||
PARTITION BY b.customer, b.partgroup, b.dataseg, b.version
|
PARTITION BY b.customer, b.partgroup, b.dataseg, b.version
|
||||||
ORDER BY CASE WHEN b.version = 'Actual' THEN b.odate ELSE NULL END DESC
|
ORDER BY b.odate DESC
|
||||||
) AS rn_dss
|
)
|
||||||
-- Most recent quote per data segment
|
END AS rn_dss
|
||||||
,ROW_NUMBER() OVER (
|
,CASE WHEN b.version = 'Quotes' THEN
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
PARTITION BY b.customer, b.partgroup, b.dataseg, b.version
|
PARTITION BY b.customer, b.partgroup, b.dataseg, b.version
|
||||||
ORDER BY CASE WHEN b.version = 'Quotes' THEN b.odate ELSE NULL END DESC
|
ORDER BY b.odate DESC
|
||||||
) AS rn_dsq
|
)
|
||||||
|
END AS rn_dsq
|
||||||
FROM base b
|
FROM base b
|
||||||
)
|
)
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@ -121,7 +129,7 @@ ON #flagged(customer, partgroup, dataseg, version, part, qty, price, odate, ordn
|
|||||||
-- Step 3.1: Explode all flags from the #flagged table
|
-- Step 3.1: Explode all flags from the #flagged table
|
||||||
WITH exploded_flags AS (
|
WITH exploded_flags AS (
|
||||||
SELECT
|
SELECT
|
||||||
customer, partgroup, part, dataseg, version, part, qty, price, odate, ordnum, quoten,
|
customer, partgroup, part, dataseg, version, qty, price, odate, ordnum, quoten,
|
||||||
flag
|
flag
|
||||||
FROM #flagged
|
FROM #flagged
|
||||||
CROSS APPLY (VALUES (f1), (f2), (f3), (f4), (f5), (f6)) AS f(flag)
|
CROSS APPLY (VALUES (f1), (f2), (f3), (f4), (f5), (f6)) AS f(flag)
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
CREATE OR REPLACE PROCEDURE pricequote.refresh_target_prices_base()
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM pricequote.target_prices_base;
|
||||||
|
|
||||||
DELETE FROM pricequote.target_prices_base;
|
WITH expand AS (
|
||||||
|
SELECT
|
||||||
WITH
|
|
||||||
expand AS (
|
|
||||||
SELECT
|
|
||||||
c.compset,
|
c.compset,
|
||||||
c.stlc,
|
c.stlc,
|
||||||
c.floor,
|
c.floor,
|
||||||
@ -13,15 +15,14 @@ SELECT
|
|||||||
b.vol,
|
b.vol,
|
||||||
b.val,
|
b.val,
|
||||||
b.price,
|
b.price,
|
||||||
b.math math
|
b.math AS math
|
||||||
FROM
|
FROM pricequote.core_target c
|
||||||
pricequote.core_target c
|
LEFT JOIN LATERAL pricequote.build_pricing_path_base(
|
||||||
LEFT JOIN LATERAL pricequote.build_pricing_path_base (options||jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price')) b ON b.lastflag
|
c.options || jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price')
|
||||||
)
|
) AS b
|
||||||
-- select count(*) from expand
|
ON b.lastflag
|
||||||
INSERT INTO
|
)
|
||||||
pricequote.target_prices_base
|
INSERT INTO pricequote.target_prices_base
|
||||||
SELECT
|
SELECT * FROM expand;
|
||||||
*
|
END;
|
||||||
FROM
|
$$;
|
||||||
expand;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user