diff --git a/build/build_merge.sql b/build/build_merge.sql deleted file mode 100644 index 56604bb..0000000 --- a/build/build_merge.sql +++ /dev/null @@ -1,19 +0,0 @@ -SELECT - version - ,iter - ,oseas - ,g.sspr || ' ' || to_char(odate,'Mon') omon - ,COUNT(*) cnt - ,sum(fb_val_loc * r_rate) amt -FROM - rlarp.osmf_stage o - INNER JOIN rlarp.gld g ON - o.odate <@ g.drange -GROUP BY - version - ,iter - ,oseas - ,g.sspr || ' ' || to_char(odate,'Mon') -ORDER BY - oseas - ,omon diff --git a/build/build_pool_schema.sql b/build/build_pool_schema.sql deleted file mode 100644 index 690f21b..0000000 --- a/build/build_pool_schema.sql +++ /dev/null @@ -1,183 +0,0 @@ -BEGIN; - -DROP TABLE IF EXISTS rlarp.osm_pool; -DROP TABLE IF EXISTS rlarp.osm_log; - -CREATE TABLE IF NOT EXISTS rlarp.osm_log(id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, doc jsonb); - -CREATE TABLE IF NOT EXISTS rlarp.osm_pool AS ( -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','Sustainable'), - ('1SU','Sustainable'), - ('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,'') <> '' -) -,logload AS ( - INSERT INTO rlarp.osm_log (doc) SELECT jsonb_build_object('user',current_user,'tag','Initial Build','type','build_pool','stamp',current_timestamp,'source','top level','message','don''t undo') RETURNING * -) -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 - --for 1RE coded product - WHEN 'Retail' THEN - CASE o.bill_class - WHEN 'RONL' THEN 'Online' - WHEN 'RNAT' THEN 'National' - WHEN 'RMAS' THEN 'National' - ELSE - ------ ship-to class --------------------- - CASE o.chan - WHEN 'GDIS' THEN 'Distribution' - WHEN 'NDIS' THEN 'Distribution' - WHEN 'RDIS' THEN 'Distribution' - WHEN 'GDRP' THEN 'Grower' - WHEN 'NDRP' THEN 'Grower' - WHEN 'RDRP' THEN 'Distribution' - WHEN 'GDIR' THEN 'Grower' - WHEN 'NDIR' THEN 'Grower' - -------this will probably need reviewed-------- - WHEN 'RDIR' THEN 'Distribution' - WHEN 'NDIR' THEN 'Grower' - WHEN 'GDIR' THEN 'Grower' - ELSE 'Distribution' - END - END - --for 1SU 1CU coded product - WHEN 'Sustainable' THEN - CASE SUBSTRING(o.coltier,1,1) - --anything with a bio color tier is bio on the channel - WHEN 'R' THEN 'Bio' - ELSE - CASE o.glec - --any 1SU that is not bio is fiber - WHEN '1SU' THEN 'Fiber' - --any 1CU that is not bio is commercial - WHEN '1CU' THEN 'Commercial' - ELSE o.chan - END - 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 - CROSS JOIN logload - 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 - --LIMIT 100 -) WITH DATA; - -CREATE INDEX osm_qr ON rlarp.osm_pool(quota_rep_descr, bill_cust_descr, ship_cust_descr); -ALTER TABLE rlarp.osm_pool ADD CONSTRAINT logfk FOREIGN KEY (logid) REFERENCES rlarp.osm_log(id); -CREATE INDEX osm_pool_logid ON rlarp.osm_pool(logid); -GRANT ALL ON TABLE rlarp.osm_log TO api; -GRANT ALL ON TABLE rlarp.osm_pool TO api; - -COMMIT; diff --git a/build/check_osmf_match.sql b/build/check_osmf_match.sql deleted file mode 100644 index 88ef531..0000000 --- a/build/check_osmf_match.sql +++ /dev/null @@ -1,22 +0,0 @@ -SELECT - order_season - ,sum(coalesce(value_usd,0)) value_usd -FROM - rlarp.osm_pool -WHERE - order_season = 2022 - --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 = 2022 - AND version = 'b22' -GROUP BY - oseas - diff --git a/build/check_osmf_match_sales.sql b/build/check_osmf_match_sales.sql deleted file mode 100644 index 7270101..0000000 --- a/build/check_osmf_match_sales.sql +++ /dev/null @@ -1,22 +0,0 @@ -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 - diff --git a/build/convert_pool.sql b/build/convert_pool.sql deleted file mode 100644 index 468964e..0000000 --- a/build/convert_pool.sql +++ /dev/null @@ -1,428 +0,0 @@ -BEGIN; - -DELETE FROM rlarp.osmfs_dev; - -INSERT INTO - rlarp.osmfs_dev -SELECT - null::int4, - null::int4, - null::int4, - null::int4, - null::int4, - null::int4, - null::int4, - null::int4, - order_date, - request_date, - null::date, - null::date, - ship_date, - null::text, - null::text, - fspr, - null::numeric, - null::numeric, - null::numeric, - null::numeric, - null::numeric, - null::numeric, - null::jsonb, - null::text, - plnt, - promo, - null::text, - terms, - null::text, - null::text, - null::text, - rtrim(substring(bill_cust_descr,1,8)), - null::text, - null::text, - null::text, - rtrim(substring(ship_cust_descr,1,8)), - null::text, - null::text, - dsm, - billto_group, - shipto_group, - null::text, - chan, - chan, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - part, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::text, - null::numeric, - null::numeric, - null::text, - fs_line, - r_currency, - r_rate, - c_currency, - c_rate, - units, - value_loc, - null::numeric, - null::numeric, - null::numeric, - null::numeric, - cost_loc, - null::numeric, - null::numeric, - calc_status, - flag, - order_date, - order_season, - request_date, - request_season, - ship_date, - ship_season, - version, - iter -FROM - rlarp.osm_pool -WHERE - iter IN ('adj price','adj volume'); - -WITH -plist AS ( - SELECT DISTINCT - part - ,plnt - FROM - rlarp.osmfS_dev -) -,clist AS ( - SELECT - p.part - ,p.plnt - ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs) stdcost - FROM - plist p - LEFT OUTER JOIN lgdat.icstm im ON - im.cgpart = p.part - AND im.cgplnt = p.plnt - LEFT OUTER JOIN lgdat.icstp ip ON - ip.chpart = p.part - AND ip.chplnt = p.plnt - LEFT OUTER JOIN lgdat.icstr ir ON - ir.y0part = p.part - AND ir.y0plnt = p.plnt -) - - -UPDATE - rlarp.osmfs_dev o -SET - fb_cst_loc_cur = c.stdcost * o.fb_qty -FROM - clist c -WHERE - c.part = o.part - AND c.plnt = o.plnt; - -----------------------------SET BILL-TO REP------------------------------------ - -UPDATE - RLARP.OSMFS_DEV S -SET - BILL_REP = C.BVSALM - ,BILL_CLASS = C.BVCLAS - ,BILL_TERR = C.BVTERR - ,BILL_CTRY = C.bvctry - ,bill_prov = C.bvprcd - ,bill_post = C.bvpost - ,remit_to = c.bvcomp - ,ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END -FROM - LGDAT.CUST C -WHERE - C.BVCUST = S.BILL_CUST - AND ( - COALESCE(S.BILL_REP,'') <> C.BVSALM - OR COALESCE(S.BILL_CLASS,'') <> C.BVCLAS - OR COALESCE(S.BILL_TERR,'') <> C.BVTERR - OR COALESCE(BILL_CTRY,'') <> C.bvctry - OR COALESCE(bill_prov,'') <> C.bvprcd - OR COALESCE(bill_post,'') <> C.bvpost - OR COALESCE(remit_to,'') <> c.bvcomp::text - ); - -----------------------------SET SHIP-TO REP------------------------------------ - -UPDATE - RLARP.OSMFS_DEV S -SET - SHIP_REP = C.BVSALM - ,SHIP_CLASS = C.BVCLAS - ,SHIP_TERR = C.BVTERR - ,dest_CTRY = C.bvctry - ,dest_prov = C.bvprcd - ,dest_post = C.bvpost -FROM - LGDAT.CUST C -WHERE - C.BVCUST = S.SHIP_CUST - AND ( - COALESCE(S.SHIP_REP,'') <> C.BVSALM - OR COALESCE(S.SHIP_CLASS,'') <> C.BVCLAS - OR COALESCE(S.SHIP_TERR,'') <> C.BVTERR - OR COALESCE(dest_CTRY,'') <> C.bvctry - OR COALESCE(dest_prov,'') <> C.bvprcd - OR COALESCE(dest_post,'') <> C.bvpost - ); - -----------------------------SET BILLTO GROUP------------------------------------ - -UPDATE - RLARP.OSMFS_DEV O -SET - ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END -FROM - LGDAT.CUST C -WHERE - C.BVCUST = O.BILL_CUST - AND coalesce(account,'') <> CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END; - - - -----------------------------SET SHIPTO GROUP------------------------------------ - -UPDATE - RLARP.OSMFS_DEV O -SET - SHIPGRP = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END -FROM - LGDAT.CUST C -WHERE - C.BVCUST = O.SHIP_CUST - AND CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END <> COALESCE(O.SHIPGRP,''); - - ----------------------------SET CHANNEL----------------------------------------- - - -UPDATE - rlarp.osmFS_dev -SET - CHAN = CASE SUBSTRING(BILL_CLASS,2,3) - --if the bill to class is ditsributor, then it's either warehouse or drop - WHEN 'DIS' THEN - --if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse - CASE SUBSTRING(SHIP_CLASS,2,3) - WHEN 'DIS' THEN 'WHS' - ELSE 'DRP' - END - --CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END - --everything else does not involve a distributor and is considered direct - ELSE 'DIR' - END, - CHANSUB = CASE SUBSTRING(BILL_CLASS,2,3) - WHEN 'DIS' THEN - --if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse - CASE SUBSTRING(SHIP_CLASS,2,3) - WHEN 'DIS' THEN 'WHS' - ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END - END - WHEN 'MAS' THEN 'RMN' - WHEN 'NAT' THEN 'RMN' - ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END - END -WHERE - COALESCE(CHAN,'') <> CASE SUBSTRING(BILL_CLASS,2,3) - --if the bill to class is ditsributor, then it's either warehouse or drop - WHEN 'DIS' THEN - --if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse - CASE SUBSTRING(SHIP_CLASS,2,3) - WHEN 'DIS' THEN 'WHS' - ELSE 'DRP' - END - --CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END - --everything else does not involve a distributor and is considered direct - ELSE 'DIR' - END - OR - COALESCE(CHANSUB,'') <> CASE SUBSTRING(BILL_CLASS,2,3) - WHEN 'DIS' THEN - --if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse - CASE SUBSTRING(SHIP_CLASS,2,3) - WHEN 'DIS' THEN 'WHS' - ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END - END - WHEN 'MAS' THEN 'RMN' - WHEN 'NAT' THEN 'RMN' - ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END - END; - - ----------------------------SET QUOTA REP--------------------------------------- - -UPDATE - rlarp.osmfs_dev s -SET - dsm = cr.quota_rep -FROM -( - SELECT DISTINCT - VERSION, - COALESCE(GLEC,'') GLEC, - MING, - BILL_CUST, - SHIP_CUST, - ------------quota rep column-------------- - CASE WHEN COALESCE(ming,'') = 'B52' THEN 'PW' ELSE - --if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available - CASE WHEN COALESCE(glec,'') = '1RE' AND COALESCE(cu.currep,'') <> '' THEN - cu.currep - --default logic - ELSE - CASE SUBSTR(bill_class,2,3) - WHEN 'DIS' THEN - ship_rep - ELSE - bill_rep - END - END - END QUOTA_REP - FROM - rlarp.osmfs_dev s - LEFT OUTER JOIN lgdat.cust ON - bvcust = bill_cust - LEFT OUTER JOIN lgpgm.usrcust cu ON - cu.cucust = s.bill_cust - WHERE - version = 'ACTUALS' - ) CR -WHERE - CR.VERSION = S.VERSION - AND CR.GLEC = COALESCE(S.GLEC,'') - AND CR.MING = S.MING - AND CR.BILL_CUST = S.BILL_CUST - AND CR.SHIP_CUST = S.SHIP_CUST - AND COALESCE(S.DSM,'') <> CR.QUOTA_REP; - - --------------------set fiscal period-------------------------------------- - -UPDATE - rlarp.osmfs_dev f -SET - fspr = gld.fspr -FROM - ( - SELECT - N1COMP COMP - ,N1CCYY FSYRq - ,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' - ) gld -WHERE - f.sdate BETWEEN gld.sdat AND gld.edat - AND coalesce(f.fspr,'') <> gld.fspr; - -UPDATE - rlarp.osmfS_dev -SET - r_rate = .7900 -WHERE - r_currency = 'CA'; - -UPDATE - rlarp.osmfS_dev -SET - r_rate = 1 -WHERE - r_currency = 'US'; - -UPDATE - rlarp.osmfS_dev -SET - c_rate = .7900 -WHERE - c_currency = 'CA'; - -UPDATE - rlarp.osmfS_dev -SET - c_rate = 1 -WHERE - c_currency = 'US'; - - -UPDATE - RLARP.OSMFS_DEV O -SET - COLC = M.COLC - ,COLGRP = M.COLGRP - ,COLTIER = M.COLTIER - ,COLSTAT = M.COLSTAT - ,SIZC = M.SIZC - ,PCKG = M.PACKAGE - ,KIT = M.KIT - ,BRND = M.BRANDING - ,MAJG = M.MAJG - ,MING = M.MING - ,MAJS = M.MAJS - ,MINS = M.MINS - ,GLDC = M.GLCD - ,GLEC = M.GLEC - ,HARM = M.HARM - ,CLSS = M.CLSS - ,BRAND = M.BRAND - ,ASSC = M.ASSC - ,LBS = CASE M.NWUN WHEN 'KG' THEN 2.2046 ELSE 1 END*M.NWHT - ,UNTI = M.UNTI -FROM - RLARP.ITEMM M -WHERE - M.ITEM = O.PART; - -DELETE FROM rlarp.osmf_dev WHERE iter IN ('adj price','adj volume'); - -INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev; - -COMMIT; diff --git a/build/edit_xover.sql b/build/edit_xover.sql deleted file mode 100644 index 27b9541..0000000 --- a/build/edit_xover.sql +++ /dev/null @@ -1,33 +0,0 @@ -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 diff --git a/build/merge_actuals_exec.sql b/build/merge_actuals_exec.sql deleted file mode 100644 index 891d662..0000000 --- a/build/merge_actuals_exec.sql +++ /dev/null @@ -1,3 +0,0 @@ - -DELETE FROM rlarp.osmf_dev WHERE odate < '2021-05-01'; -INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2021-05-01'; diff --git a/build/merge_actuals_pool.sql b/build/merge_actuals_pool.sql deleted file mode 100644 index a37b194..0000000 --- a/build/merge_actuals_pool.sql +++ /dev/null @@ -1,164 +0,0 @@ -BEGIN; - -DELETE FROM rlarp.osm_pool WHERE order_date < '2021-05-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 - ('1SU','Sustainable'), - ('1CU','Sustainable'), - ('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 < '2021-05-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; diff --git a/build/merge_actuals_prep.sql b/build/merge_actuals_prep.sql deleted file mode 100644 index a15580f..0000000 --- a/build/merge_actuals_prep.sql +++ /dev/null @@ -1,187 +0,0 @@ ---\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('2020-06-01','2021-05-01','[)') - --...or any open orders currently booked before cutoff.... - OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2021-05-01') - --...or anything that shipped in that period - OR o.fspr BETWEEN '2101' AND '2111' - ) - AND fs_line = '41010' - AND calc_status <> 'CANCELED' - AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') - AND "version" = 'ACTUALS' - 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; diff --git a/build/rec_act.sql b/build/rec_act.sql deleted file mode 100644 index fa0bed2..0000000 --- a/build/rec_act.sql +++ /dev/null @@ -1,33 +0,0 @@ - SELECT - oseas - ,go.drange - ,go.sspr - ,sum(fb_val_loc * r_rate) - FROM - rlarp.osm_dev o - --snap the ship dates of the historic fiscal period - --LEFT OUTER JOIN rlarp.gld ON - -- gld.fspr = o.fspr - LEFT OUTER JOIN rlarp.gld go ON - odate between go.sdat and go.edat - --get the shipping season for open orders based on the snapped date - --LEFT OUTER JOIN rlarp.gld ss ON - -- greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat - WHERE - ( - --base period orders booked.... - o.odate BETWEEN '2020-06-01' AND '2021-04-04' - ----...or any open orders currently booked before cutoff.... - --OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2021-04-04') - ----...or anything that shipped in that period - --OR o.fspr BETWEEN '2101' AND '2110' - ) - AND fs_line = '41010' - AND calc_status <> 'CANCELED' - --AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') - ---exclude integrated quotes---- - AND version = 'ACTUALS' - GROUP BY - oseas - ,go.drange - ,go.sspr diff --git a/build/swap_fake_parts.sql b/build/swap_fake_parts.sql deleted file mode 100644 index 3faf08e..0000000 --- a/build/swap_fake_parts.sql +++ /dev/null @@ -1,413 +0,0 @@ -with -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) -) -,fp as ( - SELECT - od.part, - sum(value_usd) sales, - sum(cost_usd) scost - FROM - rlarp.osm_pool od - LEFT OUTER JOIN rlarp.itemmv m ON - m.item = od.part - WHERE - m.item is null - AND coalesce(od.part,'') <> '' - GROUP BY - od.part -) -,repl AS ( -SELECT * FROM (VALUES - ('ANP00001A39','ANP00001A39C003LRDBP','New 2020'), - ('ANP12000A39','ANP12000A39C001LRCOM','New 2020'), - ('ANP15000A39','ANP15000A39C001LRCON','New 2020'), - ('ANP17500A39','ANP17500A39C001LRCOO','New 2020'), - ('ARP06000DE3','ARP06000DE3C012LRDBQ','New 2020'), - ('ARP06000P26','ARP06000P26C012LRDBR','New 2020'), - ('ARP06000P80','ARP06000P80C012LRDBS','New 2020'), - ('ARP06000P81','ARP06000P81C012LRDBT','New 2020'), - ('ARP08000DE3','ARP08000DE3C012LRDBU','New 2020'), - ('ARP08000P26','ARP08000P26C012LRDBV','New 2020'), - ('ARP08000P80','ARP08000P80C012LRDBW','New 2020'), - ('ARP08000P81','ARP08000P81C012LRDBX','New 2020'), - ('ARP10000DE3','ARP10000DE3C010LRDBY','New 2020'), - ('ARP10000P26','ARP10000P26C010LRDBZ','New 2020'), - ('ARP10000P80','ARP10000P80C010LRDCA','New 2020'), - ('ARP10000P81','ARP10000P81C010LRDCB','New 2020'), - ('ARP12000DE3','ARP12000DE3C010LRDCC','New 2020'), - ('ARP12000P26','ARP12000P26C010LRDCD','New 2020'), - ('ARP12000P80','ARP12000P80C010LRDCE','New 2020'), - ('ARP12000P81','ARP12000P81C010LRDCF','New 2020'), - ('ARP16000DE3','ARP16000DE3C008LRDCG','New 2020'), - ('ARP16000P26','ARP16000P26C008LRDCH','New 2020'), - ('ARP16000P80','ARP16000P80C008LRDCI','New 2020'), - ('ARP16000P81','ARP16000P81C008LRDCJ','New 2020'), - ('ASP06000DE3','ASP06000DE3C012LRDCK','New 2020'), - ('ASP06000P26','ASP06000P26C012LRDCL','New 2020'), - ('ASP06000P80','ASP06000P80C012LRDCM','New 2020'), - ('ASP06000P81','ASP06000P81C012LRDCN','New 2020'), - ('ASP08000DE3','ASP08000DE3C012LRDCO','New 2020'), - ('ASP08000P26','ASP08000P26C012LRDCP','New 2020'), - ('ASP08000P80','ASP08000P80C012LRDCQ','New 2020'), - ('ASP08000P81','ASP08000P81C012LRDCR','New 2020'), - ('ASP10000DE3','ASP10000DE3C010LRDCS','New 2020'), - ('ASP10000P26','ASP10000P26C010LRDCT','New 2020'), - ('ASP10000P80','ASP10000P80C010LRDCU','New 2020'), - ('ASP10000P81','ASP10000P81C010LRDCV','New 2020'), - ('ASP12000DE3','ASP12000DE3C010LRDCW','New 2020'), - ('ASP12000P26','ASP12000P26C010LRDCX','New 2020'), - ('ASP12000P80','ASP12000P80C010LRDCY','New 2020'), - ('ASP12000P81','ASP12000P81C010LRDCZ','New 2020'), - ('ASP16000DE3','ASP16000DE3C008LRDDB','New 2020'), - ('ASP16000P26','ASP16000P26C008LRDDC','New 2020'), - ('ASP16000P80','ASP16000P80C008LRDDE','New 2020'), - ('ASP16000P81','ASP16000P81C008LRDDF','New 2020'), - ('CAR12000P26','CAR13000P261004LRDBE','New 2020'), - ('CAR12000P80','CAR13000P801004LRDBF','New 2020'), - ('CAR15000P26','CAR16000P261004LRDBG','New 2020'), - ('CAR15000P80','CAR16000P801004LRDBH','New 2020'), - ('CAS12000P26','CAS12000P261004LRDBI','New 2020'), - ('CAS12000P80','CAS12000P801004LRDBJ','New 2020'), - ('CAS15000P26','CAS15000P261004LRDBK','New 2020'), - ('CAS15000P80','CAS15000P801004LRDBL','New 2020'), - ('CNA06000A10','CNA06000A10C024LRCJJ','New 2020'), - ('CNA06000A42','CNA06000A42C024LRCDC','New 2020'), - ('CNA06000BG3','CNA06000BG3C024LRCJK','New 2020'), - ('CNA06000F89','CNA06000F89C024LRCJL','New 2020'), - ('CNA08000A10','CNA08000A10C024LRCJM','New 2020'), - ('CNA08000A42','CNA08000A42C024LRBXH','New 2020'), - ('CNA08000BG3','CNA08000BG3C024LRCJN','New 2020'), - ('CNA08000F89','CNA08000F89C024LRCJO','New 2020'), - ('CNA10000A10','CNA10000A10C012LRCJP','New 2020'), - ('CNA10000BG3','CNA10000BG3C012LRCJQ','New 2020'), - ('CNA10000F89','CNA10000F89C012LRCJR','New 2020'), - ('CNA12000A10','CNA12000A10C012LRCJS','New 2020'), - ('CNA12000BG3','CNA12000BG3C012LRCJT','New 2020'), - ('CNA12000F89','CNA12000F89C012LRCJU','New 2020'), - ('ECA06000B78','ECA06000B781028LRCJV','New 2020'), - ('ECA06000DE2','ECA06000DE21028LRCJW','New 2020'), - ('ECA08000B78','ECA08000B781024LRCJX','New 2020'), - ('ECA08000DE2','ECA08000DE21024LRCJY','New 2020'), - ('ECA10000B78','ECA10000B781020LRCJZ','New 2020'), - ('ECA10000DE2','ECA10000DE21020LRCKA','New 2020'), - ('ECA12000B78','ECA12000B781016LRCKB','New 2020'), - ('ECA12000DE2','ECA12000DE21016LRCKC','New 2020'), - ('ECA16000B78','ECA16000B781010LRCKD','New 2020'), - ('ECA16000DE2','ECA16000DE21010LRCKE','New 2020'), - ('ECA20000B78','ECA20000B781006LRCKF','New 2020'), - ('ECA20000DE2','ECA20000DE21006LRCKG','New 2020'), - ('GAB12000BG3','GAB12000BG3C012LRCKH','New 2020'), - ('GAB12000DE2','GAB12000DE2C012LRCKI','New 2020'), - ('GAB14000BG3','GAB14000BG3C012LRCKJ','New 2020'), - ('GAB14000DE2','GAB14000DE2C012LRCKK','New 2020'), - ('GAB18000BG3','GAB18000BG3C006LRCKL','New 2020'), - ('GAB18000DE2','GAB18000DE2C006LRCKM','New 2020'), - ('GAB22000BG3','GAB22000BG3C006LRCKN','New 2020'), - ('GAB22000DE2','GAB22000DE2C006LRCKO','New 2020'), - ('GDP08000BG3','GDP08000BG3C012LRCOJ','New 2020'), - ('GDP08000DE2','GDP08000DE2C012LRCOK','New 2020'), - ('LIA06000B78','LIA06000B78C024LRCKP','New 2020'), - ('LIA06000DE2','LIA06000DE2C024LRCKQ','New 2020'), - ('LIA08000B78','LIA08000B78C024LRCKR','New 2020'), - ('LIA08000DE2','LIA08000DE2C024LRCKS','New 2020'), - ('LIA10000B78','LIA10000B78C012LRCKT','New 2020'), - ('LIA10000DE2','LIA10000DE2C012LRCKU','New 2020'), - ('LIA12000B78','LIA12000B78C012LRCKV','New 2020'), - ('LIA12000DE2','LIA12000DE2C012LRCKW','New 2020'), - ('LIA14000B78','LIA14000B78C012LRCKX','New 2020'), - ('LIA14000DE2','LIA14000DE2C012LRCKY','New 2020'), - ('LIA16000B78','LIA16000B78C012LRCKZ','New 2020'), - ('LIA16000DE2','LIA16000DE2C012LRCLA','New 2020'), - ('LIA20000B78','LIA20000B78C006LRCLB','New 2020'), - ('LIA20000DE2','LIA20000DE2C006LRCLC','New 2020'), - ('LIA24000B78','LIA24000B78C006LRCLD','New 2020'), - ('LIA24000DE2','LIA24000DE2C006LRCLE','New 2020'), - ('MSA12001A42','MSA12001A421008LRCLF','New 2020'), - ('MSA12001B78','MSA12001B781008LRCLG','New 2020'), - ('MSA12001DE2','MSA12001DE21008LRCLH','New 2020'), - ('MSA16001A42','MSA16001A42C004LRCLI','New 2020'), - ('MSA16001B78','MSA16001B78C004LRCLJ','New 2020'), - ('MSA16001DE2','MSA16001DE2C004LRCLK','New 2020'), - ('MSA20001A42','MSA20001A42C004LRCLL','New 2020'), - ('MSA20001B78','MSA20001B78C004LRCLM','New 2020'), - ('MSA20001DE2','MSA20001DE2C004LRCLN','New 2020'), - ('SEA07001A42','SEA07001A421008LRCLP','New 2020'), - ('SEA07001B78','SEA07001B781008LRCLQ','New 2020'), - ('SEA07001DE2','SEA07001DE21008LRCLR','New 2020'), - ('SEA09001A42','SEA09001A421008LRCLT','New 2020'), - ('SEA09001B78','SEA09001B781008LRCLU','New 2020'), - ('SEA09001DE2','SEA09001DE21008LRCLV','New 2020'), - ('SEA12001A42','SEA12001A421006LRCLX','New 2020'), - ('SEA12001B78','SEA12001B781006LRCLY','New 2020'), - ('SEA12001DE2','SEA12001DE21006LRCLZ','New 2020'), - ('SEA14001A42','SEA14001A421006LRCMB','New 2020'), - ('SEA14001B78','SEA14001B781006LRCMC','New 2020'), - ('SEA14001DE2','SEA14001DE21006LRCMD','New 2020'), - ('SEA16000A42','SEA16001A421006LRCMF','New 2020'), - ('SEA16000B78','SEA16001B781006LRCMG','New 2020'), - ('SEA16000DE2','SEA16001DE21006LRCMH','New 2020'), - ('SKR12000A56','SKR12000A56C010LRDDI','New 2020'), - ('SKR12000E66','SKR12000E66C010LRDDJ','New 2020'), - ('SKR12000G27','SKR12000G27C010LRDDK','New 2020'), - ('SKR16000A56','SKR16000A56C008LRDDL','New 2020'), - ('SKR16000E66','SKR16000E66C008LRDDM','New 2020'), - ('SKR16000G27','SKR16000G27C008LRDDN','New 2020'), - ('SKS12000A56','SKS12000A56C010LRDDO','New 2020'), - ('SKS12000E66','SKS12000E66C010LRDDP','New 2020'), - ('SKS12000G27','SKS12000G27C010LRDDQ','New 2020'), - ('SKS16000A56','SKS16000A56C008LRDDR','New 2020'), - ('SKS16000E66','SKS16000E66C008LRDDS','New 2020'), - ('SKS16000G27','SKS16000G27C008LRDDT','New 2020'), - ('SLI06000B78','SLI06000B78C024LRCMI','New 2020'), - ('SLI06000DE2','SLI06000DE2C024LRCMJ','New 2020'), - ('SLI08000B78','SLI08000B78C024LRCMK','New 2020'), - ('SLI08000DE2','SLI08000DE2C024LRCML','New 2020'), - ('SLI10000B78','SLI10000B78C012LRCMM','New 2020'), - ('SLI10000DE2','SLI10000DE2C012LRCMN','New 2020'), - ('SLI12000B78','SLI12000B78C012LRCMO','New 2020'), - ('SLI12000DE2','SLI12000DE2C012LRCMP','New 2020'), - ('SLI14000B78','SLI14000B78C012LRCMQ','New 2020'), - ('SLI14000DE2','SLI14000DE2C012LRCMR','New 2020'), - ('SLI16000B78','SLI17000B78C012LRCMS','New 2020'), - ('SLI17000DE2','SLI17000DE2C012LRCMT','New 2020'), - ('SLI20000B78','SLI20000B78C006LRCMU','New 2020'), - ('SLI20000DE2','SLI20000DE2C006LRCMV','New 2020'), - ('SLI24000B78','SLI24000B78C006LRCMW','New 2020'), - ('SLI24000DE2','SLI24000DE2C006LRCMX','New 2020'), - ('SVN18000A10','SVN18000A10C006LRCMY','New 2020'), - ('SVN18000A42','SVN18000A42C006LRCMZ','New 2020'), - ('SVN24000A10','SVN24000A10C006LRCNA','New 2020'), - ('SVN24000A42','SVN24000A42C006LRCNB','New 2020'), - ('SVN30000A10','SVN30000A10C006LRCNC','New 2020'), - ('SVN30000A42','SVN30000A42C006LRCND','New 2020'), - ('VNP18000A10','VNP18000A10C006LRCNE','New 2020'), - ('VNP18000A42','VNP18000A42C006LRCNF','New 2020'), - ('VNP24000A10','VNP24000A10C006LRCNG','New 2020'), - ('VNP24000A42','VNP24000A42C006LRCNH','New 2020'), - ('VNP30000A10','VNP30000A10C006LRCNI','New 2020'), - ('VNP30000A42','VNP30000A42C006LRCNJ','New 2020'), - ('WBP16000P82','WBP16000P82C008LRDDG','New 2020'), - ('ROS15500A42','ROS15500A42C012LRDFA','New 2021'), - ('SRO15500A42','SRO15500A42C012LRDFB','New 2021'), - ('CSB06000A58','CSB06000A58C020LRDHO','New 2021'), - ('CSB06000E67','CSB06000E67C020LRDHM','New 2021'), - ('CSB06000G28','CSB06000G28C020LRDHN','New 2021'), - ('CSB08000A58','CSB08000A58C020LRDHU','New 2021'), - ('CSB08000E67','CSB08000E67C020LRDHS','New 2021'), - ('CSB08000G28','CSB08000G28C020LRDHT','New 2021'), - ('CNA06000A02','CNA06000A02C024LRDGU','New 2021'), - ('CNA06000CXX','CNA06000CXXC024LRDGV','New 2021'), - ('CNA06000DE1','CNA06000DE1C024LRDGW','New 2021'), - ('CNA08000A02','CNA08000A02C024LRDGX','New 2021'), - ('CNA08000CXX','CNA08000CXXC024LRDGY','New 2021'), - ('CNA08000DE1','CNA08000DE1C024LRDGZ','New 2021'), - ('CNA10000A02','CNA10000A02C012LRDHA','New 2021'), - ('CNA10000CXX','CNA10000CXXC012LRDHB','New 2021'), - ('CNA10000DE1','CNA10000DE1C012LRDHC','New 2021'), - ('CNA12000A02','CNA12000A02C012LRDHD','New 2021'), - ('CNA12000CXX','CNA12000CXXC012LRDHE','New 2021'), - ('CNA12000DE1','CNA12000DE1C012LRDHF','New 2021'), - ('DFB06000A58','DFB06000A58C024LRDHR','New 2021'), - ('DFB06000E67','DFB06000E67C024LRDHP','New 2021'), - ('DFB06000G28','DFB06000G28C024LRDHQ','New 2021'), - ('DFB08000A58','DFB08000A58C024LRDHX','New 2021'), - ('DFB08000E67','DFB08000E67C024LRDHV','New 2021'), - ('DFB08000G28','DFB08000G28C024LRDHW','New 2021'), - ('ECH12000A42','ECH12000A421010LRDFM','New 2021'), - ('ECH12000E21','ECH12000E211010LRDFK','New 2021'), - ('ECH12000G18','ECH12000G181010LRDFL','New 2021'), - ('ECA06000A02','ECA06000A021028LRDEJ','New 2021'), - ('ECA06000A42','ECA06000A421028LRDEI','New 2021'), - ('ECA08000A02','ECA08000A021024LRDEL','New 2021'), - ('ECA08000A42','ECA08000A421024LRDEK','New 2021'), - ('ECA10000A02','ECA10000A021020LRDEM','New 2021'), - ('ECA10000A42','ECA10000A421020LRDEN','New 2021'), - ('ECA12000A02','ECA12000A021016LRDEO','New 2021'), - ('ECA12000A42','ECA12000A421016LRDEP','New 2021'), - ('ECA16000A02','ECA16000A021010LRDES','New 2021'), - ('ECA16000A42','ECA16000A421010LRDET','New 2021'), - ('ECA20000A02','ECA20000A021006LRDEW','New 2021'), - ('ECA20000A42','ECA20000A421006LRDEX','New 2021'), - ('ECI12000A42','ECI12000A421010LRDFP','New 2021'), - ('ECI12000E21','ECI12000E211010LRDFN','New 2021'), - ('ECI12000G18','ECI12000G181010LRDFO','New 2021'), - ('ECP06000A02','ECP06000A021028LRDGK','New 2021'), - ('ECP06000A42','ECP06000A421028LRDGM','New 2021'), - ('ECP06000DE2','ECP06000DE21028LRDGL','New 2021'), - ('ECP06000E35','ECP06000E351028LRDGJ','New 2021'), - ('ECP06000G18','ECP06000G181028LRDGI','New 2021'), - ('ECP08000A02','ECP08000A021024LRDGP','New 2021'), - ('ECP08000A42','ECP08000A421024LRDGR','New 2021'), - ('ECP08000DE2','ECP08000DE21024LRDGQ','New 2021'), - ('ECP08000E35','ECP08000E351024LRDGO','New 2021'), - ('ECP08000G18','ECP08000G181024LRDGN','New 2021'), - ('ECP10000A02','ECP10000A021020LRDGA','New 2021'), - ('ECP10000A42','ECP10000A421020LRDGC','New 2021'), - ('ECP10000DE2','ECP10000DE21020LRDGB','New 2021'), - ('ECP10000E35','ECP10000E351020LRDFZ','New 2021'), - ('ECP10000G18','ECP10000G181020LRDFY','New 2021'), - ('ECP12000A02','ECP12000A021016LRDGF','New 2021'), - ('ECP12000A42','ECP12000A421016LRDGH','New 2021'), - ('ECP12000DE2','ECP12000DE21016LRDGG','New 2021'), - ('ECP12000E35','ECP12000E351016LRDGE','New 2021'), - ('ECP12000G18','ECP12000G181016LRDGD','New 2021'), - ('ECW24000A10','ECW24000A101006LRDFQ','New 2021'), - ('ECW24000A42','ECW24000A421006LRDFT','New 2021'), - ('ECW24000E35','ECW24000E351006LRDFS','New 2021'), - ('ECW24000G18','ECW24000G181006LRDFR','New 2021'), - ('ECW30000A10','ECW30000A101006LRDFU','New 2021'), - ('ECW30000A42','ECW30000A421006LRDFX','New 2021'), - ('ECW30000E35','ECW30000E351006LRDFW','New 2021'), - ('ECW30000G18','ECW30000G181006LRDFV','New 2021'), - ('GAB12000A42','GAB12000A42C012LRDFC','New 2021'), - ('GAB14000A42','GAB14000A42C012LRDFD','New 2021'), - ('GAB22000A42','GAB22000A42C006LRDFE','New 2021'), - ('GDP08000A10','GDP08000A10C012LRDFF','New 2021'), - ('HBM12000H13','HBM12000H136010LRDIB','New 2021'), - ('HBM12000H26','HBM12000H226010LRDIC','New 2021'), - ('HBM12000H22','HBM12000H266010LRDIA','New 2021'), - ('PA.08005B71',CAST(NULL AS VARCHAR(255)),'New 2021'), - ('PA.08005E22','PA.08005E22C250LYHQO','New 2021'), - ('SPP08000A58','SPP08000A581004LRDHZ','New 2021'), - ('SPP08000E67','SPP08000E671004LRDHY','New 2021'), - ('PZA09000YB5','PZA09000YB5C012LRDFG','New 2021'), - ('PZA12000YB5','PZA12000YB5C012LRDFH','New 2021'), - ('PZA16000YB5','PZA16000YB5C006LRDFI','New 2021'), - ('PZA20000YB5','PZA20000YB5C006LRDFJ','New 2021'), - ('SSP02500A58','SSP02500A58C020LRDHI','New 2021'), - ('SSP02500E67','SSP02500E67C020LRDHG','New 2021'), - ('SSP02500G28','SSP02500G28C020LRDHH','New 2021'), - ('SSP03000A58','SSP03000A58C020LRDHL','New 2021'), - ('SSP03000E67','SSP03000E67C020LRDHJ','New 2021'), - ('SSP03000G28','SSP03000G28C020LRDHK','New 2021'), - ('RZ.MT160G18',CAST(NULL AS VARCHAR(255)),'New 2021'), - ('RZ.MT160A42',CAST(NULL AS VARCHAR(255)),'New 2021'), - ('RZ.MT160XXX',CAST(NULL AS VARCHAR(255)),'New 2021'), - ('RZ.WC2G3B66','RZ.WC2G3B66C020LRCOT','New 2021') -) x(f11,fp,note) -) -, fin AS ( -SELECT - fp.part, - fp.sales, - min(item) item, - repl.fp, - COALESCE(repl.fp,min(item)) pick -FROM - fp - LEFT OUTER JOIN rlarp.itemmv m ON - substring(m.item,1,11) = substring(fp.part,1,11) - LEFT OUTER JOIN repl ON - repl.f11 = substring(fp.part,1,11) -GROUP BY - fp.part, - fp.sales, - repl.fp -ORDER BY - fp.sales desc, - fp.part -) ---SELECT * FROM fin; -/* -,upd AS ( -UPDATE - rlarp.osm_pool o -SET - part = fin.pick -FROM - fin -WHERE - fin.part = o.part - RETURNING * -) -SELECT * from upd; -*/ ---SELECT * FROM rlarp.osm_pool o inner join fin on fin.part = o.part ; -select * from fin; - - -ROLLBACK; -/* -,ins AS ( - SELECT - p.fspr - ,p.plnt - ,p.promo - ,p.terms - ,p.bill_cust_descr - ,p.ship_cust_descr - ,p.dsm - ,p.quota_rep_descr - ,p.director - ,p.billto_group - ,p.shipto_group - ,p.chan - ,p.chansub - ,p.chan_retail - ,fin.pick - ,i.item||coalesce(' - '||i.descr,'') part_descr - ,i.stlc part_group - ,i.branding - ,i.majg||' - '||i.majgd majg_descr - ,i.ming||' - '||i.mingd ming_descr - ,i.majs||' - '||i.majsd majs_descr - ,i.mins||' - '||i.minsd mins_descr - ,seg.segm - ,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance - ,p.fs_line - ,p.r_currency - ,p.r_rate - ,p.c_currency - ,p.c_rate - ,p.units - ,p.value_loc - ,p.value_usd - ,p.cost_loc - ,p.cost_usd - ,p.calc_status - ,p.flag - ,p.order_date - ,p.order_month - ,p.order_season - ,p.request_date - ,p.request_month - ,p.request_season - ,p.ship_date + INTERVAL '1 year' - ,ship_month - ,ship_season - ,'b21' AS version - ,'fake parts' iter - ,logl.id logid - ,logl.doc->>'tag' tag - ,logl.doc->>'message' "comment" - ,logl.doc->>'type' module - FROM - rlarp.osm_pool p - INNER JOIN fin ON - fin.part = p.part - LEFT OUTER JOIN rlarp.itemm i ON - i.item = fin.pick - LEFT OUTER JOIN seg ON - seg.glec = i.glec; -*/ diff --git a/build/temp.sql b/build/temp.sql deleted file mode 100644 index 259a58d..0000000 --- a/build/temp.sql +++ /dev/null @@ -1,47 +0,0 @@ -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 -select oseas, sum(fb_val_loc * r_rate) - 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 BETWEEN '2019-06-01' AND '2020-05-31' - --...or any open orders currently booked before cutoff.... - OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-05-31') - OR o.sseas BETWEEN '2001' AND '2012' - ) - AND fs_line = '41010' - AND calc_status <> 'CANCELED' - AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') - AND dsm = 'PW' - and version = 'ACTUALS' -group by oseas