Compare commits
No commits in common. "master" and "detaillevel" have entirely different histories.
master
...
detailleve
@ -15,7 +15,7 @@ RETURNS @result TABLE (
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
DECLARE @age_threshold DATE = DATEADD(month, -18, GETDATE());
|
||||
DECLARE @age_threshold DATE = DATEADD(year, -1, GETDATE());
|
||||
|
||||
-- Extract all relevant objects from JSON
|
||||
DECLARE @dsq NVARCHAR(MAX), @dss NVARCHAR(MAX), @mrq NVARCHAR(MAX), @mrs NVARCHAR(MAX);
|
||||
@ -51,57 +51,39 @@ BEGIN
|
||||
|
||||
-- Use the same selection logic as before
|
||||
-- 1. Prefer the most recent of dss/dsq if either is within the age threshold
|
||||
IF (@dss_date IS NOT NULL AND @dss_date > @age_threshold)
|
||||
BEGIN
|
||||
INSERT INTO @result VALUES (@dss_price, 'dss', @dss_date, @dss_qty, @dss_dataseg, @dss_ord, @dss_quote, @dss_part);
|
||||
RETURN;
|
||||
END
|
||||
-- IF (@dsq_date IS NOT NULL AND @dsq_date > @age_threshold)
|
||||
-- OR (@dss_date IS NOT NULL AND @dss_date > @age_threshold)
|
||||
-- BEGIN
|
||||
-- IF @dsq_date IS NOT NULL AND (@dss_date IS NULL OR @dsq_date >= @dss_date) AND @dsq_date > @age_threshold
|
||||
-- INSERT INTO @result VALUES (@dsq_price, 'dsq', @dsq_date, @dsq_qty, @dsq_dataseg, @dsq_ord, @dsq_quote, @dsq_part);
|
||||
-- ELSE IF @dss_date IS NOT NULL AND @dss_date > @age_threshold
|
||||
-- INSERT INTO @result VALUES (@dss_price, 'dss', @dss_date, @dss_qty, @dss_dataseg, @dss_ord, @dss_quote, @dss_part);
|
||||
-- RETURN;
|
||||
-- END
|
||||
IF (@dsq_date IS NOT NULL AND @dsq_date > @age_threshold)
|
||||
OR (@dss_date IS NOT NULL AND @dss_date > @age_threshold)
|
||||
BEGIN
|
||||
IF @dsq_date IS NOT NULL AND (@dss_date IS NULL OR @dsq_date >= @dss_date) AND @dsq_date > @age_threshold
|
||||
INSERT INTO @result VALUES (@dsq_price, 'dsq', @dsq_date, @dsq_qty, @dsq_dataseg, @dsq_ord, @dsq_quote, @dsq_part);
|
||||
ELSE IF @dss_date IS NOT NULL AND @dss_date > @age_threshold
|
||||
INSERT INTO @result VALUES (@dss_price, 'dss', @dss_date, @dss_qty, @dss_dataseg, @dss_ord, @dss_quote, @dss_part);
|
||||
RETURN;
|
||||
END
|
||||
|
||||
-- 2. If both dss/dsq are older than the threshold, use the most recent of mrs/mrq if either exists
|
||||
IF @mrs_date IS NOT NULL AND @mrs_date > @age_threshold
|
||||
BEGIN
|
||||
INSERT INTO @result VALUES (@mrs_price, 'mrs', @mrs_date, @mrs_qty, @mrs_dataseg, @mrs_ord, @mrs_quote, @mrs_part);
|
||||
RETURN;
|
||||
END
|
||||
-- IF (@mrq_date IS NOT NULL OR @mrs_date IS NOT NULL)
|
||||
-- BEGIN
|
||||
-- IF @mrq_date IS NOT NULL AND (@mrs_date IS NULL OR @mrq_date >= @mrs_date)
|
||||
-- INSERT INTO @result VALUES (@mrq_price, 'mrq', @mrq_date, @mrq_qty, @mrq_dataseg, @mrq_ord, @mrq_quote, @mrq_part);
|
||||
-- ELSE IF @mrs_date IS NOT NULL
|
||||
-- INSERT INTO @result VALUES (@mrs_price, 'mrs', @mrs_date, @mrs_qty, @mrs_dataseg, @mrs_ord, @mrs_quote, @mrs_part);
|
||||
-- RETURN;
|
||||
-- END
|
||||
IF (@mrq_date IS NOT NULL OR @mrs_date IS NOT NULL)
|
||||
BEGIN
|
||||
IF @mrq_date IS NOT NULL AND (@mrs_date IS NULL OR @mrq_date >= @mrs_date)
|
||||
INSERT INTO @result VALUES (@mrq_price, 'mrq', @mrq_date, @mrq_qty, @mrq_dataseg, @mrq_ord, @mrq_quote, @mrq_part);
|
||||
ELSE IF @mrs_date IS NOT NULL
|
||||
INSERT INTO @result VALUES (@mrs_price, 'mrs', @mrs_date, @mrs_qty, @mrs_dataseg, @mrs_ord, @mrs_quote, @mrs_part);
|
||||
RETURN;
|
||||
END
|
||||
|
||||
-- 3. If all are at least as old as the threshold, pick the least oldest price available
|
||||
-- DECLARE
|
||||
-- @best_price NUMERIC(20,5) = NULL
|
||||
-- ,@best_source NVARCHAR(10) = NULL
|
||||
-- ,@best_date DATE = NULL
|
||||
-- ,@best_qty NUMERIC(20,5) = NULL
|
||||
-- ,@best_dataseg NVARCHAR(100) = NULL
|
||||
-- ,@best_ord NVARCHAR(20) = NULL
|
||||
-- ,@best_quote NVARCHAR(20) = NULL
|
||||
-- ,@best_part NVARCHAR(100) = NULL;
|
||||
-- IF @dsq_date IS NOT NULL
|
||||
-- SELECT @best_price = @dsq_price, @best_source = 'dsq', @best_date = @dsq_date, @best_qty = @dsq_qty, @best_dataseg = @dsq_dataseg, @best_ord = @dsq_ord, @best_quote = @dsq_quote, @best_part = @dsq_part;
|
||||
-- IF @dss_date IS NOT NULL AND (@best_date IS NULL OR @dss_date > @best_date)
|
||||
-- SELECT @best_price = @dss_price, @best_source = 'dss', @best_date = @dss_date, @best_qty = @dss_qty, @best_dataseg = @dss_dataseg, @best_ord = @dss_ord, @best_quote = @dss_quote, @best_part = @dss_part;
|
||||
-- IF @mrq_date IS NOT NULL AND (@best_date IS NULL OR @mrq_date > @best_date)
|
||||
-- SELECT @best_price = @mrq_price, @best_source = 'mrq', @best_date = @mrq_date, @best_qty = @mrq_qty, @best_dataseg = @mrq_dataseg, @best_ord = @mrq_ord, @best_quote = @mrq_quote, @best_part = @mrq_part;
|
||||
-- IF @mrs_date IS NOT NULL AND (@best_date IS NULL OR @mrs_date > @best_date)
|
||||
-- SELECT @best_price = @mrs_price, @best_source = 'mrs', @best_date = @mrs_date, @best_qty = @mrs_qty, @best_dataseg = @mrs_dataseg, @best_ord = @mrs_ord, @best_quote = @mrs_quote, @best_part = @mrs_part;
|
||||
DECLARE @best_price NUMERIC(20,5) = NULL, @best_source NVARCHAR(10) = NULL, @best_date DATE = NULL, @best_qty NUMERIC(20,5) = NULL, @best_dataseg NVARCHAR(100) = NULL, @best_ord NVARCHAR(20) = NULL, @best_quote NVARCHAR(20) = NULL, @best_part NVARCHAR(100) = NULL;
|
||||
IF @dsq_date IS NOT NULL
|
||||
SELECT @best_price = @dsq_price, @best_source = 'dsq', @best_date = @dsq_date, @best_qty = @dsq_qty, @best_dataseg = @dsq_dataseg, @best_ord = @dsq_ord, @best_quote = @dsq_quote, @best_part = @dsq_part;
|
||||
IF @dss_date IS NOT NULL AND (@best_date IS NULL OR @dss_date > @best_date)
|
||||
SELECT @best_price = @dss_price, @best_source = 'dss', @best_date = @dss_date, @best_qty = @dss_qty, @best_dataseg = @dss_dataseg, @best_ord = @dss_ord, @best_quote = @dss_quote, @best_part = @dss_part;
|
||||
IF @mrq_date IS NOT NULL AND (@best_date IS NULL OR @mrq_date > @best_date)
|
||||
SELECT @best_price = @mrq_price, @best_source = 'mrq', @best_date = @mrq_date, @best_qty = @mrq_qty, @best_dataseg = @mrq_dataseg, @best_ord = @mrq_ord, @best_quote = @mrq_quote, @best_part = @mrq_part;
|
||||
IF @mrs_date IS NOT NULL AND (@best_date IS NULL OR @mrs_date > @best_date)
|
||||
SELECT @best_price = @mrs_price, @best_source = 'mrs', @best_date = @mrs_date, @best_qty = @mrs_qty, @best_dataseg = @mrs_dataseg, @best_ord = @mrs_ord, @best_quote = @mrs_quote, @best_part = @mrs_part;
|
||||
|
||||
-- IF @best_price IS NOT NULL
|
||||
-- INSERT INTO @result VALUES (@best_price, @best_source, @best_date, @best_qty, @best_dataseg, @best_ord, @best_quote, @best_part);
|
||||
IF @best_price IS NOT NULL
|
||||
INSERT INTO @result VALUES (@best_price, @best_source, @best_date, @best_qty, @best_dataseg, @best_ord, @best_quote, @best_part);
|
||||
|
||||
RETURN;
|
||||
END
|
||||
|
@ -12,7 +12,7 @@ DECLARE
|
||||
BEGIN
|
||||
-- Central control for age threshold
|
||||
DECLARE
|
||||
age_threshold INTERVAL := INTERVAL '18 months';
|
||||
age_threshold INTERVAL := INTERVAL '1 year';
|
||||
dsq_date DATE := NULL;
|
||||
dss_date DATE := NULL;
|
||||
mrq_date DATE := NULL;
|
||||
|
@ -14,28 +14,3 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON pricequote.target_prices TO PUBLIC;
|
||||
DROP TABLE IF EXISTS import.core_target;
|
||||
|
||||
CREATE TABLE import.core_target AS (SELECT * FROM pricequote.core_target);
|
||||
|
||||
WITH
|
||||
expand AS (
|
||||
SELECT
|
||||
c.compset,
|
||||
c.stlc,
|
||||
c.floor,
|
||||
b.ds,
|
||||
b.chan,
|
||||
b.tier,
|
||||
b.vol,
|
||||
b.val,
|
||||
b.price,
|
||||
json_pretty(to_json(b.math)) math
|
||||
FROM
|
||||
pricequote.core_target c
|
||||
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
|
||||
)
|
||||
-- select count(*) from expand
|
||||
INSERT INTO
|
||||
pricequote.target_prices_base
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
expand
|
||||
|
@ -1,75 +1,73 @@
|
||||
{
|
||||
"details": [
|
||||
{
|
||||
"label": "History",
|
||||
"detailLevel": 10,
|
||||
"label": "Model Inputs",
|
||||
"details": [
|
||||
{
|
||||
"label": "Last Quote",
|
||||
"detailLevel": 10,
|
||||
"value": 0.1012,
|
||||
"type": "currency",
|
||||
"note": "XNS0T1G3G18B096 | Ord# 1008338 | 2025-06-12 | Qty 19,200"
|
||||
"label": "Base Cost",
|
||||
"value": 1.22446,
|
||||
"type": "currency"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "List",
|
||||
"detailLevel": 10,
|
||||
"label": "Peer Target",
|
||||
"details": [
|
||||
{
|
||||
"label": "Code: GUAU",
|
||||
"detailLevel": 10,
|
||||
"value": 0.11,
|
||||
"type": "currency",
|
||||
"note": "List Min Qty: 9,600"
|
||||
"label": "Peer Median Margin",
|
||||
"value": 36.873,
|
||||
"type": "percent",
|
||||
"note": "DIR|102 - HANGING POTS|110 - INJECTION|Tier 2"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "Target Calculation",
|
||||
"detailLevel": 10,
|
||||
"label": "Target Support",
|
||||
"detailLevel": 1,
|
||||
"details": [
|
||||
{
|
||||
"label": "XNS0T1G3",
|
||||
"detailLevel": 10,
|
||||
"value": 0.08,
|
||||
"label": "Tier 1 Truckload",
|
||||
"value": 80,
|
||||
"type": "currency",
|
||||
"note": "Base Floor"
|
||||
"note": "reviewed floor price"
|
||||
},
|
||||
{
|
||||
"label": "Channel:WHS",
|
||||
"detailLevel": 10,
|
||||
"value": 0.2,
|
||||
"type": "Percent",
|
||||
"note": "Premium"
|
||||
},
|
||||
{
|
||||
"label": "Volume:1-8",
|
||||
"detailLevel": 10,
|
||||
"value": 0.1,
|
||||
"type": "Percent",
|
||||
"note": "Premium"
|
||||
},
|
||||
{
|
||||
"label": "Target",
|
||||
"detailLevel": 10,
|
||||
"value": 0.1056,
|
||||
"type": "currency",
|
||||
"note": "Total"
|
||||
"label": "Warehouse",
|
||||
"value": 1.2,
|
||||
"type": "percent"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "Guidance",
|
||||
"detailLevel": 10,
|
||||
"label": "Factor Adjustment",
|
||||
"details": [
|
||||
{
|
||||
"label": "Price",
|
||||
"detailLevel": 10,
|
||||
"value": 0.1012,
|
||||
"type": "currency",
|
||||
"note": "Using target price, capped to not exceed last price"
|
||||
"label": "Package UOM",
|
||||
"value": -0.01,
|
||||
"type": "percent"
|
||||
},
|
||||
{
|
||||
"label": "# of Pallets",
|
||||
"value": 0.02,
|
||||
"type": "percent",
|
||||
"note": "0.03"
|
||||
},
|
||||
{
|
||||
"label": "Urgency",
|
||||
"value": 0.03,
|
||||
"type": "percent",
|
||||
"note": "Top Priority"
|
||||
},
|
||||
{
|
||||
"label": "State Adder/Subtractor",
|
||||
"value": -0.02,
|
||||
"type": "percent",
|
||||
"note": "OH"
|
||||
},
|
||||
{
|
||||
"label": "Branding",
|
||||
"value": 0,
|
||||
"type": "currency"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user