diff --git a/sql/quote_review.pg.sql b/sql/quote_review.pg.sql index 86fe3b6..fbaf3e3 100644 --- a/sql/quote_review.pg.sql +++ b/sql/quote_review.pg.sql @@ -48,6 +48,9 @@ lq AS MATERIALIZED ( ,lq.url ,lq.tacticalmodifier ,lq.finalrecommendedprice + ,lq.lowerpricelimit + ,lq.upperpricelimit + ,(lq.upperpricelimit + lq.lowerpricelimit) / 2 midrange ,i.partgroup part_group -- ,pricing->'product'->>'itemrel' item_fit ,i.mpck pltq @@ -55,6 +58,28 @@ lq AS MATERIALIZED ( -- ,pricing->'guidance'->'finalPrice'->>'Reason' reason ,i.curstdus cstd_usd ,i.futstdus fstd_usd + ,CASE + WHEN i.glec = '1NU' THEN + --if more than 8/24 pallets, use floor + CASE WHEN units_each >= 24*mpck THEN lq.lowerpricelimit + -- if more than a pallet use the target price + ELSE CASE WHEN units_each >= 8*mpck THEN (lq.upperpricelimit + lq.lowerpricelimit) / 2 + -- if more than a pallet use the target price + ELSE CASE WHEN units_each < 8*mpck THEN lq.upperpricelimit + -- if more than a pallet use the target price + ELSE CASE WHEN units_each < mpck THEN lq.upperpricelimit * 1.15 + END END END END + ELSE + --if more than 8/24 pallets, use floor + CASE WHEN units_each >= 08*mpck THEN lq.lowerpricelimit + -- if more than a pallet use the target price + ELSE CASE WHEN units_each >= 2*mpck THEN (lq.upperpricelimit + lq.lowerpricelimit) / 2 + -- if more than a pallet use the target price + ELSE CASE WHEN units_each < 2*mpck THEN lq.upperpricelimit + -- if more than a pallet use the target price + ELSE CASE WHEN units_each < mpck THEN lq.upperpricelimit * 1.15 + END END END END + END guidance -- ,(pricing->'guidance'->>'ltp')::numeric ltp -- ,(pricing->'guidance'->>'optimization')::numeric optimization -- ,(pricing->'guidance'->>'inflationFactor')::numeric inflation @@ -99,4 +124,4 @@ lq AS MATERIALIZED ( ,price_usd numeric ) ON TRUE ) -SELECT * FROM hist +SELECT * FROM hist --WHERE qid = 108596