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 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;

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,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

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