Compare commits

...

25 Commits

Author SHA1 Message Date
Paul Trowbridge
f924da0e4d move files around 2020-02-19 17:05:27 -05:00
Paul Trowbridge
0095e1983c forgot end 2020-02-19 16:45:52 -05:00
pt
3983f1c91a Merge branch 'feature/substance' of hc-companies/forecast_api into dev 2020-02-19 21:15:25 +00:00
Trowbridge
ff1304be3c add substance column and move some files out of the route folder that aren't actually being used by routes 2020-02-19 13:25:28 -05:00
pt
55257733b2 Merge branch 'feature/tags' of hc-companies/forecast_api into dev 2020-02-18 22:12:17 +00:00
Trowbridge
cbc2caa41d add module back in 2020-02-18 17:10:49 -05:00
Trowbridge
69346646bd change module to be the comment 2020-02-18 15:35:56 -05:00
Trowbridge
d3a4a45d53 change comment to be the tag 2020-02-18 14:47:46 -05:00
pt
83039b4a51 notes (#32) 2020-02-18 19:25:57 +00:00
pt
54668f22e1 Merge branch 'month_routes' of hc-companies/forecast_api into dev 2020-02-17 03:35:27 +00:00
pt
2ec8ec75f0 deprecate add month for volume only 2020-02-16 22:34:06 -05:00
pt
ff3e18edc7 add sort to month name 2020-02-16 22:23:38 -05:00
pt
53ac7f90e2 putting wrong sort number on month 2020-02-15 03:45:22 -05:00
pt
e7ce48405b increment year 2020-02-15 03:26:04 -05:00
pt
c602564cb7 couple minor issues 2020-02-15 02:55:33 -05:00
pt
a83708a7ca overhaul month_vp 2020-02-15 01:03:45 -05:00
Paul Trowbridge
39a96eb12b Merge branch 'dev' into month_routes 2020-02-14 23:14:13 -05:00
pt
07f69a80ae initial renaming of columns 2020-02-14 21:16:25 -05:00
pt
7d50a37e29 Merge branch 'undo' of hc-companies/forecast_api into dev 2020-02-15 00:49:59 +00:00
Trowbridge
7635380ccc ensure not to load null comments 2020-02-14 17:00:44 -05:00
Trowbridge
6774a2fdff default load as not null 2020-02-14 17:00:06 -05:00
Paul Trowbridge
db13f3d38c routes that make adjustments need to return comment info 2020-02-14 15:52:16 -05:00
Trowbridge
33041761c6 drop rows from both tables when undoing changes 2020-02-14 15:42:41 -05:00
Trowbridge
18558674c0 change key name to message 2020-02-14 14:41:51 -05:00
Trowbridge
6485613ab7 add undo route, and include comments 2020-02-14 14:41:29 -05:00
37 changed files with 4324 additions and 4365 deletions

View File

@ -7,4 +7,21 @@ Special concepts
Slowness Options Slowness Options
* move json to a separate table and the change can be marked with a sequence * move json to a separate table and the change can be marked with a sequence
* have the data actually be a query from the database * have the data actually be a query from the database
* reduce number of columns in fc_pool * reduce number of columns in fc_pool
Discussion
* special look at Mar-Apr sales since it is being copied from plan or older data
- [ ] at the end of March, we will swap out the budget from March with actuals and re-forecast
- [ ] need to think through how to overlay actuals into the budget
* last price paid snap - preload
- [ ] dont do this
* FX - currently nothing loaded
- [ ] we'll pick one (see Bruno)
* cost - snap to current cost
- [ ] snap to current
* need to be able to reload the forecast as we lock in new months of sales data - replay changes over top?
* item 1
* refresh new part list
* add comments on monthly
* add a tag that is separate from the comment?
* need to test extrapolating osm_pool into osmp_dev

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,9 @@
BEGIN;
DROP TABLE IF EXISTS rlarp.osm_pool; 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 ( CREATE TABLE IF NOT EXISTS rlarp.osm_pool AS (
WITH WITH
@ -77,6 +82,7 @@ SELECT
,o.majs||' - '||i.majsd majs_descr ,o.majs||' - '||i.majsd majs_descr
,o.mins||' - '||i.minsd mins_descr ,o.mins||' - '||i.minsd mins_descr
,seg.segm ,seg.segm
,CASE WHEN o.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
,fs_line ,fs_line
,r_currency ,r_currency
,r_rate ,r_rate
@ -90,19 +96,20 @@ SELECT
,calc_status ,calc_status
,flag ,flag
,o.odate order_date ,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 ,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 ,oseas order_season
,rdate request_date ,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 ,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 ,rseas request_season
,sdate ship_date ,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 ,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 ,sseas ship_season
,version ,version
,iter ,iter
,null::int logid ,null::int logid
,null::text "comment" ,''::text tag
,null::text module ,''::text "comment"
,''::text module
FROM FROM
rlarp.osmf_dev o rlarp.osmf_dev o
LEFT OUTER JOIN lgdat.cust bc ON LEFT OUTER JOIN lgdat.cust bc ON
@ -130,12 +137,10 @@ FROM
--LIMIT 100 --LIMIT 100
) WITH DATA; ) WITH DATA;
CREATE INDEX osm_qr ON rlarp.osm_pool(quota_rep_descr); 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);
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);
GRANT ALL ON TABLE rlarp.osm_log TO api; GRANT ALL ON TABLE rlarp.osm_log TO api;
GRANT ALL ON TABLE rlarp.osm_pool TO api; GRANT ALL ON TABLE rlarp.osm_pool TO api;
COMMIT;

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +1,52 @@
WITH WITH
pool AS ( pool AS (
SELECT SELECT
substr(a.v6part,1,3) "family" substr(a.v6part,1,3) "family"
,substr(a.v6part,1,8) mold ,substr(a.v6part,1,8) mold
,a.v6part part ,a.v6part part
,COALESCE(m.avmajg,p.awmajg) majg ,COALESCE(m.avmajg,p.awmajg) majg
,COALESCE(m.avming,p.awming) ming ,COALESCE(m.avming,p.awming) ming
,COALESCE(m.avmajs,p.awmajs) majs ,COALESCE(m.avmajs,p.awmajs) majs
,COALESCE(m.avmins,p.awmins) mins ,COALESCE(m.avmins,p.awmins) mins
FROM FROM
lgdat.stka a lgdat.stka a
LEFT OUTER JOIN lgdat.stkmm m ON LEFT OUTER JOIN lgdat.stkmm m ON
m.avpart = v6part m.avpart = v6part
LEFT OUTER JOIN lgdat.stkmp p ON LEFT OUTER JOIN lgdat.stkmp p ON
p.awpart = a.v6part p.awpart = a.v6part
WHERE WHERE
COALESCE(awgled, avgled) = '1RE' COALESCE(awgled, avgled) = '1RE'
AND v6stat = 'A' AND v6stat = 'A'
--and avmajg = '910' --and avmajg = '910'
GROUP BY GROUP BY
a.v6part a.v6part
,COALESCE(m.avmajg,p.awmajg) ,COALESCE(m.avmajg,p.awmajg)
,COALESCE(m.avming,p.awming) ,COALESCE(m.avming,p.awming)
,COALESCE(m.avmajs,p.awmajs) ,COALESCE(m.avmajs,p.awmajs)
,COALESCE(m.avmins,p.awmins) ,COALESCE(m.avmins,p.awmins)
) )
,llist AS ( ,llist AS (
SELECT SELECT
family family
,mold ,mold
,min(part) part ,min(part) part
,jsonb_agg(majg) majg ,jsonb_agg(majg) majg
,jsonb_agg(ming) ming ,jsonb_agg(ming) ming
,jsonb_agg(majs) majs ,jsonb_agg(majs) majs
,jsonb_agg(mins) mins ,jsonb_agg(mins) mins
FROM FROM
pool pool
GROUP BY GROUP BY
family family
,mold ,mold
) )
SELECT SELECT
family family
,mold ,mold
,part ,part
,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.majg) a(e)) x) majg ,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.majg) a(e)) x) majg
,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.ming) a(e)) x) ming ,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.ming) a(e)) x) ming
,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.majs) a(e)) x) majs ,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.majs) a(e)) x) majs
,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.mins) a(e)) x) mins ,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.mins) a(e)) x) mins
FROM FROM
llist llist

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,120 +1,120 @@
BEGIN; BEGIN;
with p AS ( with p AS (
SELECT SELECT
part part
,bill_cust ,bill_cust
,ship_cust ,ship_cust
,round(fb_val_loc/fb_qty,10) AS price ,round(fb_val_loc/fb_qty,10) AS price
,orderdate ,orderdate
,row_number() OVER (PARTITION BY part,bill_cust, ship_cust ORDER BY orderdate DESC) rn ,row_number() OVER (PARTITION BY part,bill_cust, ship_cust ORDER BY orderdate DESC) rn
FROM FROM
rlarp.osm rlarp.osm
WHERE WHERE
fs_line = '41010' fs_line = '41010'
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
AND COALESCE(part,'') <> '' AND COALESCE(part,'') <> ''
AND fb_qty <> 0 AND fb_qty <> 0
AND orderdate IS NOT NULL AND orderdate IS NOT NULL
ORDER BY ORDER BY
part part
,bill_cust ,bill_cust
,ship_cust ,ship_cust
,orderdate ,orderdate
) )
--SELECT * FROM p WHERE rn = 1 --SELECT * FROM p WHERE rn = 1
,incr AS ( ,incr AS (
SELECT SELECT
b.plnt b.plnt
,b."ddord#" ,b."ddord#"
,b."dditm#" ,b."dditm#"
,b."fgbol#" ,b."fgbol#"
,b."fgent#" ,b."fgent#"
,b."diinv#" ,b."diinv#"
,b."dilin#" ,b."dilin#"
,b.promo ,b.promo
,b.return_reas ,b.return_reas
,b.terms ,b.terms
,b.custpo ,b.custpo
,b.dhincr ,b.dhincr
,b.diext ,b.diext
,b.ditdis ,b.ditdis
,b.dcodat ,b.dcodat
,b.ddqdat ,b.ddqdat
,b.dcmdat ,b.dcmdat
,b.dhidat ,b.dhidat
,b.fspr ,b.fspr
,b.remit_to ,b.remit_to
,b.bill_class ,b.bill_class
,b.bill_cust ,b.bill_cust
,b.bill_rep ,b.bill_rep
,b.bill_terr ,b.bill_terr
,b.ship_class ,b.ship_class
,b.ship_cust ,b.ship_cust
,b.ship_rep ,b.ship_rep
,b.ship_terr ,b.ship_terr
,b.quota_rep ,b.quota_rep
,b.account ,b.account
,b.shipgrp ,b.shipgrp
,b.geo ,b.geo
,b.chan ,b.chan
,b.orig_ctry ,b.orig_ctry
,b.orig_prov ,b.orig_prov
,b.orig_post ,b.orig_post
,b.dest_ctry ,b.dest_ctry
,b.dest_prov ,b.dest_prov
,b.dest_post ,b.dest_post
,b.part ,b.part
,b.ord_gldc ,b.ord_gldc
,b.majg ,b.majg
,b.ming ,b.ming
,b.majs ,b.majs
,b.mins ,b.mins
,b.gldc ,b.gldc
,b.glec ,b.glec
,b.harm ,b.harm
,b.clss ,b.clss
,b.brand ,b.brand
,b.assc ,b.assc
,b.fs_line ,b.fs_line
,b.r_currency ,b.r_currency
,b.r_rate ,b.r_rate
,b.c_currency ,b.c_currency
,b.c_rate ,b.c_rate
,b.ddqtoi ,b.ddqtoi
,b.ddqtsi ,b.ddqtsi
,b.fgqshp ,b.fgqshp
,b.diqtsh ,b.diqtsh
,0 fb_qty ,0 fb_qty
,0 fb_cst_loc ,0 fb_cst_loc
,0 fb_cst_loc_cur ,0 fb_cst_loc_cur
,0 fb_cst_loc_fut ,0 fb_cst_loc_fut
,b.fb_qty * p.price - b.fb_val_loc fb_val_loc ,b.fb_qty * p.price - b.fb_val_loc fb_val_loc
,0 fb_val_loc_pl ,0 fb_val_loc_pl
,b.calc_status ,b.calc_status
,b.flag ,b.flag
,b.orderdate ,b.orderdate
,b.requestdate ,b.requestdate
,b.shipdate ,b.shipdate
,b.adj_orderdate ,b.adj_orderdate
,b.adj_requestdate ,b.adj_requestdate
,b.adj_shipdate ,b.adj_shipdate
,b."version" ,b."version"
,'last price paid' iter ,'last price paid' iter
FROM FROM
rlarp.osmfs b rlarp.osmfs b
INNER JOIN p ON INNER JOIN p ON
p.part = b.part p.part = b.part
AND p.bill_cust = b.bill_cust AND p.bill_cust = b.bill_cust
AND p.ship_cust = b.ship_cust AND p.ship_cust = b.ship_cust
AND p.rn = 1 AND p.rn = 1
WHERE WHERE
b.orderdate BETWEEN '2019-03-25' AND '2019-05-31' b.orderdate BETWEEN '2019-03-25' AND '2019-05-31'
OR b.orderdate BETWEEN '2020-03-25' AND '2020-05-31' OR b.orderdate BETWEEN '2020-03-25' AND '2020-05-31'
) )
, ins AS ( , ins AS (
INSERT INTO rlarp.osmfs SELECT * FROM incr RETURNING * INSERT INTO rlarp.osmfs SELECT * FROM incr RETURNING *
) )
SELECT fspr, sum(fb_val_loc *r_rate) FROM ins GROUP BY fspr; SELECT fspr, sum(fb_val_loc *r_rate) FROM ins GROUP BY fspr;
COMMIT; COMMIT;

