validate forecast matches actual, build in log entries for initial build
This commit is contained in:
parent
e9a0756240
commit
fcc95ecb40
@ -50,6 +50,9 @@ repc AS (
|
|||||||
,SI AS (
|
,SI AS (
|
||||||
SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> ''
|
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
|
SELECT
|
||||||
fspr
|
fspr
|
||||||
,plnt
|
,plnt
|
||||||
@ -106,12 +109,13 @@ SELECT
|
|||||||
,sseas ship_season
|
,sseas ship_season
|
||||||
,version
|
,version
|
||||||
,iter
|
,iter
|
||||||
,null::int logid
|
,logload.id logid
|
||||||
,''::text tag
|
,logload.doc->>'tag' tag
|
||||||
,''::text "comment"
|
,logload.doc->>'message' "comment"
|
||||||
,''::text module
|
,logload.doc->>'type' module
|
||||||
FROM
|
FROM
|
||||||
rlarp.osmf_dev o
|
rlarp.osmf_dev o
|
||||||
|
CROSS JOIN logload
|
||||||
LEFT OUTER JOIN lgdat.cust bc ON
|
LEFT OUTER JOIN lgdat.cust bc ON
|
||||||
bc.bvcust = o.bill_cust
|
bc.bvcust = o.bill_cust
|
||||||
LEFT OUTER JOIN lgdat.cust sc ON
|
LEFT OUTER JOIN lgdat.cust sc ON
|
||||||
|
@ -144,8 +144,11 @@ gld AS (
|
|||||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
o.odate BETWEEN '2019-06-01' AND '2019-01-31'
|
--base period orders booked....
|
||||||
|
o.odate BETWEEN '2019-06-01' AND '2020-01-31'
|
||||||
|
--...or any open orders currently booked before cutoff....
|
||||||
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-02-01')
|
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-02-01')
|
||||||
|
--...or anything that shipped in that period
|
||||||
OR o.fspr BETWEEN '2001' AND '2008'
|
OR o.fspr BETWEEN '2001' AND '2008'
|
||||||
)
|
)
|
||||||
AND fs_line = '41010'
|
AND fs_line = '41010'
|
||||||
|
@ -9,6 +9,7 @@ SELECT
|
|||||||
,order_month
|
,order_month
|
||||||
,doc->>'stamp' stamp
|
,doc->>'stamp' stamp
|
||||||
,logid
|
,logid
|
||||||
|
,tag
|
||||||
,sum(value_usd) FILTER (WHERE iter = 'copy') sales
|
,sum(value_usd) FILTER (WHERE iter = 'copy') sales
|
||||||
,sum(cost_usd) FILTER (WHERE iter = 'copy') scogs
|
,sum(cost_usd) FILTER (WHERE iter = 'copy') scogs
|
||||||
,sum(value_usd) FILTER (WHERE iter <> 'copy') sales_adj
|
,sum(value_usd) FILTER (WHERE iter <> 'copy') sales_adj
|
||||||
@ -28,17 +29,18 @@ GROUP BY
|
|||||||
,order_month
|
,order_month
|
||||||
,doc->>'stamp'
|
,doc->>'stamp'
|
||||||
,logid
|
,logid
|
||||||
|
,tag
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
director
|
director
|
||||||
,quota_rep_descr
|
,quota_rep_descr
|
||||||
,to_char(sum(sales),'999,999,999') sales
|
,to_char(sum(sales),'999,999,999') sales
|
||||||
,to_char(sum(sales - scogs),'999,999,999') margin
|
,to_char(sum(sales - scogs),'999,999,999') margin
|
||||||
,to_char(sum(sales_adj),'999,999,999') sales_adj
|
,to_char(sum(sales_adj) FILTER (WHERE tag <> 'Initial Build'),'999,999,999') sales_adj
|
||||||
,to_char(sum(sales_adj - scogs_adj),'999,999,999') margin_adj
|
,to_char(sum(sales_adj - scogs_adj) FILTER (WHERE tag <> 'Initial Build'),'999,999,999') margin_adj
|
||||||
,count(DISTINCT logid) "# of changes"
|
,count(DISTINCT logid) FILTER (WHERE tag <> 'Initial Build') "# of changes"
|
||||||
,COUNT(logid) "# of rows added"
|
,COUNT(logid) FILTER (WHERE tag <> 'Initial Build') "# of rows added"
|
||||||
,(max(stamp))::timestamptz "last edit"
|
,(max(stamp) FILTER (WHERE tag <> 'Initial Build'))::timestamptz "last edit"
|
||||||
FROM
|
FROM
|
||||||
preagg
|
preagg
|
||||||
GROUP BY
|
GROUP BY
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
UPDATE
|
UPDATE
|
||||||
rlarp.osmf_dev
|
rlarp.osmf_dev
|
||||||
SET
|
SET
|
||||||
r_rate = .75
|
r_rate = .7597
|
||||||
WHERE
|
WHERE
|
||||||
r_currency = 'CA';
|
r_currency = 'CA';
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ WHERE
|
|||||||
UPDATE
|
UPDATE
|
||||||
rlarp.osmf_dev
|
rlarp.osmf_dev
|
||||||
SET
|
SET
|
||||||
c_rate = .75
|
c_rate = .7597
|
||||||
WHERE
|
WHERE
|
||||||
c_currency = 'CA';
|
c_currency = 'CA';
|
||||||
|
|
||||||
|
2
index.js
2
index.js
@ -158,7 +158,7 @@ server.get('/list_changes', bodyParser.json(), function(req, res) {
|
|||||||
console.log(new Date().toISOString() + "-------------------------list changes:------------------------------")
|
console.log(new Date().toISOString() + "-------------------------list changes:------------------------------")
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//parse the where clause into the main sql statement
|
//parse the where clause into the main sql statement
|
||||||
sql = sql.replace(new RegExp("replace_user", 'g'), JSON.stringify(req.body.quota_rep_descr))
|
sql = sql.replace(new RegExp("replace_user", 'g'), req.body.quota_rep_descr)
|
||||||
//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)
|
||||||
|
@ -1,40 +1,29 @@
|
|||||||
WITH
|
WITH
|
||||||
list AS materialized (
|
agg as (
|
||||||
SELECT
|
SELECT
|
||||||
l.doc->>'user' "user",
|
ol.doc->>'user' "user"
|
||||||
jsonb_path_query_first(l.doc,'$.scenario.quota_rep_descr')->>0 quota_rep_descr,
|
,quota_rep_descr
|
||||||
to_char((l.doc->>'stamp')::timestamptz,'YYYY-MM-DD HH:MI:SS') "stamp",
|
,ol.doc->>'stamp' stamp
|
||||||
l.doc->>'tag' "tag",
|
,ol.doc->>'tag' tag
|
||||||
l.doc->>'message' "comment",
|
,ol.doc->>'message' "comment"
|
||||||
jsonb_pretty(l.doc) def,
|
,ol.doc
|
||||||
l.id
|
,ol.id
|
||||||
FROM
|
|
||||||
rlarp.osm_log l
|
|
||||||
WHERE
|
|
||||||
l.doc @? '$.scenario.quota_rep_descr ? (@ == replace_user)'
|
|
||||||
)
|
|
||||||
,agg as (
|
|
||||||
SELECT
|
|
||||||
list.user
|
|
||||||
,list.quota_rep_descr
|
|
||||||
,list.stamp
|
|
||||||
,list.tag
|
|
||||||
,list.comment
|
|
||||||
,list.def
|
|
||||||
,list.id
|
|
||||||
,to_char(round(sum(value_usd),2),'$999,999,999D00') sales
|
,to_char(round(sum(value_usd),2),'$999,999,999D00') sales
|
||||||
from
|
from
|
||||||
LIST
|
rlarp.osm_log ol
|
||||||
inner join rlarp.osm_pool on
|
inner join rlarp.osm_pool on
|
||||||
id = logid
|
id = logid
|
||||||
|
WHERE
|
||||||
|
quota_rep_descr = 'replace_user'
|
||||||
|
AND tag <> 'Initial Build'
|
||||||
group BY
|
group BY
|
||||||
list.user
|
ol.doc->>'user'
|
||||||
,list.quota_rep_descr
|
,quota_rep_descr
|
||||||
,list.stamp
|
,ol.doc->>'stamp'
|
||||||
,list.tag
|
,ol.doc->>'tag'
|
||||||
,list.comment
|
,ol.doc->>'comment'
|
||||||
,list.def
|
,ol.doc
|
||||||
,list.id
|
,ol.id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_agg(row_to_json(agg)::jsonb ORDER BY agg.stamp desc) x from agg
|
jsonb_agg(row_to_json(agg)::jsonb ORDER BY agg.stamp desc) x from agg
|
Loading…
Reference in New Issue
Block a user