move files around

This commit is contained in:
Paul Trowbridge 2020-02-19 17:05:27 -05:00
parent 0095e1983c
commit f924da0e4d
25 changed files with 2445 additions and 2437 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +1,52 @@
WITH
pool AS (
SELECT
substr(a.v6part,1,3) "family"
,substr(a.v6part,1,8) mold
,a.v6part part
,COALESCE(m.avmajg,p.awmajg) majg
,COALESCE(m.avming,p.awming) ming
,COALESCE(m.avmajs,p.awmajs) majs
,COALESCE(m.avmins,p.awmins) mins
FROM
lgdat.stka a
LEFT OUTER JOIN lgdat.stkmm m ON
m.avpart = v6part
LEFT OUTER JOIN lgdat.stkmp p ON
p.awpart = a.v6part
WHERE
COALESCE(awgled, avgled) = '1RE'
AND v6stat = 'A'
--and avmajg = '910'
GROUP BY
a.v6part
,COALESCE(m.avmajg,p.awmajg)
,COALESCE(m.avming,p.awming)
,COALESCE(m.avmajs,p.awmajs)
,COALESCE(m.avmins,p.awmins)
)
,llist AS (
SELECT
family
,mold
,min(part) part
,jsonb_agg(majg) majg
,jsonb_agg(ming) ming
,jsonb_agg(majs) majs
,jsonb_agg(mins) mins
FROM
pool
GROUP BY
family
,mold
)
SELECT
family
,mold
,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.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.mins) a(e)) x) mins
FROM
WITH
pool AS (
SELECT
substr(a.v6part,1,3) "family"
,substr(a.v6part,1,8) mold
,a.v6part part
,COALESCE(m.avmajg,p.awmajg) majg
,COALESCE(m.avming,p.awming) ming
,COALESCE(m.avmajs,p.awmajs) majs
,COALESCE(m.avmins,p.awmins) mins
FROM
lgdat.stka a
LEFT OUTER JOIN lgdat.stkmm m ON
m.avpart = v6part
LEFT OUTER JOIN lgdat.stkmp p ON
p.awpart = a.v6part
WHERE
COALESCE(awgled, avgled) = '1RE'
AND v6stat = 'A'
--and avmajg = '910'
GROUP BY
a.v6part
,COALESCE(m.avmajg,p.awmajg)
,COALESCE(m.avming,p.awming)
,COALESCE(m.avmajs,p.awmajs)
,COALESCE(m.avmins,p.awmins)
)
,llist AS (
SELECT
family
,mold
,min(part) part
,jsonb_agg(majg) majg
,jsonb_agg(ming) ming
,jsonb_agg(majs) majs
,jsonb_agg(mins) mins
FROM
pool
GROUP BY
family
,mold
)
SELECT
family
,mold
,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.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.mins) a(e)) x) mins
FROM
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;
with p AS (
SELECT
part
,bill_cust
,ship_cust
,round(fb_val_loc/fb_qty,10) AS price
,orderdate
,row_number() OVER (PARTITION BY part,bill_cust, ship_cust ORDER BY orderdate DESC) rn
FROM
rlarp.osm
WHERE
fs_line = '41010'
AND calc_status <> 'CANCELED'
AND COALESCE(part,'') <> ''
AND fb_qty <> 0
AND orderdate IS NOT NULL
ORDER BY
part
,bill_cust
,ship_cust
,orderdate
)
--SELECT * FROM p WHERE rn = 1
,incr AS (
SELECT
b.plnt
,b."ddord#"
,b."dditm#"
,b."fgbol#"
,b."fgent#"
,b."diinv#"
,b."dilin#"
,b.promo
,b.return_reas
,b.terms
,b.custpo
,b.dhincr
,b.diext
,b.ditdis
,b.dcodat
,b.ddqdat
,b.dcmdat
,b.dhidat
,b.fspr
,b.remit_to
,b.bill_class
,b.bill_cust
,b.bill_rep
,b.bill_terr
,b.ship_class
,b.ship_cust
,b.ship_rep
,b.ship_terr
,b.quota_rep
,b.account
,b.shipgrp
,b.geo
,b.chan
,b.orig_ctry
,b.orig_prov
,b.orig_post
,b.dest_ctry
,b.dest_prov
,b.dest_post
,b.part
,b.ord_gldc
,b.majg
,b.ming
,b.majs
,b.mins
,b.gldc
,b.glec
,b.harm
,b.clss
,b.brand
,b.assc
,b.fs_line
,b.r_currency
,b.r_rate
,b.c_currency
,b.c_rate
,b.ddqtoi
,b.ddqtsi
,b.fgqshp
,b.diqtsh
,0 fb_qty
,0 fb_cst_loc
,0 fb_cst_loc_cur
,0 fb_cst_loc_fut
,b.fb_qty * p.price - b.fb_val_loc fb_val_loc
,0 fb_val_loc_pl
,b.calc_status
,b.flag
,b.orderdate
,b.requestdate
,b.shipdate
,b.adj_orderdate
,b.adj_requestdate
,b.adj_shipdate
,b."version"
,'last price paid' iter
FROM
rlarp.osmfs b
INNER JOIN p ON
p.part = b.part
AND p.bill_cust = b.bill_cust
AND p.ship_cust = b.ship_cust
AND p.rn = 1
WHERE
b.orderdate BETWEEN '2019-03-25' AND '2019-05-31'
OR b.orderdate BETWEEN '2020-03-25' AND '2020-05-31'
)
, ins AS (
INSERT INTO rlarp.osmfs SELECT * FROM incr RETURNING *
)
SELECT fspr, sum(fb_val_loc *r_rate) FROM ins GROUP BY fspr;
BEGIN;
with p AS (
SELECT
part
,bill_cust
,ship_cust
,round(fb_val_loc/fb_qty,10) AS price
,orderdate
,row_number() OVER (PARTITION BY part,bill_cust, ship_cust ORDER BY orderdate DESC) rn
FROM
rlarp.osm
WHERE
fs_line = '41010'
AND calc_status <> 'CANCELED'
AND COALESCE(part,'') <> ''
AND fb_qty <> 0
AND orderdate IS NOT NULL
ORDER BY
part
,bill_cust
,ship_cust
,orderdate
)
--SELECT * FROM p WHERE rn = 1
,incr AS (
SELECT
b.plnt
,b."ddord#"
,b."dditm#"
,b."fgbol#"
,b."fgent#"
,b."diinv#"
,b."dilin#"
,b.promo
,b.return_reas
,b.terms
,b.custpo
,b.dhincr
,b.diext
,b.ditdis
,b.dcodat
,b.ddqdat
,b.dcmdat
,b.dhidat
,b.fspr
,b.remit_to
,b.bill_class
,b.bill_cust
,b.bill_rep
,b.bill_terr
,b.ship_class
,b.ship_cust
,b.ship_rep
,b.ship_terr
,b.quota_rep
,b.account
,b.shipgrp
,b.geo
,b.chan
,b.orig_ctry
,b.orig_prov
,b.orig_post
,b.dest_ctry
,b.dest_prov
,b.dest_post
,b.part
,b.ord_gldc
,b.majg
,b.ming
,b.majs
,b.mins
,b.gldc
,b.glec
,b.harm
,b.clss
,b.brand
,b.assc
,b.fs_line
,b.r_currency
,b.r_rate
,b.c_currency
,b.c_rate
,b.ddqtoi
,b.ddqtsi
,b.fgqshp
,b.diqtsh
,0 fb_qty
,0 fb_cst_loc
,0 fb_cst_loc_cur
,0 fb_cst_loc_fut
,b.fb_qty * p.price - b.fb_val_loc fb_val_loc
,0 fb_val_loc_pl
,b.calc_status
,b.flag
,b.orderdate
,b.requestdate
,b.shipdate
,b.adj_orderdate
,b.adj_requestdate
,b.adj_shipdate
,b."version"
,'last price paid' iter
FROM
rlarp.osmfs b
INNER JOIN p ON
p.part = b.part
AND p.bill_cust = b.bill_cust
AND p.ship_cust = b.ship_cust
AND p.rn = 1
WHERE
b.orderdate BETWEEN '2019-03-25' AND '2019-05-31'
OR b.orderdate BETWEEN '2020-03-25' AND '2020-05-31'
)
, ins AS (
INSERT INTO rlarp.osmfs SELECT * FROM incr RETURNING *
)
SELECT fspr, sum(fb_val_loc *r_rate) FROM ins GROUP BY fspr;
COMMIT;

View File

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

View File

@ -1,29 +1,29 @@
UPDATE
rlarp.osmfs 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
UPDATE
rlarp.osmfs 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.adj_shipdate BETWEEN gld.sdat AND gld.edat

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"
}

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
}