File diff suppressed because it is too large Load Diff

View File

@ -1,96 +1,96 @@
BEGIN; BEGIN;
WITH WITH
mseq AS ( mseq AS (
SELECT * FROM SELECT * FROM
( (
VALUES VALUES
('Jun',1,6,-1) ('Jun',1,6,-1)
,('Jul',2,7,-1) ,('Jul',2,7,-1)
,('Aug',3,8,-1) ,('Aug',3,8,-1)
,('Sep',4,9,-1) ,('Sep',4,9,-1)
,('Oct',5,10,-1) ,('Oct',5,10,-1)
,('Nov',6,11,-1) ,('Nov',6,11,-1)
,('Dec',7,12,-1) ,('Dec',7,12,-1)
,('Jan',8,1,0) ,('Jan',8,1,0)
,('Feb',9,2,0) ,('Feb',9,2,0)
,('Mar',10,3,0) ,('Mar',10,3,0)
,('Apr',11,4,0) ,('Apr',11,4,0)
,('May',12,5,0) ,('May',12,5,0)
) x(m,s,cal,yr) ) x(m,s,cal,yr)
) )
,alldates AS ( ,alldates AS (
SELECT SELECT
shipgrp shipgrp
,to_char(orderdate,'Mon') orderm ,to_char(orderdate,'Mon') orderm
,extract(month FROM age(requestdate,orderdate)) rmo ,extract(month FROM age(requestdate,orderdate)) rmo
,(sum((shipdate - requestdate)* (fb_val_loc * r_rate))/sum(fb_val_loc * r_rate))::int wav_lag ,(sum((shipdate - requestdate)* (fb_val_loc * r_rate))/sum(fb_val_loc * r_rate))::int wav_lag
--,sum(fb_val_loc * r_rate) value_usd --,sum(fb_val_loc * r_rate) value_usd
FROM FROM
rlarp.osm rlarp.osm
WHERE WHERE
adj_orderdate >= '2017-06-01' adj_orderdate >= '2017-06-01'
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate AND adj_orderdate <= adj_shipdate
AND fspr IS NOT NULL AND fspr IS NOT NULL
GROUP BY GROUP BY
shipgrp shipgrp
,to_char(orderdate,'Mon') ,to_char(orderdate,'Mon')
,extract(month FROM age(requestdate,orderdate)) ,extract(month FROM age(requestdate,orderdate))
HAVING HAVING
sum(fb_val_loc * r_rate) <> 0 sum(fb_val_loc * r_rate) <> 0
) )
,lag AS ( ,lag AS (
SELECT SELECT
shipgrp shipgrp
,orderm ,orderm
,rmo ,rmo
,wav_lag ,wav_lag
FROM FROM
alldates alldates
ORDER BY ORDER BY
shipgrp shipgrp
,orderm ,orderm
,rmo ,rmo
) )
,opord AS ( ,opord AS (
SELECT SELECT
shipgrp shipgrp
,orderdate ,orderdate
,requestdate ,requestdate
,shipdate ,shipdate
,to_char(orderdate,'Mon') orderm ,to_char(orderdate,'Mon') orderm
,extract(month FROM age(requestdate,orderdate)) rmo ,extract(month FROM age(requestdate,orderdate)) rmo
,sum(fb_val_loc * r_rate) value_usd ,sum(fb_val_loc * r_rate) value_usd
FROM FROM
rlarp.osm rlarp.osm
WHERE WHERE
calc_status NOT IN ('CANCELED','CLOSED') calc_status NOT IN ('CANCELED','CLOSED')
GROUP BY GROUP BY
shipgrp shipgrp
,orderdate ,orderdate
,requestdate ,requestdate
,shipdate ,shipdate
,to_char(orderdate,'Mon') ,to_char(orderdate,'Mon')
,extract(month FROM age(requestdate,orderdate)) ,extract(month FROM age(requestdate,orderdate))
ORDER BY ORDER BY
value_usd DESC value_usd DESC
) )
,upd AS ( ,upd AS (
UPDATE rlarp.osmfs o SET UPDATE rlarp.osmfs o SET
adj_shipdate = greatest(shipdate + lag.wav_lag + 5 ,shipdate) adj_shipdate = greatest(shipdate + lag.wav_lag + 5 ,shipdate)
FROM FROM
lag lag
WHERE WHERE
lag.shipgrp = o.shipgrp lag.shipgrp = o.shipgrp
AND lag.orderm = to_char(o.orderdate,'Mon') AND lag.orderm = to_char(o.orderdate,'Mon')
AND lag.rmo = extract(month FROM age(o.requestdate,o.orderdate)) AND lag.rmo = extract(month FROM age(o.requestdate,o.orderdate))
AND o.calc_status in ('BACKORDER','OPEN') AND o.calc_status in ('BACKORDER','OPEN')
RETURNING * RETURNING *
) )
SELECT SELECT
sum(fb_val_loc *r_rate) filter (where adj_shipdate < '2019-04-01') sum(fb_val_loc *r_rate) filter (where adj_shipdate < '2019-04-01')
,sum(fb_val_loc *r_rate) filter (where adj_shipdate >= '2019-04-01') ,sum(fb_val_loc *r_rate) filter (where adj_shipdate >= '2019-04-01')
from upd; from upd;
COMMIT; COMMIT;

