diff --git a/sql/quote_review.pg.sql b/sql/quote_review.pg.sql index cedf56e..f3ae2a5 100644 --- a/sql/quote_review.pg.sql +++ b/sql/quote_review.pg.sql @@ -30,6 +30,7 @@ lq AS MATERIALIZED ( ,lq.shipto ,lq.qchan ,lq.qcustomer + ,CASE lq.qchan WHEN 'DIR' THEN bc.tier ELSE sc.tier END customer_tier ,lq.part ,lq.qoptions ,lq.partbuilt @@ -55,6 +56,7 @@ lq AS MATERIALIZED ( ,lq.lowerpricelimit ,lq.upperpricelimit ,(lq.upperpricelimit + lq.lowerpricelimit) / 2 midrange + ,nt.price qtarget_price ,i.partgroup part_group -- ,pricing->'product'->>'itemrel' item_fit ,i.mpck pltq @@ -116,6 +118,12 @@ lq AS MATERIALIZED ( lq.units_each >= pl.vb_f AND lq.units_each < pl.vb_t ) + LEFT OUTER JOIN pricequote.target_prices nt ON + nt.stlc = i.stlc + AND nt.ds = lq.v1ds + AND nt.chan = lq.qchan + AND nt.tier = CASE lq.qchan WHEN 'DIR' THEN bc.tier ELSE sc.tier END + AND floor(lq.units_each/i.mpck)::int <@ nt.vol WHERE lq.qstat ~ 'Submitted' )