From 3be3aab2b1223782a53d65119a767dfba0db0a4a Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 10 Apr 2025 18:01:54 -0400 Subject: [PATCH] group and a new pricing row net of pricing changes already made --- offline/price_down_inq.pg.sql | 185 ++++++++++++++++++++++------------ 1 file changed, 119 insertions(+), 66 deletions(-) diff --git a/offline/price_down_inq.pg.sql b/offline/price_down_inq.pg.sql index 8089176..598693d 100644 --- a/offline/price_down_inq.pg.sql +++ b/offline/price_down_inq.pg.sql @@ -249,72 +249,125 @@ pgrp AS ( combine ) -- SELECT * FROM choose where shipto_group = 'MONROVIA' and part = 'NBB005G1BE2B014PYIQX' --- ,delta_row AS ( --- SELECT --- o.fspr --- ,o.plnt --- ,o.promo --- ,o.terms --- ,o.bill_cust_descr --- ,o.ship_cust_descr --- ,o.dsm --- ,o.quota_rep_descr --- ,o.director --- ,o.billto_group --- ,o.shipto_group --- ,o.chan --- ,o.chansub --- ,o.chan_retail --- ,o.part --- ,o.part_descr --- ,o.part_group --- ,o.branding --- ,o.majg_descr --- ,o.ming_descr --- ,o.majs_descr --- ,o.mins_descr --- ,o.segm --- ,o.substance --- ,o.fs_line --- ,o.r_currency --- ,o.r_rate --- ,o.c_currency --- ,o.c_rate --- ,0::numeric units --- ,(c.price_choice * o.units - value_usd)/o.r_rate value_loc --- ,c.price_choice * o.units - value_usd value_usd --- ,0::numeric cost_loc --- ,0::numeric cost_usd --- ,o.calc_status --- ,o.flag --- ,o.order_date --- ,o.order_month --- ,o.order_season --- ,o.request_date --- ,o.request_month --- ,o.request_season --- ,o.ship_date --- ,o.ship_month --- ,o.ship_season --- ,o.version --- ,'Pricing' iter --- ,logload.id logid --- ,logload.doc->>'tag' tag --- ,logload.doc->>'message' "comment" --- ,logload.doc->>'type' module --- ,0::NUMERIC pounds --- FROM --- rlarp.osm_pool o --- CROSS JOIN logload --- INNER JOIN choose c ON --- c.billto_group = o.billto_group --- AND c.shipto_group = o.shipto_group --- AND substring(c.dsm,1,5) = substring(o.dsm,1,5) --- AND c.part = o.part --- AND c.order_date = o.order_date --- WHERE --- o.order_season = 2026 --- ) +,logload AS ( + INSERT INTO rlarp.osm_log (doc) SELECT jsonb_build_object('user',current_user,'tag','Pricing 2','type','Pricing 2','stamp',current_timestamp,'source','top level','message','Pricing 2') RETURNING * +) +,delta_row AS ( + SELECT + o.fspr + ,o.plnt + ,o.promo + ,o.terms + ,o.bill_cust_descr + ,o.ship_cust_descr + ,o.dsm + ,o.quota_rep_descr + ,o.director + ,o.billto_group + ,o.shipto_group + ,o.chan + ,o.chansub + ,o.chan_retail + ,o.part + ,o.part_descr + ,o.part_group + ,o.branding + ,o.majg_descr + ,o.ming_descr + ,o.majs_descr + ,o.mins_descr + ,o.segm + ,o.substance + ,o.fs_line + ,o.r_currency + ,o.r_rate + ,o.c_currency + ,o.c_rate + ,0::numeric units + ,(c.price_choice * sum(o.units) - sum(value_usd))/o.r_rate value_loc + ,c.price_choice * sum(o.units) - sum(value_usd) value_usd + ,0::numeric cost_loc + ,0::numeric cost_usd + ,o.calc_status + ,o.flag + ,o.order_date + ,o.order_month + ,o.order_season + ,o.request_date + ,o.request_month + ,o.request_season + ,o.ship_date + ,o.ship_month + ,o.ship_season + ,o.version + ,'Pricing 2' iter + ,logload.id logid + ,logload.doc->>'tag' tag + ,logload.doc->>'message' "comment" + ,logload.doc->>'type' module + ,0::NUMERIC pounds + FROM + rlarp.osm_pool o + CROSS JOIN logload + INNER JOIN choose c ON + c.billto_group = o.billto_group + AND c.shipto_group = o.shipto_group + AND substring(c.dsm,1,5) = substring(o.dsm,1,5) + AND c.part = o.part + AND c.order_date = o.order_date + WHERE + o.order_season = 2026 + GROUP BY + o.fspr + ,o.plnt + ,o.promo + ,o.terms + ,o.bill_cust_descr + ,o.ship_cust_descr + ,o.dsm + ,o.quota_rep_descr + ,o.director + ,o.billto_group + ,o.shipto_group + ,o.chan + ,o.chansub + ,o.chan_retail + ,o.part + ,o.part_descr + ,o.part_group + ,o.branding + ,o.majg_descr + ,o.ming_descr + ,o.majs_descr + ,o.mins_descr + ,o.segm + ,o.substance + ,o.fs_line + ,o.r_currency + ,o.r_rate + ,o.c_currency + ,o.c_rate + ,c.price_choice + ,o.calc_status + ,o.flag + ,o.order_date + ,o.order_month + ,o.order_season + ,o.request_date + ,o.request_month + ,o.request_season + ,o.ship_date + ,o.ship_month + ,o.ship_season + ,o.version + ,logload.id + ,logload.doc->>'tag' + ,logload.doc->>'message' + ,logload.doc->>'type' +) +-- SELECT SUM(value_usd) from delta_row +-- SELECT * FROM delta_row WHERE shipto_group = 'MONROVIA' +INSERT INTO rlarp.osm_pool SELECT * FROM delta_row -- SELECT billto_group, shipto_group, substring(dsm,1,5), part, order_date, count(*) over (PARTITION BY billto_group, shipto_group, substring(dsm,1,5), part, order_date) cnt -- FROM -- choose