View File

@ -1,27 +1,27 @@
WITH WITH
act As ( act As (
SELECT DISTINCT SELECT DISTINCT
v6part part v6part part
FROM FROM
lgdat.stka lgdat.stka
WHERE WHERE
( (
v6stat = 'A' v6stat = 'A'
OR v6part in ('TWA10203G18B027','TWA10203G18D050','MIH09000G18E001') OR v6part in ('TWA10203G18B027','TWA10203G18D050','MIH09000G18E001')
) )
OR v6type = 'C' OR v6type = 'C'
) )
,stkm AS ( ,stkm AS (
SELECT SELECT
act.part || ' - ' ||rtrim(COALESCE(m.avdes1,p.awdes1)) part act.part || ' - ' ||rtrim(COALESCE(m.avdes1,p.awdes1)) part
--,COALESCE(m.avgled, p.awgled) glec --,COALESCE(m.avgled, p.awgled) glec
FROM FROM
act act
LEFT OUTER JOIN lgdat.stkmm m ON LEFT OUTER JOIN lgdat.stkmm m ON
m.avpart = act.part m.avpart = act.part
LEFT OUTER JOIN lgdat.stkmp p ON LEFT OUTER JOIN lgdat.stkmp p ON
p.awpart = act.part p.awpart = act.part
WHERE WHERE
substr(COALESCE(m.avgled, p.awgled),1,1) <= '2' substr(COALESCE(m.avgled, p.awgled),1,1) <= '2'
) )
select part from stkm select part from stkm

View File

@ -1,29 +1,29 @@
UPDATE UPDATE
rlarp.osmfs f rlarp.osmfs f
SET SET
fspr = gld.fspr fspr = gld.fspr
FROM FROM
( (
SELECT SELECT
N1COMP COMP N1COMP COMP
,N1CCYY FSYRq ,N1CCYY FSYRq
,KPMAXP PERDS ,KPMAXP PERDS
,N1FSPP PERD ,N1FSPP PERD
,to_char(N1FSYP,'FM0000') FSPR ,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT ,N1SD01 SDAT
,N1ED01 EDAT ,N1ED01 EDAT
,to_char(N1ED01,'yymm') CAPR ,to_char(N1ED01,'yymm') CAPR
,N1ED01 - N1SD01 +1 NDAYS ,N1ED01 - N1SD01 +1 NDAYS
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR ,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 ,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 FROM
LGDAT.GLDATREF LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON INNER JOIN LGDAT.GLDATE ON
KPCOMP = N1COMP AND KPCOMP = N1COMP AND
KPCCYY = N1CCYY KPCCYY = N1CCYY
WHERE WHERE
N1COMP = 93 N1COMP = 93
--AND DIGITS(N1FSYP) = '1901' --AND DIGITS(N1FSYP) = '1901'
) gld ) gld
WHERE WHERE
f.adj_shipdate BETWEEN gld.sdat AND gld.edat f.adj_shipdate BETWEEN gld.sdat AND gld.edat

View File

