From cf6e3b6695ef4e707e53216e265b4e26c9b6f98d Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 13 Apr 2021 16:51:00 -0400 Subject: [PATCH 1/4] 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; From 3854bed603e3cffee447c307fd95314a1c9413da Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 13 Apr 2021 17:44:06 -0400 Subject: [PATCH 2/4] further isolate odd orders, create change log --- change_log.sql | 13 +++++++++++++ over_under_ship.sql | 28 +++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 change_log.sql diff --git a/change_log.sql b/change_log.sql new file mode 100644 index 0000000..5a22ae2 --- /dev/null +++ b/change_log.sql @@ -0,0 +1,13 @@ +WITH l AS ( + SELECT DISTINCT logid FROM rlarp.osm_pool +) +SELECT + doc->>'user' as user, + (doc->>'stamp')::timestamptz stamp, + CASE WHEN logid IS NULL THEN 'undone' ELSE '' END flag, + doc->>'tag', doc->>'message', + doc->'scenario'->>'quota_rep_descr' dsm +FROM + rlarp.osm_log + LEFT OUTER JOIN l ON logid = id +LIMIT 1000; diff --git a/over_under_ship.sql b/over_under_ship.sql index aec6a87..80aa929 100644 --- a/over_under_ship.sql +++ b/over_under_ship.sql @@ -1,15 +1,25 @@ SELECT - calc_status, - flag, - sum(fb_val_loc * r_rate) filter (where fb_qty < 0) overship, - sum(fb_val_loc * r_rate) filter (where fb_qty > 0) undership + calc_status + ,flag + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty < 0) overship + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty > 0) undership + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND fb_qty = 0) no_units + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND dhincr = 'C') credits + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND "ddord#" = 0 ) no_units FROM - rlarp.osm_dev + rlarp.osmf_dev WHERE - oseas = 2021 - AND version = 'ACTUALS' - AND calc_status = 'CLOSED' - AND flag = 'REMAINDER' + ( + ( + oseas = 2021 + AND odate <@ daterange('2020-06-01','2021-04-11') + ) + OR sseas = 2021 + ) + AND fs_line = '41010' + --AND version = 'ACTUALS' + --AND calc_status = 'CLOSED' + --AND flag = 'REMAINDER' GROUP BY calc_status, flag; From d13519c07c65f44267f4bb0bad6f0ced41a6c387 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 14 Apr 2021 15:26:36 +0000 Subject: [PATCH 3/4] trim part number coming from CMS listing in spreadsheet with whitespace at end --- route_sql/new_basket.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index 89c8553..a29819f 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -246,7 +246,7 @@ SELECT ,mxm.r_currency ,jr.bill_cust_descr ,jr.ship_cust_descr - ,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part + ,rtrim((regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1]) part ,jr.part_descr ,substring(jr.part_descr,1,8) part_group ,mxm.qty*mxm.momix*jr.mix units From 6f0d8745d2c57d479f2e0b806ed717c4f47132aa Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 14 Apr 2021 11:28:11 -0400 Subject: [PATCH 4/4] include module used --- change_log.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/change_log.sql b/change_log.sql index 5a22ae2..52ec984 100644 --- a/change_log.sql +++ b/change_log.sql @@ -4,6 +4,7 @@ WITH l AS ( SELECT doc->>'user' as user, (doc->>'stamp')::timestamptz stamp, + doc->>'type' as type, CASE WHEN logid IS NULL THEN 'undone' ELSE '' END flag, doc->>'tag', doc->>'message', doc->'scenario'->>'quota_rep_descr' dsm