From 28214bece738f33f18516f0049a09825d98f719d Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 2 Apr 2020 10:05:14 -0400 Subject: [PATCH 01/12] update fx rates --- build/snap_fx.sql | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/build/snap_fx.sql b/build/snap_fx.sql index 07ca5c1..99ed391 100644 --- a/build/snap_fx.sql +++ b/build/snap_fx.sql @@ -1,27 +1,7 @@ -UPDATE - rlarp.osmf_dev -SET - r_rate = .7597 -WHERE - r_currency = 'CA'; - -UPDATE - rlarp.osmf_dev -SET - r_rate = 1 -WHERE - r_currency = 'US'; - -UPDATE - rlarp.osmf_dev -SET - c_rate = .7597 -WHERE - c_currency = 'CA'; - -UPDATE - rlarp.osmf_dev -SET - c_rate = 1 -WHERE - c_currency = 'US'; \ No newline at end of file +------------update fx rates----------------------------------------------------------------- +UPDATE rlarp.osmf_dev SET r_rate = .7518 WHERE r_currency = 'CA' +UPDATE rlarp.osmf_dev SET c_rate = .7518 WHERE c_currency = 'CA' +UPDATE rlarp.osm_pool SET r_rate = .7518 WHERE r_currency = 'CA' +UPDATE rlarp.osm_pool SET value_usd = value_loc * r_rate WHERE r_currency = 'CA' +UPDATE rlarp.osm_pool SET c_rate = .7518 WHERE c_currency = 'CA' +UPDATE rlarp.osm_pool SET cost_usd = cost_loc * c_rate WHERE c_currency = 'CA' \ No newline at end of file From f764bc4c31606520908963a8adf53a687d31b2fd Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 2 Apr 2020 10:06:22 -0400 Subject: [PATCH 02/12] swap fake parts --- build/swap_fake_parts.sql | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 build/swap_fake_parts.sql diff --git a/build/swap_fake_parts.sql b/build/swap_fake_parts.sql new file mode 100644 index 0000000..32b0073 --- /dev/null +++ b/build/swap_fake_parts.sql @@ -0,0 +1,26 @@ +with +fp as ( + SELECT + od.part, + sum(fb_val_loc * r_rate) sales, + sum(fb_cst_loc * c_rate) scost + FROM + rlarp.osmf_dev od + LEFT OUTER JOIN rlarp.itemmv m ON + m.item = od.part + WHERE + m.item is null + GROUP BY + od.part +) +SELECT + fp.part, + min(item) item +FROM + fp + LEFT OUTER JOIN rlarp.itemmv m ON + substring(m.item,1,11) = fp.part +GROUP BY + fp.part +ORDER BY + fp.part \ No newline at end of file From 6265a4ff4efa6d0584da41face389bc2ac6a338e Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 7 Apr 2020 14:28:32 -0400 Subject: [PATCH 03/12] script pieces for merging actuals --- build/merge_actuals_exec.sql | 6 ++ build/merge_actuals_pool.sql | 163 ++++++++++++++++++++++++++++++ build/merge_actuals_prep.sql | 186 +++++++++++++++++++++++++++++++++++ build/snap_cost_current.sql | 3 +- build/snap_fx.sql | 14 +-- tots.sql | 16 +++ 6 files changed, 381 insertions(+), 7 deletions(-) create mode 100644 build/merge_actuals_exec.sql create mode 100644 build/merge_actuals_pool.sql create mode 100644 build/merge_actuals_prep.sql create mode 100644 tots.sql diff --git a/build/merge_actuals_exec.sql b/build/merge_actuals_exec.sql new file mode 100644 index 0000000..6ab1fe6 --- /dev/null +++ b/build/merge_actuals_exec.sql @@ -0,0 +1,6 @@ + +DELETE FROM rlarp.osmf_dev WHERE odate < '2020-04-01'; +INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2020-04-01'; + + + diff --git a/build/merge_actuals_pool.sql b/build/merge_actuals_pool.sql new file mode 100644 index 0000000..d3034e6 --- /dev/null +++ b/build/merge_actuals_pool.sql @@ -0,0 +1,163 @@ +BEGIN; + +DELETE FROM rlarp.osm_pool WHERE order_date < '2020-04-01'; + +INSERT INTO rlarp.osm_pool +WITH +repc AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' +) +,SEG AS ( + SELECT + GLEC + ,SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) +) +----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- +,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' +) +----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- +,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' +) +SELECT + fspr + ,plnt + ,promo + ,terms + ,bill_cust||' - '||bc.bvname bill_cust_descr + ,ship_cust||' - '||sc.bvname ship_cust_descr + ,dsm + ,coalesce(repc.repp,dsm) quota_rep_descr + ,repc.director + ,account billto_group + ,shipgrp shipto_group + ,chan + ,chansub + ,CASE seg.segm + WHEN 'Retail' THEN + CASE o.bill_class + WHEN 'RMAS' THEN 'MASS' + WHEN 'RNAT' THEN 'NATIONAL' + ELSE 'OTHER' + END + ELSE o.chan + END chan_retail + ,part + ,part||coalesce(' - '||i.descr,'') part_descr + ,stlcd part_group + ,brnd branding + ,o.majg||' - '||i.majgd majg_descr + ,o.ming||' - '||i.mingd ming_descr + ,o.majs||' - '||i.majsd majs_descr + ,o.mins||' - '||i.minsd mins_descr + ,seg.segm + ,CASE WHEN o.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance + ,fs_line + ,r_currency + ,r_rate + ,c_currency + ,c_rate + ,fb_qty units + ,fb_val_loc value_loc + ,fb_val_loc * r_rate value_usd + ,fb_cst_loc_cur cost_loc + ,fb_cst_loc_cur * c_rate cost_usd + ,calc_status + ,flag + ,o.odate order_date + ,to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month + ,oseas order_season + ,rdate request_date + ,to_char(CASE WHEN extract(month FROM o.rdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.rdate),'FM00')||' - '||to_char(o.rdate,'TMMon') request_month + ,rseas request_season + ,sdate ship_date + ,to_char(CASE WHEN extract(month FROM o.sdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.sdate),'FM00')||' - '||to_char(o.sdate,'TMMon') ship_month + ,sseas ship_season + ,version + ,iter + ,logload.id logid + ,logload.doc->>'tag' tag + ,logload.doc->>'message' "comment" + ,logload.doc->>'type' module +FROM + rlarp.osmf_dev o + INNER JOIN rlarp.osm_log logload ON + logload.id = 1 + LEFT OUTER JOIN lgdat.cust bc ON + bc.bvcust = o.bill_cust + LEFT OUTER JOIN lgdat.cust sc ON + sc.bvcust = o.ship_cust + LEFT OUTER JOIN repc ON + repc.rcode = o.dsm + /* + LEFT OUTER JOIN lgdat.majg ON + bqgrp = o.majg + LEFT OUTER JOIN lgdat.mmgp ON + brmgrp = o.ming + AND BRGRP = o.majg + LEFT OUTER JOIN si ON + si.bsmjcd = o.majs + AND si.bsmncd = o.mins + LEFT OUTER JOIN sj ON + sj.bsmjcd = o.majs + */ + LEFT OUTER JOIN seg ON + seg.glec = o.glec + LEFT OUTER JOIN rlarp.itemm i ON + i.item = o.part +WHERE + odate < '2020-04-01'; + + +SELECT + "version", + iter, + order_season, + order_month , + sum(value_usd ) value_usd +FROM + RLARP.osm_pool op +WHERE + --oseas = 2020 + fs_line = '41010' + --AND odate < '2020-04-01' + AND CALC_STATUS <> 'CANCELED' + AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') +GROUP BY + "version", + iter, + order_season, + order_month; + + +--ROLLBACK; + +commit; \ No newline at end of file diff --git a/build/merge_actuals_prep.sql b/build/merge_actuals_prep.sql new file mode 100644 index 0000000..bc4e96e --- /dev/null +++ b/build/merge_actuals_prep.sql @@ -0,0 +1,186 @@ +--\timing +truncate table rlarp.osmfs_dev; + +WITH +gld AS ( + SELECT + N1COMP COMP + ,N1CCYY FSYR + ,KPMAXP PERDS + ,N1FSPP PERD + ,to_char(N1FSYP,'FM0000') FSPR + ,N1SD01 SDAT + ,N1ED01 EDAT + ,to_char(N1ED01,'yymm') CAPR + ,N1ED01 - N1SD01 +1 NDAYS + ,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR + ,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR + FROM + LGDAT.GLDATREF + INNER JOIN LGDAT.GLDATE ON + KPCOMP = N1COMP AND + KPCCYY = N1CCYY + WHERE + N1COMP = 93 + --AND DIGITS(N1FSYP) = '1901' +) +--SELECT * FROM gld +,baseline AS ( + SELECT + -----------documents------------- + null::int "ddord#" + ,null::int "dditm#" + ,null::int "fgbol#" + ,null::int "fgent#" + ,null::int "diinv#" + ,null::int "dilin#" + ,null::int quoten + ,null::int quotel + ----------dates/status------------------ + ,o.odate dcodat + ,o.rdate ddqdat + ,null::date dcmdat + ,null::date fesdat + ,greatest(least(o.sdate,gld.edat),gld.sdat) dhidat + ,null::text fesind + ,null::text dhpost + ,o.fspr + -----------measures-------------------- + ,null::numeric ddqtoi + ,null::numeric ddqtsi + ,null::numeric fgqshp + ,null::numeric diqtsh + ,null::numeric diext + ,null::numeric ditdis + ,null::jsonb discj + ,null::text dhincr + ,plnt + ,COALESCE(o.promo,'') promo + ,null::text return_reas + ,o.terms + ,null::text custpo + ,null::text remit_to + ,null::text bill_class + ,o.bill_cust + ,null::text bill_rep + ,null::text bill_terr + ,null::text ship_class + ,ship_cust + ,null::text ship_rep + ,null::text ship_terr + ,null::text dsm + ,null::text account + ,null::text shipgrp + ,null::text geo + ,null::text chan + ,null::text chansub + ,null::text orig_ctry + ,null::text orig_prov + ,null::text orig_post + ,null::text bill_ctry + ,null::text bill_prov + ,null::text bill_post + ,null::text dest_ctry + ,null::text dest_prov + ,null::text dest_post + ,o.part + ,null::text styc + ,null::text colc + ,null::text colgrp + ,null::text coltier + ,null::text colstat + ,null::text sizc + ,null::text pckg + ,null::text kit + ,null::text brnd + ,null::text majg + ,null::text ming + ,null::text majs + ,null::text mins + ,null::text gldco + ,null::text gldc + ,null::text glec + ,null::text harm + ,null::text clss + ,null::text brand + ,null::text assc + ,null::text ddunit + ,null::text unti + ,null::numeric lbs + ,null::numeric plt + ,null::text plcd + ,o.fs_line + ,o.r_currency + ,o.r_rate r_rate + ,o.c_currency + ,o.c_rate c_rate + ,sum(o.fb_qty) fb_qty + ,sum(o.fb_val_loc) fb_val_loc + ,sum(o.fb_val_loc_dis) fb_val_loc_dis + ,sum(o.fb_val_loc_qt) fb_val_loc_qt + ,sum(o.fb_val_loc_pl) fb_val_loc_pl + ,sum(o.fb_val_loc_tar) fb_val_loc_tar + ,sum(o.fb_cst_loc) fb_cst_loc + ,sum(o.fb_cst_loc_cur) fb_cst_loc_cur + ,sum(o.fb_cst_loc_fut) fb_cst_loc_fut + ,o.calc_status + ,o.flag + ,o.odate + ,o.oseas + ,o.rdate + ,o.rseas + -----when null, greatest/least is just going to act like coalesce + ,greatest(least(o.sdate,gld.edat),gld.sdat) sdate + ,ss.ssyr sseas + ,'15mo' "version" + ,'actuals' iter + FROM + rlarp.osm_dev o + --snap the ship dates of the historic fiscal period + LEFT OUTER JOIN gld ON + gld.fspr = o.fspr + --get the shipping season for open orders based on the snapped date + LEFT OUTER JOIN gld ss ON + greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat + WHERE + ( + --base period orders booked.... + o.odate <@ daterange('2019-06-01','2020-04-01') + --...or any open orders currently booked before cutoff.... + OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-04-01') + --...or anything that shipped in that period + OR o.fspr BETWEEN '2001' AND '2010' + ) + AND fs_line = '41010' + AND calc_status <> 'CANCELED' + AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') + GROUP BY + o.fspr + ,plnt + ,COALESCE(o.promo,'') + ,o.terms + ,o.bill_cust + ,ship_cust + ,o.part + ,o.fs_line + ,o.r_currency + ,o.r_rate + ,o.c_currency + ,o.c_rate + ,o.calc_status + ,o.flag + ,o.odate + ,o.oseas + ,o.rdate + ,o.rseas + ,greatest(least(o.sdate,gld.edat),gld.sdat) + ,ss.ssyr +) +INSERT INTO rlarp.osmfs_dev +SELECT * FROM baseline; + +---identify short ships: causes disconnect with actual sales------------------------------------------------------------------- +--UPDATE rlarp.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER'; + +---identify goofy ship dates: causes disconnect with sales when splicing in a forecast that has this problem------------------- +--UPDATE rlarp.osmfs SET iter = 'bad date' WHERE adj_shipdate < adj_orderdate; \ No newline at end of file diff --git a/build/snap_cost_current.sql b/build/snap_cost_current.sql index fa54065..6dcc112 100644 --- a/build/snap_cost_current.sql +++ b/build/snap_cost_current.sql @@ -33,6 +33,7 @@ FROM clist c WHERE c.part = o.part - AND c.plnt = o.plnt; + AND c.plnt = o.plnt + AND version = 'b21'; commit; \ No newline at end of file diff --git a/build/snap_fx.sql b/build/snap_fx.sql index 99ed391..606d732 100644 --- a/build/snap_fx.sql +++ b/build/snap_fx.sql @@ -1,7 +1,9 @@ ------------update fx rates----------------------------------------------------------------- -UPDATE rlarp.osmf_dev SET r_rate = .7518 WHERE r_currency = 'CA' -UPDATE rlarp.osmf_dev SET c_rate = .7518 WHERE c_currency = 'CA' -UPDATE rlarp.osm_pool SET r_rate = .7518 WHERE r_currency = 'CA' -UPDATE rlarp.osm_pool SET value_usd = value_loc * r_rate WHERE r_currency = 'CA' -UPDATE rlarp.osm_pool SET c_rate = .7518 WHERE c_currency = 'CA' -UPDATE rlarp.osm_pool SET cost_usd = cost_loc * c_rate WHERE c_currency = 'CA' \ No newline at end of file +UPDATE rlarp.osmf_dev SET r_rate = .7518 WHERE r_currency = 'CA' AND version = 'b21'; +UPDATE rlarp.osmf_dev SET r_rate = 1.0000 WHERE r_currency = 'US' AND version = 'b21'; +UPDATE rlarp.osmf_dev SET c_rate = .7518 WHERE c_currency = 'CA' AND version = 'b21'; +UPDATE rlarp.osmf_dev SET c_rate = 1.0000 WHERE c_currency = 'US' AND version = 'b21'; +UPDATE rlarp.osm_pool SET r_rate = .7518 WHERE r_currency = 'CA' AND version = 'b21'; +UPDATE rlarp.osm_pool SET value_usd = value_loc * r_rate WHERE r_currency = 'CA' AND version = 'b21'; +UPDATE rlarp.osm_pool SET c_rate = .7518 WHERE c_currency = 'CA' AND version = 'b21'; +UPDATE rlarp.osm_pool SET cost_usd = cost_loc * c_rate WHERE c_currency = 'CA' AND version = 'b21'; \ No newline at end of file diff --git a/tots.sql b/tots.sql new file mode 100644 index 0000000..fa0d17c --- /dev/null +++ b/tots.sql @@ -0,0 +1,16 @@ +SELECT + oseas, + to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month, + version, + iter, + sum(fb_val_loc) value_loc +FROM + rlarp.osmfs_dev o +GROUP BY + oseas, + to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon'), + version, + iter +ORDER BY + oseas asc, + order_month asc From 17265d0b36b9e375e3486bb6bec40c77234bb7e6 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 7 Apr 2020 14:53:53 -0400 Subject: [PATCH 04/12] add totals queries for tie-outs --- build/tots.sql | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ tots.sql | 16 ------------- 2 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 build/tots.sql delete mode 100644 tots.sql diff --git a/build/tots.sql b/build/tots.sql new file mode 100644 index 0000000..4300e0c --- /dev/null +++ b/build/tots.sql @@ -0,0 +1,63 @@ +SELECT + oseas, + to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month, + version, + iter, + sum(fb_val_loc) value_loc +FROM + rlarp.osmfs_dev o +GROUP BY + oseas, + to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon'), + version, + iter +ORDER BY + oseas asc, + order_month asc + + +------------------------------------------short ships------------------------------------- +SELECT + version, + iter, + oseas, + SUM(FB_VAL_LOC::numeric *r_rate::Numeric) +FROM + RLARP.osmf_dev +WHERE + --oseas = 2020 + fs_line = '41010' + --AND odate < '2020-04-01' + AND CALC_STATUS <> 'CANCELED' + AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') +GROUP BY + version, + iter, + oseas + + select distinct version from rlarp.osm_pool + + + + +SELECT + oseas, + to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month, + r_currency, + r_rate, + sum(fb_val_loc) value_loc +FROM + rlarp.osmf_dev o +WHERE + oseas >= 2020 + --AND fs_line = '41010' + --AND odate < '2020-04-01' +GROUP BY + oseas, + to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon'), + r_currency, + r_rate + --glec +ORDER BY + oseas asc, + order_month asc diff --git a/tots.sql b/tots.sql deleted file mode 100644 index fa0d17c..0000000 --- a/tots.sql +++ /dev/null @@ -1,16 +0,0 @@ -SELECT - oseas, - to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month, - version, - iter, - sum(fb_val_loc) value_loc -FROM - rlarp.osmfs_dev o -GROUP BY - oseas, - to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon'), - version, - iter -ORDER BY - oseas asc, - order_month asc From 9826b5f810f02bfe98bb03fff91d2101e307d4b6 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 16 Apr 2020 19:15:55 -0400 Subject: [PATCH 05/12] prevent joining to fake parts, and eliminate b21 filter --- build/snap_cost_current.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build/snap_cost_current.sql b/build/snap_cost_current.sql index 6dcc112..de94437 100644 --- a/build/snap_cost_current.sql +++ b/build/snap_cost_current.sql @@ -7,6 +7,10 @@ plist AS ( ,plnt FROM rlarp.osmf_dev + -----prevent a list of fake parts + INNER JOIN lgdat.stka ON + v6part = part + AND v6plnt = plnt ) ,clist AS ( SELECT @@ -33,7 +37,7 @@ FROM clist c WHERE c.part = o.part - AND c.plnt = o.plnt - AND version = 'b21'; + AND c.plnt = o.plnt; + --AND version = 'b21'; commit; \ No newline at end of file From 474b1339153d70b2e5288d622178800b21dbcfbe Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 5 May 2020 11:31:27 -0400 Subject: [PATCH 06/12] increment cutoff date for actuals --- build/merge_actuals_exec.sql | 4 ++-- build/merge_actuals_prep.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/merge_actuals_exec.sql b/build/merge_actuals_exec.sql index 6ab1fe6..179177d 100644 --- a/build/merge_actuals_exec.sql +++ b/build/merge_actuals_exec.sql @@ -1,6 +1,6 @@ -DELETE FROM rlarp.osmf_dev WHERE odate < '2020-04-01'; -INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2020-04-01'; +DELETE FROM rlarp.osmf_dev WHERE odate < '2020-05-01'; +INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2020-05-01'; diff --git a/build/merge_actuals_prep.sql b/build/merge_actuals_prep.sql index bc4e96e..d70e25e 100644 --- a/build/merge_actuals_prep.sql +++ b/build/merge_actuals_prep.sql @@ -145,9 +145,9 @@ gld AS ( WHERE ( --base period orders booked.... - o.odate <@ daterange('2019-06-01','2020-04-01') + o.odate <@ daterange('2019-06-01','2020-05-01') --...or any open orders currently booked before cutoff.... - OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-04-01') + OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-05-01') --...or anything that shipped in that period OR o.fspr BETWEEN '2001' AND '2010' ) From c0e348bb2f75fbab7a191afd2e1fff0d5e1cd69d Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 5 May 2020 16:52:53 -0400 Subject: [PATCH 07/12] increment range for actuals --- build/merge_actuals_exec.sql | 5 +---- build/merge_actuals_pool.sql | 4 ++-- build/merge_actuals_prep.sql | 3 ++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build/merge_actuals_exec.sql b/build/merge_actuals_exec.sql index 179177d..852c99b 100644 --- a/build/merge_actuals_exec.sql +++ b/build/merge_actuals_exec.sql @@ -1,6 +1,3 @@ DELETE FROM rlarp.osmf_dev WHERE odate < '2020-05-01'; -INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2020-05-01'; - - - +INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2020-05-01'; \ No newline at end of file diff --git a/build/merge_actuals_pool.sql b/build/merge_actuals_pool.sql index d3034e6..369f2be 100644 --- a/build/merge_actuals_pool.sql +++ b/build/merge_actuals_pool.sql @@ -1,6 +1,6 @@ BEGIN; -DELETE FROM rlarp.osm_pool WHERE order_date < '2020-04-01'; +DELETE FROM rlarp.osm_pool WHERE order_date < '2020-05-01'; INSERT INTO rlarp.osm_pool WITH @@ -134,7 +134,7 @@ FROM LEFT OUTER JOIN rlarp.itemm i ON i.item = o.part WHERE - odate < '2020-04-01'; + odate < '2020-05-01'; SELECT diff --git a/build/merge_actuals_prep.sql b/build/merge_actuals_prep.sql index d70e25e..513d845 100644 --- a/build/merge_actuals_prep.sql +++ b/build/merge_actuals_prep.sql @@ -149,11 +149,12 @@ gld AS ( --...or any open orders currently booked before cutoff.... OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-05-01') --...or anything that shipped in that period - OR o.fspr BETWEEN '2001' AND '2010' + OR o.fspr BETWEEN '2001' AND '2011' ) AND fs_line = '41010' AND calc_status <> 'CANCELED' AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') + AND "version" = 'ACTUALS' GROUP BY o.fspr ,plnt From 48b1beb8afab15815afff0f641830285faed1856 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 5 May 2020 19:41:07 -0400 Subject: [PATCH 08/12] values have large decimals, round them to 2 --- build/round_pool.sql | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 build/round_pool.sql diff --git a/build/round_pool.sql b/build/round_pool.sql new file mode 100644 index 0000000..d3d05a7 --- /dev/null +++ b/build/round_pool.sql @@ -0,0 +1,7 @@ +UPDATE rlarp.osm_pool +SET + value_loc = round(value_loc,2), + value_usd = round(value_usd,2), + cost_usd = round(cost_usd,2), + cost_loc = round(cost_loc,2), + units = round(units,2); \ No newline at end of file From a2a7bee6e04ec485f82c400ec69d64e8e0c755a8 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 6 May 2020 17:43:13 -0400 Subject: [PATCH 09/12] delete accidental cross-over update --- build/edit_xover.sql | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 build/edit_xover.sql diff --git a/build/edit_xover.sql b/build/edit_xover.sql new file mode 100644 index 0000000..27b9541 --- /dev/null +++ b/build/edit_xover.sql @@ -0,0 +1,33 @@ +begin; + +WITH d AS ( +DELETE FROM + rlarp.osm_pool +WHERE + logid IN ( + SELECT + p.logid + --jsonb_agg(DISTINCT p.quota_rep_descr), + --l.doc->>'user' usr, + --l.doc->>'message' com, + --(l.doc->>'stamp')::timestamp stamp, + ,sum(value_usd) value_usd + FROM + rlarp.osm_pool p + INNER JOIN rlarp.osm_log l ON + l.id = p.logid + WHERE + l.doc->>'user' = 'Baggetta, Antony' + AND dsm NOT IN ('10023','10026','10032','30010','30033','30035','90050') + --quota_rep_descr IN ('JORDAN BUKOWSKI' ,'RICHARD MEULE') + AND logid > 1 + GROUP BY + p.logid + --p.quota_rep_descr, + --l.doc->>'user', + --l.doc->>'message', + --(l.doc->>'stamp')::timestamp + ) + AND dsm NOT IN ('10023','10026','10032','30010','30033','30035','90050') +) +SELECT * FROM d \ No newline at end of file From f57cb5f26aae7aab5176a9c8bd476987c4a43e1c Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 11 May 2020 20:05:46 -0400 Subject: [PATCH 10/12] update fx rate, probably should not override anyways --- build/convert_pool.sql | 6 +++--- build/swap_fake_parts.sql | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build/convert_pool.sql b/build/convert_pool.sql index 6f38fec..f3cd8f7 100644 --- a/build/convert_pool.sql +++ b/build/convert_pool.sql @@ -141,7 +141,7 @@ plist AS ( UPDATE - rlarp.osmfS_dev o + rlarp.osmfs_dev o SET fb_cst_loc_cur = c.stdcost * o.fb_qty FROM @@ -364,7 +364,7 @@ WHERE UPDATE rlarp.osmfS_dev SET - r_rate = .7597 + r_rate = .7518 WHERE r_currency = 'CA'; @@ -378,7 +378,7 @@ WHERE UPDATE rlarp.osmfS_dev SET - c_rate = .7597 + c_rate = .7518 WHERE c_currency = 'CA'; diff --git a/build/swap_fake_parts.sql b/build/swap_fake_parts.sql index 32b0073..0e21b96 100644 --- a/build/swap_fake_parts.sql +++ b/build/swap_fake_parts.sql @@ -15,12 +15,15 @@ fp as ( ) SELECT fp.part, + fp.sales, min(item) item FROM fp LEFT OUTER JOIN rlarp.itemmv m ON substring(m.item,1,11) = fp.part GROUP BY - fp.part + fp.part, + fp.sales ORDER BY + fp.sales desc,` fp.part \ No newline at end of file From f5d464677e057b8c07f719513fa79070277bbb1c Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 11 May 2020 20:54:35 -0400 Subject: [PATCH 11/12] add tie-out check for post-conversion --- build/check_osmf_match.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 build/check_osmf_match.sql diff --git a/build/check_osmf_match.sql b/build/check_osmf_match.sql new file mode 100644 index 0000000..fda0286 --- /dev/null +++ b/build/check_osmf_match.sql @@ -0,0 +1,22 @@ +SELECT + order_season + ,sum(value_usd) value_usd +FROM + rlarp.osm_pool +WHERE + order_season = 2021 + --AND version = 'b21' +GROUP BY + order_season +UNION ALL +SELECT + oseas + ,sum(fb_val_loc * r_rate) value_usd +FROM + rlarp.osmf_dev +WHERE + oseas = 2021 + AND version = 'b21' +GROUP BY + oseas + From 76edca43dc3c502508793284558071f67fe60bf4 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 12 May 2020 08:51:25 -0400 Subject: [PATCH 12/12] test for match after pool conversion --- build/check_osmf_match_sales.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 build/check_osmf_match_sales.sql diff --git a/build/check_osmf_match_sales.sql b/build/check_osmf_match_sales.sql new file mode 100644 index 0000000..7270101 --- /dev/null +++ b/build/check_osmf_match_sales.sql @@ -0,0 +1,22 @@ +SELECT + ship_season + ,sum(value_usd) value_usd +FROM + rlarp.osm_pool +WHERE + ship_season = 2021 + --AND version = 'b21' +GROUP BY + ship_season +UNION ALL +SELECT + sseas + ,sum(fb_val_loc * r_rate) value_usd +FROM + rlarp.osmf_dev +WHERE + sseas = 2021 + --AND version = 'b21' +GROUP BY + sseas +