@ -80,6 +80,7 @@ server.get('/get_pool', bodyParser.json(), function(req, res) {
console.log(new Date().toISOString() + "-------------------------get pool:----------------------------"); console.log(new Date().toISOString() + "-------------------------get pool:----------------------------");
console.log(req.body.quota_rep); console.log(req.body.quota_rep);
sql = sql.replace("rep_replace", req.body.quota_rep); sql = sql.replace("rep_replace", req.body.quota_rep);
console.log(sql);
Postgres.FirstRow(sql, [], res) Postgres.FirstRow(sql, [], res)
}; };
@ -128,7 +129,7 @@ server.get('/scenario_package', bodyParser.json(), function(req, res) {
//parse the where clause into the main sql statement //parse the where clause into the main sql statement
sql = sql.replace(new RegExp("where_clause", 'g'), w) sql = sql.replace(new RegExp("where_clause", 'g'), w)
//execute the sql and send the result //execute the sql and send the result
//console.log(sql); console.log(sql);
Postgres.FirstRow(sql, [], res) Postgres.FirstRow(sql, [], res)
}; };
}) })
@ -164,6 +165,39 @@ server.get('/list_changes', bodyParser.json(), function(req, res) {
}; };
}) })
server.get('/undo_change', bodyParser.json(), function(req, res) {
var sql = "";
var w = "";
var c = 1;
var d = 1;
var args = [];
var path = './route_sql/undo.sql';
fs.readFile(path, 'utf8', function(err, data) {
if (!err) {
callback(data);
} else {
console.log("fatal error pulling sql file")
callback(err);
}
});
var callback = function(arg) {
sql = arg;
console.log(new Date().toISOString() + "-------------------------undo change:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("replace_id", 'g'), JSON.stringify(req.body.logid))
//execute the sql and send the result
console.log(sql);
Postgres.FirstRow(sql, [], res)
};
})
//deprecating this route, just use _vp for volume and prive
/*
server.post('/addmonth_v', bodyParser.json(), function(req, res) { server.post('/addmonth_v', bodyParser.json(), function(req, res) {
var sql = ""; var sql = "";
@ -205,6 +239,7 @@ server.post('/addmonth_v', bodyParser.json(), function(req, res) {
Postgres.FirstRow(sql, [], res) Postgres.FirstRow(sql, [], res)
} }
}) })
*/
server.post('/addmonth_vp', bodyParser.json(), function(req, res) { server.post('/addmonth_vp', bodyParser.json(), function(req, res) {

View File

@ -1,20 +0,0 @@
{
"scenario": {
"ship_season": 2019,
"ship_month": "Mar",
"order_season": 2019,
"order_month": "Mar",
"version": "9p3",
"iter": [
"forecast"
]
},
"adj_amount": -1248994,
"adj_qty": -2828623,
"tar_amount": 5335749,
"tar_qty": 18623740,
"stamp": "2019-03-01 10:00:00",
"user": "Trowbridge, Paul",
"source": "forecast ui",
"type":"scale_v"
}

View File

@ -5,21 +5,20 @@ the volume must be expressed in terms of units, since that is what it will be sc
target AS (select target_volume vincr, target_price pincr) target AS (select target_volume vincr, target_price pincr)
,testv AS ( ,testv AS (
SELECT SELECT
sum(fb_qty) tot sum(units) tot
,sum(fb_qty) FILTER (WHERE iter = 'copy') base ,sum(units) FILTER (WHERE iter = 'copy') base
,COALESCE(sum(fb_qty) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpart ,COALESCE(sum(units) FILTER (WHERE module = 'new basket'),0) newpart
,sum(fb_val_loc *r_rate) totsales ,sum(value_loc *r_rate) totsales
,sum(fb_val_loc *r_rate) FILTER (WHERE iter = 'copy') basesales ,sum(value_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
,COALESCE(sum(fb_val_loc *r_rate) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpartsales ,COALESCE(sum(value_loc *r_rate) FILTER (WHERE module = 'new basket'),0) newpartsales
FROM FROM
rlarp.osm_fcpool rlarp.osm_pool
WHERE WHERE
-----------------scenario---------------------------- -----------------scenario----------------------------
where_clause where_clause
-----------------additional params------------------- -----------------additional params-------------------
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate AND order_date <= ship_date
) )
,flagv AS ( ,flagv AS (
SELECT SELECT
@ -55,7 +54,7 @@ target AS (select target_volume vincr, target_price pincr)
FROM FROM
testv testv
) )
,GLD AS ( ,GLD AS MATERIALIZED (
SELECT SELECT
N1COMP COMP N1COMP COMP
,N1CCYY FSYR ,N1CCYY FSYR
@ -64,10 +63,11 @@ target AS (select target_volume vincr, target_price pincr)
,to_char(N1FSYP,'FM0000') FSPR ,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT ,N1SD01 SDAT
,N1ED01 EDAT ,N1ED01 EDAT
,daterange(n1sd01, n1ed01) drange
,to_char(N1ED01,'yymm') CAPR ,to_char(N1ED01,'yymm') CAPR
,N1ED01 - N1SD01 +1 NDAYS ,N1ED01 - N1SD01 +1 NDAYS
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR ,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 ,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'FM00') SSPR
FROM FROM
LGDAT.GLDATREF LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON INNER JOIN LGDAT.GLDATE ON
@ -75,38 +75,37 @@ target AS (select target_volume vincr, target_price pincr)
KPCCYY = N1CCYY KPCCYY = N1CCYY
WHERE WHERE
N1COMP = 93 N1COMP = 93
--AND DIGITS(N1FSYP) = '1901'
) )
,mseq AS ( ,mseq AS (
SELECT * FROM SELECT * FROM
( (
VALUES VALUES
('Jun',1,6,-1) ('01 - Jun',1,6,-1)
,('Jul',2,7,-1) ,('02 - Jul',2,7,-1)
,('Aug',3,8,-1) ,('03 - Aug',3,8,-1)
,('Sep',4,9,-1) ,('04 - Sep',4,9,-1)
,('Oct',5,10,-1) ,('05 - Oct',5,10,-1)
,('Nov',6,11,-1) ,('06 - Nov',6,11,-1)
,('Dec',7,12,-1) ,('07 - Dec',7,12,-1)
,('Jan',8,1,0) ,('08 - Jan',8,1,0)
,('Feb',9,2,0) ,('09 - Feb',9,2,0)
,('Mar',10,3,0) ,('10 - Mar',10,3,0)
,('Apr',11,4,0) ,('11 - Apr',11,4,0)
,('May',12,5,0) ,('12 - May',12,5,0)
) x(m,s,cal,yr) ) x(m,s,cal,yr)
) )
,alldates AS ( ,alldates AS MATERIALIZED(
SELECT SELECT
promo promo
,terms ,terms
,order_month ,order_month
,mseq.s seq ,mseq.s seq
,orderdate ,order_date
,requestdate ,request_date
,shipdate ,ship_date
,sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) value_usd ,sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) value_usd
FROM FROM
rlarp.osm_fcpool rlarp.osm_pool
LEFT OUTER JOIN mseq ON LEFT OUTER JOIN mseq ON
mseq.m = order_month mseq.m = order_month
WHERE WHERE
@ -116,52 +115,52 @@ target AS (select target_volume vincr, target_price pincr)
AND CASE (SELECT flag FROM flagv) AND CASE (SELECT flag FROM flagv)
WHEN 'scale all' THEN true WHEN 'scale all' THEN true
WHEN 'scale copy' THEN iter = 'copy' WHEN 'scale copy' THEN iter = 'copy'
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket' WHEN 'scale new part' THEN module = 'new basket'
END END
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate AND order_date <= ship_date
GROUP BY GROUP BY
promo promo
,terms ,terms
,order_month ,order_month
,mseq.s ,mseq.s
,orderdate ,order_date
,requestdate ,request_date
,shipdate ,ship_date
HAVING HAVING
sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) <> 0 sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) <> 0
) )
--select * from alldates --select * from alldates
,dom AS ( ,dom AS (
SELECT SELECT
extract(day FROM orderdate) DOM extract(day FROM order_date) DOM
,sum(value_usd) value_usd ,sum(value_usd) value_usd
FROM FROM
alldates alldates
GROUP BY GROUP BY
extract(day FROM orderdate) extract(day FROM order_date)
) )
---------------------may want ot look at a top-5 mix solution in the future facilitated by sum() over (order by sales desc)--------------- ---------------------may want ot look at a top-5 mix solution in the future facilitated by sum() over (order by sales desc)---------------
,mmix AS ( ,mmix AS (
SELECT SELECT
to_char(orderdate,'Mon') _month to_char(order_date,'Mon') _month
,seq ,seq
,promo ,promo
,sum(extract(day from orderdate)*value_usd) dom_wa ,sum(extract(day from order_date)*value_usd) dom_wa
--,requestdate-orderdate rlag --,request_date-order_date rlag
,sum((requestdate-orderdate)*(value_usd)) rlag_wa ,sum((request_date-order_date)*(value_usd)) rlag_wa
--,shipdate - requestdate slag --,ship_date - request_date slag
,sum((shipdate - requestdate)*(value_usd)) slag_wa ,sum((ship_date - request_date)*(value_usd)) slag_wa
,sum(value_usd) value_usd ,sum(value_usd) value_usd
FROM FROM
alldates alldates
GROUP BY GROUP BY
to_char(orderdate,'Mon') to_char(order_date,'Mon')
,seq ,seq
,promo ,promo
--,extract(day from orderdate) --,extract(day from order_date)
--,requestdate-orderdate --,request_date-order_date
--,shipdate - requestdate --,ship_date - request_date
) )
,targm AS (select s, m from mseq where m = 'target_month' ) ,targm AS (select s, m from mseq where m = 'target_month' )
,mmixp AS ( ,mmixp AS (
@ -187,117 +186,50 @@ target AS (select target_volume vincr, target_price pincr)
abs(seq - targm.s) ASC abs(seq - targm.s) ASC
LIMIT 1 LIMIT 1
) )
--SELECT * FROM mmixp order by seq asc, vperc desc ---------------------the role of basemix here is to get non-dated info which is then dated in the next step---------------------
,basemix AS ( ,basemix AS (
SELECT SELECT
plnt ---master data --fspr in next step
,0::numeric(11,0) "ddord#" --0 o.plnt
,0::numeric(11,0) "dditm#" --0 --promo in next step
,0::numeric(11,0) "fgbol#" --0 --terms in next step
,0::numeric(11,0) "fgent#" --0 ,c.bvterm terms
,0::numeric(9,0) "diinv#" --0 ,o.bill_cust_descr
,0::numeric(3,0) "dilin#" --0 ,o.ship_cust_descr
,null::text promo --history date mix ,o.dsm
,null::text return_reas --0 ,o.quota_rep_descr
,terms ,o.director
,''::text custpo --0 ,o.billto_group
,'I' dhincr --0 ,o.shipto_group
,null::numeric diext ,o.chan
,null::numeric ditdis ,o.chansub
,null::date dcodat --calculated date mix ,o.chan_retail
,null::date ddqdat --calculated date mix ,o.part
,null::date dcmdat --calculated date mix ,o.part_descr
,null::date dhidat --calculated date mix ,o.part_group
,null::text fspr --calculated date mix ,o.branding
,remit_to --master data ,o.majg_descr
,bill_class --master data ,o.ming_descr
,bill_cust --history cust mix ,o.majs_descr
,bill_rep --master data ,o.mins_descr
,bill_terr --master data ,o.segm
,ship_class --master data ,o.substance
,ship_cust --history cust mix ,o.fs_line
,ship_rep --master data ,o.r_currency
,ship_terr --master data ,o.r_rate
,quota_rep --master data ,o.c_currency
,account --master data ,o.c_rate
,shipgrp --master data ,sum(coalesce(o.units,0)) units
,geo --master data ,sum(coalesce(o.value_loc,0)) value_loc
,chan --master data ,sum(coalesce(o.value_usd,0)) value_usd
,orig_ctry --master data ,sum(coalesce(o.cost_loc,0)) cost_loc
,orig_prov --master data ,sum(coalesce(o.cost_usd,0)) cost_usd
,orig_post --master data ,o.calc_status
,dest_ctry --master data ,o.flag
,dest_prov --master data
,dest_post --master data
,part --history part mix
,ord_gldc --master data
,majg --master data
,ming --master data
,majs --master data
,mins --master data
,gldc --master data
,glec --master data
,harm --master data
,clss --master data
,brand --master data
,assc --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,0::numeric(15,5) ddqtoi --0
,0::numeric(15,5) ddqtsi --0
,0::numeric(15,5) fgqshp --0
,0::numeric(15,5) diqtsh --0
,sum(coalesce(fb_qty,0)) fb_qty --history value
,sum(coalesce(fb_cst_loc,0)) fb_cst_loc --history part mix
,sum(coalesce(fb_cst_loc_cur,0)) fb_cst_loc_cur --master data
,sum(coalesce(fb_cst_loc_fut,0)) fb_cst_loc_fut --master data
,sum(coalesce(fb_val_loc,0)) fb_val_loc --history value
,sum(coalesce(fb_val_loc_pl,0)) fb_val_loc_pl --0
,calc_status --0
,flag --0
,null::date orderdate --history date mix
,null::date requestdate --history date mix
,null::date shipdate --history date mix
,null::date adj_orderdate --history
,null::date adj_requestdate --history
,null::date adj_shipdate --history
,'b20' "version" --calculated
,'adjustment' iter --calculated
---------------ui columns-------------------------
,null::numeric order_season
,null::text order_month
,null::numeric ship_season
,null::text ship_month
,null::numeric request_season
,null::text request_month
,part_descr
,part_family
,part_group
,branding
,color
,segm
,bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,mod_chan
,mod_chansub
,quota_rep_descr
,director_descr
,null value_loc
,null value_usd
,null cost_loc
,null cost_usd
,null units
FROM FROM
rlarp.osm_fcpool rlarp.osm_pool o
LEFT OUTER JOIN lgdat.cust c ON
c.bvcust = rtrim(substr(o.bill_cust_descr,1,8))
WHERE WHERE
-----------------scenario---------------------------- -----------------scenario----------------------------
where_clause where_clause
@ -305,217 +237,137 @@ SELECT
AND CASE (SELECT flag FROM flagv) AND CASE (SELECT flag FROM flagv)
WHEN 'scale all' THEN true WHEN 'scale all' THEN true
WHEN 'scale copy' THEN iter = 'copy' WHEN 'scale copy' THEN iter = 'copy'
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket' WHEN 'scale new part' THEN module = 'new basket'
END END
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate AND order_date <= ship_date
GROUP BY GROUP BY
plnt ---master data --fspr in next step
,terms o.plnt
,remit_to --master data ,c.bvterm
,bill_class --master data --promo in next step
,bill_cust --history cust mix --terms in next step
,bill_rep --master data ,o.bill_cust_descr
,bill_terr --master data ,o.ship_cust_descr
,ship_class --master data ,o.dsm
,ship_cust --history cust mix ,o.quota_rep_descr
,ship_rep --master data ,o.director
,ship_terr --master data ,o.billto_group
,quota_rep --master data ,o.shipto_group
,account --master data ,o.chan
,shipgrp --master data ,o.chansub
,geo --master data ,o.chan_retail
,chan --master data ,o.part
,orig_ctry --master data ,o.part_descr
,orig_prov --master data ,o.part_group
,orig_post --master data ,o.branding
,dest_ctry --master data ,o.majg_descr
,dest_prov --master data ,o.ming_descr
,dest_post --master data ,o.majs_descr
,part --history part mix ,o.mins_descr
,ord_gldc --master data ,o.segm
,majg --master data ,o.substance
,ming --master data ,o.fs_line
,majs --master data ,o.r_currency
,mins --master data ,o.r_rate
,gldc --master data ,o.c_currency
,glec --master data ,o.c_rate
,harm --master data ,o.calc_status
,clss --master data ,o.flag
,brand --master data
,assc --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status
,flag
,part_descr
,part_family
,part_group
,branding
,color
,segm
,bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,mod_chan
,mod_chansub
,quota_rep_descr
,director_descr
) )
,vscale AS ( ,vscale AS (
SELECT SELECT
(SELECT vincr::numeric FROM target) incr (SELECT vincr::numeric FROM target) incr
,(SELECT sum(fb_qty) FROM basemix) base ,(SELECT sum(units) FROM basemix) base
,(SELECT vincr::numeric FROM target)/(SELECT sum(fb_qty) FROM basemix) factor ,(SELECT vincr::numeric FROM target)/(SELECT sum(units) FROM basemix) factor
) )
--select * from SCALE --select * from SCALE
,log AS (
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
)
,volume AS ( ,volume AS (
SELECT SELECT
b.plnt --master data sd.fspr
,b."ddord#" --0 ,b.plnt
,b."dditm#" --0 ,m.promo
,b."fgbol#" --0 ,b.terms
,b."fgent#" --0 ,b.bill_cust_descr
,b."diinv#" --0 ,b.ship_cust_descr
,b."dilin#" --0 ,b.dsm
,m.promo --history date mix ,b.quota_rep_descr
,b.return_reas --0 ,b.director
,b.terms --history cust mix ,b.billto_group
,b.custpo --0 ,b.shipto_group
,b.dhincr --0 ,b.chan
,b.diext --0 ,b.chansub
,b.ditdis --0 ,b.chan_retail
,b.dcodat --calculated date mix ,b.part
,b.ddqdat --calculated date mix
,b.dcmdat --calculated date mix
,b.dhidat --calculated date mix
,b.fspr --calculated date mix
,b.remit_to --master data
,b.bill_class --master data
,b.bill_cust --history cust mix
,b.bill_rep --master data
,b.bill_terr --master data
,b.ship_class --master data
,b.ship_cust --history cust mix
,b.ship_rep --master data
,b.ship_terr --master data
,b.quota_rep --master data
,b.account --master data
,b.shipgrp --master data
,b.geo --master data
,b.chan --master data
,b.orig_ctry --master data
,b.orig_prov --master data
,b.orig_post --master data
,b.dest_ctry --master data
,b.dest_prov --master data
,b.dest_post --master data
,b.part --history part mix
,b.ord_gldc --master data
,b.majg --master data
,b.ming --master data
,b.majs --master data
,b.mins --master data
,b.gldc --master data
,b.glec --master data
,b.harm --master data
,b.clss --master data
,b.brand --master data
,b.assc --master data
,b.fs_line --master data
,b.r_currency --history cust mix
,b.r_rate --master data
,b.c_currency --master data
,b.c_rate --master data
,b.ddqtoi --0
,b.ddqtsi --0
,b.fgqshp --0
,b.diqtsh --0
,b.fb_qty*s.factor*m.momix fb_qty
,b.fb_cst_loc*s.factor*m.momix fb_cst_loc
,b.fb_cst_loc_cur*s.factor*m.momix fb_cst_loc_cur
,b.fb_cst_loc_fut*s.factor*m.momix fb_cst_loc_fut
,b.fb_val_loc*s.factor*m.momix fb_val_loc
,b.fb_val_loc_pl*s.factor*m.momix fb_val_loc_pl
,b.calc_status --0
,b.flag --0
,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
,'replace_version' "version" --calculated
,'replace_source'||' volume' iter
-----------------------ui columns--------------------------------
,'replace_iterdet' iterdet
,$$replace_iterdef$$::jsonb iterdef
,od.ssyr order_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
,sd.ssyr ship_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,rd.ssyr request_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month
,b.part_descr ,b.part_descr
,b.part_family
,b.part_group ,b.part_group
,b.branding ,b.branding
,b.color
,b.segm
,b.bill_cust_descr
,b.billto_group
,b.ship_cust_descr
,b.shipto_group
,b.majg_descr ,b.majg_descr
,b.ming_descr ,b.ming_descr
,b.majs_descr ,b.majs_descr
,b.mins_descr ,b.mins_descr
,b.mod_chan ,b.segm
,b.mod_chansub ,b.substance
,b.quota_rep_descr ,b.fs_line
,b.director_descr ,b.r_currency
,b.fb_val_loc*s.factor*m.momix value_loc ,b.r_rate
,b.fb_val_loc*s.factor*m.momix*r_rate value_usd ,b.c_currency
,b.fb_cst_loc*s.factor*m.momix cost_loc ,b.c_rate
,b.fb_cst_loc*s.factor*m.momix*c_rate cost_usd ,b.units*s.factor*m.momix units
,(b.fb_qty*s.factor*m.momix) units ,b.value_loc*s.factor*m.momix value_loc
,b.value_usd*s.factor*m.momix value_usd
,b.cost_loc*s.factor*m.momix cost_loc
,b.cost_usd*s.factor*m.momix cost_usd
,b.calc_status
,b.flag
,make_date(mseq.yr + 2021,mseq.cal,m.odom) order_date
,od.sspr || ' - ' || to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom),'Mon') order_month
,od.ssyr order_season
,make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag request_date
,rd.sspr || ' - ' ||to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag,'Mon') request_month
,rd.ssyr request_season
,make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag ship_date
,sd.sspr || ' - ' || to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,sd.ssyr ship_season
,'replace_version' "version"
,'replace_source'||' volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'module' module
FROM FROM
basemix b basemix b
CROSS JOIN vscale s CROSS JOIN vscale s
CROSS JOIN mmixp m CROSS JOIN mmixp m
CROSS JOIN closest CROSS JOIN closest
CROSS JOIN log
LEFT OUTER JOIN mseq ON LEFT OUTER JOIN mseq ON
mseq.m = closest.m mseq.m = closest.m
LEFT OUTER JOIN gld od ON LEFT OUTER JOIN gld od ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat make_date(mseq.yr + 2021,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON LEFT OUTER JOIN gld rd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON LEFT OUTER JOIN gld sd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
WHERE WHERE
m._month = (SELECT _month FROM closest) m._month = (SELECT _month FROM closest)
) )
,pscale AS ( ,pscale AS (
SELECT SELECT
(SELECT pincr::numeric FROM target) incr (SELECT pincr::numeric FROM target) incr
,(SELECT sum(fb_val_loc * r_rate) FROM volume) base ,(SELECT sum(value_loc * r_rate) FROM volume) base
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
0 0
ELSE ELSE
((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume))/(SELECT sum(fb_val_loc * r_rate) FROM volume) ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(value_loc * r_rate) FROM volume)
END factor END factor
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume)) <> 0 THEN CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume)) <> 0 THEN
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply --if the base value is -0- but the target value hasn't been achieved, derive a price to apply
((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume))/(SELECT sum(fb_qty) FROM volume) ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume)
ELSE ELSE
0 0
END END
@ -525,188 +377,147 @@ WHERE
) )
,price AS ( ,price AS (
SELECT SELECT
b.plnt --master data b.fspr
,b."ddord#" --0 ,b.plnt
,b."dditm#" --0 ,b.promo
,b."fgbol#" --0 ,b.terms
,b."fgent#" --0 ,b.bill_cust_descr
,b."diinv#" --0 ,b.ship_cust_descr
,b."dilin#" --0 ,b.dsm
,b.promo --history date mix ,b.quota_rep_descr
,b.return_reas --0 ,b.director
,b.terms --history cust mix ,b.billto_group
,b.custpo --0 ,b.shipto_group
,b.dhincr --0 ,b.chan
,b.diext --0 ,b.chansub
,b.ditdis --0 ,b.chan_retail
,b.dcodat --calculated date mix ,b.part
,b.ddqdat --calculated date mix
,b.dcmdat --calculated date mix
,b.dhidat --calculated date mix
,b.fspr --calculated date mix
,b.remit_to --master data
,b.bill_class --master data
,b.bill_cust --history cust mix
,b.bill_rep --master data
,b.bill_terr --master data
,b.ship_class --master data
,b.ship_cust --history cust mix
,b.ship_rep --master data
,b.ship_terr --master data
,b.quota_rep --master data
,b.account --master data
,b.shipgrp --master data
,b.geo --master data
,b.chan --master data
,b.orig_ctry --master data
,b.orig_prov --master data
,b.orig_post --master data
,b.dest_ctry --master data
,b.dest_prov --master data
,b.dest_post --master data
,b.part --history part mix
,b.ord_gldc --master data
,b.majg --master data
,b.ming --master data
,b.majs --master data
,b.mins --master data
,b.gldc --master data
,b.glec --master data
,b.harm --master data
,b.clss --master data
,b.brand --master data
,b.assc --master data
,b.fs_line --master data
,b.r_currency --history cust mix
,b.r_rate --master data
,b.c_currency --master data
,b.c_rate --master data
,b.ddqtoi --0
,b.ddqtsi --0
,b.fgqshp --0
,b.diqtsh --0
,0 fb_qty
,0 fb_cst_loc
,0 fb_cst_loc_cur
,0 fb_cst_loc_fut
,b.fb_val_loc*p.factor fb_val_loc
,b.fb_val_loc_pl*p.factor fb_val_loc_pl
,b.calc_status --0
,b.flag --0
,b.orderdate
,b.requestdate
,b.shipdate
,b.adj_orderdate
,b.adj_requestdate
,b.adj_shipdate
,'replace_version' "version" --calculated
,'replace_source'||' price' iter --calculateds
,'replace_iterdet' iterdet
,$$replace_iterdef$$::jsonb iterdef
,b.order_season
,b.order_month
,b.ship_season
,b.ship_month
,b.request_season
,b.request_month
,b.part_descr ,b.part_descr
,b.part_family
,b.part_group ,b.part_group
,b.branding ,b.branding
,b.color
,b.segm
,b.bill_cust_descr
,b.billto_group
,b.ship_cust_descr
,b.shipto_group
,b.majg_descr ,b.majg_descr
,b.ming_descr ,b.ming_descr
,b.majs_descr ,b.majs_descr
,b.mins_descr ,b.mins_descr
,b.mod_chan ,b.segm
,b.mod_chansub ,b.substance
,b.quota_rep_descr ,b.fs_line
,b.director_descr ,b.r_currency
,(CASE WHEN p.factor = 0 THEN b.fb_qty * p.mod_price/b.r_rate ELSE b.fb_val_loc*p.factor END)::numeric value_loc ,b.r_rate
,(CASE WHEN p.factor = 0 THEN b.fb_qty * p.mod_price ELSE b.fb_val_loc*p.factor END)::numeric value_usd ,b.c_currency
,0 cost_loc ,b.c_rate
,0 cost_usd ,0::numeric units
,0 units ,(CASE WHEN p.factor = 0 THEN b.units * p.mod_price/b.r_rate ELSE b.value_loc*p.factor END)::numeric value_loc
,(CASE WHEN p.factor = 0 THEN b.units * p.mod_price ELSE b.value_usd*p.factor END)::numeric value_usd
,0::numeric cost_loc
,0::numeric cost_usd
,b.calc_status
,b.flag
,b.order_date
,b.order_month
,b.order_season
,b.request_date
,b.request_month
,b.request_season
,b.ship_date
,b.ship_month
,b.ship_season
,'replace_version' "version"
,'replace_source'||' price' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'module' module
FROM FROM
volume b volume b
CROSS JOIN pscale p CROSS JOIN pscale p
CROSS JOIN log
WHERE WHERE
p.factor <> 0 or p.mod_price <> 0 p.factor <> 0 or p.mod_price <> 0
) )
, ins AS ( , ins AS (
INSERT INTO rlarp.osm_fcpool (SELECT * FROM price UNION ALL SELECT * FROM volume) RETURNING * INSERT INTO rlarp.osm_pool (SELECT * FROM price UNION ALL SELECT * FROM volume) RETURNING *
) )
,insagg AS ( ,insagg AS (
SELECT SELECT
bill_cust_descr ---------customer info-----------------
,billto_group bill_cust_descr
,ship_cust_descr ,billto_group
,shipto_group ,ship_cust_descr
,quota_rep_descr ,shipto_group
,director_descr ,quota_rep_descr
,segm ,director
,mod_chan ,segm
,mod_chansub ,substance
,majg_descr ,chan
,ming_descr ,chansub
,majs_descr ---------product info------------------
,mins_descr ,majg_descr
,brand ,ming_descr
,part_family ,majs_descr
,part_group ,mins_descr
,branding --,brand
,color --,part_family
,part_descr ,part_group
,order_season ,branding
,order_month --,color
,ship_season ,part_descr
,ship_month ---------dates-------------------------
,request_season ,order_season
,request_month ,order_month
,promo ,ship_season
,version ,ship_month
,iter ,request_season
,sum(value_loc) value_loc ,request_month
,sum(value_usd) value_usd ,promo
,sum(cost_loc) cost_loc ,version
,sum(cost_usd) cost_usd ,iter
,sum(units) units ,logid
FROM ,tag
ins ,comment
GROUP BY --------values-------------------------
bill_cust_descr ,sum(value_loc) value_loc
,billto_group ,sum(value_usd) value_usd
,ship_cust_descr ,sum(cost_loc) cost_loc
,shipto_group ,sum(cost_usd) cost_usd
,quota_rep_descr ,sum(units) units
,director_descr FROM
,segm ins
,mod_chan GROUP BY
,mod_chansub ---------customer info-----------------
,majg_descr bill_cust_descr
,ming_descr ,billto_group
,majs_descr ,ship_cust_descr
,mins_descr ,shipto_group
,brand ,quota_rep_descr
,part_family ,director
,part_group ,segm
,branding ,substance
,color ,chan
,part_descr ,chansub
,order_season ---------product info------------------
,order_month ,majg_descr
,ship_season ,ming_descr
,ship_month ,majs_descr
,request_season ,mins_descr
,request_month --,brand
,promo --,part_family
,version ,part_group
,iter ,branding
--,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
,logid
,tag
,comment
) )
--SELECT * FROM insagg SELECT json_agg(row_to_json(insagg)) x from insagg
SELECT json_agg(row_to_json(insagg)) x from insagg

