From cf6e3b6695ef4e707e53216e265b4e26c9b6f98d Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 13 Apr 2021 16:51:00 -0400 Subject: [PATCH] save work on post-volume price adjustment --- offline/last_price.sql | 216 +++++++++++++++++++++++++---------------- 1 file changed, 135 insertions(+), 81 deletions(-) diff --git a/offline/last_price.sql b/offline/last_price.sql index 305530d..74f8352 100644 --- a/offline/last_price.sql +++ b/offline/last_price.sql @@ -1,4 +1,4 @@ -BEGIN; +--BEGIN; WITH ------------------goal price increases--------------------- @@ -257,96 +257,150 @@ FROM }$$::jsonb doc RETURNING * ) --------------build the iteration rows---------------- -,ins AS ( +,poolprice AS ( SELECT - o.fspr - ,o.plnt ---master data - ,o.promo --history date mix - ,o.terms - ,o.bill_cust_descr --history cust mix - ,o.ship_cust_descr --history cust mix - ,o.dsm - ,o.quota_rep_descr --master data - ,o.director - ,o.billto_group --master data + i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) product + ,o.quota_rep_descr + ,o.billto_group ,o.shipto_group - ,o.chan --master data - ,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 --master data - ,o.r_currency --history cust mix - ,o.r_rate --master data - ,o.c_currency --master data - ,o.c_rate --master data - ,0::numeric units - ,ROUND(o.units * (a.price_increment/o.r_rate),2) value_loc - ,ROUND(o.units * a.price_increment,2) value_usd - ,0::numeric cost_loc - ,0::numeric cost_usd - ,o.calc_status --0 - ,o.flag --0 - ,o.order_date --history date mix - ,o.order_month - ,o.order_season - ,o.request_date --history date mix - ,o.request_month - ,o.request_season - ,o.ship_date --history date mix - ,o.ship_month - ,o.ship_season - ,o.version - ---this iteration has to be listed in the master template file in order to be effectively included--- - ,'upload price' iter - ,log.id - ,COALESCE(log.doc->>'tag','') "tag" - ,log.doc->>'message' "comment" - ,log.doc->>'type' module - -----------debug columns--------- - --,value_usd/units price - --,a.py_gasp - --,a.rate - --,a.last_price - --,a.price_increment + ,order_season + ,sum(units) units + ,sum(value_loc) valloc + ,sum(value_usd) valusd + ,sum(o.value_loc)/sum(o.units) price + ,jsonb_agg(DISTINCT iter) iters FROM rlarp.osm_pool o ,rlarp.itemmv i - ,adj a - ,log WHERE i.item = o.part - AND a.product = i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) - AND a.account = o.billto_group - AND a.shipgrp = o.shipto_group - AND a.price_increment <> 0 - AND o.units <> 0 + --AND o.units <> 0 ---only apply to 2022 orders---- AND o.order_date >= '2021-06-01' --only include baseline stuff--- - AND iter IN ('actuals','copy','actuals_plug') + AND segm <> 'Retail' +GROUP BY + i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) + ,o.quota_rep_descr + ,o.billto_group + ,o.shipto_group + ,order_season + --AND iter <> 'upload price' ) ------------aggregate the impact------------ ---SELECT * FROM ins limit 10000 +, pooladj AS ( + SELECT + p.product + ,p.quota_rep_descr + ,p.billto_group + ,p.shipto_group + ,p.price + ,a.py_gasp + ,a.rate + ,a.last_price + ,a.price_increment + FROM + poolprice p + ,adj a + WHERE + a.product = p.product + AND a.account = p.billto_group + AND a.shipgrp = p.shipto_group +) +SELECT * FROM pooladj WHERE product ~ 'STG06000' AND shipto_group = 'BWI' limit 100 +--SELECT * FROM poolprice WHERE product ~ 'TCA06600' AND shipto_group = 'BWI' AND quota_rep_descr = 'BRYAN HILL' LIMIT 1000 +-------------build the iteration rows---------------- +--,ins AS ( --SELECT --- order_season --- ,sum(value_loc) val_loc --- ,sum(value_usd) val_usd +-- o.fspr +-- ,o.plnt ---master data +-- ,o.promo --history date mix +-- ,o.terms +-- ,o.bill_cust_descr --history cust mix +-- ,o.ship_cust_descr --history cust mix +-- ,o.dsm +-- ,o.quota_rep_descr --master data +-- ,o.director +-- ,o.billto_group --master data +-- ,o.shipto_group +-- ,o.chan --master data +-- ,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 --master data +-- ,o.r_currency --history cust mix +-- ,o.r_rate --master data +-- ,o.c_currency --master data +-- ,o.c_rate --master data +-- ,0::numeric units +-- ,ROUND(o.units * (a.price_increment/o.r_rate),2) value_loc +-- ,ROUND(o.units * a.price_increment,2) value_usd +-- ,0::numeric cost_loc +-- ,0::numeric cost_usd +-- ,o.calc_status --0 +-- ,o.flag --0 +-- ,o.order_date --history date mix +-- ,o.order_month +-- ,o.order_season +-- ,o.request_date --history date mix +-- ,o.request_month +-- ,o.request_season +-- ,o.ship_date --history date mix +-- ,o.ship_month +-- ,o.ship_season +-- ,o.version +-- ---this iteration has to be listed in the master template file in order to be effectively included--- +-- ,'upload price' iter +-- ,log.id +-- ,COALESCE(log.doc->>'tag','') "tag" +-- ,log.doc->>'message' "comment" +-- ,log.doc->>'type' module +-- -----------debug columns--------- +-- --,value_usd/units price +-- --,a.py_gasp +-- --,a.rate +-- --,a.last_price +-- --,a.price_increment --FROM --- ins ---GROUP BY --- order_season; -INSERT INTO - rlarp.osm_pool -SELECT * FROM ins; - -COMMIT; +-- rlarp.osm_pool o +-- ,rlarp.itemmv i +-- ,adj a +-- ,log +--WHERE +-- i.item = o.part +-- AND a.product = i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) +-- AND a.account = o.billto_group +-- AND a.shipgrp = o.shipto_group +-- AND a.price_increment <> 0 +-- AND o.units <> 0 +-- ---only apply to 2022 orders---- +-- AND o.order_date >= '2021-06-01' +-- --only include baseline stuff--- +-- AND iter <> 'upload price' +--) +-------------aggregate the impact------------ +----SELECT * FROM ins limit 10000 +----SELECT +---- order_season +---- ,sum(value_loc) val_loc +---- ,sum(value_usd) val_usd +----FROM +---- ins +----GROUP BY +---- order_season; +--,del AS ( +-- DELETE FROM rlarp.osm_pool WHERE iter = 'upload price' RETURNING * +--) +--INSERT INTO +-- rlarp.osm_pool +--SELECT * FROM ins; +-- +--COMMIT;