View File

@ -8,6 +8,7 @@ SELECT
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -29,14 +30,17 @@ SELECT
,request_season ,request_season
,request_month ,request_month
,promo ,promo
,version
,iter
--------values------------------------- --------values-------------------------
,sum(value_loc) value_loc ,sum(value_loc) value_loc
,sum(value_usd) value_usd ,sum(value_usd) value_usd
,sum(cost_loc) cost_loc ,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd ,sum(cost_usd) cost_usd
,sum(units) units ,sum(units) units
,version
,iter
,logid
,tag
,comment
FROM FROM
rlarp.osm_pool rlarp.osm_pool
WHERE WHERE
@ -50,6 +54,7 @@ GROUP BY
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -73,6 +78,10 @@ GROUP BY
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
,substance
) )
SELECT SELECT
json_agg(row_to_json(rows)) x json_agg(row_to_json(rows)) x

View File

@ -4,6 +4,7 @@ SELECT
l.doc->>'user' "user", l.doc->>'user' "user",
jsonb_path_query_first(l.doc,'$.scenario.quota_rep_descr')->>0 quota_rep_descr, jsonb_path_query_first(l.doc,'$.scenario.quota_rep_descr')->>0 quota_rep_descr,
to_char((l.doc->>'stamp')::timestamptz,'YYYY-MM-DD HH:MI:SS') "stamp", to_char((l.doc->>'stamp')::timestamptz,'YYYY-MM-DD HH:MI:SS') "stamp",
l.doc->>'tag' "tag",
l.doc->>'message' "comment", l.doc->>'message' "comment",
jsonb_pretty(l.doc) def, jsonb_pretty(l.doc) def,
l.id l.id
@ -17,6 +18,7 @@ SELECT
list.user list.user
,list.quota_rep_descr ,list.quota_rep_descr
,list.stamp ,list.stamp
,list.tag
,list.comment ,list.comment
,list.def ,list.def
,list.id ,list.id
@ -29,6 +31,7 @@ group BY
list.user list.user
,list.quota_rep_descr ,list.quota_rep_descr
,list.stamp ,list.stamp
,list.tag
,list.comment ,list.comment
,list.def ,list.def
,list.id ,list.id

View File

@ -308,6 +308,7 @@ SELECT
,i.majs||' - '||i.majsd majs_descr ,i.majs||' - '||i.majsd majs_descr
,i.mins||' - '||i.minsd mins_descr ,i.mins||' - '||i.minsd mins_descr
,seg.segm ,seg.segm
,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
,'41010' fs_line --master data ,'41010' fs_line --master data
,bc.bvcurr r_currency --history cust mix ,bc.bvcurr r_currency --history cust mix
,rx.rate r_rate --master data ,rx.rate r_rate --master data
@ -332,8 +333,9 @@ SELECT
,'replace_version' "version" ,'replace_version' "version"
,'replace_source'||' volume' iter ,'replace_source'||' volume' iter
,log.id ,log.id
,log.doc->>'comment' "comment" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'type' module ,log.doc->>'message' "comment"
,log.doc->>'module' module
FROM FROM
basemix b basemix b
CROSS JOIN log CROSS JOIN log
@ -429,6 +431,7 @@ FROM
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -452,6 +455,9 @@ FROM
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
--------values------------------------- --------values-------------------------
,sum(value_loc) value_loc ,sum(value_loc) value_loc
,sum(value_usd) value_usd ,sum(value_usd) value_usd
@ -469,6 +475,7 @@ FROM
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -492,5 +499,8 @@ FROM
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
) )
SELECT json_agg(row_to_json(insagg)) x from insagg SELECT json_agg(row_to_json(insagg)) x from insagg

View File

@ -25,6 +25,7 @@ target AS (select target_increment incr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -78,6 +79,7 @@ target AS (select target_increment incr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -143,6 +145,7 @@ target AS (select target_increment incr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -167,8 +170,9 @@ target AS (select target_increment incr)
,'replace_version' "version" ,'replace_version' "version"
,'replace_source'||' price' iter ,'replace_source'||' price' iter
,log.id ,log.id
,log.doc->>'comment' "comment" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'type' module ,log.doc->>'message' "comment"
,log.doc->>'module' module
FROM FROM
basemix b basemix b
CROSS JOIN scale s CROSS JOIN scale s
@ -190,6 +194,7 @@ target AS (select target_increment incr)
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -213,6 +218,9 @@ target AS (select target_increment incr)
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
--------values------------------------- --------values-------------------------
,sum(value_loc) value_loc ,sum(value_loc) value_loc
,sum(value_usd) value_usd ,sum(value_usd) value_usd
@ -230,6 +238,7 @@ target AS (select target_increment incr)
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -253,5 +262,8 @@ target AS (select target_increment incr)
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
) )
SELECT json_agg(row_to_json(insagg)) x from insagg SELECT json_agg(row_to_json(insagg)) x from insagg

View File

@ -61,6 +61,7 @@ target AS (select incr_qty qincr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -119,6 +120,7 @@ target AS (select incr_qty qincr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -172,6 +174,7 @@ target AS (select incr_qty qincr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -196,8 +199,9 @@ target AS (select incr_qty qincr)
,'replace_version' "version" ,'replace_version' "version"
,'replace_source'||' volume' iter ,'replace_source'||' volume' iter
,log.id ,log.id
,log.doc->>'comment' "comment" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'type' module ,log.doc->>'message' "comment"
,log.doc->>'module' module
FROM FROM
basemix b basemix b
CROSS JOIN scale s CROSS JOIN scale s
@ -217,6 +221,7 @@ FROM
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -240,6 +245,9 @@ FROM
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
--------values------------------------- --------values-------------------------
,sum(value_loc) value_loc ,sum(value_loc) value_loc
,sum(value_usd) value_usd ,sum(value_usd) value_usd
@ -257,6 +265,7 @@ FROM
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -280,5 +289,8 @@ FROM
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
) )
SELECT json_agg(row_to_json(insagg)) x from insagg SELECT json_agg(row_to_json(insagg)) x from insagg

View File

@ -61,6 +61,7 @@ target AS (select target_vol vincr, target_prc pincr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -119,6 +120,7 @@ target AS (select target_vol vincr, target_prc pincr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -171,6 +173,7 @@ target AS (select target_vol vincr, target_prc pincr)
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -195,8 +198,9 @@ target AS (select target_vol vincr, target_prc pincr)
,'replace_version' "version" ,'replace_version' "version"
,'replace_source'||' volume' iter ,'replace_source'||' volume' iter
,log.id ,log.id
,log.doc->>'comment' "comment" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'type' module ,log.doc->>'message' "comment"
,log.doc->>'module' module
FROM FROM
basemix b basemix b
CROSS JOIN vscale s CROSS JOIN vscale s
@ -250,6 +254,7 @@ FROM
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,segm ,segm
,substance
,fs_line --master data ,fs_line --master data
,r_currency --history cust mix ,r_currency --history cust mix
,r_rate --master data ,r_rate --master data
@ -274,8 +279,9 @@ FROM
,'replace_version' "version" ,'replace_version' "version"
,'replace_source'||' price' iter ,'replace_source'||' price' iter
,log.id ,log.id
,log.doc->>'comment' "comment" ,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'type' module ,log.doc->>'message' "comment"
,log.doc->>'module' module
FROM FROM
volume b volume b
CROSS JOIN pscale s CROSS JOIN pscale s
@ -297,6 +303,7 @@ FROM
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -320,6 +327,9 @@ FROM
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
--------values------------------------- --------values-------------------------
,sum(value_loc) value_loc ,sum(value_loc) value_loc
,sum(value_usd) value_usd ,sum(value_usd) value_usd
@ -337,6 +347,7 @@ FROM
,quota_rep_descr ,quota_rep_descr
,director ,director
,segm ,segm
,substance
,chan ,chan
,chansub ,chansub
---------product info------------------ ---------product info------------------
@ -360,5 +371,8 @@ FROM
,promo ,promo
,version ,version
,iter ,iter
,logid
,tag
,comment
) )
SELECT json_agg(row_to_json(insagg)) x from insagg SELECT json_agg(row_to_json(insagg)) x from insagg

View File

@ -142,6 +142,19 @@ GROUP BY
,version ,version
,iter ,iter
) )
,tags AS (
SELECT DISTINCT
doc->>'tag' tag
FROM
rlarp.osm_log
WHERE doc ? 'tag'
UNION
SELECT * FROM
(VALUES
('price'),
('volume')
) x(tag)
)
SELECT SELECT
jsonb_build_object( jsonb_build_object(
'months' 'months'
@ -152,4 +165,6 @@ SELECT
,(SELECT jsonb_agg(row_to_json(basket)::jsonb) FROM basket) ,(SELECT jsonb_agg(row_to_json(basket)::jsonb) FROM basket)
,'totals' ,'totals'
,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals)
,'tags'
,(SELECT jsonb_agg(tag) FROM tags)
) package ) package

8
route_sql/undo.sql Normal file
View File

@ -0,0 +1,8 @@
WITH
d AS (
DELETE FROM rlarp.osm_log WHERE id = replace_id RETURNING id
)
,d_osm AS (
DELETE FROM rlarp.osm_pool WHERE logid IN (select id from d)
)
SELECT json_agg(row_to_json(d)) x from d

28
sample_request.json Normal file
View File

@ -0,0 +1,28 @@
{
"scenario": {
"quota_rep_descr": "TINA PETTIGREW",
"substance": "Plastic",
"chan": "DIR",
"billto_group": "H&A MASTRONARDI",
"shipto_group": "H&A MASTRONARDI",
"majg_descr": "110 - INJECTION",
"part_descr": "HWA13000E21B025LZBLD - 13.00 WRAPT HP CHOCOLATE",
"version": "b21",
"iter": [
"copy",
"adj volume",
"adj price",
"upload volume",
"upload price"
]
},
"stamp": "2020-02-19 17:03:38",
"user": "Trowbridge, Paul",
"source": "adj",
"message": "2% on volume and price",
"tag": "standard price",
"version": "b21",
"type": "scale_vp",
"qty": 453.60,
"amount": 728.43624
}