Compare commits
193 Commits
c088150ad3
...
d3937fc406
Author | SHA1 | Date | |
---|---|---|---|
d3937fc406 | |||
d541ee16cc | |||
60b57263d0 | |||
745f83e502 | |||
5162839c5d | |||
6f0d8745d2 | |||
d13519c07c | |||
89e4983a03 | |||
3854bed603 | |||
cf6e3b6695 | |||
14ed4a95fe | |||
fee1b9202f | |||
ab7af8d2ed | |||
94ae5e192c | |||
b38150e128 | |||
7e4049d27d | |||
50da4dfa17 | |||
3b3b01bb90 | |||
9db81ace17 | |||
f156d599e5 | |||
409522677e | |||
ab1d8f8778 | |||
7dab34e949 | |||
4c43a79f15 | |||
9f208bc0b7 | |||
a50de52702 | |||
037070ed1e | |||
ce91851d48 | |||
3fae4d50cc | |||
c8cb809e18 | |||
|
6c6452014f | ||
19fc49420d | |||
a328aaeaaf | |||
f7f26b2804 | |||
b487430057 | |||
28ee5dfbb4 | |||
6e4e64b3a4 | |||
07f36612d5 | |||
e4604a16f5 | |||
a12fc36bad | |||
94f925f1d8 | |||
5dc43123c9 | |||
2013609c25 | |||
694d805aaf | |||
59c32d8619 | |||
4acee798d2 | |||
883840d565 | |||
551a4867d6 | |||
1b0f4b9f04 | |||
a0a6a94107 | |||
e4054326d0 | |||
8307b7c8ea | |||
fd855cda72 | |||
c4f3abd733 | |||
6984b039f2 | |||
b9ff9c1493 | |||
c6df2774cb | |||
c0c0a98e1f | |||
d53c7bec0a | |||
3b983140b6 | |||
cf82925eca | |||
98eff757c0 | |||
22542837ac | |||
5b4a61c542 | |||
8a3baf269d | |||
652720ff32 | |||
|
834d52a2a2 | ||
|
3592120b54 | ||
|
ca996adac6 | ||
|
17dc465cdc | ||
|
76edca43dc | ||
|
f5d464677e | ||
|
f57cb5f26a | ||
|
a2a7bee6e0 | ||
|
48b1beb8af | ||
|
c0e348bb2f | ||
|
474b133915 | ||
|
9826b5f810 | ||
|
17265d0b36 | ||
27628f0185 | |||
|
6265a4ff4e | ||
|
f764bc4c31 | ||
|
28214bece7 | ||
|
e3205a94c1 | ||
|
37eb9d519f | ||
|
9539b99301 | ||
|
aca8fa7aeb | ||
|
85db8616e5 | ||
|
1c0e07502d | ||
|
ebc7d90dc5 | ||
|
3540c35629 | ||
|
f34b0d539d | ||
|
e201302953 | ||
|
13d71fff21 | ||
|
d279c4841c | ||
|
3d5cd9b2ff | ||
|
87d5dbceaf | ||
|
77fe829ece | ||
|
28865863bd | ||
|
3492c802b9 | ||
|
6bee5571dc | ||
|
9b030dc191 | ||
|
d5f3c74c6f | ||
|
10d20e050e | ||
|
8838fdbcbc | ||
|
43a194b116 | ||
|
fb1fcabb00 | ||
|
ebc169e34a | ||
|
ffee472954 | ||
|
e05efeb1e2 | ||
|
df02a31000 | ||
|
d5e19bc309 | ||
|
abfa3d0e7c | ||
|
a835ed7b3e | ||
|
03e532857d | ||
|
787cc9452f | ||
|
879319b889 | ||
|
60ace348b8 | ||
|
9584f8026a | ||
|
99c9136580 | ||
|
e030cce8b3 | ||
|
00cf371bc5 | ||
|
df1e2f0e58 | ||
|
8bed8cd399 | ||
|
ab72f94775 | ||
|
5c04f7c913 | ||
|
8f23f43492 | ||
|
fcc95ecb40 | ||
|
e9a0756240 | ||
|
f924da0e4d | ||
|
0095e1983c | ||
|
3983f1c91a | ||
|
ff1304be3c | ||
|
55257733b2 | ||
|
cbc2caa41d | ||
|
69346646bd | ||
|
d3a4a45d53 | ||
|
83039b4a51 | ||
|
54668f22e1 | ||
|
2ec8ec75f0 | ||
|
ff3e18edc7 | ||
|
53ac7f90e2 | ||
|
e7ce48405b | ||
|
c602564cb7 | ||
|
a83708a7ca | ||
|
39a96eb12b | ||
|
07f69a80ae | ||
|
7d50a37e29 | ||
|
7635380ccc | ||
|
6774a2fdff | ||
|
db13f3d38c | ||
|
33041761c6 | ||
|
18558674c0 | ||
|
6485613ab7 | ||
|
b881fae5b4 | ||
|
1b8c101429 | ||
|
6e8f026770 | ||
|
8aeecc845b | ||
|
8d1cd1ade6 | ||
|
acca526dca | ||
|
07bd753a8e | ||
|
0c394b2557 | ||
|
b3122a50bb | ||
|
a4cf5b7607 | ||
|
9793596d27 | ||
|
79ec4739c1 | ||
|
a4d34ec83a | ||
|
e49c051383 | ||
|
f83746b892 | ||
|
fb7fdc7959 | ||
|
5e4690a1f4 | ||
|
ef914f3d5e | ||
|
994b076321 | ||
|
610c78f36f | ||
|
04276a89cb | ||
|
21cb531e56 | ||
|
eddece49e1 | ||
|
040ba4caf6 | ||
|
d557fe9cc3 | ||
|
061387c1dc | ||
|
ba28bb9f15 | ||
|
73ff0da13b | ||
|
9ed969d9ef | ||
|
270409895c | ||
|
ae9bba67bd | ||
|
e7904d5040 | ||
|
f111c8818f | ||
|
3a8dd84aec | ||
|
63e3133c9d | ||
|
f1dede7c2e | ||
|
6e21464e65 | ||
|
cd67f316fc | ||
|
f49e514a7f |
8
.env.sample
Normal file
8
.env.sample
Normal file
@ -0,0 +1,8 @@
|
||||
user=api
|
||||
password=pw
|
||||
host=usmidlnx01
|
||||
port=5030
|
||||
database=ubm
|
||||
ssl=enable
|
||||
wd=/mnt/c/Users/PTrowbridge/forecast_api/
|
||||
nodeport=8080
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,3 +8,5 @@ stat.html
|
||||
changes.html
|
||||
*.pem
|
||||
*.log
|
||||
/.dbeaver
|
||||
.project
|
||||
|
BIN
Master Template 1.6.xlsm
Normal file
BIN
Master Template 1.6.xlsm
Normal file
Binary file not shown.
54
README.md
Normal file
54
README.md
Normal file
@ -0,0 +1,54 @@
|
||||
Special concepts
|
||||
* relationships betwen dates (order, request, ship) and apply that mix to a new month
|
||||
* apply a base mix of promo codes and terms codes to a new month of forecast where there is no existing baseline to pull from
|
||||
* effects of building baselines off of original, or all changes so far
|
||||
* pricing and units
|
||||
|
||||
Slowness Options
|
||||
* 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
|
||||
* 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
|
||||
|
||||
Review
|
||||
* continuous update with actuals
|
||||
* next years sales is going to change everyday as new things happen with open orders
|
||||
* need to be populating shipping season instead of leaving null
|
||||
* need to do with past-due's -> when do they ship?
|
||||
* snapshot several years of history into the forecast so there is no need to bring in actuals
|
||||
* going to have to rebuild the forecast when actuals change
|
||||
|
||||
CI
|
||||
* snapshot pool
|
||||
* adjust 2021 orders
|
||||
* integrate with 2020 open to get to 2021 sales (osm_stack)
|
||||
* show 2021 forecasted order as forecast
|
||||
* show 2021 forecasted sales (need to update ship season so it is not null)
|
||||
|
||||
Walk Issues
|
||||
* canceled orders
|
||||
* changed orders
|
||||
* short ships
|
||||
* exchange rates
|
||||
|
||||
Things to Demo
|
||||
* product swap out
|
||||
* pivot re-org
|
||||
* don't use filters
|
||||
* assumes all changes target USD
|
2
build/act_to_fcst/exec_actual_to_forecast.sql
Normal file
2
build/act_to_fcst/exec_actual_to_forecast.sql
Normal file
@ -0,0 +1,2 @@
|
||||
DELETE FROM rlarp.osmf_dev WHERE dsm = 'PW';
|
||||
INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev;
|
163
build/act_to_fcst/merge_actuals_pool.sql
Normal file
163
build/act_to_fcst/merge_actuals_pool.sql
Normal file
@ -0,0 +1,163 @@
|
||||
BEGIN;
|
||||
|
||||
DELETE FROM rlarp.osm_pool WHERE quota_rep_descr = 'PW';
|
||||
|
||||
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
|
||||
('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)
|
||||
)
|
||||
----------------------------------------------------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.osmfs_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
|
||||
dsm = 'PW';
|
||||
|
||||
/*
|
||||
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;
|
43
build/act_to_fcst/snap_cost_current.sql
Normal file
43
build/act_to_fcst/snap_cost_current.sql
Normal file
@ -0,0 +1,43 @@
|
||||
BEGIN;
|
||||
|
||||
WITH
|
||||
plist AS (
|
||||
SELECT DISTINCT
|
||||
part
|
||||
,plnt
|
||||
FROM
|
||||
rlarp.osmfs_dev
|
||||
-----prevent a list of fake parts
|
||||
INNER JOIN lgdat.stka ON
|
||||
v6part = part
|
||||
AND v6plnt = plnt
|
||||
)
|
||||
,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;
|
||||
--AND version = 'b21';
|
||||
|
||||
commit;
|
209
build/act_to_fcst/snap_customer.sql
Normal file
209
build/act_to_fcst/snap_customer.sql
Normal file
@ -0,0 +1,209 @@
|
||||
----------------------------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,
|
||||
COALESCE(MING,'') MING,
|
||||
BILL_CUST,
|
||||
SHIP_CUST,
|
||||
------------quota rep column--------------
|
||||
RTRIM(
|
||||
--retail items go to currep, or if null go to 90005
|
||||
CASE WHEN S.GLEC IN ('1RE','1CU') THEN
|
||||
CASE WHEN BVCTRY = 'CAN' THEN
|
||||
--Rachel Bowman
|
||||
'50300'
|
||||
ELSE
|
||||
--select customers go to select reps
|
||||
CASE ACCOUNT
|
||||
------Alecia Latini-------------------------------
|
||||
WHEN 'DO IT BEST' THEN '90006'
|
||||
WHEN 'ACE HARDWARE' THEN '90006'
|
||||
WHEN 'ALDI' THEN '90006'
|
||||
WHEN 'AMAZON.COM' THEN '90006'
|
||||
WHEN 'GARDEN RIDGE CORP' THEN '90006' --AKA "At Home"
|
||||
WHEN 'TRUE VALUE' THEN '90006'
|
||||
WHEN 'WAYFAIR' THEN '90006'
|
||||
WHEN 'GRIFFIN' THEN '90006'
|
||||
WHEN 'WAL-MART' THEN '90006'
|
||||
------Tony Landino--------------------------------
|
||||
WHEN 'THE HOME DEPOT' THEN '50802'
|
||||
WHEN 'FRED MEYER' THEN '50802'
|
||||
WHEN 'MENARDS' THEN '50802'
|
||||
WHEN 'KROGER' THEN '50802'
|
||||
WHEN 'OCEAN STATE JOBBERS' THEN '50802'
|
||||
WHEN 'AURORA WHOLESALE' THEN '50802'
|
||||
WHEN 'LEON KORRAL' THEN '50802'
|
||||
--all other retail goes to Doran Marable-----------
|
||||
ELSE '50200'
|
||||
END
|
||||
END
|
||||
--minor group b52 goes to dedicated rep
|
||||
ELSE
|
||||
CASE WHEN MING = 'B52' THEN
|
||||
'PW'
|
||||
--gdir, ndir go to bill-to rep
|
||||
ELSE
|
||||
CASE WHEN BILL_CLASS IN ('GDIR','NDIR') THEN
|
||||
BILL_REP
|
||||
ELSE
|
||||
SHIP_REP
|
||||
END
|
||||
END
|
||||
END
|
||||
) QUOTA_REP
|
||||
FROM
|
||||
RLARP.OSMFS_DEV S
|
||||
LEFT OUTER JOIN LGDAT.CUST ON
|
||||
BVCUST = BILL_CUST
|
||||
WHERE
|
||||
COALESCE(GLEC,'') IS NOT NULL
|
||||
) CR
|
||||
WHERE
|
||||
CR.VERSION = S.VERSION
|
||||
AND CR.GLEC = COALESCE(S.GLEC,'')
|
||||
AND CR.MING = COALESCE(S.MING,'')
|
||||
AND CR.BILL_CUST = S.BILL_CUST
|
||||
AND CR.SHIP_CUST = S.SHIP_CUST
|
||||
AND COALESCE(S.DSM,'') <> CR.QUOTA_REP;
|
30
build/act_to_fcst/snap_fspr.sql
Normal file
30
build/act_to_fcst/snap_fspr.sql
Normal file
@ -0,0 +1,30 @@
|
||||
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;
|
9
build/act_to_fcst/snap_fx.sql
Normal file
9
build/act_to_fcst/snap_fx.sql
Normal file
@ -0,0 +1,9 @@
|
||||
------------update fx rates-----------------------------------------------------------------
|
||||
UPDATE rlarp.osmf_dev SET r_rate = .7518 WHERE r_currency = 'CA' AND version = 'b21';
|
||||
UPDATE rlarp.osmf_dev SET r_rate = 1.0000 WHERE r_currency = 'US' AND version = 'b21';
|
||||
UPDATE rlarp.osmf_dev SET c_rate = .7518 WHERE c_currency = 'CA' AND version = 'b21';
|
||||
UPDATE rlarp.osmf_dev SET c_rate = 1.0000 WHERE c_currency = 'US' AND version = 'b21';
|
||||
UPDATE rlarp.osm_pool SET r_rate = .7518 WHERE r_currency = 'CA' AND version = 'b21';
|
||||
UPDATE rlarp.osm_pool SET value_usd = value_loc * r_rate WHERE r_currency = 'CA' AND version = 'b21';
|
||||
UPDATE rlarp.osm_pool SET c_rate = .7518 WHERE c_currency = 'CA' AND version = 'b21';
|
||||
UPDATE rlarp.osm_pool SET cost_usd = cost_loc * c_rate WHERE c_currency = 'CA' AND version = 'b21';
|
27
build/act_to_fcst/snap_itemm.sql
Normal file
27
build/act_to_fcst/snap_itemm.sql
Normal file
@ -0,0 +1,27 @@
|
||||
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
|
299
build/act_to_fcst/stage_act_to_forecast.sql
Normal file
299
build/act_to_fcst/stage_act_to_forecast.sql
Normal file
@ -0,0 +1,299 @@
|
||||
--\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
|
||||
,o.c_currency
|
||||
,o.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 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.fspr BETWEEN '2001' AND '2012'
|
||||
)
|
||||
AND fs_line = '41010'
|
||||
AND calc_status <> 'CANCELED'
|
||||
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
||||
AND version = 'ACTUALS'
|
||||
AND dsm = 'PW'
|
||||
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
|
||||
)
|
||||
,incr AS (
|
||||
SELECT
|
||||
o."ddord#"
|
||||
,o."dditm#"
|
||||
,o."fgbol#"
|
||||
,o."fgent#"
|
||||
,o."diinv#"
|
||||
,o."dilin#"
|
||||
,o.quoten
|
||||
,o.quotel
|
||||
,o.dcodat + interval '1 year' --incremented
|
||||
,o.ddqdat + interval '1 year' --incremented
|
||||
,o.dcmdat
|
||||
,o.fesdat
|
||||
,o.dhidat + interval '1 year' --incremented
|
||||
,o.fesind
|
||||
,o.dhpost
|
||||
,gld.fspr --incremented
|
||||
,o.ddqtoi
|
||||
,o.ddqtsi
|
||||
,o.fgqshp
|
||||
,o.diqtsh
|
||||
,o.diext
|
||||
,o.ditdis
|
||||
,o.discj
|
||||
,o.dhincr
|
||||
,o.plnt
|
||||
,o.promo
|
||||
,o.return_reas
|
||||
,o.terms
|
||||
,o.custpo
|
||||
,o.remit_to
|
||||
,o.bill_class
|
||||
,o.bill_cust
|
||||
,o.bill_rep
|
||||
,o.bill_terr
|
||||
,o.ship_class
|
||||
,o.ship_cust
|
||||
,o.ship_rep
|
||||
,o.ship_terr
|
||||
,o.dsm
|
||||
,o.account
|
||||
,o.shipgrp
|
||||
,o.geo
|
||||
,o.chan
|
||||
,o.chansub
|
||||
,o.orig_ctry
|
||||
,o.orig_prov
|
||||
,o.orig_post
|
||||
,o.bill_ctry
|
||||
,o.bill_prov
|
||||
,o.bill_post
|
||||
,o.dest_ctry
|
||||
,o.dest_prov
|
||||
,o.dest_post
|
||||
,o.part
|
||||
,o.styc
|
||||
,o.colc
|
||||
,o.colgrp
|
||||
,o.coltier
|
||||
,o.colstat
|
||||
,o.sizc
|
||||
,o.pckg
|
||||
,o.kit
|
||||
,o.brnd
|
||||
,o.majg
|
||||
,o.ming
|
||||
,o.majs
|
||||
,o.mins
|
||||
,o.gldco
|
||||
,o.gldc
|
||||
,o.glec
|
||||
,o.harm
|
||||
,o.clss
|
||||
,o.brand
|
||||
,o.assc
|
||||
,o.ddunit
|
||||
,o.unti
|
||||
,o.lbs
|
||||
,o.plt
|
||||
,o.plcd
|
||||
,o.fs_line
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,o.fb_qty
|
||||
,o.fb_val_loc
|
||||
,o.fb_val_loc_dis
|
||||
,o.fb_val_loc_qt
|
||||
,o.fb_val_loc_pl
|
||||
,o.fb_val_loc_tar
|
||||
,o.fb_cst_loc
|
||||
,o.fb_cst_loc_cur
|
||||
,o.fb_cst_loc_fut
|
||||
,o.calc_status
|
||||
,o.flag
|
||||
,o.odate + interval '1 year' --incremented
|
||||
,o.oseas + 1 --incremented
|
||||
,o.rdate + interval '1 year' --incremented
|
||||
,o.rseas + 1 --incremented
|
||||
,o.sdate + interval '1 year' --incremented
|
||||
,o.sseas + 1 --incremented
|
||||
,'b21' "version"
|
||||
,'copy' iter
|
||||
FROM
|
||||
baseline o
|
||||
LEFT OUTER JOIN gld ON
|
||||
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
|
||||
)
|
||||
INSERT INTO rlarp.osmfs_dev
|
||||
SELECT * FROM incr
|
||||
UNION ALL
|
||||
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;
|
586
build/build_forecast.sql
Normal file
586
build/build_forecast.sql
Normal file
@ -0,0 +1,586 @@
|
||||
--\timing
|
||||
truncate table rlarp.osmf_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
|
||||
,o.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
|
||||
,o.ship_cust
|
||||
,null::text ship_rep
|
||||
,null::text ship_terr
|
||||
,o.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
|
||||
,o.c_currency
|
||||
,o.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 BETWEEN '2020-06-01' AND '2021-04-11'
|
||||
--...or any open orders currently booked before cutoff....
|
||||
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2021-04-11')
|
||||
--...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
|
||||
o.fspr
|
||||
,o.plnt
|
||||
,COALESCE(o.promo,'')
|
||||
,o.terms
|
||||
,o.bill_cust
|
||||
,o.ship_cust
|
||||
,o.dsm
|
||||
,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
|
||||
UNION ALL
|
||||
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 + interval '1 year' dcodat
|
||||
,o.rdate + interval '1 year' ddqdat
|
||||
,null::date dcmdat
|
||||
,null::date fesdat
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' 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
|
||||
,o.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
|
||||
,o.c_currency
|
||||
,o.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 + interval '1 year' odate
|
||||
,o.oseas + 1 rseas
|
||||
,o.rdate + interval '1 year' rdate
|
||||
,o.rseas + 1 rseas
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
||||
,ss.ssyr sseas
|
||||
,'actuals' "version"
|
||||
,'actuals_plug' iter
|
||||
FROM
|
||||
rlarp.osm_dev o
|
||||
LEFT OUTER JOIN gld ON
|
||||
gld.fspr = o.fspr
|
||||
LEFT OUTER JOIN gld ss ON
|
||||
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
|
||||
WHERE
|
||||
o.odate BETWEEN '2020-04-12' AND '2020-05-31'
|
||||
AND fs_line = '41010'
|
||||
AND calc_status <> 'CANCELED'
|
||||
------exclude actuals for now and use forecast to get the plug for the rest of the year
|
||||
AND version = 'ACTUALS'
|
||||
GROUP BY
|
||||
o.fspr
|
||||
,plnt
|
||||
,COALESCE(o.promo,'')
|
||||
,o.terms
|
||||
,o.bill_cust
|
||||
,o.ship_cust
|
||||
,o.dsm
|
||||
,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
|
||||
UNION ALL
|
||||
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 + interval '1 year' dcodat
|
||||
,o.rdate + interval '1 year' ddqdat
|
||||
,null::date dcmdat
|
||||
,null::date fesdat
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' 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
|
||||
,null::numeric r_rate
|
||||
,o.c_currency
|
||||
,null::numeric 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 odate
|
||||
,o.oseas rseas
|
||||
,o.rdate rdate
|
||||
,o.rseas rseas
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||
,ss.ssyr sseas
|
||||
,'actuals' "version"
|
||||
,'forecast_plug' iter
|
||||
FROM
|
||||
rlarp.osmp_dev o
|
||||
LEFT OUTER JOIN gld ON
|
||||
gld.fspr = o.fspr
|
||||
LEFT OUTER JOIN gld ss ON
|
||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||
WHERE
|
||||
false
|
||||
--o.odate BETWEEN '2020-03-01' AND '2020-05-31'
|
||||
--AND fs_line = '41010'
|
||||
--AND calc_status <> 'CANCELED'
|
||||
------dont pull forecast for a baseline this time around--
|
||||
GROUP BY
|
||||
o.fspr
|
||||
,plnt
|
||||
,COALESCE(o.promo,'')
|
||||
,o.terms
|
||||
,o.bill_cust
|
||||
,ship_cust
|
||||
,o.part
|
||||
,o.fs_line
|
||||
,o.r_currency
|
||||
,o.c_currency
|
||||
,o.calc_status
|
||||
,o.flag
|
||||
,o.odate
|
||||
,o.oseas
|
||||
,o.rdate
|
||||
,o.rseas
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||
,ss.ssyr
|
||||
)
|
||||
,incr AS (
|
||||
SELECT
|
||||
o."ddord#"
|
||||
,o."dditm#"
|
||||
,o."fgbol#"
|
||||
,o."fgent#"
|
||||
,o."diinv#"
|
||||
,o."dilin#"
|
||||
,o.quoten
|
||||
,o.quotel
|
||||
,o.dcodat + interval '1 year' --incremented
|
||||
,o.ddqdat + interval '1 year' --incremented
|
||||
,o.dcmdat
|
||||
,o.fesdat
|
||||
,o.dhidat + interval '1 year' --incremented
|
||||
,o.fesind
|
||||
,o.dhpost
|
||||
,gld.fspr --incremented
|
||||
,o.ddqtoi
|
||||
,o.ddqtsi
|
||||
,o.fgqshp
|
||||
,o.diqtsh
|
||||
,o.diext
|
||||
,o.ditdis
|
||||
,o.discj
|
||||
,o.dhincr
|
||||
,o.plnt
|
||||
,o.promo
|
||||
,o.return_reas
|
||||
,o.terms
|
||||
,o.custpo
|
||||
,o.remit_to
|
||||
,o.bill_class
|
||||
,o.bill_cust
|
||||
,o.bill_rep
|
||||
,o.bill_terr
|
||||
,o.ship_class
|
||||
,o.ship_cust
|
||||
,o.ship_rep
|
||||
,o.ship_terr
|
||||
,o.dsm
|
||||
,o.account
|
||||
,o.shipgrp
|
||||
,o.geo
|
||||
,o.chan
|
||||
,o.chansub
|
||||
,o.orig_ctry
|
||||
,o.orig_prov
|
||||
,o.orig_post
|
||||
,o.bill_ctry
|
||||
,o.bill_prov
|
||||
,o.bill_post
|
||||
,o.dest_ctry
|
||||
,o.dest_prov
|
||||
,o.dest_post
|
||||
,o.part
|
||||
,o.styc
|
||||
,o.colc
|
||||
,o.colgrp
|
||||
,o.coltier
|
||||
,o.colstat
|
||||
,o.sizc
|
||||
,o.pckg
|
||||
,o.kit
|
||||
,o.brnd
|
||||
,o.majg
|
||||
,o.ming
|
||||
,o.majs
|
||||
,o.mins
|
||||
,o.gldco
|
||||
,o.gldc
|
||||
,o.glec
|
||||
,o.harm
|
||||
,o.clss
|
||||
,o.brand
|
||||
,o.assc
|
||||
,o.ddunit
|
||||
,o.unti
|
||||
,o.lbs
|
||||
,o.plt
|
||||
,o.plcd
|
||||
,o.fs_line
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,o.fb_qty
|
||||
,o.fb_val_loc
|
||||
,o.fb_val_loc_dis
|
||||
,o.fb_val_loc_qt
|
||||
,o.fb_val_loc_pl
|
||||
,o.fb_val_loc_tar
|
||||
,o.fb_cst_loc
|
||||
,o.fb_cst_loc_cur
|
||||
,o.fb_cst_loc_fut
|
||||
,o.calc_status
|
||||
,o.flag
|
||||
,o.odate + interval '1 year' --incremented
|
||||
,o.oseas + 1 --incremented
|
||||
,o.rdate + interval '1 year' --incremented
|
||||
,o.rseas + 1 --incremented
|
||||
,o.sdate + interval '1 year' --incremented
|
||||
,o.sseas + 1 --incremented
|
||||
,'b22' "version"
|
||||
,'copy' iter
|
||||
FROM
|
||||
baseline o
|
||||
LEFT OUTER JOIN gld ON
|
||||
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
|
||||
WHERE
|
||||
o.odate + interval '1 year' >= '2021-06-01'
|
||||
)
|
||||
INSERT INTO rlarp.osmf_dev
|
||||
SELECT * FROM incr
|
||||
UNION ALL
|
||||
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;
|
183
build/build_pool.sql
Normal file
183
build/build_pool.sql
Normal file
@ -0,0 +1,183 @@
|
||||
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;
|
22
build/check_osmf_match.sql
Normal file
22
build/check_osmf_match.sql
Normal file
@ -0,0 +1,22 @@
|
||||
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
|
||||
|
22
build/check_osmf_match_sales.sql
Normal file
22
build/check_osmf_match_sales.sql
Normal file
@ -0,0 +1,22 @@
|
||||
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
|
||||
|
428
build/convert_pool.sql
Normal file
428
build/convert_pool.sql
Normal file
@ -0,0 +1,428 @@
|
||||
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;
|
435
build/convert_pool_all.sql
Normal file
435
build/convert_pool_all.sql
Normal file
@ -0,0 +1,435 @@
|
||||
CREATE OR REPLACE PROCEDURE rlarp.convert_pool_all()
|
||||
LANGUAGE plpgsql AS
|
||||
$func$
|
||||
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;
|
||||
|
||||
-------need to set item master values before other things-----------
|
||||
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;
|
||||
|
||||
|
||||
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,
|
||||
COALESCE(MING,'') 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
|
||||
COALESCE(GLEC,'') IS NOT NULL
|
||||
) CR
|
||||
WHERE
|
||||
CR.VERSION = S.VERSION
|
||||
AND CR.GLEC = COALESCE(S.GLEC,'')
|
||||
AND CR.MING = COALESCE(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;
|
||||
|
||||
--avoid setting fx as that should have been done up front to osmf
|
||||
--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';
|
||||
|
||||
--DELETE FROM rlarp.osmf_dev WHERE iter IN ('adj price','adj volume');
|
||||
|
||||
--INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev;
|
||||
|
||||
COMMIT;
|
||||
END
|
||||
$func$;
|
||||
|
||||
GRANT ALL ON PROCEDURE rlarp.convert_pool_all() TO PUBLIC;
|
33
build/edit_xover.sql
Normal file
33
build/edit_xover.sql
Normal file
@ -0,0 +1,33 @@
|
||||
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
|
3
build/merge_actuals_exec.sql
Normal file
3
build/merge_actuals_exec.sql
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
DELETE FROM rlarp.osmf_dev WHERE odate < '2020-06-01';
|
||||
INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2020-06-01';
|
164
build/merge_actuals_pool.sql
Normal file
164
build/merge_actuals_pool.sql
Normal file
@ -0,0 +1,164 @@
|
||||
BEGIN;
|
||||
|
||||
DELETE FROM rlarp.osm_pool WHERE order_date < '2020-06-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 < '2020-06-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;
|
187
build/merge_actuals_prep.sql
Normal file
187
build/merge_actuals_prep.sql
Normal file
@ -0,0 +1,187 @@
|
||||
--\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('2019-06-01','2020-06-01')
|
||||
--...or any open orders currently booked before cutoff....
|
||||
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-06-01')
|
||||
--...or anything that shipped in that period
|
||||
OR o.fspr BETWEEN '2001' AND '2012'
|
||||
)
|
||||
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;
|
111
build/move_sales/account_seg_basis.sql
Normal file
111
build/move_sales/account_seg_basis.sql
Normal file
@ -0,0 +1,111 @@
|
||||
WITH
|
||||
targ AS (
|
||||
SELECT * FROM (VALUES
|
||||
('Pierre','Nursery','HYDROFARM',267888.16),
|
||||
('Pierre','Nursery','ALTMAN PLANTS',71626.22),
|
||||
('Pierre','Nursery','RS GROWERS SUPPLY',17154.0599999999),
|
||||
('Pierre','Nursery','MID-AMERICAN GROWERS',51663.75),
|
||||
('Pierre','Nursery','KAWAHARA NURSERY',48859.2),
|
||||
('Baggetta','Nursery','PACIFIC NURSERY POTS',194412.359999999),
|
||||
('Baggetta','Nursery','FARRAND',171375.300000001),
|
||||
('Baggetta','Nursery','ALPHA FOLIAGE',59200.45),
|
||||
('Baggetta','Nursery','HOLMBERG FARMS INC',52911.6),
|
||||
('Baggetta','Nursery','MATSUDAS BY GREEN ACRES LLC',46723.47),
|
||||
('Baggetta','Nursery','GREENLEAF NURSERY CO',24829.2),
|
||||
('Baggetta','Nursery','GREENHOUSE MEGASTORE',22552.0399999999),
|
||||
('Baggetta','Nursery','HICKORY HILL NURSERY',11072.7),
|
||||
('Baggetta','Nursery','BRANTLEY NURSERIES',9762.47999999998),
|
||||
('Baggetta','Nursery','DALLAS JOHNSON GREENHOUSE',8229.6),
|
||||
('Baggetta','Nursery','BAMA GREEN',1165.5),
|
||||
('Vander Deen','Greenhouse','HJS WHOLESALE LTD',310027.34),
|
||||
('Vander Deen','Greenhouse','DEGOEYS NURSERY FLOWERS',26858.558706),
|
||||
('Vander Deen','Greenhouse','DEVRY GREENHOUSES',10713.15),
|
||||
('Vander Deen','Greenhouse','BIOFLORAL INC',9192.59000000001),
|
||||
('Baggetta','Greenhouse','COSTA',600234.409999999),
|
||||
('Baggetta','Greenhouse','SPARETIME SUPPLY',37966.8499999999),
|
||||
('Baggetta','Greenhouse','ALPHA FOLIAGE',32183.66),
|
||||
('Baggetta','Greenhouse','CASSCO',24248.74)
|
||||
) x(director,glec,account,amount)
|
||||
)
|
||||
,sdate AS (
|
||||
SELECT
|
||||
targ.director
|
||||
,targ.glec
|
||||
,targ.account
|
||||
,targ.amount
|
||||
,p.order_season
|
||||
,p.order_date
|
||||
,p.ship_date
|
||||
,p.ship_season
|
||||
,p.part
|
||||
,sum(p.value_usd) value_usd
|
||||
FROM
|
||||
rlarp.osm_pool p
|
||||
INNER JOIN targ ON
|
||||
p.billto_group = targ.account
|
||||
AND p.segm = targ.glec
|
||||
AND p.director = targ.director
|
||||
WHERE
|
||||
--order_season = 2021
|
||||
ship_season = 2021
|
||||
GROUP BY
|
||||
targ.director
|
||||
,targ.glec
|
||||
,targ.account
|
||||
,targ.amount
|
||||
,p.order_season
|
||||
,p.order_date
|
||||
,p.ship_date
|
||||
,p.ship_season
|
||||
,p.part
|
||||
)
|
||||
,rev AS (
|
||||
SELECT
|
||||
director
|
||||
,glec
|
||||
,account
|
||||
,amount
|
||||
,order_season
|
||||
,order_date
|
||||
,part
|
||||
,ship_date
|
||||
,ship_season
|
||||
,(ship_date + INTERVAL '1 year')::date rev_date
|
||||
,gld.ssyr
|
||||
,gld.fspr
|
||||
,value_usd
|
||||
,sum(value_usd) OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC, part) agg
|
||||
,row_number() OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC) rn
|
||||
,CASE WHEN sum(value_usd) OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC, part) >= amount THEN true ELSE false END flag
|
||||
FROM
|
||||
sdate
|
||||
LEFT OUTER JOIN rlarp.gld gld ON
|
||||
gld.drange @> (ship_date + INTERVAL '1 year')::date
|
||||
ORDER BY
|
||||
director
|
||||
,glec
|
||||
,account
|
||||
,order_season
|
||||
,amount
|
||||
,ship_date DESC
|
||||
)
|
||||
,rnk AS (
|
||||
SELECT
|
||||
director,glec ,account
|
||||
,min(rn) FILTER (WHERE flag = true) mflag
|
||||
FROM
|
||||
rev
|
||||
GROUP BY
|
||||
director,glec ,account ,account
|
||||
)
|
||||
,rejoin AS (
|
||||
SELECT
|
||||
rev.*
|
||||
,rnk.mflag
|
||||
,account || ' - '||to_char(amount,'FM999,999') goal
|
||||
,rev.rn <= rnk.mflag AS include
|
||||
FROM
|
||||
rnk
|
||||
NATURAL JOIN rev
|
||||
)
|
||||
SELECT * FROM rejoin
|
260
build/move_sales/account_seg_basis_exec.sql
Normal file
260
build/move_sales/account_seg_basis_exec.sql
Normal file
@ -0,0 +1,260 @@
|
||||
WITH
|
||||
targ AS (
|
||||
SELECT * FROM (VALUES
|
||||
('Pierre','Nursery','HYDROFARM',267888.16),
|
||||
('Pierre','Nursery','ALTMAN PLANTS',71626.22),
|
||||
('Pierre','Nursery','RS GROWERS SUPPLY',17154.0599999999),
|
||||
('Pierre','Nursery','MID-AMERICAN GROWERS',51663.75),
|
||||
('Pierre','Nursery','KAWAHARA NURSERY',48859.2),
|
||||
('Baggetta','Nursery','PACIFIC NURSERY POTS',194412.359999999),
|
||||
('Baggetta','Nursery','FARRAND',171375.300000001),
|
||||
('Baggetta','Nursery','ALPHA FOLIAGE',59200.45),
|
||||
('Baggetta','Nursery','HOLMBERG FARMS INC',52911.6),
|
||||
('Baggetta','Nursery','MATSUDAS BY GREEN ACRES LLC',46723.47),
|
||||
('Baggetta','Nursery','GREENLEAF NURSERY CO',24829.2),
|
||||
('Baggetta','Nursery','GREENHOUSE MEGASTORE',22552.0399999999),
|
||||
('Baggetta','Nursery','HICKORY HILL NURSERY',11072.7),
|
||||
('Baggetta','Nursery','BRANTLEY NURSERIES',9762.47999999998),
|
||||
('Baggetta','Nursery','DALLAS JOHNSON GREENHOUSE',8229.6),
|
||||
('Baggetta','Nursery','BAMA GREEN',1165.5),
|
||||
('Vander Deen','Greenhouse','HJS WHOLESALE LTD',310027.34),
|
||||
('Vander Deen','Greenhouse','DEGOEYS NURSERY FLOWERS',26858.558706),
|
||||
('Vander Deen','Greenhouse','DEVRY GREENHOUSES',10713.15),
|
||||
('Vander Deen','Greenhouse','BIOFLORAL INC',9192.59000000001),
|
||||
('Baggetta','Greenhouse','COSTA',600234.409999999),
|
||||
('Baggetta','Greenhouse','SPARETIME SUPPLY',37966.8499999999),
|
||||
('Baggetta','Greenhouse','ALPHA FOLIAGE',32183.66),
|
||||
('Baggetta','Greenhouse','CASSCO',24248.74)
|
||||
) x(director,glec,account,amount)
|
||||
)
|
||||
,sdate AS (
|
||||
SELECT
|
||||
targ.director
|
||||
,targ.glec
|
||||
,targ.account
|
||||
,targ.amount
|
||||
,p.order_season
|
||||
,p.order_date
|
||||
,p.ship_date
|
||||
,p.ship_season
|
||||
,p.part
|
||||
,sum(p.value_usd) value_usd
|
||||
FROM
|
||||
rlarp.osm_pool p
|
||||
INNER JOIN targ ON
|
||||
p.billto_group = targ.account
|
||||
AND p.segm = targ.glec
|
||||
AND p.director = targ.director
|
||||
WHERE
|
||||
--order_season = 2021
|
||||
ship_season = 2021
|
||||
GROUP BY
|
||||
targ.director
|
||||
,targ.glec
|
||||
,targ.account
|
||||
,targ.amount
|
||||
,p.order_season
|
||||
,p.order_date
|
||||
,p.ship_date
|
||||
,p.ship_season
|
||||
,p.part
|
||||
)
|
||||
,rev AS (
|
||||
SELECT
|
||||
director
|
||||
,glec
|
||||
,account
|
||||
,amount
|
||||
,order_season
|
||||
,order_date
|
||||
,part
|
||||
,ship_date
|
||||
,ship_season
|
||||
,(ship_date + INTERVAL '1 year')::date rev_date
|
||||
,gld.ssyr
|
||||
,gld.fspr
|
||||
,value_usd
|
||||
,sum(value_usd) OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC, part) agg
|
||||
,row_number() OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC) rn
|
||||
,CASE WHEN sum(value_usd) OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC, part) >= amount THEN true ELSE false END flag
|
||||
FROM
|
||||
sdate
|
||||
LEFT OUTER JOIN rlarp.gld gld ON
|
||||
gld.drange @> (ship_date + INTERVAL '1 year')::date
|
||||
ORDER BY
|
||||
director
|
||||
,glec
|
||||
,account
|
||||
,order_season
|
||||
,amount
|
||||
,ship_date DESC
|
||||
)
|
||||
,rnk AS (
|
||||
SELECT
|
||||
director,glec ,account
|
||||
,min(rn) FILTER (WHERE flag = true) mflag
|
||||
FROM
|
||||
rev
|
||||
GROUP BY
|
||||
director,glec ,account ,account
|
||||
)
|
||||
,rejoin AS (
|
||||
SELECT
|
||||
rev.*
|
||||
,rnk.mflag
|
||||
,account || ' - '||to_char(amount,'FM999,999') goal
|
||||
,rev.rn <= rnk.mflag AS include
|
||||
FROM
|
||||
rnk
|
||||
NATURAL JOIN rev
|
||||
)
|
||||
--SELECT * FROM rejoin
|
||||
,logl AS (
|
||||
INSERT INTO
|
||||
rlarp.osm_log(doc)
|
||||
SELECT
|
||||
jsonb_build_object(
|
||||
'stamp',current_timestamp
|
||||
,'user','Trowbridge, Paul'
|
||||
,'source','script'
|
||||
,'tag','smooth sales'
|
||||
,'message','need to carry more orders to reflect what happened in 2020'
|
||||
,'type','smooth sales'
|
||||
,'version','b21'
|
||||
) doc RETURNING *
|
||||
)
|
||||
,remove 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
|
||||
,p.part
|
||||
,p.part_descr
|
||||
,p.part_group
|
||||
,p.branding
|
||||
,p.majg_descr
|
||||
,p.ming_descr
|
||||
,p.majs_descr
|
||||
,p.mins_descr
|
||||
,p.segm
|
||||
,p.substance
|
||||
,p.fs_line
|
||||
,p.r_currency
|
||||
,p.r_rate
|
||||
,p.c_currency
|
||||
,p.c_rate
|
||||
,-p.units units
|
||||
,-p.value_loc value_loc
|
||||
,-p.value_usd value_usd
|
||||
,-p.cost_loc cost_loc
|
||||
,-p.cost_usd 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
|
||||
,p.ship_month
|
||||
,p.ship_season
|
||||
,'b21' AS version
|
||||
,'adj timing' iter
|
||||
,logl.id logid
|
||||
,logl.doc->>'tag' tag
|
||||
,logl.doc->>'message' "comment"
|
||||
,logl.doc->>'type' module
|
||||
FROM
|
||||
rlarp.osm_pool p
|
||||
INNER JOIN rejoin r ON
|
||||
r.account = p.billto_group
|
||||
AND r.director = p.director
|
||||
AND r.glec = p.segm
|
||||
AND r.order_date = p.order_date
|
||||
AND r.ship_date = p.ship_date
|
||||
AND r.part = p.part
|
||||
CROSS JOIN logl
|
||||
WHERE
|
||||
r.include
|
||||
)
|
||||
,repl AS (
|
||||
SELECT
|
||||
gld.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
|
||||
,p.part
|
||||
,p.part_descr
|
||||
,p.part_group
|
||||
,p.branding
|
||||
,p.majg_descr
|
||||
,p.ming_descr
|
||||
,p.majs_descr
|
||||
,p.mins_descr
|
||||
,p.segm
|
||||
,p.substance
|
||||
,p.fs_line
|
||||
,p.r_currency
|
||||
,p.r_rate
|
||||
,p.c_currency
|
||||
,p.c_rate
|
||||
,p.units units
|
||||
,p.value_loc value_loc
|
||||
,p.value_usd value_usd
|
||||
,p.cost_loc cost_loc
|
||||
,p.cost_usd 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'
|
||||
,gld.sspr || ' - ' || to_char(p.ship_date,'Mon') ship_month
|
||||
,gld.ssyr ship_season
|
||||
,'b21' AS version
|
||||
,'adj timing' iter
|
||||
,logl.id logid
|
||||
,logl.doc->>'tag' tag
|
||||
,logl.doc->>'message' "comment"
|
||||
,logl.doc->>'type' module
|
||||
FROM
|
||||
rlarp.osm_pool p
|
||||
INNER JOIN rejoin r ON
|
||||
r.account = p.billto_group
|
||||
AND r.director = p.director
|
||||
AND r.glec = p.segm
|
||||
AND r.order_date = p.order_date
|
||||
AND r.ship_date = p.ship_date
|
||||
AND r.part = p.part
|
||||
CROSS JOIN logl
|
||||
LEFT OUTER JOIN rlarp.gld gld ON
|
||||
gld.drange @> (p.ship_date + INTERVAL '1 year')::date
|
||||
WHERE
|
||||
r.include
|
||||
)
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM remove UNION ALL SELECT * FROM repl;
|
8
build/move_sales/list_date.sql
Normal file
8
build/move_sales/list_date.sql
Normal file
@ -0,0 +1,8 @@
|
||||
SELECT
|
||||
ship_cust_descr, order_date, ship_date, sum(value_usd) sales
|
||||
from
|
||||
rlarp.osm_pool
|
||||
where
|
||||
ship_season = 2021
|
||||
group by
|
||||
ship_cust_descr, order_date, ship_date;
|
79
build/move_sales/remove_other.sql
Normal file
79
build/move_sales/remove_other.sql
Normal file
@ -0,0 +1,79 @@
|
||||
BEGIN;
|
||||
with
|
||||
logl AS (
|
||||
INSERT INTO
|
||||
rlarp.osm_log(doc)
|
||||
SELECT
|
||||
jsonb_build_object(
|
||||
'stamp',current_timestamp
|
||||
,'user','Trowbridge, Paul'
|
||||
,'source','script'
|
||||
,'tag','remove other'
|
||||
,'message','remove budget for quota reps rolling into director Other'
|
||||
,'type','remove other'
|
||||
,'version','b21'
|
||||
) doc RETURNING *
|
||||
)
|
||||
,targ 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
|
||||
,p.part
|
||||
,p.part_descr
|
||||
,p.part_group
|
||||
,p.branding
|
||||
,p.majg_descr
|
||||
,p.ming_descr
|
||||
,p.majs_descr
|
||||
,p.mins_descr
|
||||
,p.segm
|
||||
,p.substance
|
||||
,p.fs_line
|
||||
,p.r_currency
|
||||
,p.r_rate
|
||||
,p.c_currency
|
||||
,p.c_rate
|
||||
,-p.units units
|
||||
,-p.value_loc value_loc
|
||||
,-p.value_usd value_usd
|
||||
,-p.cost_loc cost_loc
|
||||
,-p.cost_usd 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
|
||||
,p.ship_month
|
||||
,p.ship_season
|
||||
,'b21' AS version
|
||||
,'adj volume' iter
|
||||
,logl.id logid
|
||||
,logl.doc->>'tag' tag
|
||||
,logl.doc->>'message' "comment"
|
||||
,logl.doc->>'type' module
|
||||
from
|
||||
rlarp.osm_pool p
|
||||
CROSS JOIN logl
|
||||
where
|
||||
director = 'Other'
|
||||
and (order_season >= 2021 or ship_season >= 2021)
|
||||
)
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM targ;
|
||||
|
||||
COMMIT;
|
357
build/move_sales/sales_months.sql
Normal file
357
build/move_sales/sales_months.sql
Normal file
@ -0,0 +1,357 @@
|
||||
BEGIN;
|
||||
|
||||
WITH
|
||||
move AS (
|
||||
SELECT * FROM (VALUES
|
||||
('HOME0004 - ALLIANCE INTERNATIONAL LLC',CAST('10/7/2019' AS DATE),CAST('6/1/2020' AS DATE),11322.85,CAST('7/2/2020' AS DATE)),
|
||||
('CORS0004 - CORSOS PERENNIALS',CAST('10/23/2019' AS DATE),CAST('6/1/2020' AS DATE),30916.44,CAST('7/2/2020' AS DATE)),
|
||||
('MONR0007 - MONROVIA - VISALIA CA',CAST('2/3/2020' AS DATE),CAST('6/1/2020' AS DATE),8409.6,CAST('7/2/2020' AS DATE)),
|
||||
('BATT0001 - BATTLEFIELD FARMS',CAST('2/5/2020' AS DATE),CAST('6/1/2020' AS DATE),2285,CAST('7/2/2020' AS DATE)),
|
||||
('BABI0001 - BABIKOW GREENHOUSES',CAST('2/7/2020' AS DATE),CAST('6/1/2020' AS DATE),9640.8,CAST('7/2/2020' AS DATE)),
|
||||
('KALA0002 - KALAMAZOO FLOWER GROUP LLC',CAST('2/10/2020' AS DATE),CAST('6/1/2020' AS DATE),1005.4,CAST('7/2/2020' AS DATE)),
|
||||
('HATR0001 - H.A. TREICHLER SONS',CAST('2/11/2020' AS DATE),CAST('6/1/2020' AS DATE),13425.44,CAST('7/2/2020' AS DATE)),
|
||||
('KALA0002 - KALAMAZOO FLOWER GROUP LLC',CAST('3/13/2020' AS DATE),CAST('6/1/2020' AS DATE),2464,CAST('7/2/2020' AS DATE)),
|
||||
('METR0002 - METROLINA GREENHOUSES',CAST('3/17/2020' AS DATE),CAST('6/1/2020' AS DATE),17619.12,CAST('7/2/2020' AS DATE)),
|
||||
('JOHN0020 - JOHN BARONEDBA BARONE FARM',CAST('3/23/2020' AS DATE),CAST('6/1/2020' AS DATE),5571.85,CAST('7/2/2020' AS DATE)),
|
||||
('JENS0002 - JENSEN DISTRIBUTION SERVICES',CAST('3/24/2020' AS DATE),CAST('6/1/2020' AS DATE),487.15,CAST('7/2/2020' AS DATE)),
|
||||
('DIST0007 - TERIS SERVICES-PICK UP ONLY U',CAST('3/31/2020' AS DATE),CAST('6/1/2020' AS DATE),5318.78,CAST('7/2/2020' AS DATE)),
|
||||
('DIST0007 - TERIS SERVICES-PICK UP ONLY U',CAST('4/7/2020' AS DATE),CAST('6/1/2020' AS DATE),400.28,CAST('7/2/2020' AS DATE)),
|
||||
('BELA0001 - BELA FLOR NURSERIES',CAST('4/15/2020' AS DATE),CAST('6/1/2020' AS DATE),1219.71,CAST('7/2/2020' AS DATE)),
|
||||
('JENS0002 - JENSEN DISTRIBUTION SERVICES',CAST('4/15/2020' AS DATE),CAST('6/1/2020' AS DATE),395.01,CAST('7/2/2020' AS DATE)),
|
||||
('LLNU0003 - LL NURSERY SUPPLY INC WA',CAST('4/16/2020' AS DATE),CAST('6/1/2020' AS DATE),656.7,CAST('7/2/2020' AS DATE)),
|
||||
('INTE0003 - GREENHOUSE MEGASTORE',CAST('4/23/2020' AS DATE),CAST('6/1/2020' AS DATE),283.06,CAST('7/2/2020' AS DATE)),
|
||||
('CALC0004 - CAL COLOR GROWERS LLC',CAST('4/28/2020' AS DATE),CAST('6/1/2020' AS DATE),8273.25,CAST('7/2/2020' AS DATE)),
|
||||
('BATT0001 - BATTLEFIELD FARMS',CAST('5/1/2020' AS DATE),CAST('6/1/2020' AS DATE),18919.26,CAST('7/2/2020' AS DATE)),
|
||||
('LOWE3110 - LOWES OF MILTON CANADA # 3110',CAST('5/4/2020' AS DATE),CAST('6/1/2020' AS DATE),8901.3,CAST('7/2/2020' AS DATE)),
|
||||
('SILV0007 - SILVERLEAF GHSE',CAST('5/6/2020' AS DATE),CAST('6/1/2020' AS DATE),19368.3,CAST('7/2/2020' AS DATE)),
|
||||
('HOME0004 - ALLIANCE INTERNATIONAL LLC',CAST('5/11/2020' AS DATE),CAST('6/1/2020' AS DATE),6312.37,CAST('7/2/2020' AS DATE)),
|
||||
('SHAD0009 - SHADY CREEK GREENHOUSES',CAST('5/12/2020' AS DATE),CAST('6/1/2020' AS DATE),1395.9,CAST('7/2/2020' AS DATE)),
|
||||
('ISLA0008 - ISLAND GROWER SUPPLIES LLC',CAST('5/13/2020' AS DATE),CAST('6/1/2020' AS DATE),2160,CAST('7/2/2020' AS DATE)),
|
||||
('LYSH0001 - LYS HYDRO GARDEN FRESNO',CAST('5/13/2020' AS DATE),CAST('6/1/2020' AS DATE),5383.08,CAST('7/2/2020' AS DATE)),
|
||||
('LLNU0003 - LL NURSERY SUPPLY INC WA',CAST('5/13/2020' AS DATE),CAST('6/1/2020' AS DATE),667.89,CAST('7/2/2020' AS DATE)),
|
||||
('STAN0009 - STANDEX ELECTRONICS',CAST('5/15/2020' AS DATE),CAST('6/1/2020' AS DATE),47.25,CAST('7/2/2020' AS DATE)),
|
||||
('BRAD0020 - BRADFORD CO-OP STORAGE LTD (U)',CAST('5/15/2020' AS DATE),CAST('6/1/2020' AS DATE),460.8,CAST('7/2/2020' AS DATE)),
|
||||
('CANA0034 - CANADIAN TIRE RETAIL DC 9004',CAST('5/16/2020' AS DATE),CAST('6/1/2020' AS DATE),4908.09,CAST('7/2/2020' AS DATE)),
|
||||
('AJBI0001 - AJ BILLES DC CANADIAN TIRE',CAST('5/16/2020' AS DATE),CAST('6/1/2020' AS DATE),29620.77,CAST('7/2/2020' AS DATE)),
|
||||
('LOWE3110 - LOWES OF MILTON CANADA # 3110',CAST('5/18/2020' AS DATE),CAST('6/1/2020' AS DATE),1595.47,CAST('7/2/2020' AS DATE)),
|
||||
('BATT0001 - BATTLEFIELD FARMS',CAST('5/19/2020' AS DATE),CAST('6/1/2020' AS DATE),2088,CAST('7/2/2020' AS DATE)),
|
||||
('HYDR0010 - HYDROFARM INC',CAST('5/20/2020' AS DATE),CAST('6/1/2020' AS DATE),22368.8,CAST('7/2/2020' AS DATE)),
|
||||
('WILD0012 - WILDWOODS-PACIFIC NURSERY POTS',CAST('5/20/2020' AS DATE),CAST('6/1/2020' AS DATE),4180,CAST('7/2/2020' AS DATE)),
|
||||
('GULF0002 - SUNBLEST GARDENS',CAST('5/20/2020' AS DATE),CAST('6/1/2020' AS DATE),21501.89,CAST('7/2/2020' AS DATE)),
|
||||
('LOUI0001 - LOUIS DAVINO SR LLC',CAST('5/20/2020' AS DATE),CAST('6/1/2020' AS DATE),38150.76,CAST('7/2/2020' AS DATE)),
|
||||
('DIST0007 - TERIS SERVICES-PICK UP ONLY U',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),3626.73,CAST('7/2/2020' AS DATE)),
|
||||
('FRED0038 - FRED MEYER STORES',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),38706.76,CAST('7/2/2020' AS DATE)),
|
||||
('LLNU0003 - LL NURSERY SUPPLY INC WA',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),3205.89,CAST('7/2/2020' AS DATE)),
|
||||
('DOIT0008 - DO IT BEST CORP',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),551.34,CAST('7/2/2020' AS DATE)),
|
||||
('BATT0001 - BATTLEFIELD FARMS',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),25150,CAST('7/2/2020' AS DATE)),
|
||||
('AJBI0001 - AJ BILLES DC CANADIAN TIRE',CAST('5/23/2020' AS DATE),CAST('6/1/2020' AS DATE),339.94,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0033 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),998.94,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0134 - AMAZON LGB6',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),1058.85,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0115 - AMAZON.COM LGB4 LLC',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),743.79,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0093 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),3087.16,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0055 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),772.44,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0008 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),1735.38,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0123 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),720.9,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0156 - AMAZON - MEM1',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),750.12,CAST('7/2/2020' AS DATE)),
|
||||
('FRED0038 - FRED MEYER STORES',CAST('5/26/2020' AS DATE),CAST('6/1/2020' AS DATE),4972.75,CAST('7/2/2020' AS DATE)),
|
||||
('INTE0003 - GREENHOUSE MEGASTORE',CAST('5/26/2020' AS DATE),CAST('6/1/2020' AS DATE),16602.93,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0156 - AMAZON - MEM1',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),14.46,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0159 - AMAZON - SCK1',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0045 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
|
||||
('STON0028 - STONINGTON GARDENS',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),1370.99,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0083 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),130.14,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0073 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0012 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),28.92,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0127 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0093 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),14.46,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0043 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0140 - AMAZON - CLT3',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0114 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),81.81,CAST('7/2/2020' AS DATE)),
|
||||
('COPP0002 - COPPERSTATE FARMS MGMT LLC',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),16156.8,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0148 - AMAZON - IND9 9912622',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),14.46,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0144 - AMAZON - CMH3',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
|
||||
('INTE0003 - GREENHOUSE MEGASTORE',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),16810.8,CAST('7/2/2020' AS DATE)),
|
||||
('DCME0009 - 9 DIS ASM DC 7103 MERCH WM',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),26970.81,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0019 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0155 - AMAZON - XIX7',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0107 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),65.4,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0099 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0108 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
|
||||
('AMAZ0090 - AMAZON.COM FULFILLMENT CTRCHH2',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
|
||||
('GOLD0038 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
|
||||
('GASK0001 - GASKO GREENHOUSES',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),39166.05,CAST('7/2/2020' AS DATE)),
|
||||
('EAGL0001 - EAGLE CREEK WHOLESALE',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),489.5,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0123 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0127 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0029 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('DIST0007 - TERIS SERVICES-PICK UP ONLY U',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),19122.39,CAST('8/2/2020' AS DATE)),
|
||||
('BEAU0002 - BEAUTIFUL LAND PRODUCTS',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),282.85,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0068 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0045 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0121 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0058 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0051 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('DEWA0001 - DEWAR NURSERIES',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),24181.3,CAST('8/2/2020' AS DATE)),
|
||||
('AMAZ0091 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
|
||||
('LUPI0001 - LUPINE LADY PORCUPINE GNHSE',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),112.42,CAST('8/2/2020' AS DATE)),
|
||||
('YODE0010 - YODERS PRODUCE INC',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),228.75,CAST('8/2/2020' AS DATE)),
|
||||
('JACK0020 - JACKSON COUNTY ARC INC',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),63.2,CAST('8/2/2020' AS DATE)),
|
||||
('RAND0011 - RANDY WESTRATE GREENHOUSE',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),420.75,CAST('8/2/2020' AS DATE)),
|
||||
('JOSE0006 - JOSE OCHOA',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),520.86,CAST('8/2/2020' AS DATE)),
|
||||
('WERA0001 - WE RADTKE INC',CAST('5/30/2020' AS DATE),CAST('6/1/2020' AS DATE),1747.05,CAST('8/2/2020' AS DATE)),
|
||||
('ERNS0003 - ERNST NURSERY',CAST('9/9/2019' AS DATE),CAST('6/2/2020' AS DATE),23493.6,CAST('8/2/2020' AS DATE)),
|
||||
('SANM0002 - SAN MARCOS-AMER HORT SUPPLY',CAST('10/7/2019' AS DATE),CAST('6/2/2020' AS DATE),23118.67,CAST('8/2/2020' AS DATE)),
|
||||
('CORS0004 - CORSOS PERENNIALS',CAST('10/23/2019' AS DATE),CAST('6/2/2020' AS DATE),18034.59,CAST('8/2/2020' AS DATE)),
|
||||
('ALTM0034 - ALTMAN PLANTS - SALINAS',CAST('11/15/2019' AS DATE),CAST('6/2/2020' AS DATE),6092.7,CAST('8/2/2020' AS DATE)),
|
||||
('ALTM0021 - ALTMANS SPECIALTY PLANTS PERRI',CAST('11/15/2019' AS DATE),CAST('6/2/2020' AS DATE),36831.64,CAST('8/2/2020' AS DATE)),
|
||||
('WILL0064 - WILLOWBROOK NURSERIES INC',CAST('11/25/2019' AS DATE),CAST('6/2/2020' AS DATE),3474,CAST('8/2/2020' AS DATE)),
|
||||
('CAVI0001 - CAVICCHIO GREENHOUSES INC',CAST('12/10/2019' AS DATE),CAST('6/2/2020' AS DATE),12716.82,CAST('8/2/2020' AS DATE)),
|
||||
('ENVI0008 - EVL NURSERY',CAST('12/16/2019' AS DATE),CAST('6/2/2020' AS DATE),3551.31,CAST('8/2/2020' AS DATE)),
|
||||
('MONR0018 - MONROVIA - DAYTON OR',CAST('1/6/2020' AS DATE),CAST('6/2/2020' AS DATE),29433.6,CAST('8/2/2020' AS DATE)),
|
||||
('WALD0003 - WALDO ASSOCIATES',CAST('1/30/2020' AS DATE),CAST('6/2/2020' AS DATE),924.93,CAST('8/2/2020' AS DATE)),
|
||||
('METR0002 - METROLINA GREENHOUSES',CAST('2/11/2020' AS DATE),CAST('6/2/2020' AS DATE),13200,CAST('8/2/2020' AS DATE)),
|
||||
('HEAR0011 - HEARTLAND-SUN WAREHOUSE24HR N',CAST('2/28/2020' AS DATE),CAST('6/2/2020' AS DATE),4442.04,CAST('8/2/2020' AS DATE)),
|
||||
('FORE0005 - FOREST GLEN GREENHOUSES (C)',CAST('3/4/2020' AS DATE),CAST('6/2/2020' AS DATE),1747.44,CAST('8/2/2020' AS DATE)),
|
||||
('VPNU0002 - VP NURSERY',CAST('3/6/2020' AS DATE),CAST('6/2/2020' AS DATE),19356.48,CAST('8/2/2020' AS DATE)),
|
||||
('ACOS0002 - ACOSTA FARMS NURSERY INC',CAST('3/9/2020' AS DATE),CAST('6/2/2020' AS DATE),4391.78,CAST('8/2/2020' AS DATE)),
|
||||
('ACOS0002 - ACOSTA FARMS NURSERY INC',CAST('3/10/2020' AS DATE),CAST('6/2/2020' AS DATE),8700,CAST('8/2/2020' AS DATE)),
|
||||
('PLEA0026 - PLEASANT VALLEY FARM INC',CAST('3/11/2020' AS DATE),CAST('6/2/2020' AS DATE),731.2,CAST('8/2/2020' AS DATE)),
|
||||
('ROCK0026 - ROCKWELL FARMS',CAST('3/16/2020' AS DATE),CAST('6/2/2020' AS DATE),15949.44,CAST('8/2/2020' AS DATE)),
|
||||
('CLEA0015 - CLEARVIEW GREENHOUSES',CAST('3/16/2020' AS DATE),CAST('6/2/2020' AS DATE),6698.45,CAST('8/2/2020' AS DATE)),
|
||||
('OLDN0001 - OLD NORTH GROWERS',CAST('3/16/2020' AS DATE),CAST('6/2/2020' AS DATE),7484.51,CAST('8/2/2020' AS DATE)),
|
||||
('METR0002 - METROLINA GREENHOUSES',CAST('3/17/2020' AS DATE),CAST('6/2/2020' AS DATE),6767.1,CAST('8/2/2020' AS DATE)),
|
||||
('BAMA0001 - BAMA GREEN',CAST('3/17/2020' AS DATE),CAST('6/2/2020' AS DATE),13264.85,CAST('8/2/2020' AS DATE)),
|
||||
('WALD0003 - WALDO ASSOCIATES',CAST('3/18/2020' AS DATE),CAST('6/2/2020' AS DATE),1234.9,CAST('8/2/2020' AS DATE)),
|
||||
('TREE0044 - TREESAP FARMS-FOREST GROVE OR',CAST('3/24/2020' AS DATE),CAST('6/2/2020' AS DATE),3047.22,CAST('8/2/2020' AS DATE)),
|
||||
('HEAR0011 - HEARTLAND-SUN WAREHOUSE24HR N',CAST('3/24/2020' AS DATE),CAST('6/2/2020' AS DATE),271,CAST('8/2/2020' AS DATE)),
|
||||
('YOUN0005 - YOUNGS PLANT FARM INC - FARM 2',CAST('3/25/2020' AS DATE),CAST('6/2/2020' AS DATE),44807.6,CAST('8/2/2020' AS DATE)),
|
||||
('YOUN0004 - YOUNGS PLANT FARM INC - FARM 1',CAST('3/25/2020' AS DATE),CAST('6/2/2020' AS DATE),27216.51,CAST('8/2/2020' AS DATE)),
|
||||
('DIXI0001 - DIXIE GREEN INC.',CAST('3/26/2020' AS DATE),CAST('6/2/2020' AS DATE),8568,CAST('8/2/2020' AS DATE)),
|
||||
('WILL0028 - WILLIAMS PLANT FARM',CAST('3/31/2020' AS DATE),CAST('6/2/2020' AS DATE),2812.5,CAST('8/2/2020' AS DATE)),
|
||||
('PLEA0026 - PLEASANT VALLEY FARM INC',CAST('4/2/2020' AS DATE),CAST('6/2/2020' AS DATE),468.18,CAST('8/2/2020' AS DATE)),
|
||||
('SPAR0001 - SPARETIME SUPPLY',CAST('4/2/2020' AS DATE),CAST('6/2/2020' AS DATE),17690.4,CAST('8/2/2020' AS DATE)),
|
||||
('HYDR0010 - HYDROFARM INC',CAST('4/3/2020' AS DATE),CAST('6/2/2020' AS DATE),19445.93,CAST('8/2/2020' AS DATE)),
|
||||
('CARL0001 - CARL BREHOB SON',CAST('4/10/2020' AS DATE),CAST('6/2/2020' AS DATE),450.6,CAST('8/2/2020' AS DATE)),
|
||||
('ALPH0003 - ALPHA FOLIAGE',CAST('4/13/2020' AS DATE),CAST('6/2/2020' AS DATE),16207.16,CAST('8/2/2020' AS DATE)),
|
||||
('FISH0009 - FISHER NURSERY INC - CA',CAST('4/13/2020' AS DATE),CAST('6/2/2020' AS DATE),2211.86,CAST('8/2/2020' AS DATE)),
|
||||
('WALD0003 - WALDO ASSOCIATES',CAST('4/14/2020' AS DATE),CAST('6/2/2020' AS DATE),2769.33,CAST('8/2/2020' AS DATE)),
|
||||
('ROCK0026 - ROCKWELL FARMS',CAST('4/15/2020' AS DATE),CAST('6/2/2020' AS DATE),5061.84,CAST('8/2/2020' AS DATE)),
|
||||
('SCOT0019 - SCOTTS NURSERY LTD (C)',CAST('4/17/2020' AS DATE),CAST('6/2/2020' AS DATE),18909.45,CAST('8/2/2020' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('4/17/2020' AS DATE),CAST('6/2/2020' AS DATE),172.4,CAST('8/2/2020' AS DATE)),
|
||||
('WALD0003 - WALDO ASSOCIATES',CAST('4/22/2020' AS DATE),CAST('6/2/2020' AS DATE),607.81,CAST('8/2/2020' AS DATE)),
|
||||
('KMNU0003 - KM NURSERY',CAST('4/22/2020' AS DATE),CAST('6/2/2020' AS DATE),30531.6,CAST('8/2/2020' AS DATE)),
|
||||
('SPAR0001 - SPARETIME SUPPLY',CAST('4/27/2020' AS DATE),CAST('6/2/2020' AS DATE),6633.9,CAST('2/2/2021' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('4/28/2020' AS DATE),CAST('6/2/2020' AS DATE),8518.61,CAST('2/2/2021' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('4/29/2020' AS DATE),CAST('6/2/2020' AS DATE),926.2,CAST('2/2/2021' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('4/30/2020' AS DATE),CAST('6/2/2020' AS DATE),6024.27,CAST('2/2/2021' AS DATE)),
|
||||
('AJBI0001 - AJ BILLES DC CANADIAN TIRE',CAST('5/2/2020' AS DATE),CAST('6/2/2020' AS DATE),752.43,CAST('2/2/2021' AS DATE)),
|
||||
('CARL0001 - CARL BREHOB SON',CAST('5/6/2020' AS DATE),CAST('6/2/2020' AS DATE),627.25,CAST('2/2/2021' AS DATE)),
|
||||
('ENVI0008 - EVL NURSERY',CAST('5/6/2020' AS DATE),CAST('6/2/2020' AS DATE),1587.84,CAST('2/2/2021' AS DATE)),
|
||||
('WALD0003 - WALDO ASSOCIATES',CAST('5/7/2020' AS DATE),CAST('6/2/2020' AS DATE),1734.3,CAST('2/2/2021' AS DATE)),
|
||||
('LOWE3110 - LOWES OF MILTON CANADA # 3110',CAST('5/11/2020' AS DATE),CAST('6/2/2020' AS DATE),3066.42,CAST('2/2/2021' AS DATE)),
|
||||
('BUCK0006 - BUCKHORN NURSERY',CAST('5/11/2020' AS DATE),CAST('6/2/2020' AS DATE),1804,CAST('2/2/2021' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/12/2020' AS DATE),CAST('6/2/2020' AS DATE),73.8,CAST('2/2/2021' AS DATE)),
|
||||
('WALD0003 - WALDO ASSOCIATES',CAST('5/13/2020' AS DATE),CAST('6/2/2020' AS DATE),5142.12,CAST('2/2/2021' AS DATE)),
|
||||
('WHIT0003 - WHITES NURSERY',CAST('5/14/2020' AS DATE),CAST('6/2/2020' AS DATE),1859.68,CAST('2/2/2021' AS DATE)),
|
||||
('MENA3339 - MENARDS INC',CAST('5/18/2020' AS DATE),CAST('6/2/2020' AS DATE),1974.54,CAST('2/2/2021' AS DATE)),
|
||||
('WEST0646 - NUTRIEN AG SOL. - WATSONVILLE',CAST('5/18/2020' AS DATE),CAST('6/2/2020' AS DATE),9660.19,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5089 - THE HOME DEPOT #5089 PICK UP',CAST('5/19/2020' AS DATE),CAST('6/2/2020' AS DATE),4166.76,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5642 - THE HOME DEPOT #5642 PICK UP',CAST('5/19/2020' AS DATE),CAST('6/2/2020' AS DATE),7687.15,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5030 - THE HOME DEPOT #5030 PICK UP',CAST('5/19/2020' AS DATE),CAST('6/2/2020' AS DATE),4395.64,CAST('2/2/2021' AS DATE)),
|
||||
('HYDR0010 - HYDROFARM INC',CAST('5/20/2020' AS DATE),CAST('6/2/2020' AS DATE),12492.62,CAST('2/2/2021' AS DATE)),
|
||||
('CARL0001 - CARL BREHOB SON',CAST('5/20/2020' AS DATE),CAST('6/2/2020' AS DATE),1747.28,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5034 - THE HOME DEPOT #5034 PICK UP',CAST('5/21/2020' AS DATE),CAST('6/2/2020' AS DATE),18292.72,CAST('2/2/2021' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/21/2020' AS DATE),CAST('6/2/2020' AS DATE),1104.45,CAST('2/2/2021' AS DATE)),
|
||||
('WOOD0001 - WOODBURN NURSERY',CAST('5/21/2020' AS DATE),CAST('6/2/2020' AS DATE),6138,CAST('2/2/2021' AS DATE)),
|
||||
('ROBE0014 - ROBERTAS YOUNG PLANTS',CAST('5/21/2020' AS DATE),CAST('6/2/2020' AS DATE),9819.29,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5084 - THE HOME DEPOT #5084 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),6897.97,CAST('2/2/2021' AS DATE)),
|
||||
('CASS0002 - CASSCO',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),20617.7,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5085 - THE HOME DEPOT #5085 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),17337.57,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5089 - THE HOME DEPOT #5089 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),9208.18,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5643 - THE HOME DEPOT #5643 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),963.84,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5642 - THE HOME DEPOT #5642 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),576.04,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5520 - THE HOME DEPOT #5520 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),7713.04,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5030 - THE HOME DEPOT #5030 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),5072.52,CAST('2/2/2021' AS DATE)),
|
||||
('AMAZ0058 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/2/2020' AS DATE),578.27,CAST('2/2/2021' AS DATE)),
|
||||
('LOWE3110 - LOWES OF MILTON CANADA # 3110',CAST('5/25/2020' AS DATE),CAST('6/2/2020' AS DATE),1637.71,CAST('2/2/2021' AS DATE)),
|
||||
('AMAZ0006 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/2/2020' AS DATE),2438.8,CAST('2/2/2021' AS DATE)),
|
||||
('AMAZ0085 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/2/2020' AS DATE),2800.81,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5851 - THE HOME DEPOT #5851 PICK UP',CAST('5/26/2020' AS DATE),CAST('6/2/2020' AS DATE),19600.94,CAST('2/2/2021' AS DATE)),
|
||||
('HOMU5520 - THE HOME DEPOT #5520 PICK UP',CAST('5/26/2020' AS DATE),CAST('6/2/2020' AS DATE),10885.09,CAST('5/2/2021' AS DATE)),
|
||||
('HOMU5084 - THE HOME DEPOT #5084 PICK UP',CAST('5/26/2020' AS DATE),CAST('6/2/2020' AS DATE),3289.09,CAST('4/2/2021' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/26/2020' AS DATE),CAST('6/2/2020' AS DATE),1422.36,CAST('4/2/2021' AS DATE)),
|
||||
('BRAN0014 - BRANTLEY NURSERIES-BUSHNELL',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),9762.48,CAST('5/2/2021' AS DATE)),
|
||||
('BWIC000G - BWI - SPRINGFIELD MO',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),12315.24,CAST('3/2/2021' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),408,CAST('3/2/2021' AS DATE)),
|
||||
('DIST0004 - TERIS SVSC DAPPROVISIONNEMNTC',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),1942.22,CAST('3/2/2021' AS DATE)),
|
||||
('WALM602A - WALMART DC 6002A-ASM DIS',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),30551,CAST('3/2/2021' AS DATE)),
|
||||
('CASS0002 - CASSCO',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),6635.15,CAST('3/2/2021' AS DATE)),
|
||||
('HOMU5087 - THE HOME DEPOT #5087 PICK UP',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),12138.15,CAST('3/2/2021' AS DATE)),
|
||||
('TJSG0001 - TJS GREENHOUSE LANDSCAPE',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),1085.19,CAST('3/2/2021' AS DATE)),
|
||||
('HOMU5642 - THE HOME DEPOT #5642 PICK UP',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),4149.17,CAST('3/2/2021' AS DATE)),
|
||||
('SCMD0001 - SCM DC 6063A-ASM DIS WM PICKUP',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),18407.75,CAST('3/2/2021' AS DATE)),
|
||||
('HOMU5639 - THE HOME DEPOT #5639 PICK UP',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),4594.91,CAST('3/2/2021' AS DATE)),
|
||||
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/28/2020' AS DATE),CAST('6/2/2020' AS DATE),660.9,CAST('3/2/2021' AS DATE)),
|
||||
('CWKI0001 - CW KITCHENS INC',CAST('5/28/2020' AS DATE),CAST('6/2/2020' AS DATE),780.23,CAST('3/2/2021' AS DATE)),
|
||||
('LLNU0001 - LL NURSERY SUPPLY INC CA',CAST('5/28/2020' AS DATE),CAST('6/2/2020' AS DATE),40536.37,CAST('3/2/2021' AS DATE)),
|
||||
('ROSE0026 - ROSEVILLE FARMS',CAST('5/29/2020' AS DATE),CAST('6/2/2020' AS DATE),10254.6,CAST('3/2/2021' AS DATE)),
|
||||
('PLEA0026 - PLEASANT VALLEY FARM INC',CAST('5/29/2020' AS DATE),CAST('6/2/2020' AS DATE),12979.2,CAST('3/2/2021' AS DATE)),
|
||||
('BRAD0020 - BRADFORD CO-OP STORAGE LTD (U)',CAST('5/29/2020' AS DATE),CAST('6/2/2020' AS DATE),5908.07,CAST('3/2/2021' AS DATE)),
|
||||
('GLOB0004 - GLOBAL HORTICULTURAL INC (C)',CAST('5/31/2019' AS DATE),CAST('6/3/2020' AS DATE),4159.13,CAST('3/2/2021' AS DATE)),
|
||||
('GREE0092 - GREENSCAPE',CAST('8/13/2019' AS DATE),CAST('6/3/2020' AS DATE),565.45,CAST('3/2/2021' AS DATE)),
|
||||
('QUAL0021 - QUALITY GHSE SITE 2',CAST('8/15/2019' AS DATE),CAST('6/3/2020' AS DATE),28746.9,CAST('3/2/2021' AS DATE)),
|
||||
('MARK0020 - MARKET BASKET OF ST PETERS #6',CAST('9/5/2019' AS DATE),CAST('6/3/2020' AS DATE),89.16,CAST('3/2/2021' AS DATE)),
|
||||
('TWIN0007 - TWIN OAKS GROWERS',CAST('9/9/2019' AS DATE),CAST('6/3/2020' AS DATE),2310,CAST('3/2/2021' AS DATE)),
|
||||
('UCGM0001 - UGC - MARKET BASKET',CAST('9/17/2019' AS DATE),CAST('6/3/2020' AS DATE),133.77,CAST('3/2/2021' AS DATE)),
|
||||
('DREA0005 - DREAMS WITH COLORS INC',CAST('10/3/2019' AS DATE),CAST('6/3/2020' AS DATE),11549.2,CAST('4/2/2021' AS DATE)),
|
||||
('RSGR0004 - RS GROWERS SUPPLY INC',CAST('10/14/2019' AS DATE),CAST('6/3/2020' AS DATE),4339.84,CAST('4/2/2021' AS DATE)),
|
||||
('WEAV0003 - WEAVERLAND VALLEY GREENHOUSE',CAST('10/18/2019' AS DATE),CAST('6/3/2020' AS DATE),1039.92,CAST('4/2/2021' AS DATE)),
|
||||
('FOST0001 - FOSTERS INC RETAIL',CAST('10/22/2019' AS DATE),CAST('6/3/2020' AS DATE),1162.1,CAST('4/2/2021' AS DATE)),
|
||||
('WETS0003 - BFG SUPPLY - HARRISONBURG(W13)',CAST('10/22/2019' AS DATE),CAST('6/3/2020' AS DATE),1788.07,CAST('4/2/2021' AS DATE)),
|
||||
('BFGS0011 - BFG SUPPLY - ST PAUL',CAST('10/22/2019' AS DATE),CAST('6/3/2020' AS DATE),1448.7,CAST('4/2/2021' AS DATE)),
|
||||
('BFGS0004 - BFG SUPPLY - GRAND RAPIDS(W04)',CAST('10/22/2019' AS DATE),CAST('6/3/2020' AS DATE),973.07,CAST('4/2/2021' AS DATE)),
|
||||
('BFGS0015 - BFG SUPPLY - CHESWICK (W08)',CAST('10/23/2019' AS DATE),CAST('6/3/2020' AS DATE),2197.89,CAST('4/2/2021' AS DATE)),
|
||||
('FOST0001 - FOSTERS INC RETAIL',CAST('10/25/2019' AS DATE),CAST('6/3/2020' AS DATE),1575.99,CAST('4/2/2021' AS DATE)),
|
||||
('ARTK0002 - ART KNAPP - HESTIA PRODUCTIONS',CAST('10/28/2019' AS DATE),CAST('6/3/2020' AS DATE),610.56,CAST('4/2/2021' AS DATE)),
|
||||
('EARL0012 - EARL MAY SEED NURSERY',CAST('10/28/2019' AS DATE),CAST('6/3/2020' AS DATE),174.23,CAST('4/2/2021' AS DATE)),
|
||||
('DEGR0004 - DEGROOTS NURSERIES',CAST('10/31/2019' AS DATE),CAST('6/3/2020' AS DATE),205.12,CAST('4/2/2021' AS DATE)),
|
||||
('PLAN0009 - PLANTERS SEED SPICE RET',CAST('11/1/2019' AS DATE),CAST('6/3/2020' AS DATE),234.61,CAST('4/2/2021' AS DATE)),
|
||||
('CYGR0003 - CY GROWERS SUPPLIES LTD U',CAST('11/4/2019' AS DATE),CAST('6/3/2020' AS DATE),1566,CAST('4/2/2021' AS DATE)),
|
||||
('BFGS0004 - BFG SUPPLY - GRAND RAPIDS(W04)',CAST('11/4/2019' AS DATE),CAST('6/3/2020' AS DATE),187.77,CAST('4/2/2021' AS DATE)),
|
||||
('CISC0001 - CISCO COMPANIES (THE)',CAST('11/11/2019' AS DATE),CAST('6/3/2020' AS DATE),533.92,CAST('4/2/2021' AS DATE)),
|
||||
('BERG0012 - BERGENS GREENHOUSE',CAST('11/12/2019' AS DATE),CAST('6/3/2020' AS DATE),84.46,CAST('4/2/2021' AS DATE)),
|
||||
('BERG0029 - BERGEN NURSERY',CAST('11/12/2019' AS DATE),CAST('6/3/2020' AS DATE),759.73,CAST('4/2/2021' AS DATE)),
|
||||
('GREE0223 - EDDIS WHOLESALE GDN SUPPLIES',CAST('11/13/2019' AS DATE),CAST('6/3/2020' AS DATE),87.58,CAST('4/2/2021' AS DATE)),
|
||||
('KOLL0002 - KOLLMANS GREENHOUSE',CAST('11/15/2019' AS DATE),CAST('6/3/2020' AS DATE),174.67,CAST('4/2/2021' AS DATE)),
|
||||
('ALTM0032 - ALTMAN PLANTS - TROUP',CAST('11/15/2019' AS DATE),CAST('6/3/2020' AS DATE),933,CAST('4/2/2021' AS DATE)),
|
||||
('MISC0001 - MISC ACCT - (US )',CAST('11/18/2019' AS DATE),CAST('6/3/2020' AS DATE),0,CAST('4/2/2021' AS DATE)),
|
||||
('DOIT0030 - DIB-ROLLIERS INC #4447',CAST('11/19/2019' AS DATE),CAST('6/3/2020' AS DATE),23.04,CAST('4/2/2021' AS DATE)),
|
||||
('BWIC000T - BWI - TEXARKANA TX',CAST('11/20/2019' AS DATE),CAST('6/3/2020' AS DATE),21.77,CAST('4/2/2021' AS DATE)),
|
||||
('GREE0005 - GREEN ISLAND DISTRIBUTORS INC.',CAST('11/20/2019' AS DATE),CAST('6/3/2020' AS DATE),156.56,CAST('4/2/2021' AS DATE)),
|
||||
('MAPL0025 - MAPLE LEAF GARDEN',CAST('11/20/2019' AS DATE),CAST('6/3/2020' AS DATE),87.58,CAST('4/2/2021' AS DATE)),
|
||||
('WYAT0007 - WYATT QUARLES SEED CO',CAST('11/21/2019' AS DATE),CAST('6/3/2020' AS DATE),506.32,CAST('4/2/2021' AS DATE)),
|
||||
('BWIC000E - BWI - GREENVILLE-SPARTANBURG',CAST('11/22/2019' AS DATE),CAST('6/3/2020' AS DATE),662.73,CAST('4/2/2021' AS DATE)),
|
||||
('HALI0002 - HALIFAX SEED DIST CENTER (C)',CAST('11/22/2019' AS DATE),CAST('6/3/2020' AS DATE),555.71,CAST('4/2/2021' AS DATE)),
|
||||
('EDDI0001 - EDDIS WHOLESALE GDN SUPPLIES',CAST('12/2/2019' AS DATE),CAST('6/3/2020' AS DATE),86.01,CAST('4/2/2021' AS DATE)),
|
||||
('MARI0030 - MARIA GARDENS',CAST('12/3/2019' AS DATE),CAST('6/3/2020' AS DATE),790.55,CAST('4/2/2021' AS DATE)),
|
||||
('MARI0007 - MARIA GARDENS - N. ROYALTON',CAST('12/4/2019' AS DATE),CAST('6/3/2020' AS DATE),675.25,CAST('4/2/2021' AS DATE)),
|
||||
('LLNU0003 - LL NURSERY SUPPLY INC WA',CAST('12/5/2019' AS DATE),CAST('6/3/2020' AS DATE),445.85,CAST('4/2/2021' AS DATE)),
|
||||
('LLNU0001 - LL NURSERY SUPPLY INC CA',CAST('12/5/2019' AS DATE),CAST('6/3/2020' AS DATE),358.1,CAST('4/2/2021' AS DATE)),
|
||||
('CAVI0001 - CAVICCHIO GREENHOUSES INC',CAST('12/6/2019' AS DATE),CAST('6/3/2020' AS DATE),2316.1,CAST('4/2/2021' AS DATE)),
|
||||
('GRIF0010 - GRIFFIN GREENHOUSE - STAFFORD',CAST('12/6/2019' AS DATE),CAST('6/3/2020' AS DATE),527.51,CAST('4/2/2021' AS DATE)),
|
||||
('BFGS0015 - BFG SUPPLY - CHESWICK (W08)',CAST('12/6/2019' AS DATE),CAST('6/3/2020' AS DATE),1640.54,CAST('4/2/2021' AS DATE)),
|
||||
('COST0015 - COSTA FARMS-FOLIAGE DIV (CNF)',CAST('12/6/2019' AS DATE),CAST('6/3/2020' AS DATE),18673.2,CAST('4/2/2021' AS DATE)),
|
||||
('BFGS0015 - BFG SUPPLY - CHESWICK (W08)',CAST('12/9/2019' AS DATE),CAST('6/3/2020' AS DATE),716.74,CAST('4/2/2021' AS DATE)),
|
||||
('BFGS0004 - BFG SUPPLY - GRAND RAPIDS(W04)',CAST('12/9/2019' AS DATE),CAST('6/3/2020' AS DATE),521.93,CAST('4/2/2021' AS DATE)),
|
||||
('HORI0005 - HORIZON DISTRIBUTION INC',CAST('12/10/2019' AS DATE),CAST('6/3/2020' AS DATE),133.47,CAST('4/2/2021' AS DATE)),
|
||||
('CARL0002 - CARLIN HORTICULTURAL SUPP U',CAST('12/10/2019' AS DATE),CAST('6/3/2020' AS DATE),155.55,CAST('4/2/2021' AS DATE)),
|
||||
('CAVI0001 - CAVICCHIO GREENHOUSES INC',CAST('12/10/2019' AS DATE),CAST('6/3/2020' AS DATE),1695.58,CAST('4/2/2021' AS DATE)),
|
||||
('CARL0001 - CARL BREHOB SON',CAST('12/12/2019' AS DATE),CAST('6/3/2020' AS DATE),478.87,CAST('4/2/2021' AS DATE)),
|
||||
('BWIC000G - BWI - SPRINGFIELD MO',CAST('12/12/2019' AS DATE),CAST('6/3/2020' AS DATE),68.23,CAST('4/2/2021' AS DATE)),
|
||||
('GARD0095 - GARD N WISE SALT LAKE',CAST('12/12/2019' AS DATE),CAST('6/3/2020' AS DATE),214.58,CAST('4/2/2021' AS DATE)),
|
||||
('GARD0122 - GARD N WISE DENVER',CAST('12/12/2019' AS DATE),CAST('6/3/2020' AS DATE),632.41,CAST('4/2/2021' AS DATE)),
|
||||
('STRA0022 - STRADERS GARDEN SUPPLY',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),186.94,CAST('4/2/2021' AS DATE)),
|
||||
('STRA0020 - STRADERS GARDEN CENTER #1',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),290.19,CAST('4/2/2021' AS DATE)),
|
||||
('PLRO0001 - PL ROHRER BRO INC RET',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),21.77,CAST('4/2/2021' AS DATE)),
|
||||
('STRA0001 - STRADERS GREENHOUSE-POWELL',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),119.62,CAST('4/2/2021' AS DATE)),
|
||||
('STRA0023 - STRADERS GARDEN SUPPLY',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),186.94,CAST('4/2/2021' AS DATE)),
|
||||
('STRA0002 - STRADERS GREENHOUSE-GROVE CITY',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),186.94,CAST('4/2/2021' AS DATE)),
|
||||
('LUCA0001 - LUCAS GREENHOUSE',CAST('12/16/2019' AS DATE),CAST('6/3/2020' AS DATE),101062.73,CAST('4/2/2021' AS DATE)),
|
||||
('ENVI0008 - EVL NURSERY',CAST('12/16/2019' AS DATE),CAST('6/3/2020' AS DATE),22023.66,CAST('4/2/2021' AS DATE)),
|
||||
('WILD0012 - WILDWOODS-PACIFIC NURSERY POTS',CAST('12/16/2019' AS DATE),CAST('6/3/2020' AS DATE),14853.15,CAST('4/2/2021' AS DATE)),
|
||||
('APAC0001 - APACHE SEEDS LTD',CAST('12/17/2019' AS DATE),CAST('6/3/2020' AS DATE),663.82,CAST('4/2/2021' AS DATE)),
|
||||
('GALE0003 - GALES GARDEN CENTER',CAST('12/18/2019' AS DATE),CAST('6/3/2020' AS DATE),622.16,CAST('4/2/2021' AS DATE)),
|
||||
('OTTO0004 - OTTEN BROS NRSY LANDSCPG INC',CAST('12/19/2019' AS DATE),CAST('6/3/2020' AS DATE),211.66,CAST('4/2/2021' AS DATE)),
|
||||
('INTE0014 - INTERMOUNTAIN FARMERS ASSN',CAST('12/20/2019' AS DATE),CAST('6/3/2020' AS DATE),87.46,CAST('4/2/2021' AS DATE)),
|
||||
('GARD0095 - GARD N WISE SALT LAKE',CAST('12/20/2019' AS DATE),CAST('6/3/2020' AS DATE),71.63,CAST('4/2/2021' AS DATE)),
|
||||
('GRIF0002 - GRIFFIN GREENHOUSE - SCHENECTA',CAST('12/26/2019' AS DATE),CAST('6/3/2020' AS DATE),1849.79,CAST('4/2/2021' AS DATE)),
|
||||
('COST0007 - COSTA COLOR-MIAMI FL',CAST('1/8/2020' AS DATE),CAST('6/3/2020' AS DATE),15629.4,CAST('4/2/2021' AS DATE)),
|
||||
('COST0015 - COSTA FARMS-FOLIAGE DIV (CNF)',CAST('1/9/2020' AS DATE),CAST('6/3/2020' AS DATE),6652.8,CAST('4/2/2021' AS DATE)),
|
||||
('COST0015 - COSTA FARMS-FOLIAGE DIV (CNF)',CAST('1/10/2020' AS DATE),CAST('6/3/2020' AS DATE),944,CAST('4/2/2021' AS DATE)),
|
||||
('FOST0001 - FOSTERS INC RETAIL',CAST('1/13/2020' AS DATE),CAST('6/3/2020' AS DATE),888.04,CAST('4/2/2021' AS DATE)),
|
||||
('INTE0003 - GREENHOUSE MEGASTORE',CAST('1/13/2020' AS DATE),CAST('6/3/2020' AS DATE),368.52,CAST('4/2/2021' AS DATE)),
|
||||
('JOSE0009 - JOSEPH GEREMIA FARM',CAST('1/13/2020' AS DATE),CAST('6/3/2020' AS DATE),1739.3,CAST('4/2/2021' AS DATE)),
|
||||
('COST0015 - COSTA FARMS-FOLIAGE DIV (CNF)',CAST('1/14/2020' AS DATE),CAST('6/3/2020' AS DATE),5026.94,CAST('4/2/2021' AS DATE)),
|
||||
('RITC0001 - RITCHIE FEED SEED C',CAST('1/15/2020' AS DATE),CAST('6/3/2020' AS DATE),1.1,CAST('4/2/2021' AS DATE)),
|
||||
('KUBE0001 - KUBE PAK CORPORATION',CAST('1/16/2020' AS DATE),CAST('6/3/2020' AS DATE),874.5,CAST('4/2/2021' AS DATE)),
|
||||
('FRYS0001 - FRYSVILLE FARMS (MILES FRY)',CAST('1/17/2020' AS DATE),CAST('6/3/2020' AS DATE),1857.6,CAST('4/2/2021' AS DATE)),
|
||||
('PRIN0001 - PRINCE CORPORATION',CAST('1/20/2020' AS DATE),CAST('6/3/2020' AS DATE),211.16,CAST('4/2/2021' AS DATE)),
|
||||
('GALE0006 - GALES GARDEN CENTER',CAST('1/20/2020' AS DATE),CAST('6/3/2020' AS DATE),19.47,CAST('4/2/2021' AS DATE)),
|
||||
('CKGR0004 - CK GREENHOUSES',CAST('1/20/2020' AS DATE),CAST('6/3/2020' AS DATE),4442.04,CAST('4/2/2021' AS DATE)),
|
||||
('MATS0002 - MATSUDAS OF SACRAMENTO',CAST('1/20/2020' AS DATE),CAST('6/3/2020' AS DATE),57056.64,CAST('5/2/2021' AS DATE)),
|
||||
('GRIF0005 - GRIFFIN GREENHOUSE - AUBURN',CAST('1/21/2020' AS DATE),CAST('6/3/2020' AS DATE),7399.49,CAST('5/2/2021' AS DATE)),
|
||||
('GRIF0014 - GRIFFIN GREENHOUSE - MORGANTWN',CAST('1/21/2020' AS DATE),CAST('6/3/2020' AS DATE),16031.53,CAST('5/2/2021' AS DATE)),
|
||||
('GRIF0004 - GRIFFIN GREENHOUSE - CHESHIRE',CAST('1/21/2020' AS DATE),CAST('6/3/2020' AS DATE),6166.24,CAST('5/2/2021' AS DATE)),
|
||||
('GROW0001 - GROWER DIRECT FARMS INC',CAST('1/24/2020' AS DATE),CAST('6/3/2020' AS DATE),1199.44,CAST('5/2/2021' AS DATE)),
|
||||
('CHAR0009 - CHARLES SPITZNER',CAST('1/24/2020' AS DATE),CAST('6/3/2020' AS DATE),7350,CAST('5/2/2021' AS DATE)),
|
||||
('KURT0018 - KURTZ FARMS',CAST('1/27/2020' AS DATE),CAST('6/3/2020' AS DATE),3689.69,CAST('5/2/2021' AS DATE)),
|
||||
('PARK0004 - PARKS BROTHERS FARMS',CAST('1/27/2020' AS DATE),CAST('6/3/2020' AS DATE),2250,CAST('5/2/2021' AS DATE)),
|
||||
('JAYW0001 - JAY W GUILD',CAST('1/28/2020' AS DATE),CAST('6/3/2020' AS DATE),8388.9,CAST('5/2/2021' AS DATE)),
|
||||
('VAND0001 - VANDENBERG BULB CO INC',CAST('1/29/2020' AS DATE),CAST('6/3/2020' AS DATE),70.35,CAST('5/2/2021' AS DATE)),
|
||||
('LITT0001 - LITTLE MOUNTAIN GREENHOUSES U',CAST('2/3/2020' AS DATE),CAST('6/3/2020' AS DATE),61.92,CAST('5/2/2021' AS DATE)),
|
||||
('JIFF0006 - JIFFY PRODUCTS OF AMERICA',CAST('2/4/2020' AS DATE),CAST('6/3/2020' AS DATE),16652.25,CAST('5/2/2021' AS DATE)),
|
||||
('RSGR0004 - RS GROWERS SUPPLY INC',CAST('2/6/2020' AS DATE),CAST('6/3/2020' AS DATE),0.02,CAST('5/2/2021' AS DATE)),
|
||||
('SCHL0001 - SCHLEGEL GRHSE',CAST('2/6/2020' AS DATE),CAST('6/3/2020' AS DATE),3646.58,CAST('5/2/2021' AS DATE)),
|
||||
('VANW0013 - VAN WINGERDEN GREENHOUSE LLC',CAST('2/7/2020' AS DATE),CAST('6/3/2020' AS DATE),537.3,CAST('5/2/2021' AS DATE)),
|
||||
('RITC0001 - RITCHIE FEED SEED C',CAST('2/7/2020' AS DATE),CAST('6/3/2020' AS DATE),179.46,CAST('5/2/2021' AS DATE)),
|
||||
('LONG0002 - LONGFELLOWS GREENHOUSE',CAST('2/7/2020' AS DATE),CAST('6/3/2020' AS DATE),5536.48,CAST('5/2/2021' AS DATE)),
|
||||
('AAPL0001 - AA PLANTS INC',CAST('2/7/2020' AS DATE),CAST('6/3/2020' AS DATE),3843,CAST('5/2/2021' AS DATE)),
|
||||
('BFGS0004 - BFG SUPPLY - GRAND RAPIDS(W04)',CAST('2/10/2020' AS DATE),CAST('6/3/2020' AS DATE),553.3,CAST('5/2/2021' AS DATE)),
|
||||
('KALA0002 - KALAMAZOO FLOWER GROUP LLC',CAST('2/10/2020' AS DATE),CAST('6/3/2020' AS DATE),502.7,CAST('5/2/2021' AS DATE)),
|
||||
('DOIT0079 - DO IT BEST CORP',CAST('2/10/2020' AS DATE),CAST('6/3/2020' AS DATE),494.4,CAST('5/2/2021' AS DATE)),
|
||||
('DOIT0004 - DO IT BEST CORP',CAST('2/11/2020' AS DATE),CAST('6/3/2020' AS DATE),82.4,CAST('5/2/2021' AS DATE)),
|
||||
('GRIF0002 - GRIFFIN GREENHOUSE - SCHENECTA',CAST('2/12/2020' AS DATE),CAST('6/3/2020' AS DATE),376.6,CAST('5/2/2021' AS DATE)),
|
||||
('NATU0027 - NATURALLY BEAUTIFUL PLANT PROD',CAST('2/12/2020' AS DATE),CAST('6/3/2020' AS DATE),31636.8,CAST('5/2/2021' AS DATE)),
|
||||
('FARM0012 - FARMETTE GARDENS',CAST('2/13/2020' AS DATE),CAST('6/3/2020' AS DATE),6028.37,CAST('5/2/2021' AS DATE)),
|
||||
('SPOR0002 - SPORTEL GREENHOUSE',CAST('2/13/2020' AS DATE),CAST('6/3/2020' AS DATE),3728.54,CAST('5/2/2021' AS DATE)),
|
||||
('ARET0001 - ARETT SALES - BRISTOL',CAST('2/14/2020' AS DATE),CAST('6/3/2020' AS DATE),266.62,CAST('5/2/2021' AS DATE)),
|
||||
('GREE0005 - GREEN ISLAND DISTRIBUTORS INC.',CAST('2/14/2020' AS DATE),CAST('6/3/2020' AS DATE),21.21,CAST('5/2/2021' AS DATE)),
|
||||
('FARM0001 - FARMERS COOPERATIVE ELEVATOR',CAST('2/17/2020' AS DATE),CAST('6/3/2020' AS DATE),495,CAST('5/2/2021' AS DATE)),
|
||||
('VANW0009 - VAN WINGERDEN INTERNATIONAL',CAST('2/17/2020' AS DATE),CAST('6/3/2020' AS DATE),908.6,CAST('5/2/2021' AS DATE)),
|
||||
('CIVA0001 - CIVANO NURSERY',CAST('2/18/2020' AS DATE),CAST('6/3/2020' AS DATE),50700,CAST('5/2/2021' AS DATE))
|
||||
) x(ship_cust_descr,order_date,ship_date,sales,revised)
|
||||
)
|
||||
,upd AS (
|
||||
UPDATE
|
||||
rlarp.osm_pool p
|
||||
SET
|
||||
ship_date = revised
|
||||
FROM
|
||||
move
|
||||
WHERE
|
||||
move.ship_cust_descr = p.ship_cust_descr
|
||||
AND move.order_date = p.order_date
|
||||
AND move.ship_date = p.ship_date
|
||||
AND p.ship_season = 2021
|
||||
RETURNING *
|
||||
)
|
||||
SELECT ship_month ,sum(value_usd) FROM upd group by ship_month;
|
||||
|
||||
UPDATE
|
||||
rlarp.osm_pool
|
||||
SET
|
||||
ship_month = gld.sspr || ' - ' || to_char(ship_date,'FMMon')
|
||||
,ship_season = gld.ssyr
|
||||
,fspr = gld.fspr
|
||||
FROM
|
||||
rlarp.gld gld
|
||||
WHERE
|
||||
ship_date BETWEEN gld.sdat AND gld.edat
|
||||
RETURNING *;
|
||||
--ROLLBACK;
|
||||
|
||||
|
||||
--SELECT
|
||||
-- move.revised
|
||||
-- ,sum(sales)
|
||||
-- ,sum(value_usd)
|
||||
--FROM
|
||||
-- rlarp.osm_pool p
|
||||
-- INNER JOIN move ON
|
||||
-- move.ship_cust_descr = p.ship_cust_descr
|
||||
-- AND move.order_date = p.order_date
|
||||
-- AND move.ship_date = p.ship_date
|
||||
--WHERE
|
||||
-- ship_season = 2021
|
||||
--GROUP BY
|
||||
-- move.revised
|
13
build/readme.md
Normal file
13
build/readme.md
Normal file
@ -0,0 +1,13 @@
|
||||
Build A New Forecast
|
||||
------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
* overwrite osmf: review dates and execute build_forecase.sql
|
||||
* the product and customer attributes are wiped, they will need to be snapped (itemm must come first)
|
||||
1. snap_itemm.sql
|
||||
2. snap_customer.sql
|
||||
3. snap_cost_current.sql
|
||||
4. snap_fx.sql (if necessary)
|
||||
5. offline/last_price.sql (if necessary)
|
||||
* build the pool for the more limited UI data set: build_pool.sql
|
||||
* copy the pool to osmfs_dev from inclusion in the osm_stack and reporting: convert_pool_all.sql
|
||||
* refresh osm_stack_refresh() to integrate into reporting
|
8
build/rebuild_forecast.sh
Normal file
8
build/rebuild_forecast.sh
Normal file
@ -0,0 +1,8 @@
|
||||
$PG -f build_forecast.sql
|
||||
$PG -f snap_itemm.sql
|
||||
$PG -f snap_cost_current.sql
|
||||
$PG -f snap_customer.sql
|
||||
$PG -f snap_fx.sql
|
||||
$PG -f build_pool.sql
|
||||
$PG -f convert_pool_all.sql
|
||||
$PG -c "CALL rlarp.osm_stack_refresh();"
|
33
build/rec_act.sql
Normal file
33
build/rec_act.sql
Normal file
@ -0,0 +1,33 @@
|
||||
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
|
7
build/round_pool.sql
Normal file
7
build/round_pool.sql
Normal file
@ -0,0 +1,7 @@
|
||||
UPDATE rlarp.osm_pool
|
||||
SET
|
||||
value_loc = round(value_loc,2),
|
||||
value_usd = round(value_usd,2),
|
||||
cost_usd = round(cost_usd,2),
|
||||
cost_loc = round(cost_loc,2),
|
||||
units = round(units,2);
|
43
build/snap_cost_current.sql
Normal file
43
build/snap_cost_current.sql
Normal file
@ -0,0 +1,43 @@
|
||||
BEGIN;
|
||||
|
||||
WITH
|
||||
plist AS (
|
||||
SELECT DISTINCT
|
||||
part
|
||||
,plnt
|
||||
FROM
|
||||
rlarp.osmf_dev
|
||||
-----prevent a list of fake parts
|
||||
INNER JOIN lgdat.stka ON
|
||||
v6part = part
|
||||
AND v6plnt = plnt
|
||||
)
|
||||
,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.osmf_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;
|
||||
--AND version = 'b21';
|
||||
|
||||
commit;
|
44
build/snap_cust_osmfs.sql
Normal file
44
build/snap_cust_osmfs.sql
Normal file
@ -0,0 +1,44 @@
|
||||
UPDATE
|
||||
RLARP.OSMFS_DEV S
|
||||
SET
|
||||
DSM = CR.QUOTA_REP
|
||||
FROM
|
||||
(
|
||||
SELECT DISTINCT
|
||||
VERSION,
|
||||
COALESCE(GLEC,'') GLEC,
|
||||
COALESCE(MING,'') 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
|
||||
-- COALESCE(GLEC,'') IS NOT NULL
|
||||
) CR
|
||||
WHERE
|
||||
CR.VERSION = S.VERSION
|
||||
AND CR.GLEC = COALESCE(S.GLEC,'')
|
||||
AND CR.MING = COALESCE(S.MING,'')
|
||||
AND CR.BILL_CUST = S.BILL_CUST
|
||||
AND CR.SHIP_CUST = S.SHIP_CUST
|
||||
AND COALESCE(S.DSM,'') <> CR.QUOTA_REP;
|
||||
|
70
build/snap_cust_pool.sql
Normal file
70
build/snap_cust_pool.sql
Normal file
@ -0,0 +1,70 @@
|
||||
BEGIN;
|
||||
|
||||
--SELECT dsm, director, quota_rep_descr, billto_group, shipto_group, sum(value_usd ), count(*) from rlarp.osm_pool where order_season = 2021 group by dsm, director, quota_rep_descr, billto_group, shipto_group;
|
||||
|
||||
UPDATE
|
||||
rlarp.osm_pool o
|
||||
SET
|
||||
chan = CASE SUBSTRING(b.bvclas,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(s.bvclas,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(b.bvclas,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(s.bvclas,2,3)
|
||||
WHEN 'DIS' THEN 'WHS'
|
||||
ELSE CASE SUBSTRING(s.bvclas,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
|
||||
END
|
||||
WHEN 'MAS' THEN 'RMN'
|
||||
WHEN 'NAT' THEN 'RMN'
|
||||
ELSE CASE SUBSTRING(s.bvclas,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
|
||||
END,
|
||||
dsm =
|
||||
------------quota rep column--------------
|
||||
CASE WHEN COALESCE(substring(ming_descr,1,3),'') = '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(o.segm,'') = 'Retail' AND COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust),'') <> ''
|
||||
THEN
|
||||
(SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust)
|
||||
--default logic
|
||||
ELSE
|
||||
CASE SUBSTR(b.bvclas,2,3)
|
||||
WHEN 'DIS' THEN s.bvsalm
|
||||
ELSE b.bvsalm
|
||||
END
|
||||
END
|
||||
END,
|
||||
billto_group = CASE b.bvadr6 WHEN '' THEN b.bvname ELSE b.bvadr6 END,
|
||||
shipto_group = CASE s.bvadr6 WHEN '' THEN s.bvname ELSE s.bvadr6 END
|
||||
FROM
|
||||
lgdat.cust b,
|
||||
lgdat.cust s
|
||||
WHERE
|
||||
b.bvcust = rtrim(substring(o.bill_cust_descr,1,8))
|
||||
AND s.bvcust = rtrim(substring(o.ship_cust_descr,1,8));
|
||||
--BEGIN;
|
||||
|
||||
UPDATE
|
||||
rlarp.osm_pool o
|
||||
SET
|
||||
quota_rep_descr = c.a30
|
||||
,director = COALESCE(Q.DIR,'Other')
|
||||
FROM
|
||||
lgdat.code c
|
||||
,rlarp.qrh q
|
||||
WHERE
|
||||
LTRIM(RTRIM(c.a9)) = o.dsm
|
||||
and c.a2 = 'MM'
|
||||
AND q.qr = LTRIM(RTRIM(c.a9));
|
||||
|
||||
COMMIT;
|
||||
--ROLLBACK;
|
180
build/snap_customer.sql
Normal file
180
build/snap_customer.sql
Normal file
@ -0,0 +1,180 @@
|
||||
----------------------------SET BILL-TO REP------------------------------------
|
||||
|
||||
UPDATE
|
||||
RLARP.OSMF_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.OSMF_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.OSMF_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.OSMF_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.osmF_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.OSMF_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.OSMF_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;
|
10
build/snap_fx.sql
Normal file
10
build/snap_fx.sql
Normal file
@ -0,0 +1,10 @@
|
||||
------------update fx rates-----------------------------------------------------------------
|
||||
---only apply fx to forecast orders----
|
||||
UPDATE rlarp.osmf_dev SET r_rate = .7900 WHERE r_currency = 'CA' AND odate >= '2021-04-08';
|
||||
UPDATE rlarp.osmf_dev SET r_rate = 1.0000 WHERE r_currency = 'US' AND odate >= '2021-04-08';
|
||||
UPDATE rlarp.osmf_dev SET c_rate = .7900 WHERE c_currency = 'CA' AND odate >= '2021-04-08';
|
||||
UPDATE rlarp.osmf_dev SET c_rate = 1.0000 WHERE c_currency = 'US' AND odate >= '2021-04-08';
|
||||
--UPDATE rlarp.osm_pool SET r_rate = .7900 WHERE r_currency = 'CA' AND version = 'b22';
|
||||
--UPDATE rlarp.osm_pool SET value_usd = value_loc * r_rate WHERE r_currency = 'CA' AND version = 'b22';
|
||||
--UPDATE rlarp.osm_pool SET c_rate = .7900 WHERE c_currency = 'CA' AND version = 'b22';
|
||||
--UPDATE rlarp.osm_pool SET cost_usd = cost_loc * c_rate WHERE c_currency = 'CA' AND version = 'b22';
|
28
build/snap_itemm.sql
Normal file
28
build/snap_itemm.sql
Normal file
@ -0,0 +1,28 @@
|
||||
UPDATE
|
||||
RLARP.OSMF_DEV O
|
||||
SET
|
||||
STYC = M.STLC
|
||||
,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
|
64
build/snap_itemm_pool.sql
Normal file
64
build/snap_itemm_pool.sql
Normal file
@ -0,0 +1,64 @@
|
||||
BEGIN;
|
||||
|
||||
WITH
|
||||
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)
|
||||
)
|
||||
,fin AS (
|
||||
SELECT DISTINCT
|
||||
o.part
|
||||
,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
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
LEFT OUTER JOIN rlarp.itemm i ON
|
||||
i.item = o.part
|
||||
LEFT OUTER JOIN seg ON
|
||||
seg.glec = i.glec
|
||||
)
|
||||
UPDATE
|
||||
rlarp.osm_pool o
|
||||
SET
|
||||
part_descr = fin.part_descr
|
||||
,part_group = fin.part_group
|
||||
,branding = fin.branding
|
||||
,majg_descr = fin.majg_descr
|
||||
,ming_descr = fin.ming_descr
|
||||
,majs_descr = fin.majs_descr
|
||||
,mins_descr = fin.mins_descr
|
||||
,segm = fin.segm
|
||||
,substance = fin.substance
|
||||
FROM
|
||||
fin
|
||||
WHERE
|
||||
fin.part = o.part;
|
||||
|
||||
COMMIT;
|
413
build/swap_fake_parts.sql
Normal file
413
build/swap_fake_parts.sql
Normal file
@ -0,0 +1,413 @@
|
||||
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;
|
||||
*/
|
47
build/temp.sql
Normal file
47
build/temp.sql
Normal file
@ -0,0 +1,47 @@
|
||||
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
|
63
build/tots.sql
Normal file
63
build/tots.sql
Normal file
@ -0,0 +1,63 @@
|
||||
SELECT
|
||||
oseas,
|
||||
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,
|
||||
version,
|
||||
iter,
|
||||
sum(fb_val_loc) value_loc
|
||||
FROM
|
||||
rlarp.osmfs_dev o
|
||||
GROUP BY
|
||||
oseas,
|
||||
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'),
|
||||
version,
|
||||
iter
|
||||
ORDER BY
|
||||
oseas asc,
|
||||
order_month asc
|
||||
|
||||
|
||||
------------------------------------------short ships-------------------------------------
|
||||
SELECT
|
||||
version,
|
||||
iter,
|
||||
oseas,
|
||||
SUM(FB_VAL_LOC::numeric *r_rate::Numeric)
|
||||
FROM
|
||||
RLARP.osmf_dev
|
||||
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,
|
||||
oseas
|
||||
|
||||
select distinct version from rlarp.osm_pool
|
||||
|
||||
|
||||
|
||||
|
||||
SELECT
|
||||
oseas,
|
||||
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,
|
||||
r_currency,
|
||||
r_rate,
|
||||
sum(fb_val_loc) value_loc
|
||||
FROM
|
||||
rlarp.osmf_dev o
|
||||
WHERE
|
||||
oseas >= 2020
|
||||
--AND fs_line = '41010'
|
||||
--AND odate < '2020-04-01'
|
||||
GROUP BY
|
||||
oseas,
|
||||
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'),
|
||||
r_currency,
|
||||
r_rate
|
||||
--glec
|
||||
ORDER BY
|
||||
oseas asc,
|
||||
order_month asc
|
14
change_log.sql
Normal file
14
change_log.sql
Normal file
@ -0,0 +1,14 @@
|
||||
WITH l AS (
|
||||
SELECT DISTINCT logid FROM rlarp.osm_pool
|
||||
)
|
||||
SELECT
|
||||
doc->>'user' as user,
|
||||
(doc->>'stamp')::timestamptz stamp,
|
||||
doc->>'type' as type,
|
||||
CASE WHEN logid IS NULL THEN 'undone' ELSE '' END flag,
|
||||
doc->>'tag', doc->>'message',
|
||||
doc->'scenario'->>'quota_rep_descr' dsm
|
||||
FROM
|
||||
rlarp.osm_log
|
||||
LEFT OUTER JOIN l ON logid = id
|
||||
LIMIT 1000;
|
126
columns.md
Normal file
126
columns.md
Normal file
@ -0,0 +1,126 @@
|
||||
|column |alt_name |osmp_dev|osm_fcpool|osmp_source|osm_stack_retain|ui |revised_pool|
|
||||
|---------------|--------------|--------|----------|-----------|----------------|---|------------|
|
||||
|ddord# | |x | |null |x | | |
|
||||
|dditm# | |x | |null | | | |
|
||||
|fgbol# | |x | |null | | | |
|
||||
|fgent# | |x | |null | | | |
|
||||
|diinv# | |x | |null |x | | |
|
||||
|dilin# | |x | |null | | | |
|
||||
|quoten | |x | |null |x | | |
|
||||
|quotel | |x | |null | | | |
|
||||
|dcodat | |x | |null | | | |
|
||||
|ddqdat | |x | |null | | | |
|
||||
|dcmdat | |x | |null | | | |
|
||||
|fesdat | |x | |null | | | |
|
||||
|dhidat | |x | |null | | | |
|
||||
|fesind | |x | |null | | | |
|
||||
|dhpost | |x | |null | | | |
|
||||
|fspr | |x | |forecast | | |x |
|
||||
|ddqtoi | |x | |forecast | | |x |
|
||||
|ddqtsi | |x | |null | | | |
|
||||
|fgqshp | |x | |null | | | |
|
||||
|diqtsh | |x | |null | | | |
|
||||
|diext | |x | |null | | | |
|
||||
|ditdis | |x | |null | | | |
|
||||
|discj | |x | |null | | | |
|
||||
|dhincr | |x | |forecast | | |x |
|
||||
|plnt | |x | |forecast |x | |x |
|
||||
|promo | |x | |forecast |x |x |x |
|
||||
|return_reas | |x | |null | | | |
|
||||
|terms | |x | |forecast | | |x |
|
||||
|custpo | |x | |null | | | |
|
||||
|remit_to | |x | |forecast | | |x |
|
||||
|bill_class | |x | |cust |x | | |
|
||||
|bill_cust | |x | |forecast | | |x |
|
||||
|bill_cust_descr| | | |ui_only | |x |x |
|
||||
|bill_rep | |x | |cust | | | |
|
||||
|bill_terr | |x | |cust | | | |
|
||||
|ship_class | |x | |cust |x | | |
|
||||
|ship_cust | |x | |forecast |x | |x |
|
||||
|ship_cust_descr| | | |ui_only | |x |x |
|
||||
|ship_rep | |x | |cust | | | |
|
||||
|ship_terr | |x | |cust | | | |
|
||||
|dsm |quota_rep |x | |forecast |x |x |x |
|
||||
|quota_rep_descr| | | |ui_only | |x |x |
|
||||
|account |billto_group |x | |cust |x |x |x |
|
||||
|shipgrp |shipto_group |x | |cust |x |x |x |
|
||||
|geo | |x | |cust |x | | |
|
||||
|chan | |x | |cust |x |x |x |
|
||||
|chansub |mod_chan |x | |cust |x |x |x |
|
||||
|chanretail |mod_chansub | | |ui_only | |x |x |
|
||||
|orig_ctry | |x | |plnt | | | |
|
||||
|orig_prov | |x | |plnt | | | |
|
||||
|orig_post | |x | |plnt | | | |
|
||||
|bill_ctry | |x | |cust |x | | |
|
||||
|bill_prov | |x | |cust |x | | |
|
||||
|bill_post | |x | |cust |x | | |
|
||||
|dest_ctry | |x | |cust |x | | |
|
||||
|dest_prov | |x | |cust |x | | |
|
||||
|dest_post | |x | |cust |x | | |
|
||||
|part | |x | |forecast |x | |x |
|
||||
|part_descr | | | |ui_only | |x |x |
|
||||
|part_group | | | |ui_only | |x |x |
|
||||
|styc | |x | |itemm |x | | |
|
||||
|colc |color |x | |itemm |x | | |
|
||||
|colgrp | |x | |itemm |x | | |
|
||||
|coltier | |x | |itemm |x | | |
|
||||
|colstat | |x | |itemm | | | |
|
||||
|sizc | |x | |itemm |x | | |
|
||||
|pckg | |x | |itemm |x | | |
|
||||
|kit | |x | |itemm |x | | |
|
||||
|brnd |branding |x | |itemm |x |x |x |
|
||||
|majg | |x | |itemm |x | | |
|
||||
|majgd |majg_descr | | |ui_only | |x |x |
|
||||
|ming | |x | |itemm |x | | |
|
||||
|mingd |ming_descr | | |ui_only | |x |x |
|
||||
|majs | |x | |itemm |x | | |
|
||||
|majsd |majs_descr | | |ui_only | |x |x |
|
||||
|mins | |x | |itemm |x | | |
|
||||
|minsd |mins_descr | | |ui_only | |x |x |
|
||||
|gldco |ord_gldc |x | |itemm | | | |
|
||||
|gldc | |x | |itemm | | | |
|
||||
|glec | |x | |itemm |x | | |
|
||||
|segm | | | |ui_only | |x |x |
|
||||
|harm | |x | |itemm | | | |
|
||||
|clss | |x | |itemm |x | | |
|
||||
|brand | |x | |itemm | | | |
|
||||
|assc | |x | |itemm | | | |
|
||||
|ddunit | |x | |itemm | | | |
|
||||
|unti |units |x | |itemm | | | |
|
||||
|lbs | |x | |itemm |x | | |
|
||||
|plt | |x | |punit |x | | |
|
||||
|plcd | |x | |iprcbhc |x | | |
|
||||
|fs_line | |x | |forecast |x | |x |
|
||||
|r_currency | |x | |forecast |x | |x |
|
||||
|r_rate | |x | |forecast |x | |x |
|
||||
|c_currency | |x | |forecast |x | |x |
|
||||
|c_rate | |x | |forecast |x | |x |
|
||||
|fb_qty | |x | |forecast |x |x |x |
|
||||
|fb_val_loc |value_loc |x | |forecast |x |x |x |
|
||||
|value_usd | | | |ui_only | |x |x |
|
||||
|fb_val_loc_dis | |x | |null | | | |
|
||||
|fb_val_loc_qt | |x | |null |x | | |
|
||||
|fb_val_loc_pl | |x | |pricel |x | | |
|
||||
|fb_val_loc_tar | |x | |target |x | | |
|
||||
|fb_cst_loc |cost_loc |x | |forecast |x |x |x |
|
||||
|cost_usd | | | |ui_only | |x |x |
|
||||
|fb_cst_loc_cur | |x | |icstx |x | | |
|
||||
|fb_cst_loc_fut | |x | |icstx | | | |
|
||||
|calc_status | |x | |forecast |x | |x |
|
||||
|flag | |x | |forecast |x | |x |
|
||||
|odate |orderdate |x | |forecast |x |x |x |
|
||||
|order_month | | | |ui_only | |x |x |
|
||||
|oseas |order_season |x | |forecast |x |x |x |
|
||||
|rdate |requestdate |x | |forecast |x |x |x |
|
||||
|request_month | | | |ui_only | |x |x |
|
||||
|rseas |request_season|x | |forecast |x |x |x |
|
||||
|sdate |shipdate |x | |forecast |x |x |x |
|
||||
|ship_month | | | |ui_only | |x |x |
|
||||
|sseas |ship_season |x | |forecast |x |x |x |
|
||||
|version | |x | |forecast | |x |x |
|
||||
|iter | |x | |forecast | |x |x |
|
||||
|log | |x | |forecast | |x |x |
|
||||
|comment | | | |ui_only | |x |x |
|
||||
|iterdet | | | |forecast | | |x |
|
||||
|iterdef | | | |forecast | | |x |
|
||||
|director_descr | | | |forecast | | |x |
|
4
create_certs.sh
Normal file
4
create_certs.sh
Normal file
@ -0,0 +1,4 @@
|
||||
openssl genrsa -out key.pem
|
||||
openssl req -new -key key.pem -out csr.pem
|
||||
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
|
||||
rm csr.pem
|
13
forecast_api.service
Normal file
13
forecast_api.service
Normal file
@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=forecast_api
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/node //opt/forecast_api/index.js
|
||||
Restart=always
|
||||
User=fc_api
|
||||
Environemnt=NODE_ENV=production
|
||||
WorkingDirectory=//opt/forecast_api/
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
439
index.js
439
index.js
@ -18,8 +18,8 @@ var options = {
|
||||
passprase: []
|
||||
};
|
||||
|
||||
https.createServer(options,server).listen(process.env.nodeport, () => {
|
||||
console.log('started on '+ process.env.nodeport)
|
||||
https.createServer(options, server).listen(process.env.nodeport, () => {
|
||||
console.log('started on ' + process.env.nodeport)
|
||||
});
|
||||
//server.listen(3000, () => console.log('started'))
|
||||
|
||||
@ -34,7 +34,7 @@ var Postgres = new pg.Client({
|
||||
});
|
||||
Postgres.connect();
|
||||
|
||||
Postgres.FirstRow = function (inSQL, args, inResponse) {
|
||||
Postgres.FirstRow = function(inSQL, args, inResponse) {
|
||||
Postgres.query(inSQL, args, (err, res) => {
|
||||
if (err === null) {
|
||||
inResponse.json(res.rows[0]);
|
||||
@ -55,14 +55,14 @@ server.get('/pgbadger', (req, res) => res.sendFile(process.env.wd + 'logs.html')
|
||||
|
||||
server.get('/totals', (req, res) => res.sendFile(process.env.wd + 'totals.log'))
|
||||
|
||||
server.get('/test_sql', function(req, res){
|
||||
server.get('/test_sql', function(req, res) {
|
||||
var path = './route_meta/scenario_package.sql'
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
res.send(arg)
|
||||
};
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
callback(err);
|
||||
@ -70,21 +70,22 @@ server.get('/test_sql', function(req, res){
|
||||
});
|
||||
});
|
||||
|
||||
server.get('/get_pool', bodyParser.json(), function (req, res) {
|
||||
server.get('/get_pool', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var args = [req.body.quota_rep];
|
||||
var path = './route_sql/get_pool.sql';
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
console.log(new Date().toISOString() + "-------------------------get pool:----------------------------");
|
||||
console.log(req.body.quota_rep);
|
||||
sql = sql.replace("rep_replace",req.body.quota_rep);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
sql = sql.replace("rep_replace", req.body.quota_rep);
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -94,7 +95,7 @@ server.get('/get_pool', bodyParser.json(), function (req, res) {
|
||||
|
||||
})
|
||||
|
||||
server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
||||
server.get('/scenario_package', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -103,8 +104,8 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/scenario_package.sql';
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -112,7 +113,7 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
//parse request body into a where clause
|
||||
@ -126,14 +127,141 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
||||
console.log(new Date().toISOString() + "-------------------------get scenario:------------------------------")
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w)
|
||||
//execute the sql and send the result
|
||||
//console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w)
|
||||
//execute the sql and send the result
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
})
|
||||
|
||||
server.get('/list_changes', bodyParser.json(), function (req, res) {
|
||||
server.get('/swap_fit', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
var c = 1;
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/swap_fit.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;
|
||||
|
||||
//parse request body into a where clause
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
|
||||
//if there was no body sent, return with nothing
|
||||
if (c == 1) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------")
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("replace_new_mold", 'g'), req.body.new_mold);
|
||||
//execute the sql and send the result
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
})
|
||||
|
||||
server.post('/swap', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
var c = 1;
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/swap_post.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;
|
||||
|
||||
//parse request body into a where clause
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
|
||||
//if there was no body sent, return with nothing
|
||||
if (c == 1) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------")
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("swap_doc", 'g'), JSON.stringify(req.body.swap));
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
//execute the sql and send the result
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
})
|
||||
|
||||
server.post('/cust_swap', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
var c = 1;
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/swap_cust.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;
|
||||
|
||||
//parse request body into a where clause
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
|
||||
//if there was no body sent, return with nothing
|
||||
if (c == 1) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------")
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("swap_doc", 'g'), JSON.stringify(req.body.swap));
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
//execute the sql and send the result
|
||||
console.log(sql);
|
||||
//res.json(null);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
})
|
||||
|
||||
server.get('/list_changes', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -142,8 +270,8 @@ server.get('/list_changes', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/list_changes.sql';
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -151,20 +279,53 @@ server.get('/list_changes', bodyParser.json(), function (req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
console.log(new Date().toISOString() +"-------------------------list changes:------------------------------")
|
||||
console.log(new Date().toISOString() + "-------------------------list changes:------------------------------")
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("replace_user",'g'),JSON.stringify(req.body))
|
||||
sql = sql.replace(new RegExp("replace_user", 'g'), req.body.scenario.quota_rep_descr)
|
||||
//execute the sql and send the result
|
||||
//console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
})
|
||||
|
||||
server.post('/addmonth_v', 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) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -173,8 +334,8 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/addmonth_vd.sql';
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -182,7 +343,7 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
//buile where clause expression
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
@ -191,22 +352,23 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() +"-----------------------------add month volume:---------------------------------");
|
||||
console.log(new Date().toISOString() + "-----------------------------add month volume:---------------------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("scenario = target_scenario",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_increment",'g'),req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_month",'g'),req.body.month);
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("scenario = target_scenario", 'g'), w);
|
||||
sql = sql.replace(new RegExp("target_increment", 'g'), req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_month", 'g'), req.body.month);
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
console.log(sql)
|
||||
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) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -215,7 +377,7 @@ server.post('/addmonth_vp', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/addmonth_vupd.sql';
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
@ -224,23 +386,23 @@ server.post('/addmonth_vp', bodyParser.json(), function (req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() +"------------------add month volume and price:-------------------");
|
||||
console.log(new Date().toISOString() + "------------------add month volume and price:-------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_volume",'g'),req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_price",'g'),req.body.amount);
|
||||
sql = sql.replace(new RegExp("target_month",'g'),req.body.month);
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("target_volume", 'g'), req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_price", 'g'), req.body.amount);
|
||||
sql = sql.replace(new RegExp("target_month", 'g'), req.body.month);
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
}
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -249,7 +411,7 @@ server.post('/addmonth_vp', bodyParser.json(), function (req, res) {
|
||||
});
|
||||
})
|
||||
|
||||
server.post('/scale_v', bodyParser.json(), function (req, res) {
|
||||
server.post('/scale_v', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -258,7 +420,7 @@ server.post('/scale_v', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/scale_vd.sql';
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
@ -267,21 +429,21 @@ server.post('/scale_v', bodyParser.json(), function (req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() +"-----------------------scale volume:------------------------------");
|
||||
console.log(new Date().toISOString() + "-----------------------scale volume:------------------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
||||
sql = sql.replace(new RegExp("incr_qty",'g'),req.body.qty);
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("incr_qty", 'g'), req.body.qty);
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
}
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -290,7 +452,7 @@ server.post('/scale_v', bodyParser.json(), function (req, res) {
|
||||
});
|
||||
})
|
||||
|
||||
server.post('/scale_p', bodyParser.json(), function (req, res) {
|
||||
server.post('/scale_p', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -299,7 +461,7 @@ server.post('/scale_p', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/scale_pd.sql';
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
@ -308,21 +470,21 @@ server.post('/scale_p', bodyParser.json(), function (req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() +"--------------------scale price:-------------------");
|
||||
console.log(new Date().toISOString() + "--------------------scale price:-------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_increment",'g'),req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("target_increment", 'g'), req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
}
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -331,7 +493,7 @@ server.post('/scale_p', bodyParser.json(), function (req, res) {
|
||||
});
|
||||
})
|
||||
|
||||
server.post('/scale_vp', bodyParser.json(), function (req, res) {
|
||||
server.post('/scale_vp', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -340,7 +502,7 @@ server.post('/scale_vp', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/scale_vupd.sql';
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
@ -349,22 +511,22 @@ server.post('/scale_vp', bodyParser.json(), function (req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() +"--------------------scale volume & price:-------------------");
|
||||
console.log(new Date().toISOString() + "--------------------scale volume & price:-------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_vol",'g'),req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_prc",'g'),req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
}
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -373,7 +535,49 @@ server.post('/scale_vp', bodyParser.json(), function (req, res) {
|
||||
});
|
||||
})
|
||||
|
||||
server.post('/new_part', bodyParser.json(), function (req, res) {
|
||||
server.post('/scale_vp_sales', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
var c = 1;
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/scale_vupd.sql';
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
|
||||
if (c == 1) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "--------------------scale volume & price:-------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
}
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
server.post('/new_part', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -382,7 +586,7 @@ server.post('/new_part', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/new_part.sql';
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
@ -391,23 +595,23 @@ server.post('/new_part', bodyParser.json(), function (req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() +"--------------------new part:-------------------");
|
||||
console.log(new Date().toISOString() + "--------------------new part:-------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_vol",'g'),req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_prc",'g'),req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_request",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_request", 'g'), JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
}
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -416,7 +620,7 @@ server.post('/new_part', bodyParser.json(), function (req, res) {
|
||||
});
|
||||
})
|
||||
|
||||
server.post('/new_basket', bodyParser.json(), function (req, res) {
|
||||
server.post('/new_basket', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
@ -425,8 +629,9 @@ server.post('/new_basket', bodyParser.json(), function (req, res) {
|
||||
var args = [];
|
||||
var path = './route_sql/new_basket.sql';
|
||||
|
||||
var callback = function(arg){
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
req.body.scenario.iter.push("adj volume"); //intercept the request body and force in a "adj volume" at position 1, only a "copy" iteration is being used
|
||||
|
||||
({ c, w, d } = build_where(req, c, w, d, args));
|
||||
|
||||
@ -434,23 +639,23 @@ server.post('/new_basket', bodyParser.json(), function (req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() +"--------------------new basket:-------------------");
|
||||
console.log(new Date().toISOString() + "--------------------new basket:-------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_vol",'g'),req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_prc",'g'),req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_request",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
|
||||
sql = sql.replace(new RegExp("replace_request", 'g'), JSON.stringify(req.body));
|
||||
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
}
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data){
|
||||
if (!err){
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
@ -480,13 +685,11 @@ function build_where(req, c, w, d, args) {
|
||||
d = d + 1;
|
||||
}
|
||||
w = w + ")";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
w = w + i + " = '" + req.body.scenario[i] + "'";
|
||||
}
|
||||
args.push(req.body.scenario[i]);
|
||||
c = c + 1;
|
||||
}
|
||||
;
|
||||
};
|
||||
return { c, w, d };
|
||||
}
|
||||
|
@ -9,21 +9,20 @@ WITH
|
||||
target AS (select target_increment incr)
|
||||
,testv AS (
|
||||
SELECT
|
||||
sum(fb_qty) tot
|
||||
,sum(fb_qty) FILTER (WHERE iter = 'copy') base
|
||||
,COALESCE(sum(fb_qty) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpart
|
||||
,sum(fb_val_loc *r_rate) totsales
|
||||
,sum(fb_val_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
|
||||
,COALESCE(sum(fb_val_loc *r_rate) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpartsales
|
||||
sum(units) tot
|
||||
,sum(units) FILTER (WHERE iter = 'copy') base
|
||||
,COALESCE(sum(units) FILTER (WHERE module = 'new basket'),0) newpart
|
||||
,sum(value_loc *r_rate) totsales
|
||||
,sum(value_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
|
||||
,COALESCE(sum(value_loc *r_rate) FILTER (WHERE module = 'new basket'),0) newpartsales
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
|
||||
AND order_date <= ship_date
|
||||
)
|
||||
,flagv AS (
|
||||
SELECT
|
||||
@ -68,6 +67,7 @@ target AS (select target_increment incr)
|
||||
,to_char(N1FSYP,'FM0000') FSPR
|
||||
,N1SD01 SDAT
|
||||
,N1ED01 EDAT
|
||||
,daterange(n1sd01, n1ed01,'[]') drange
|
||||
,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
|
||||
@ -85,18 +85,18 @@ target AS (select target_increment incr)
|
||||
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)
|
||||
('01 - Jun',1,6,-1)
|
||||
,('02 - Jul',2,7,-1)
|
||||
,('03 - Aug',3,8,-1)
|
||||
,('04 - Sep',4,9,-1)
|
||||
,('05 - Oct',5,10,-1)
|
||||
,('06 - Nov',6,11,-1)
|
||||
,('07 - Dec',7,12,-1)
|
||||
,('08 - Jan',8,1,0)
|
||||
,('09 - Feb',9,2,0)
|
||||
,('10 - Mar',10,3,0)
|
||||
,('11 - Apr',11,4,0)
|
||||
,('12 - May',12,5,0)
|
||||
) x(m,s,cal,yr)
|
||||
)
|
||||
,alldates AS (
|
||||
@ -105,68 +105,68 @@ target AS (select target_increment incr)
|
||||
,terms
|
||||
,order_month
|
||||
,mseq.s seq
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
,sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) value_usd
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
LEFT OUTER JOIN mseq ON
|
||||
mseq.m = order_month
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
-----------------additional params-------------------
|
||||
AND version = 'b20'
|
||||
AND version = 'b21'
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
promo
|
||||
,terms
|
||||
,order_month
|
||||
,mseq.s
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
HAVING
|
||||
sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) <> 0
|
||||
)
|
||||
--select * from alldates
|
||||
,dom AS (
|
||||
SELECT
|
||||
extract(day FROM orderdate) dom
|
||||
extract(day FROM order_date) dom
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
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)---------------
|
||||
,mmix AS (
|
||||
SELECT
|
||||
to_char(orderdate,'Mon') _month
|
||||
to_char(order_date,'Mon') _month
|
||||
,seq
|
||||
,promo
|
||||
,sum(extract(day from orderdate)*value_usd) dom_wa
|
||||
--,requestdate-orderdate rlag
|
||||
,sum((requestdate-orderdate)*(value_usd)) rlag_wa
|
||||
--,shipdate - requestdate slag
|
||||
,sum((shipdate - requestdate)*(value_usd)) slag_wa
|
||||
,sum(extract(day from order_date)*value_usd) dom_wa
|
||||
--,request_date-order_date rlag
|
||||
,sum((request_date-order_date)*(value_usd)) rlag_wa
|
||||
--,ship_date - request_date slag
|
||||
,sum((ship_date - request_date)*(value_usd)) slag_wa
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
GROUP BY
|
||||
to_char(orderdate,'Mon')
|
||||
to_char(order_date,'Mon')
|
||||
,seq
|
||||
,promo
|
||||
--,extract(day from orderdate)
|
||||
--,requestdate-orderdate
|
||||
--,shipdate - requestdate
|
||||
--,extract(day from order_date)
|
||||
--,request_date-order_date
|
||||
--,ship_date - request_date
|
||||
)
|
||||
,targm AS (select s, m from mseq where m = 'target_month' )
|
||||
,mmixp AS (
|
||||
@ -255,20 +255,20 @@ SELECT
|
||||
,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(units,0)) units --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
|
||||
,sum(coalesce(value_loc,0)) value_loc --history value
|
||||
,sum(coalesce(value_loc_pl,0)) value_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
|
||||
,null::date order_date --history date mix
|
||||
,null::date request_date --history date mix
|
||||
,null::date ship_date --history date mix
|
||||
,null::date order_date --history
|
||||
,null::date adj_request_date --history
|
||||
,null::date ship_date --history
|
||||
---------------ui columns-------------------------
|
||||
,null::numeric order_season
|
||||
,null::text order_month
|
||||
@ -300,7 +300,7 @@ SELECT
|
||||
,null cost_usd
|
||||
,null units
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
@ -308,10 +308,10 @@ SELECT
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
plnt ---master data
|
||||
,terms
|
||||
@ -376,8 +376,8 @@ SELECT
|
||||
,scale AS (
|
||||
SELECT
|
||||
(SELECT incr::numeric FROM target) incr
|
||||
,(SELECT sum(fb_qty) FROM basemix) base
|
||||
,(SELECT incr::numeric FROM target)/(SELECT sum(fb_qty) FROM basemix) factor
|
||||
,(SELECT sum(units) FROM basemix) base
|
||||
,(SELECT incr::numeric FROM target)/(SELECT sum(units) FROM basemix) factor
|
||||
)
|
||||
,final AS (
|
||||
SELECT
|
||||
@ -441,20 +441,20 @@ SELECT
|
||||
,b.ddqtsi --0
|
||||
,b.fgqshp --0
|
||||
,b.diqtsh --0
|
||||
,b.fb_qty*s.factor*m.momix fb_qty
|
||||
,b.units*s.factor*m.momix units
|
||||
,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.value_loc*s.factor*m.momix value_loc
|
||||
,b.value_loc_pl*s.factor*m.momix value_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
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) order_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag request_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag ship_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) order_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_request_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag ship_date
|
||||
,'replace_version' "version" --calculated
|
||||
,'replace_source'||' volume' iter --calculated
|
||||
-----------------------ui columns--------------------------------
|
||||
@ -484,11 +484,11 @@ SELECT
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,(b.fb_val_loc*s.factor*m.momix)::numeric value_loc
|
||||
,(b.fb_val_loc*s.factor*m.momix*r_rate)::numeric value_usd
|
||||
,(b.value_loc*s.factor*m.momix)::numeric value_loc
|
||||
,(b.value_loc*s.factor*m.momix*r_rate)::numeric value_usd
|
||||
,(b.fb_cst_loc*s.factor*m.momix)::numeric cost_loc
|
||||
,(b.fb_cst_loc*s.factor*m.momix*c_rate)::numeric cost_usd
|
||||
,(b.fb_qty*s.factor*m.momix)::numeric units
|
||||
,(b.units*s.factor*m.momix)::numeric units
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN scale s
|
||||
@ -506,7 +506,7 @@ WHERE
|
||||
m._month = (SELECT _month FROM closest)
|
||||
)
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING *
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM final RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
406
offline/last_price.sql
Normal file
406
offline/last_price.sql
Normal file
@ -0,0 +1,406 @@
|
||||
--BEGIN;
|
||||
|
||||
WITH
|
||||
------------------goal price increases---------------------
|
||||
incr AS (
|
||||
SELECT * FROM (VALUES
|
||||
('110','PP','B',0.25),
|
||||
('110','PP','T',0.25),
|
||||
('110','PP','L',0.4),
|
||||
('110','PP','M',0.4),
|
||||
('110','PP','P',0.4),
|
||||
('110','PP','C',0.4),
|
||||
('210','PE','B',0.25),
|
||||
('210','PE','T',0.25),
|
||||
('210','PE','L',0.25),
|
||||
('210','PE','M',0.25),
|
||||
('210','PE','P',0.25),
|
||||
('210','PE','C',0.25),
|
||||
('310','PE','B',0.15),
|
||||
('310','PE','T',0.25),
|
||||
('310','PE','L',0.25),
|
||||
('310','PE','M',0.25),
|
||||
('310','PE','P',0.25),
|
||||
('310','PE','C',0.25),
|
||||
('310','PP','B',0.13),
|
||||
('310','PP','T',0.16),
|
||||
('310','PP','L',0.16),
|
||||
('310','PP','M',0.16),
|
||||
('310','PP','P',0.16),
|
||||
('310','PP','C',0.16),
|
||||
('310','PS','B',0.13),
|
||||
('310','PS','T',0.16),
|
||||
('310','PS','L',0.16),
|
||||
('310','PS','M',0.16),
|
||||
('310','PS','P',0.16),
|
||||
('310','PS','C',0.16),
|
||||
('320','PE','B',0.25),
|
||||
('320','PE','T',0.25),
|
||||
('320','PE','L',0.25),
|
||||
('320','PE','M',0.25),
|
||||
('320','PE','P',0.25),
|
||||
('320','PE','C',0.25),
|
||||
('320','PP','B',0.25),
|
||||
('320','PP','T',0.25),
|
||||
('320','PP','L',0.25),
|
||||
('320','PP','M',0.25),
|
||||
('320','PP','P',0.25),
|
||||
('320','PP','C',0.25),
|
||||
('910','PE','B',0.15),
|
||||
('910','PE','D',0.25),
|
||||
('910','PE','F',0.25),
|
||||
('910','PP','B',0.15),
|
||||
('910','PP','D',0.25),
|
||||
('910','PP','F',0.25),
|
||||
('910','PS','B',0.15),
|
||||
('910','','B',0.15),
|
||||
('910','','D',0.25),
|
||||
('910','','F',0.25),
|
||||
('910','','T',0.25),
|
||||
('910','','L',0.25),
|
||||
('910','','M',0.25),
|
||||
('910','','P',0.25),
|
||||
('910','','C',0.25),
|
||||
('910','PS','D',0.25),
|
||||
('910','PS','F',0.25),
|
||||
('610','','B',0.02),
|
||||
('610','','S',0.02),
|
||||
('610','','W',0.02)
|
||||
) x(MAJG,ASSC,COLTIER,RATE)
|
||||
)
|
||||
------------carve out pricing baseline data--------------------
|
||||
,p AS (
|
||||
SELECT
|
||||
o.part
|
||||
,o.styc||'.'||o.colgrp||substring(o.sizc,1,3) product
|
||||
,o.glec
|
||||
,o.styc
|
||||
,o.majg
|
||||
,i.assc
|
||||
,o.coltier
|
||||
,o.colgrp
|
||||
,o.sizc
|
||||
,i.suffix
|
||||
,substring(o.chan,1,1) chgrp
|
||||
,o.account
|
||||
,o.shipgrp
|
||||
,o.fb_qty units
|
||||
,o.fb_val_loc*r_rate val_usd
|
||||
,round(o.fb_val_loc/o.fb_qty,10) AS price
|
||||
,o.odate
|
||||
,o.oseas
|
||||
,row_number() OVER (PARTITION BY o.styc||'.'||o.colgrp||substring(o.sizc,1,3),o.account, o.shipgrp ORDER BY o.odate DESC) rn
|
||||
FROM
|
||||
rlarp.osm_dev o
|
||||
INNER JOIN rlarp.itemmv i ON
|
||||
i.item = o.part
|
||||
WHERE
|
||||
---exclude R&A's
|
||||
o.fs_line = '41010'
|
||||
---exclude canceled orders
|
||||
AND o.calc_status <> 'CANCELED'
|
||||
---exclude quotes
|
||||
AND o.version = 'ACTUALS'
|
||||
---only finished goods
|
||||
AND substring(o.glec,1,1) <= '2'
|
||||
---exclude blank parts
|
||||
AND COALESCE(o.part,'') <> ''
|
||||
---must have a quantity
|
||||
AND o.fb_qty <> 0
|
||||
---must have a price
|
||||
AND o.fb_val_loc <> 0
|
||||
---must come from and order
|
||||
AND o.odate IS NOT NULL
|
||||
---exclude samples
|
||||
AND o.bill_class <> 'SALE'
|
||||
---only use recent history
|
||||
AND o.oseas >= 2020
|
||||
---only for direct and drop
|
||||
--AND o.chan IN ('DIR','DRP')
|
||||
ORDER BY
|
||||
o.part
|
||||
,o.styc
|
||||
,o.coltier
|
||||
,o.sizc
|
||||
,i.suffix
|
||||
,o.account
|
||||
,o.shipgrp
|
||||
,o.odate DESC
|
||||
)
|
||||
--SELECT * FROM p WHERE account ~ 'ACOSTA'
|
||||
------------build global py asp------------------
|
||||
,baseline AS (
|
||||
SELECT
|
||||
product
|
||||
,majg
|
||||
,assc
|
||||
,chgrp
|
||||
,round(sum(val_usd) FILTER (WHERE oseas = 2020)/sum(units) FILTER (WHERE oseas = 2020),5) py_gasp
|
||||
FROM
|
||||
p
|
||||
GROUP BY
|
||||
product
|
||||
,majg
|
||||
,assc
|
||||
,chgrp
|
||||
)
|
||||
----------pivot the pricing out into columns per customer/product--------
|
||||
,pivot AS (
|
||||
SELECT
|
||||
p.product
|
||||
,p.styc
|
||||
,p.glec
|
||||
,p.majg
|
||||
,p.assc
|
||||
,p.colgrp
|
||||
,p.coltier
|
||||
,p.sizc
|
||||
,p.suffix
|
||||
,p.chgrp
|
||||
,p.account
|
||||
,p.shipgrp
|
||||
,bl.py_gasp
|
||||
,sum(units) FILTER (WHERE oseas = 2021) cy_units
|
||||
,round(sum(val_usd) FILTER (WHERE oseas = 2020)/sum(units) FILTER (WHERE oseas = 2020),5) py_asp
|
||||
,round(avg(price) FILTER (WHERE rn = 1),5) last_price
|
||||
,max(odate) FILTER (WHERE rn = 1) last_order
|
||||
,CASE p.chgrp
|
||||
WHEN 'D' THEN i.rate
|
||||
ELSE CASE p.majg
|
||||
WHEN '610' THEN .02
|
||||
ElSE CASE p.colgrp
|
||||
WHEN 'B' THEN .1
|
||||
WHEN 'C' THEN .15
|
||||
ELSE 1
|
||||
END
|
||||
END
|
||||
END rate
|
||||
,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL
|
||||
THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
|
||||
THEN 'unknown'
|
||||
ELSE 'new'
|
||||
END
|
||||
ELSE CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
|
||||
THEN 'lost'
|
||||
ELSE 'repeat'
|
||||
END
|
||||
END flag
|
||||
FROM
|
||||
p
|
||||
LEFT OUTER JOIN baseline bl ON
|
||||
bl.product = p.product
|
||||
AND bl.majg = p.majg
|
||||
AND bl.assc = p.assc
|
||||
AND bl.chgrp = p.chgrp
|
||||
LEFT OUTER JOIN incr i ON
|
||||
i.majg = p.majg
|
||||
AND i.assc = p.assc
|
||||
AND i.coltier = p.coltier
|
||||
AND p.glec <> '1RE'
|
||||
|
||||
GROUP BY
|
||||
p.product
|
||||
,p.styc
|
||||
,p.glec
|
||||
,p.majg
|
||||
,p.assc
|
||||
,p.coltier
|
||||
,p.colgrp
|
||||
,p.sizc
|
||||
,p.suffix
|
||||
,p.chgrp
|
||||
,p.account
|
||||
,p.shipgrp
|
||||
,bl.py_gasp
|
||||
,i.rate
|
||||
)
|
||||
----------------create the new price-----------------
|
||||
,adj AS (
|
||||
SELECT
|
||||
p.product
|
||||
,p.styc
|
||||
,p.glec
|
||||
,p.majg
|
||||
,p.assc
|
||||
,p.coltier
|
||||
,p.sizc
|
||||
,p.suffix
|
||||
,p.account
|
||||
,p.shipgrp
|
||||
,p.py_gasp
|
||||
,p.cy_units
|
||||
,p.py_asp
|
||||
,p.last_price
|
||||
,p.last_order
|
||||
,p.rate
|
||||
,p.flag
|
||||
,CASE p.flag
|
||||
----------------------if repeat business then get to prior year + target %--------------------------------------------------------------
|
||||
WHEN 'repeat' THEN greatest(py_asp * COALESCE(1+rate,1) - last_price,0)
|
||||
WHEN 'lost' THEN greatest(py_asp * COALESCE(1+rate,1) - last_price,0)
|
||||
----------------------if new business, move towards py_gasp + target % : lesser of py gloabl + target or last + target------------------
|
||||
WHEN 'new' THEN least(last_price * COALESCE(1+rate,1) - last_price,greatest(py_gasp * COALESCE(1+rate,1) - last_price,0))
|
||||
END price_increment
|
||||
FROM
|
||||
pivot p
|
||||
)
|
||||
--SELECT * FROM adj LIMIT 10000
|
||||
--------------create a log entry--------------------
|
||||
,log AS (
|
||||
INSERT INTO
|
||||
rlarp.osm_log(doc)
|
||||
SELECT
|
||||
$${
|
||||
"message":"application of last price and target increases to all forecast orders",
|
||||
"tag":"last price",
|
||||
"type":"build"
|
||||
}$$::jsonb doc
|
||||
RETURNING *
|
||||
)
|
||||
,poolprice AS (
|
||||
SELECT
|
||||
i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) product
|
||||
,o.quota_rep_descr
|
||||
,o.billto_group
|
||||
,o.shipto_group
|
||||
,order_season
|
||||
,sum(units) units
|
||||
,sum(value_loc) valloc
|
||||
,sum(value_usd) valusd
|
||||
,sum(o.value_loc)/sum(o.units) price
|
||||
,jsonb_agg(DISTINCT iter) iters
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
,rlarp.itemmv i
|
||||
WHERE
|
||||
i.item = o.part
|
||||
--AND o.units <> 0
|
||||
---only apply to 2022 orders----
|
||||
AND o.order_date >= '2021-06-01'
|
||||
--only include baseline stuff---
|
||||
AND segm <> 'Retail'
|
||||
GROUP BY
|
||||
i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
||||
,o.quota_rep_descr
|
||||
,o.billto_group
|
||||
,o.shipto_group
|
||||
,order_season
|
||||
--AND iter <> 'upload price'
|
||||
)
|
||||
, pooladj AS (
|
||||
SELECT
|
||||
p.product
|
||||
,p.quota_rep_descr
|
||||
,p.billto_group
|
||||
,p.shipto_group
|
||||
,p.price
|
||||
,a.py_gasp
|
||||
,a.rate
|
||||
,a.last_price
|
||||
,a.price_increment
|
||||
FROM
|
||||
poolprice p
|
||||
,adj a
|
||||
WHERE
|
||||
a.product = p.product
|
||||
AND a.account = p.billto_group
|
||||
AND a.shipgrp = p.shipto_group
|
||||
)
|
||||
SELECT * FROM pooladj WHERE product ~ 'STG06000' AND shipto_group = 'BWI' limit 100
|
||||
--SELECT * FROM poolprice WHERE product ~ 'TCA06600' AND shipto_group = 'BWI' AND quota_rep_descr = 'BRYAN HILL' LIMIT 1000
|
||||
-------------build the iteration rows----------------
|
||||
--,ins AS (
|
||||
--SELECT
|
||||
-- o.fspr
|
||||
-- ,o.plnt ---master data
|
||||
-- ,o.promo --history date mix
|
||||
-- ,o.terms
|
||||
-- ,o.bill_cust_descr --history cust mix
|
||||
-- ,o.ship_cust_descr --history cust mix
|
||||
-- ,o.dsm
|
||||
-- ,o.quota_rep_descr --master data
|
||||
-- ,o.director
|
||||
-- ,o.billto_group --master data
|
||||
-- ,o.shipto_group
|
||||
-- ,o.chan --master data
|
||||
-- ,o.chansub
|
||||
-- ,o.chan_retail
|
||||
-- ,o.part
|
||||
-- ,o.part_descr
|
||||
-- ,o.part_group
|
||||
-- ,o.branding
|
||||
-- ,o.majg_descr
|
||||
-- ,o.ming_descr
|
||||
-- ,o.majs_descr
|
||||
-- ,o.mins_descr
|
||||
-- ,o.segm
|
||||
-- ,o.substance
|
||||
-- ,o.fs_line --master data
|
||||
-- ,o.r_currency --history cust mix
|
||||
-- ,o.r_rate --master data
|
||||
-- ,o.c_currency --master data
|
||||
-- ,o.c_rate --master data
|
||||
-- ,0::numeric units
|
||||
-- ,ROUND(o.units * (a.price_increment/o.r_rate),2) value_loc
|
||||
-- ,ROUND(o.units * a.price_increment,2) value_usd
|
||||
-- ,0::numeric cost_loc
|
||||
-- ,0::numeric cost_usd
|
||||
-- ,o.calc_status --0
|
||||
-- ,o.flag --0
|
||||
-- ,o.order_date --history date mix
|
||||
-- ,o.order_month
|
||||
-- ,o.order_season
|
||||
-- ,o.request_date --history date mix
|
||||
-- ,o.request_month
|
||||
-- ,o.request_season
|
||||
-- ,o.ship_date --history date mix
|
||||
-- ,o.ship_month
|
||||
-- ,o.ship_season
|
||||
-- ,o.version
|
||||
-- ---this iteration has to be listed in the master template file in order to be effectively included---
|
||||
-- ,'upload price' iter
|
||||
-- ,log.id
|
||||
-- ,COALESCE(log.doc->>'tag','') "tag"
|
||||
-- ,log.doc->>'message' "comment"
|
||||
-- ,log.doc->>'type' module
|
||||
-- -----------debug columns---------
|
||||
-- --,value_usd/units price
|
||||
-- --,a.py_gasp
|
||||
-- --,a.rate
|
||||
-- --,a.last_price
|
||||
-- --,a.price_increment
|
||||
--FROM
|
||||
-- rlarp.osm_pool o
|
||||
-- ,rlarp.itemmv i
|
||||
-- ,adj a
|
||||
-- ,log
|
||||
--WHERE
|
||||
-- i.item = o.part
|
||||
-- AND a.product = i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
||||
-- AND a.account = o.billto_group
|
||||
-- AND a.shipgrp = o.shipto_group
|
||||
-- AND a.price_increment <> 0
|
||||
-- AND o.units <> 0
|
||||
-- ---only apply to 2022 orders----
|
||||
-- AND o.order_date >= '2021-06-01'
|
||||
-- --only include baseline stuff---
|
||||
-- AND iter <> 'upload price'
|
||||
--)
|
||||
-------------aggregate the impact------------
|
||||
----SELECT * FROM ins limit 10000
|
||||
----SELECT
|
||||
---- order_season
|
||||
---- ,sum(value_loc) val_loc
|
||||
---- ,sum(value_usd) val_usd
|
||||
----FROM
|
||||
---- ins
|
||||
----GROUP BY
|
||||
---- order_season;
|
||||
--,del AS (
|
||||
-- DELETE FROM rlarp.osm_pool WHERE iter = 'upload price' RETURNING *
|
||||
--)
|
||||
--INSERT INTO
|
||||
-- rlarp.osm_pool
|
||||
--SELECT * FROM ins;
|
||||
--
|
||||
--COMMIT;
|
25
over_under_ship.sql
Normal file
25
over_under_ship.sql
Normal file
@ -0,0 +1,25 @@
|
||||
SELECT
|
||||
calc_status
|
||||
,flag
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty < 0) overship
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty > 0) undership
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND fb_qty = 0) no_units
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND dhincr = 'C') credits
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND "ddord#" = 0 ) no_units
|
||||
FROM
|
||||
rlarp.osmf_dev
|
||||
WHERE
|
||||
(
|
||||
(
|
||||
oseas = 2021
|
||||
AND odate <@ daterange('2020-06-01','2021-04-11')
|
||||
)
|
||||
OR sseas = 2021
|
||||
)
|
||||
AND fs_line = '41010'
|
||||
--AND version = 'ACTUALS'
|
||||
--AND calc_status = 'CLOSED'
|
||||
--AND flag = 'REMAINDER'
|
||||
GROUP BY
|
||||
calc_status,
|
||||
flag;
|
490
package-lock.json
generated
Normal file
490
package-lock.json
generated
Normal file
@ -0,0 +1,490 @@
|
||||
{
|
||||
"name": "nodet",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"accepts": {
|
||||
"version": "1.3.7",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
|
||||
"integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==",
|
||||
"requires": {
|
||||
"mime-types": "~2.1.24",
|
||||
"negotiator": "0.6.2"
|
||||
}
|
||||
},
|
||||
"array-flatten": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
|
||||
},
|
||||
"body-parser": {
|
||||
"version": "1.19.0",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
|
||||
"integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==",
|
||||
"requires": {
|
||||
"bytes": "3.1.0",
|
||||
"content-type": "~1.0.4",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~1.1.2",
|
||||
"http-errors": "1.7.2",
|
||||
"iconv-lite": "0.4.24",
|
||||
"on-finished": "~2.3.0",
|
||||
"qs": "6.7.0",
|
||||
"raw-body": "2.4.0",
|
||||
"type-is": "~1.6.17"
|
||||
}
|
||||
},
|
||||
"buffer-writer": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz",
|
||||
"integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw=="
|
||||
},
|
||||
"bytes": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
|
||||
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
|
||||
},
|
||||
"content-disposition": {
|
||||
"version": "0.5.3",
|
||||
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
|
||||
"integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==",
|
||||
"requires": {
|
||||
"safe-buffer": "5.1.2"
|
||||
}
|
||||
},
|
||||
"content-type": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
|
||||
},
|
||||
"cookie": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz",
|
||||
"integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg=="
|
||||
},
|
||||
"cookie-signature": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"depd": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
|
||||
},
|
||||
"destroy": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "6.2.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.2.0.tgz",
|
||||
"integrity": "sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w=="
|
||||
},
|
||||
"ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
|
||||
},
|
||||
"encodeurl": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
|
||||
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k="
|
||||
},
|
||||
"escape-html": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
||||
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
|
||||
},
|
||||
"etag": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
||||
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
|
||||
},
|
||||
"express": {
|
||||
"version": "4.17.1",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz",
|
||||
"integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==",
|
||||
"requires": {
|
||||
"accepts": "~1.3.7",
|
||||
"array-flatten": "1.1.1",
|
||||
"body-parser": "1.19.0",
|
||||
"content-disposition": "0.5.3",
|
||||
"content-type": "~1.0.4",
|
||||
"cookie": "0.4.0",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~1.1.2",
|
||||
"encodeurl": "~1.0.2",
|
||||
"escape-html": "~1.0.3",
|
||||
"etag": "~1.8.1",
|
||||
"finalhandler": "~1.1.2",
|
||||
"fresh": "0.5.2",
|
||||
"merge-descriptors": "1.0.1",
|
||||
"methods": "~1.1.2",
|
||||
"on-finished": "~2.3.0",
|
||||
"parseurl": "~1.3.3",
|
||||
"path-to-regexp": "0.1.7",
|
||||
"proxy-addr": "~2.0.5",
|
||||
"qs": "6.7.0",
|
||||
"range-parser": "~1.2.1",
|
||||
"safe-buffer": "5.1.2",
|
||||
"send": "0.17.1",
|
||||
"serve-static": "1.14.1",
|
||||
"setprototypeof": "1.1.1",
|
||||
"statuses": "~1.5.0",
|
||||
"type-is": "~1.6.18",
|
||||
"utils-merge": "1.0.1",
|
||||
"vary": "~1.1.2"
|
||||
}
|
||||
},
|
||||
"finalhandler": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
|
||||
"integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==",
|
||||
"requires": {
|
||||
"debug": "2.6.9",
|
||||
"encodeurl": "~1.0.2",
|
||||
"escape-html": "~1.0.3",
|
||||
"on-finished": "~2.3.0",
|
||||
"parseurl": "~1.3.3",
|
||||
"statuses": "~1.5.0",
|
||||
"unpipe": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"forwarded": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
|
||||
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
|
||||
},
|
||||
"fresh": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
|
||||
},
|
||||
"http-errors": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
|
||||
"integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==",
|
||||
"requires": {
|
||||
"depd": "~1.1.2",
|
||||
"inherits": "2.0.3",
|
||||
"setprototypeof": "1.1.1",
|
||||
"statuses": ">= 1.5.0 < 2",
|
||||
"toidentifier": "1.0.0"
|
||||
}
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||
"requires": {
|
||||
"safer-buffer": ">= 2.1.2 < 3"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"ipaddr.js": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz",
|
||||
"integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA=="
|
||||
},
|
||||
"media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
|
||||
},
|
||||
"merge-descriptors": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
|
||||
"integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E="
|
||||
},
|
||||
"methods": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
|
||||
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
|
||||
},
|
||||
"mime": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
|
||||
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg=="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.43.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz",
|
||||
"integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.26",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz",
|
||||
"integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==",
|
||||
"requires": {
|
||||
"mime-db": "1.43.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"negotiator": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
|
||||
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
|
||||
},
|
||||
"on-finished": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
||||
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
|
||||
"requires": {
|
||||
"ee-first": "1.1.1"
|
||||
}
|
||||
},
|
||||
"packet-reader": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
|
||||
"integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ=="
|
||||
},
|
||||
"parseurl": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
||||
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="
|
||||
},
|
||||
"path-to-regexp": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||
},
|
||||
"pg": {
|
||||
"version": "7.18.1",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-7.18.1.tgz",
|
||||
"integrity": "sha512-1KtKBKg/zWrjEEv//klBbVOPGucuc7HHeJf6OEMueVcUeyF3yueHf+DvhVwBjIAe9/97RAydO/lWjkcMwssuEw==",
|
||||
"requires": {
|
||||
"buffer-writer": "2.0.0",
|
||||
"packet-reader": "1.0.0",
|
||||
"pg-connection-string": "0.1.3",
|
||||
"pg-packet-stream": "^1.1.0",
|
||||
"pg-pool": "^2.0.10",
|
||||
"pg-types": "^2.1.0",
|
||||
"pgpass": "1.x",
|
||||
"semver": "4.3.2"
|
||||
}
|
||||
},
|
||||
"pg-connection-string": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-0.1.3.tgz",
|
||||
"integrity": "sha1-2hhHsglA5C7hSSvq9l1J2RskXfc="
|
||||
},
|
||||
"pg-int8": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
||||
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
|
||||
},
|
||||
"pg-packet-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz",
|
||||
"integrity": "sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg=="
|
||||
},
|
||||
"pg-pool": {
|
||||
"version": "2.0.10",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.10.tgz",
|
||||
"integrity": "sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg=="
|
||||
},
|
||||
"pg-types": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
|
||||
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
|
||||
"requires": {
|
||||
"pg-int8": "1.0.1",
|
||||
"postgres-array": "~2.0.0",
|
||||
"postgres-bytea": "~1.0.0",
|
||||
"postgres-date": "~1.0.4",
|
||||
"postgres-interval": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"pgpass": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
|
||||
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
|
||||
"requires": {
|
||||
"split": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"postgres-array": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
|
||||
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA=="
|
||||
},
|
||||
"postgres-bytea": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
|
||||
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU="
|
||||
},
|
||||
"postgres-date": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.4.tgz",
|
||||
"integrity": "sha512-bESRvKVuTrjoBluEcpv2346+6kgB7UlnqWZsnbnCccTNq/pqfj1j6oBaN5+b/NrDXepYUT/HKadqv3iS9lJuVA=="
|
||||
},
|
||||
"postgres-interval": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
|
||||
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
|
||||
"requires": {
|
||||
"xtend": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"proxy-addr": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",
|
||||
"integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==",
|
||||
"requires": {
|
||||
"forwarded": "~0.1.2",
|
||||
"ipaddr.js": "1.9.0"
|
||||
}
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.7.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
|
||||
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
|
||||
},
|
||||
"range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
||||
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="
|
||||
},
|
||||
"raw-body": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz",
|
||||
"integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==",
|
||||
"requires": {
|
||||
"bytes": "3.1.0",
|
||||
"http-errors": "1.7.2",
|
||||
"iconv-lite": "0.4.24",
|
||||
"unpipe": "1.0.0"
|
||||
}
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"semver": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz",
|
||||
"integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c="
|
||||
},
|
||||
"send": {
|
||||
"version": "0.17.1",
|
||||
"resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz",
|
||||
"integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==",
|
||||
"requires": {
|
||||
"debug": "2.6.9",
|
||||
"depd": "~1.1.2",
|
||||
"destroy": "~1.0.4",
|
||||
"encodeurl": "~1.0.2",
|
||||
"escape-html": "~1.0.3",
|
||||
"etag": "~1.8.1",
|
||||
"fresh": "0.5.2",
|
||||
"http-errors": "~1.7.2",
|
||||
"mime": "1.6.0",
|
||||
"ms": "2.1.1",
|
||||
"on-finished": "~2.3.0",
|
||||
"range-parser": "~1.2.1",
|
||||
"statuses": "~1.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ms": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"serve-static": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz",
|
||||
"integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==",
|
||||
"requires": {
|
||||
"encodeurl": "~1.0.2",
|
||||
"escape-html": "~1.0.3",
|
||||
"parseurl": "~1.3.3",
|
||||
"send": "0.17.1"
|
||||
}
|
||||
},
|
||||
"setprototypeof": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||
},
|
||||
"split": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
|
||||
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
|
||||
"requires": {
|
||||
"through": "2"
|
||||
}
|
||||
},
|
||||
"statuses": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
||||
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
|
||||
},
|
||||
"through": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
|
||||
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
|
||||
},
|
||||
"toidentifier": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
||||
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
|
||||
},
|
||||
"type-is": {
|
||||
"version": "1.6.18",
|
||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
||||
"requires": {
|
||||
"media-typer": "0.3.0",
|
||||
"mime-types": "~2.1.24"
|
||||
}
|
||||
},
|
||||
"unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
|
||||
},
|
||||
"utils-merge": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
|
||||
},
|
||||
"vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^6.2.0",
|
||||
"express": "^4.16.4",
|
||||
"pg": "^7.8.0"
|
||||
"express": "^4.17.1",
|
||||
"pg": "^7.18.1"
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
@ -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)
|
||||
,testv AS (
|
||||
SELECT
|
||||
sum(fb_qty) tot
|
||||
,sum(fb_qty) FILTER (WHERE iter = 'copy') base
|
||||
,COALESCE(sum(fb_qty) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpart
|
||||
,sum(fb_val_loc *r_rate) totsales
|
||||
,sum(fb_val_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
|
||||
,COALESCE(sum(fb_val_loc *r_rate) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpartsales
|
||||
sum(units) tot
|
||||
,sum(units) FILTER (WHERE iter = 'copy') base
|
||||
,COALESCE(sum(units) FILTER (WHERE module = 'new basket'),0) newpart
|
||||
,sum(value_loc *r_rate) totsales
|
||||
,sum(value_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
|
||||
,COALESCE(sum(value_loc *r_rate) FILTER (WHERE module = 'new basket'),0) newpartsales
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
|
||||
AND order_date <= ship_date
|
||||
)
|
||||
,flagv AS (
|
||||
SELECT
|
||||
@ -55,7 +54,7 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
FROM
|
||||
testv
|
||||
)
|
||||
,GLD AS (
|
||||
,GLD AS MATERIALIZED (
|
||||
SELECT
|
||||
N1COMP COMP
|
||||
,N1CCYY FSYR
|
||||
@ -64,10 +63,11 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
,to_char(N1FSYP,'FM0000') FSPR
|
||||
,N1SD01 SDAT
|
||||
,N1ED01 EDAT
|
||||
,daterange(n1sd01, n1ed01,'[]') drange
|
||||
,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
|
||||
,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
|
||||
LGDAT.GLDATREF
|
||||
INNER JOIN LGDAT.GLDATE ON
|
||||
@ -75,38 +75,37 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
KPCCYY = N1CCYY
|
||||
WHERE
|
||||
N1COMP = 93
|
||||
--AND DIGITS(N1FSYP) = '1901'
|
||||
)
|
||||
,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)
|
||||
('01 - Jun',1,6,-1)
|
||||
,('02 - Jul',2,7,-1)
|
||||
,('03 - Aug',3,8,-1)
|
||||
,('04 - Sep',4,9,-1)
|
||||
,('05 - Oct',5,10,-1)
|
||||
,('06 - Nov',6,11,-1)
|
||||
,('07 - Dec',7,12,-1)
|
||||
,('08 - Jan',8,1,0)
|
||||
,('09 - Feb',9,2,0)
|
||||
,('10 - Mar',10,3,0)
|
||||
,('11 - Apr',11,4,0)
|
||||
,('12 - May',12,5,0)
|
||||
) x(m,s,cal,yr)
|
||||
)
|
||||
,alldates AS (
|
||||
,alldates AS MATERIALIZED(
|
||||
SELECT
|
||||
promo
|
||||
,terms
|
||||
,order_month
|
||||
,mseq.s seq
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
,sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) value_usd
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
LEFT OUTER JOIN mseq ON
|
||||
mseq.m = order_month
|
||||
WHERE
|
||||
@ -116,52 +115,52 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
promo
|
||||
,terms
|
||||
,order_month
|
||||
,mseq.s
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
HAVING
|
||||
sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) <> 0
|
||||
)
|
||||
--select * from alldates
|
||||
,dom AS (
|
||||
SELECT
|
||||
extract(day FROM orderdate) DOM
|
||||
extract(day FROM order_date) DOM
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
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)---------------
|
||||
,mmix AS (
|
||||
SELECT
|
||||
to_char(orderdate,'Mon') _month
|
||||
to_char(order_date,'Mon') _month
|
||||
,seq
|
||||
,promo
|
||||
,sum(extract(day from orderdate)*value_usd) dom_wa
|
||||
--,requestdate-orderdate rlag
|
||||
,sum((requestdate-orderdate)*(value_usd)) rlag_wa
|
||||
--,shipdate - requestdate slag
|
||||
,sum((shipdate - requestdate)*(value_usd)) slag_wa
|
||||
,sum(extract(day from order_date)*value_usd) dom_wa
|
||||
--,request_date-order_date rlag
|
||||
,sum((request_date-order_date)*(value_usd)) rlag_wa
|
||||
--,ship_date - request_date slag
|
||||
,sum((ship_date - request_date)*(value_usd)) slag_wa
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
GROUP BY
|
||||
to_char(orderdate,'Mon')
|
||||
to_char(order_date,'Mon')
|
||||
,seq
|
||||
,promo
|
||||
--,extract(day from orderdate)
|
||||
--,requestdate-orderdate
|
||||
--,shipdate - requestdate
|
||||
--,extract(day from order_date)
|
||||
--,request_date-order_date
|
||||
--,ship_date - request_date
|
||||
)
|
||||
,targm AS (select s, m from mseq where m = 'target_month' )
|
||||
,mmixp AS (
|
||||
@ -187,117 +186,50 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
abs(seq - targm.s) ASC
|
||||
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 (
|
||||
SELECT
|
||||
plnt ---master data
|
||||
,0::numeric(11,0) "ddord#" --0
|
||||
,0::numeric(11,0) "dditm#" --0
|
||||
,0::numeric(11,0) "fgbol#" --0
|
||||
,0::numeric(11,0) "fgent#" --0
|
||||
,0::numeric(9,0) "diinv#" --0
|
||||
,0::numeric(3,0) "dilin#" --0
|
||||
,null::text promo --history date mix
|
||||
,null::text return_reas --0
|
||||
,terms
|
||||
,''::text custpo --0
|
||||
,'I' dhincr --0
|
||||
,null::numeric diext
|
||||
,null::numeric ditdis
|
||||
,null::date dcodat --calculated date mix
|
||||
,null::date ddqdat --calculated date mix
|
||||
,null::date dcmdat --calculated date mix
|
||||
,null::date dhidat --calculated date mix
|
||||
,null::text fspr --calculated date mix
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,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
|
||||
--fspr in next step
|
||||
o.plnt
|
||||
--promo in next step
|
||||
--terms in next step
|
||||
,c.bvterm terms
|
||||
,o.bill_cust_descr
|
||||
,o.ship_cust_descr
|
||||
,o.dsm
|
||||
,o.quota_rep_descr
|
||||
,o.director
|
||||
,o.billto_group
|
||||
,o.shipto_group
|
||||
,o.chan
|
||||
,o.chansub
|
||||
,o.chan_retail
|
||||
,o.part
|
||||
,o.part_descr
|
||||
,o.part_group
|
||||
,o.branding
|
||||
,o.majg_descr
|
||||
,o.ming_descr
|
||||
,o.majs_descr
|
||||
,o.mins_descr
|
||||
,o.segm
|
||||
,o.substance
|
||||
,o.fs_line
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,sum(coalesce(o.units,0)) units
|
||||
,sum(coalesce(o.value_loc,0)) value_loc
|
||||
,sum(coalesce(o.value_usd,0)) value_usd
|
||||
,sum(coalesce(o.cost_loc,0)) cost_loc
|
||||
,sum(coalesce(o.cost_usd,0)) cost_usd
|
||||
,o.calc_status
|
||||
,o.flag
|
||||
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
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
@ -305,217 +237,137 @@ SELECT
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
plnt ---master data
|
||||
,terms
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,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
|
||||
,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
|
||||
--fspr in next step
|
||||
o.plnt
|
||||
,c.bvterm
|
||||
--promo in next step
|
||||
--terms in next step
|
||||
,o.bill_cust_descr
|
||||
,o.ship_cust_descr
|
||||
,o.dsm
|
||||
,o.quota_rep_descr
|
||||
,o.director
|
||||
,o.billto_group
|
||||
,o.shipto_group
|
||||
,o.chan
|
||||
,o.chansub
|
||||
,o.chan_retail
|
||||
,o.part
|
||||
,o.part_descr
|
||||
,o.part_group
|
||||
,o.branding
|
||||
,o.majg_descr
|
||||
,o.ming_descr
|
||||
,o.majs_descr
|
||||
,o.mins_descr
|
||||
,o.segm
|
||||
,o.substance
|
||||
,o.fs_line
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,o.calc_status
|
||||
,o.flag
|
||||
)
|
||||
,vscale AS (
|
||||
SELECT
|
||||
(SELECT vincr::numeric FROM target) incr
|
||||
,(SELECT sum(fb_qty) FROM basemix) base
|
||||
,(SELECT vincr::numeric FROM target)/(SELECT sum(fb_qty) FROM basemix) factor
|
||||
,(SELECT sum(units) FROM basemix) base
|
||||
,(SELECT vincr::numeric FROM target)/(SELECT sum(units) FROM basemix) factor
|
||||
)
|
||||
--select * from SCALE
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,volume AS (
|
||||
SELECT
|
||||
b.plnt --master data
|
||||
,b."ddord#" --0
|
||||
,b."dditm#" --0
|
||||
,b."fgbol#" --0
|
||||
,b."fgent#" --0
|
||||
,b."diinv#" --0
|
||||
,b."dilin#" --0
|
||||
,m.promo --history date mix
|
||||
,b.return_reas --0
|
||||
,b.terms --history cust mix
|
||||
,b.custpo --0
|
||||
,b.dhincr --0
|
||||
,b.diext --0
|
||||
,b.ditdis --0
|
||||
,b.dcodat --calculated date mix
|
||||
,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
|
||||
sd.fspr
|
||||
,b.plnt
|
||||
,m.promo
|
||||
,b.terms
|
||||
,b.bill_cust_descr
|
||||
,b.ship_cust_descr
|
||||
,b.dsm
|
||||
,b.quota_rep_descr
|
||||
,b.director
|
||||
,b.billto_group
|
||||
,b.shipto_group
|
||||
,b.chan
|
||||
,b.chansub
|
||||
,b.chan_retail
|
||||
,b.part
|
||||
,b.part_descr
|
||||
,b.part_family
|
||||
,b.part_group
|
||||
,b.branding
|
||||
,b.color
|
||||
,b.segm
|
||||
,b.bill_cust_descr
|
||||
,b.billto_group
|
||||
,b.ship_cust_descr
|
||||
,b.shipto_group
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.mod_chan
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,b.fb_val_loc*s.factor*m.momix value_loc
|
||||
,b.fb_val_loc*s.factor*m.momix*r_rate value_usd
|
||||
,b.fb_cst_loc*s.factor*m.momix cost_loc
|
||||
,b.fb_cst_loc*s.factor*m.momix*c_rate cost_usd
|
||||
,(b.fb_qty*s.factor*m.momix) units
|
||||
,b.segm
|
||||
,b.substance
|
||||
,b.fs_line
|
||||
,b.r_currency
|
||||
,b.r_rate
|
||||
,b.c_currency
|
||||
,b.c_rate
|
||||
,b.units*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 + 2022,mseq.cal,m.odom) order_date
|
||||
,od.sspr || ' - ' || to_char(make_date(mseq.yr + 2022,mseq.cal,m.odom),'Mon') order_month
|
||||
,od.ssyr order_season
|
||||
,make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag request_date
|
||||
,rd.sspr || ' - ' ||to_char(make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag,'Mon') request_month
|
||||
,rd.ssyr request_season
|
||||
,make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag + slag ship_date
|
||||
,sd.sspr || ' - ' || to_char(make_date(mseq.yr + 2022,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->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN vscale s
|
||||
CROSS JOIN mmixp m
|
||||
CROSS JOIN closest
|
||||
CROSS JOIN log
|
||||
LEFT OUTER JOIN mseq ON
|
||||
mseq.m = closest.m
|
||||
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 + 2022,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
|
||||
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 + 2022,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
||||
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 + 2022,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
||||
WHERE
|
||||
m._month = (SELECT _month FROM closest)
|
||||
)
|
||||
,pscale AS (
|
||||
SELECT
|
||||
(SELECT pincr::numeric FROM target) incr
|
||||
,(SELECT sum(fb_val_loc * r_rate) FROM volume) base
|
||||
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN
|
||||
,(SELECT sum(value_loc * r_rate) FROM volume) base
|
||||
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
|
||||
0
|
||||
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
|
||||
,CASE WHEN (SELECT sum(fb_val_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 sum(value_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
|
||||
((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
|
||||
0
|
||||
END
|
||||
@ -525,188 +377,147 @@ WHERE
|
||||
)
|
||||
,price AS (
|
||||
SELECT
|
||||
b.plnt --master data
|
||||
,b."ddord#" --0
|
||||
,b."dditm#" --0
|
||||
,b."fgbol#" --0
|
||||
,b."fgent#" --0
|
||||
,b."diinv#" --0
|
||||
,b."dilin#" --0
|
||||
,b.promo --history date mix
|
||||
,b.return_reas --0
|
||||
,b.terms --history cust mix
|
||||
,b.custpo --0
|
||||
,b.dhincr --0
|
||||
,b.diext --0
|
||||
,b.ditdis --0
|
||||
,b.dcodat --calculated date mix
|
||||
,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.fspr
|
||||
,b.plnt
|
||||
,b.promo
|
||||
,b.terms
|
||||
,b.bill_cust_descr
|
||||
,b.ship_cust_descr
|
||||
,b.dsm
|
||||
,b.quota_rep_descr
|
||||
,b.director
|
||||
,b.billto_group
|
||||
,b.shipto_group
|
||||
,b.chan
|
||||
,b.chansub
|
||||
,b.chan_retail
|
||||
,b.part
|
||||
,b.part_descr
|
||||
,b.part_family
|
||||
,b.part_group
|
||||
,b.branding
|
||||
,b.color
|
||||
,b.segm
|
||||
,b.bill_cust_descr
|
||||
,b.billto_group
|
||||
,b.ship_cust_descr
|
||||
,b.shipto_group
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.mod_chan
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,(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
|
||||
,(CASE WHEN p.factor = 0 THEN b.fb_qty * p.mod_price ELSE b.fb_val_loc*p.factor END)::numeric value_usd
|
||||
,0 cost_loc
|
||||
,0 cost_usd
|
||||
,0 units
|
||||
,b.segm
|
||||
,b.substance
|
||||
,b.fs_line
|
||||
,b.r_currency
|
||||
,b.r_rate
|
||||
,b.c_currency
|
||||
,b.c_rate
|
||||
,0::numeric 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->>'type' module
|
||||
FROM
|
||||
volume b
|
||||
CROSS JOIN pscale p
|
||||
CROSS JOIN log
|
||||
WHERE
|
||||
p.factor <> 0 or p.mod_price <> 0
|
||||
)
|
||||
, 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 (
|
||||
SELECT
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,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
|
||||
|
54
route_sql/adj_totals.sql
Normal file
54
route_sql/adj_totals.sql
Normal file
@ -0,0 +1,54 @@
|
||||
WITH
|
||||
preagg AS (
|
||||
SELECT
|
||||
coalesce(director,'None') director
|
||||
,coalesce(quota_rep_descr,'None') quota_rep_descr
|
||||
,part
|
||||
,bill_cust_descr
|
||||
,ship_cust_descr
|
||||
,order_month
|
||||
,doc->>'stamp' stamp
|
||||
,logid
|
||||
,tag
|
||||
,sum(value_usd) FILTER (WHERE iter = 'copy') sales
|
||||
,sum(cost_usd) FILTER (WHERE iter = 'copy') scogs
|
||||
,sum(value_usd) FILTER (WHERE iter <> 'copy') sales_adj
|
||||
,sum(cost_usd) FILTER (WHERE iter <> 'copy') scogs_adj
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
LEFT OUTER JOIN rlarp.osm_log ON
|
||||
id = logid
|
||||
WHERE
|
||||
order_season = 2022
|
||||
GROUP BY
|
||||
director
|
||||
,quota_rep_descr
|
||||
,part
|
||||
,bill_cust_descr
|
||||
,ship_cust_descr
|
||||
,order_month
|
||||
,doc->>'stamp'
|
||||
,logid
|
||||
,tag
|
||||
)
|
||||
SELECT
|
||||
director
|
||||
,quota_rep_descr
|
||||
,to_char(sum(sales),'999,999,999') sales
|
||||
,to_char(sum(sales - scogs),'999,999,999') margin
|
||||
,to_char(sum(sales_adj) FILTER (WHERE tag <> 'Initial Build'),'999,999,999') sales_adj
|
||||
,to_char(sum(sales_adj - scogs_adj) FILTER (WHERE tag <> 'Initial Build'),'999,999,999') margin_adj
|
||||
,count(DISTINCT logid) FILTER (WHERE tag <> 'Initial Build') "# of changes"
|
||||
,COUNT(logid) FILTER (WHERE tag <> 'Initial Build') "# of rows added"
|
||||
,(max(stamp) FILTER (WHERE tag <> 'Initial Build'))::timestamptz "last edit"
|
||||
FROM
|
||||
preagg
|
||||
GROUP BY
|
||||
GROUPING SETS (
|
||||
(director,quota_rep_descr),
|
||||
(director),
|
||||
()
|
||||
)
|
||||
ORDER BY
|
||||
director
|
||||
,quota_rep_descr
|
@ -1,120 +0,0 @@
|
||||
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;
|
@ -1,47 +0,0 @@
|
||||
WITH
|
||||
preagg AS (
|
||||
SELECT
|
||||
director_descr
|
||||
,quota_rep_descr
|
||||
,part
|
||||
,bill_cust
|
||||
,ship_cust
|
||||
,order_month
|
||||
,iterdef
|
||||
,sum(fb_val_loc * r_rate) FILTER (WHERE iter = 'copy') sales
|
||||
,sum(fb_cst_loc * c_rate) FILTER (WHERE iter = 'copy') scogs
|
||||
,sum(fb_val_loc * r_rate) FILTER (WHERE iter <> 'copy') sales_adj
|
||||
,sum(fb_cst_loc * c_rate) FILTER (WHERE iter <> 'copy') scogs_adj
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
WHERE
|
||||
order_season = 2020
|
||||
GROUP BY
|
||||
director_descr
|
||||
,quota_rep_descr
|
||||
,part
|
||||
,bill_cust
|
||||
,ship_cust
|
||||
,order_month
|
||||
,iterdef
|
||||
)
|
||||
SELECT
|
||||
director_descr
|
||||
,quota_rep_descr
|
||||
,to_char(sum(sales),'999,999,999') sales
|
||||
,to_char(sum(sales - scogs),'999,999,999') margin
|
||||
,to_char(sum(sales_adj),'999,999,999') sales_adj
|
||||
,to_char(sum(sales_adj - scogs_adj),'999,999,999') margin_adj
|
||||
,count(iterdef) "# of changes"
|
||||
,(max(iterdef->>'stamp'))::timestamptz "last edit"
|
||||
FROM
|
||||
preagg
|
||||
GROUP BY
|
||||
GROUPING SETS (
|
||||
(director_descr,quota_rep_descr),
|
||||
(director_descr),
|
||||
()
|
||||
)
|
||||
ORDER BY
|
||||
director_descr
|
||||
,quota_rep_descr
|
@ -6,20 +6,21 @@ SELECT
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,director
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
@ -29,16 +30,19 @@ SELECT
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
quota_rep_descr = 'rep_replace'
|
||||
GROUP BY
|
||||
@ -48,20 +52,21 @@ GROUP BY
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,director
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
@ -73,6 +78,10 @@ GROUP BY
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
,substance
|
||||
)
|
||||
SELECT
|
||||
json_agg(row_to_json(rows)) x
|
||||
|
@ -1,21 +1,31 @@
|
||||
WITH
|
||||
list AS (
|
||||
agg as (
|
||||
SELECT
|
||||
iterdef->>'user' "user",
|
||||
iterdef->>'stamp' "stamp",
|
||||
iterdef->>'mesasage' "comment",
|
||||
round(SUM(fb_val_loc * r_rate)::numeric,2) sales,
|
||||
jsonb_pretty(iterdef) def
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
ol.doc->>'user' "user"
|
||||
,quota_rep_descr
|
||||
,to_char((ol.doc->>'stamp')::timestamptz,'Mon-DD HH24:MI:SS') stamp
|
||||
,ol.doc->>'tag' tag
|
||||
,ol.doc->>'message' "comment"
|
||||
,jsonb_pretty(ol.doc) doc
|
||||
,ol.id
|
||||
,to_char(round(sum(value_usd),2),'$999,999,999D00') sales
|
||||
from
|
||||
rlarp.osm_log ol
|
||||
inner join rlarp.osm_pool on
|
||||
id = logid
|
||||
WHERE
|
||||
iterdef IS NOT NULL
|
||||
AND iterdef @> $$replace_user$$::jsonb
|
||||
GROUP BY
|
||||
iterdef->>'user',
|
||||
iterdef->>'stamp',
|
||||
iterdef->>'message',
|
||||
iterdef
|
||||
quota_rep_descr = 'replace_user'
|
||||
AND tag NOT IN ('Initial Build','last price')
|
||||
group BY
|
||||
ol.doc->>'user'
|
||||
,quota_rep_descr
|
||||
,ol.doc->>'stamp'
|
||||
,ol.doc->>'tag'
|
||||
,ol.doc->>'comment'
|
||||
,jsonb_pretty(ol.doc)
|
||||
,ol.id
|
||||
ORDER BY
|
||||
(ol.doc->>'stamp')::timestamptz desc
|
||||
)
|
||||
SELECT
|
||||
jsonb_agg(row_to_json(list)::jsonb) x from list
|
||||
jsonb_agg(row_to_json(agg)::jsonb ORDER BY agg.stamp desc) x from agg
|
||||
|
@ -13,10 +13,12 @@ target AS (select $$replace_request$$::json def)
|
||||
,to_char(N1FSYP,'FM0000') FSPR
|
||||
,N1SD01 SDAT
|
||||
,N1ED01 EDAT
|
||||
,daterange(n1sd01, n1ed01,'[]') drange
|
||||
,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
|
||||
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'FM00') SSPR
|
||||
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'FM00') || ' - '|| TO_CHAR(n1ed01,'FMMon') SORTMO
|
||||
FROM
|
||||
LGDAT.GLDATREF
|
||||
INNER JOIN LGDAT.GLDATE ON
|
||||
@ -30,18 +32,18 @@ target AS (select $$replace_request$$::json def)
|
||||
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)
|
||||
('01 - Jun',1,6,-1)
|
||||
,('02 - Jul',2,7,-1)
|
||||
,('03 - Aug',3,8,-1)
|
||||
,('04 - Sep',4,9,-1)
|
||||
,('05 - Oct',5,10,-1)
|
||||
,('06 - Nov',6,11,-1)
|
||||
,('07 - Dec',7,12,-1)
|
||||
,('08 - Jan',8,1,0)
|
||||
,('09 - Feb',9,2,0)
|
||||
,('10 - Mar',10,3,0)
|
||||
,('11 - Apr',11,4,0)
|
||||
,('12 - May',12,5,0)
|
||||
) x(m,s,cal,yr)
|
||||
)
|
||||
,SEG AS (
|
||||
@ -51,7 +53,8 @@ target AS (select $$replace_request$$::json def)
|
||||
FROM
|
||||
(
|
||||
VALUES
|
||||
('1CU','Retail'),
|
||||
('1SU','Sustainable'),
|
||||
('1CU','Sustainable'),
|
||||
('1GR','Greenhouse'),
|
||||
('1NU','Nursery'),
|
||||
('1RE','Retail'),
|
||||
@ -67,33 +70,10 @@ target AS (select $$replace_request$$::json def)
|
||||
('9TO','Other')
|
||||
) X(GLEC, SEGM)
|
||||
)
|
||||
,MG AS (
|
||||
SELECT
|
||||
X.F1, X.MING, X.GRP
|
||||
FROM
|
||||
(
|
||||
VALUES
|
||||
('L','000','Branded'),
|
||||
('L','B10','Branded'),
|
||||
('L','B11','Branded'),
|
||||
('L','B52','Branded'),
|
||||
('L','C10','Branded'),
|
||||
('L','D12','Branded'),
|
||||
('L','M11','Branded'),
|
||||
('L','P12','Branded'),
|
||||
('L','P13','Branded'),
|
||||
('L','S10','Branded'),
|
||||
('L','Y10','Branded'),
|
||||
('L','Y11','Branded'),
|
||||
('L','Y12','Branded'),
|
||||
('P','B10','Branded'),
|
||||
('P','B11','Branded'),
|
||||
('P','B52','Branded')
|
||||
) AS X (F1, MING, GRP)
|
||||
)
|
||||
,REPC AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(C.A9)) RCODE
|
||||
,c.a30 rname
|
||||
,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP
|
||||
,COALESCE(Q.DIR,'Other') DIRECTOR
|
||||
FROM
|
||||
@ -103,46 +83,6 @@ target AS (select $$replace_request$$::json def)
|
||||
WHERE
|
||||
C.A2 = 'MM'
|
||||
)
|
||||
--MOLD DESCRIPTIONS
|
||||
,MD AS (
|
||||
SELECT
|
||||
U.MOLD
|
||||
,MAX(U.DESCR) DESCR
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
SUBSTR(M.AVPART,1,8) MOLD
|
||||
,MAX(M.AVDES1) DESCR
|
||||
FROM
|
||||
LGDAT.STKMM M
|
||||
WHERE
|
||||
LENGTH(M.AVPART) > 8
|
||||
AND SUBSTR(M.AVGLED,1,1) <= '2'
|
||||
GROUP BY
|
||||
SUBSTR(M.AVPART,1,8)
|
||||
UNION ALL
|
||||
SELECT
|
||||
SUBSTR(P.AWPART,1,8) MOLD
|
||||
,MAX(P.AWDES1) DESCR
|
||||
FROM
|
||||
LGDAT.STKMP P
|
||||
WHERE
|
||||
LENGTH(P.AWPART) > 8
|
||||
AND SUBSTR(P.AWGLED,1,1) <= '2'
|
||||
GROUP BY
|
||||
SUBSTR(P.AWPART,1,8)
|
||||
) U
|
||||
GROUP BY
|
||||
U.MOLD
|
||||
)
|
||||
----------------------------------------------------sales major codes----------------------------------------------------------------------------------------------------------------------------------
|
||||
,SJ AS (
|
||||
SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = ''
|
||||
)
|
||||
----------------------------------------------------sales minor codes----------------------------------------------------------------------------------------------------------------------------------
|
||||
,SI AS (
|
||||
SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> ''
|
||||
)
|
||||
,copr AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(A9)) AS COMP,
|
||||
@ -167,14 +107,15 @@ target AS (select $$replace_request$$::json def)
|
||||
SELECT
|
||||
promo
|
||||
,terms
|
||||
,r_currency
|
||||
,order_month
|
||||
,mseq.s seq
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
LEFT OUTER JOIN mseq ON
|
||||
mseq.m = order_month
|
||||
WHERE
|
||||
@ -183,50 +124,57 @@ target AS (select $$replace_request$$::json def)
|
||||
--probably dont want to include adjustments that have blown away volume and good sources of dating info
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
promo
|
||||
,terms
|
||||
,r_currency
|
||||
,order_month
|
||||
,mseq.s
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
HAVING
|
||||
sum(value_usd) <> 0
|
||||
)
|
||||
--select * from alldates
|
||||
,dom AS (
|
||||
SELECT
|
||||
extract(day FROM orderdate) DOM
|
||||
extract(day FROM order_date) DOM
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
GROUP BY
|
||||
extract(day FROM orderdate)
|
||||
extract(day FROM order_date)
|
||||
)
|
||||
--select * from dom
|
||||
---------------------may want ot look at a top-5 mix solution in the future facilitated by sum() over (order by sales desc)---------------
|
||||
,mmix AS (
|
||||
SELECT
|
||||
to_char(orderdate,'Mon') _month
|
||||
to_char(order_date,'Mon') _month
|
||||
,seq
|
||||
,promo
|
||||
,sum(extract(day from orderdate)*value_usd) dom_wa
|
||||
--,requestdate-orderdate rlag
|
||||
,sum((requestdate-orderdate)*(value_usd)) rlag_wa
|
||||
--,shipdate - requestdate slag
|
||||
,sum((shipdate - requestdate)*(value_usd)) slag_wa
|
||||
,terms
|
||||
,(SELECT r_currency FROM alldates GROUP BY r_currency ORDER BY SUM(value_usd) DESC LIMIT 1) r_currency
|
||||
--should terms be included here?
|
||||
,sum(extract(day from order_date)*value_usd) dom_wa
|
||||
--,request_date-order_date rlag
|
||||
,sum((request_date-order_date)*(value_usd)) rlag_wa
|
||||
--,ship_date - request_date slag
|
||||
,sum((ship_date - request_date)*(value_usd)) slag_wa
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
GROUP BY
|
||||
to_char(orderdate,'Mon')
|
||||
to_char(order_date,'Mon')
|
||||
,seq
|
||||
,promo
|
||||
--,extract(day from orderdate)
|
||||
--,requestdate-orderdate
|
||||
--,shipdate - requestdate
|
||||
,terms
|
||||
--,extract(day from order_date)
|
||||
--,request_date-order_date
|
||||
--,ship_date - request_date
|
||||
)
|
||||
--select * from mmix
|
||||
,targm AS (
|
||||
SELECT
|
||||
je.key as month
|
||||
@ -242,11 +190,14 @@ target AS (select $$replace_request$$::json def)
|
||||
LEFT OUTER JOIN mseq ON
|
||||
mseq.m = je.key
|
||||
)
|
||||
--select * from targm
|
||||
,mmixp AS (
|
||||
SELECT
|
||||
_month
|
||||
,seq
|
||||
,promo
|
||||
,terms
|
||||
,r_currency
|
||||
,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom
|
||||
,round((rlag_wa/value_usd)::numeric,0)::int rlag
|
||||
,round((slag_wa/value_usd)::numeric,0)::int slag
|
||||
@ -255,6 +206,7 @@ target AS (select $$replace_request$$::json def)
|
||||
FROM
|
||||
mmix
|
||||
)
|
||||
--select * from mmixp
|
||||
--month cross join mix
|
||||
,mxm AS (
|
||||
SELECT
|
||||
@ -269,6 +221,8 @@ SELECT
|
||||
,x.rlag
|
||||
,x.slag
|
||||
,x.promo
|
||||
,x.terms
|
||||
,x.r_currency
|
||||
FROM
|
||||
targm t
|
||||
LEFT OUTER JOIN mmixp x ON
|
||||
@ -286,114 +240,26 @@ FROM
|
||||
--this basemix is probably join going to be part-bill-ship with all master data joined later since it is not known if any original is salvaged
|
||||
,basemix AS (
|
||||
SELECT
|
||||
null::text plnt ---master data
|
||||
,0::numeric(11,0) "ddord#"
|
||||
,0::numeric(11,0) "dditm#"
|
||||
,0::numeric(11,0) "fgbol#"
|
||||
,0::numeric(11,0) "fgent#"
|
||||
,0::numeric(9,0) "diinv#"
|
||||
,0::numeric(3,0) "dilin#"
|
||||
,mxm.promo --history
|
||||
,null::text return_reas
|
||||
,null::text terms
|
||||
,''::text custpo
|
||||
,'I' dhincr
|
||||
,null::numeric diext
|
||||
,null::numeric ditdis
|
||||
,null::date dcodat
|
||||
,null::date ddqdat
|
||||
,null::date dcmdat
|
||||
,null::date dhidat
|
||||
,sd.fspr
|
||||
,null::text remit_to
|
||||
,null::text bill_class
|
||||
,(regexp_match(jr.bill_cust_descr,'(.*?)(?= - |$)'))[1] bill_cust
|
||||
,null:: text bill_rep
|
||||
,null::text bill_terr
|
||||
,null::text ship_class
|
||||
,(regexp_match(jr.ship_cust_descr,'(.*?)(?= - |$)'))[1] ship_cust
|
||||
,null::text ship_rep
|
||||
,null::text ship_terr
|
||||
,null::text quota_rep
|
||||
,null::text account
|
||||
,null::text shipgrp
|
||||
,null::text geo
|
||||
,null::text chan
|
||||
,null::text orig_ctry
|
||||
,null::text orig_prov
|
||||
,null::text orig_post
|
||||
,null::text dest_ctry
|
||||
,null::text dest_prov
|
||||
,null::text dest_post
|
||||
,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part
|
||||
,null::text ord_gldc
|
||||
,null::text majg
|
||||
,null::text ming
|
||||
,null::text majs
|
||||
,null::text mins
|
||||
,null::text gldc
|
||||
,null::text glec
|
||||
,null::text harm
|
||||
,null::text clss
|
||||
,null::text brand
|
||||
,null::text assc
|
||||
,'41010'::text fs_line
|
||||
,null::text r_currency
|
||||
,null::numeric r_rate
|
||||
,null::text c_currency
|
||||
,null::numeric c_rate
|
||||
,0::numeric(15,5) ddqtoi
|
||||
,0::numeric(15,5) ddqtsi
|
||||
,0::numeric(15,5) fgqshp
|
||||
,0::numeric(15,5) diqtsh
|
||||
,mxm.qty*mxm.momix*jr.mix fb_qty --history value
|
||||
,0::numeric fb_cst_loc --history part mix
|
||||
,0::numeric fb_cst_loc_cur
|
||||
,0::numeric fb_cst_loc_fut
|
||||
,mxm.amount*mxm.momix*jr.mix fb_val_loc --history value
|
||||
,0::numeric fb_val_loc_pl
|
||||
,''::text calc_status
|
||||
,''::text flag
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) orderdate
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag requestdate
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag shipdate
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) adj_orderdate
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag adj_requestdate
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag adj_shipdate
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
-----------------------ui columns--------------------------------
|
||||
,'replace_iterdet' iterdet
|
||||
,$$replace_iterdef$$::json iterdef
|
||||
,od.ssyr order_season
|
||||
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom),'Mon') order_month
|
||||
,sd.ssyr ship_season
|
||||
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag,'Mon') ship_month
|
||||
,rd.ssyr request_season
|
||||
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag,'Mon') request_month
|
||||
,jr.part_descr part_descr
|
||||
,null::text part_family
|
||||
,null::text part_group
|
||||
,null::text branding
|
||||
,null::text color
|
||||
,null::text segm
|
||||
sd.fspr
|
||||
,mxm.promo
|
||||
,mxm.terms
|
||||
,mxm.r_currency
|
||||
,jr.bill_cust_descr
|
||||
,null::text billto_group
|
||||
,jr.ship_cust_descr
|
||||
,null::text shipto_group
|
||||
,null::text majg_descr
|
||||
,null::text ming_descr
|
||||
,null::text majs_descr
|
||||
,null::text mins_descr
|
||||
,null::text mod_chan
|
||||
,null::text mod_chansub
|
||||
,null::text quota_rep_descr
|
||||
,null::text director_descr
|
||||
,null::numeric value_loc
|
||||
,null::numeric value_usd
|
||||
,null::numeric cost_loc
|
||||
,null::numeric cost_usd
|
||||
,null::numeric units
|
||||
,rtrim((regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1]) part
|
||||
,jr.part_descr
|
||||
,substring(jr.part_descr,1,8) part_group
|
||||
,mxm.qty*mxm.momix*jr.mix units
|
||||
,mxm.amount*mxm.momix*jr.mix value_usd --assume that target dollars are USD
|
||||
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) order_date
|
||||
,od.sortmo order_month
|
||||
,od.ssyr order_season
|
||||
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag request_date
|
||||
,rd.sortmo request_month
|
||||
,rd.ssyr request_season
|
||||
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag + slag ship_date
|
||||
,sd.sortmo ship_month
|
||||
,sd.ssyr ship_season
|
||||
,jr.mix
|
||||
FROM
|
||||
target
|
||||
@ -401,387 +267,255 @@ SELECT
|
||||
JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true
|
||||
CROSS JOIN mxm
|
||||
LEFT OUTER JOIN gld od ON
|
||||
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) BETWEEN od.sdat AND od.edat
|
||||
od.drange @> make_date(mxm.yr + 2022,mxm.cal,mxm.odom)
|
||||
LEFT OUTER JOIN gld rd ON
|
||||
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
||||
rd.drange @> (make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag)
|
||||
LEFT OUTER JOIN gld sd ON
|
||||
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
||||
sd.drange @> (make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag + slag)
|
||||
)
|
||||
--SELECT * FROM basemix
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,final AS (
|
||||
SELECT
|
||||
COALESCE(m.avdplt,p.awdplt) plnt --master data
|
||||
,b."ddord#"
|
||||
,b."dditm#"
|
||||
,b."fgbol#"
|
||||
,b."fgent#"
|
||||
,b."diinv#"
|
||||
,b."dilin#"
|
||||
,b.promo --history
|
||||
,b.return_reas
|
||||
,bc.bvterm terms --history cust mix
|
||||
,b.custpo
|
||||
,b.dhincr
|
||||
,b.diext
|
||||
,b.ditdis
|
||||
,b.dcodat
|
||||
,b.ddqdat
|
||||
,b.dcmdat
|
||||
,b.dhidat
|
||||
,b.fspr
|
||||
,bc.bvcomp remit_to --master data
|
||||
,bc.bvclas bill_class --master data
|
||||
,b.bill_cust --history cust mix
|
||||
,bc.bvsalm bill_rep --master data
|
||||
,bc.bvterr bill_terr --master data
|
||||
,sc.bvclas ship_class --master data
|
||||
,b.ship_cust --history cust mix
|
||||
,sc.bvsalm ship_rep --master data
|
||||
,sc.bvterr ship_terr --master data
|
||||
--quota rep--------------------------------------------
|
||||
,RTRIM(
|
||||
COALESCE(
|
||||
--retail items go to currep, or if null go to 90005
|
||||
CASE WHEN COALESCE(avgled,awgled) IN ('1RE','1CU') THEN
|
||||
CASE WHEN bc.bvctry = 'CAN' THEN
|
||||
--Rachel Bowman
|
||||
'50300'
|
||||
ELSE
|
||||
--retail chain got to Mark Wilkinson
|
||||
CASE COALESCE(cg.cgrp,bc.bvname)
|
||||
WHEN 'THE HOME DEPOT' THEN '90005'
|
||||
WHEN 'DO IT BEST' THEN '90005'
|
||||
WHEN 'ACE HARDWARE' THEN '90005'
|
||||
WHEN 'ALDI' THEN '90005'
|
||||
WHEN 'AMAZON.COM' THEN '90005'
|
||||
WHEN 'GARDEN RIDGE CORP' THEN '90005'
|
||||
--all other retail goes to Doran Marable
|
||||
ELSE '50200'
|
||||
END
|
||||
b.fspr
|
||||
,i.dplt plnt
|
||||
,b.promo
|
||||
,COALESCE(b.terms,bc.bvterm) terms
|
||||
,b.bill_cust_descr
|
||||
,b.ship_cust_descr
|
||||
,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm
|
||||
,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr
|
||||
,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director
|
||||
,COALESCE(CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END,b.bill_cust_descr) billto_group
|
||||
,COALESCE(CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE sc.BVADR6 END,b.ship_cust_descr) shipto_group
|
||||
,CASE SUBSTRING(bc.bvclas,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(sc.bvclas,2,3)
|
||||
WHEN 'DIS' THEN 'WHS'
|
||||
ELSE 'DRP'
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN COALESCE(avming,awming) = 'B52' THEN
|
||||
'PW'
|
||||
--gdir, ndir go to bill-to rep
|
||||
ELSE
|
||||
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
|
||||
bc.bvsalm
|
||||
ELSE
|
||||
sc.bvsalm
|
||||
END
|
||||
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 chan
|
||||
,CASE SUBSTRING(bc.bvclas,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(sc.bvclas,2,3)
|
||||
WHEN 'DIS' THEN 'WHS'
|
||||
ELSE CASE SUBSTRING(sc.bvclas,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
|
||||
END
|
||||
,''
|
||||
)
|
||||
) quota_rep
|
||||
,coalesce(cg.cgrp,bc.bvname) account
|
||||
,coalesce(sg.cgrp,sc.bvname) shipgrp
|
||||
,coalesce(t.geo,'UNDEFINED') geo
|
||||
,coalesce(c.chan,'UNDEFINED') chan
|
||||
,ad.qzcryc orig_ctry
|
||||
,ad.qzprov orig_prov
|
||||
,ad.qzpost orig_post
|
||||
,sc.bvctry dest_ctry
|
||||
,sc.bvprcd dest_prov
|
||||
,sc.bvpost dest_post
|
||||
,b.part --history part mix
|
||||
,COALESCE(m.avglcd, p.awgldc) ord_gldc --master data
|
||||
,COALESCE(m.avmajg,p.awmajg) majg --master data
|
||||
,COALESCE(m.avming,p.awming) ming --master data
|
||||
,COALESCE(m.avmajs,p.awmajs) majs --master data
|
||||
,COALESCE(m.avmins,p.awmins) mins --master data
|
||||
,COALESCE(m.avglcd,p.awgldc) gldc --master data
|
||||
,COALESCE(m.avgled,p.awgled) glec --master data
|
||||
,COALESCE(m.avharm,p.awharm) harm --master data
|
||||
,COALESCE(m.avclss,p.awclss) clss --master data
|
||||
,SUBSTR(COALESCE(m."avcpt#",p."awvpt#"),1,1) brand --master data
|
||||
,COALESCE(m.avassc,p.awassc) assc --master data
|
||||
,b.fs_line --master data
|
||||
,bc.bvcurr r_currency --history cust mix
|
||||
WHEN 'MAS' THEN 'RMN'
|
||||
WHEN 'NAT' THEN 'RMN'
|
||||
ELSE CASE SUBSTRING(sc.bvclas,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
|
||||
END chansub
|
||||
,null::text chan_retail
|
||||
,b.part
|
||||
,b.part_descr
|
||||
,b.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
|
||||
,'41010' fs_line --master data
|
||||
,b.r_currency --history cust mix
|
||||
,rx.rate r_rate --master data
|
||||
,copr.curr c_currency --master data
|
||||
,cx.rate c_rate --master data
|
||||
,b.ddqtoi
|
||||
,b.ddqtsi
|
||||
,b.fgqshp
|
||||
,b.diqtsh
|
||||
,b.fb_qty
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty fb_cst_loc
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty fb_cst_loc_cur
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty fb_cst_loc_fut
|
||||
,b.fb_val_loc
|
||||
,b.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"
|
||||
,b.iter
|
||||
-----------------------ui columns--------------------------------
|
||||
,b.iterdet
|
||||
,b.iterdef
|
||||
,b.order_season
|
||||
,b.units
|
||||
,b.value_usd / COALESCE(rx.rate,1) --b.value is denominated in USD, need to apply currency to get to local, assume 1 if using a fake customer
|
||||
,b.value_usd value_usd --b.value is already denominated in usd
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units cost_loc
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_usd
|
||||
,'CLOSED' calc_status
|
||||
,'SHIPMENT' flag
|
||||
,b.order_date
|
||||
,b.order_month
|
||||
,b.ship_season
|
||||
,b.ship_month
|
||||
,b.request_season
|
||||
,b.order_season
|
||||
,b.request_date
|
||||
,b.request_month
|
||||
,b.part_descr
|
||||
,SUBSTR(b.part,1,3)||coalesce(' - '||F.DESCR,'') part_family
|
||||
,SUBSTRING(b.part,1,8)||coalesce(' - '||MD.DESCR,'') part_group
|
||||
,COALESCE(MG.GRP,'Unbranded') branding
|
||||
,CASE WHEN substring(COALESCE(m.avgled, p.awgled),1,1) <= '2' THEN SUBSTRING(b.part,9,3) ELSE '' END color
|
||||
,COALESCE(SEG.SEGM,'Other') segm
|
||||
,b.bill_cust_descr
|
||||
,coalesce(cg.cgrp,bc.bvname) billto_group
|
||||
,b.ship_cust_descr
|
||||
,coalesce(sg.cgrp,sc.bvname) shipto_group
|
||||
,COALESCE(m.avmajg,p.awmajg)||COALESCE(' - '||BQDES,'') majg_descr
|
||||
,COALESCE(m.avming,p.awming)||COALESCE(' - '||BRDES,'') ming_descr
|
||||
,COALESCE(m.avmajs,p.awmajs)||COALESCE(' - '||SJ.BSDES1,'') majs_descr
|
||||
,COALESCE(m.avmins,p.awmins)||COALESCE(' - '||SI.BSDES1,'') mins_descr
|
||||
,CASE COALESCE(SEG.SEGM,'Other')
|
||||
WHEN 'Retail' THEN c.RETAIL
|
||||
ELSE coalesce(c.chan,'UNDEFINED')
|
||||
END mod_chan
|
||||
,CASE COALESCE(SEG.SEGM,'Other')
|
||||
WHEN 'Retail' THEN c.RETAILSUB
|
||||
ELSE ''
|
||||
END mod_chansub
|
||||
,repc.repp quota_rep_descr
|
||||
,repc.director director_descr
|
||||
,b.fb_val_loc value_loc
|
||||
,b.fb_val_loc * rx.rate value_usd
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty cost_loc
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty*cx.rate cost_usd
|
||||
,b.fb_qty units
|
||||
,b.request_season
|
||||
,b.ship_date
|
||||
,b.ship_month
|
||||
,b.ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
LEFT OUTER JOIN LGDAT.STKMM M ON
|
||||
M.AVPART = b.PART
|
||||
LEFT OUTER JOIN LGDAT.STKMP P ON
|
||||
P.AWPART = b.PART
|
||||
LEFT OUTER JOIN lgdat.stka a ON
|
||||
v6part = b.part
|
||||
AND v6plnt = COALESCE(m.avdplt,p.awdplt)
|
||||
CROSS JOIN log
|
||||
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||
i.item = b.part
|
||||
LEFT OUTER JOIN SEG ON
|
||||
SEG.GLEC = COALESCE(m.avgled,p.awgled)
|
||||
SEG.GLEC = i.glec
|
||||
--AND SEG.SEGM <> 'Other'
|
||||
LEFT OUTER JOIN MG ON
|
||||
MG.F1 = SUBSTR(b.PART,16,1)
|
||||
AND MG.MING = COALESCE(m.avming,p.awming)
|
||||
LEFT OUTER JOIN RLARP.FAMILY F ON
|
||||
F.F3 = SUBSTR(b.PART,1,3)
|
||||
LEFT OUTER JOIN MD ON
|
||||
MD.MOLD = SUBSTR(b.PART,1,8)
|
||||
LEFT OUTER JOIN LGDAT.CUST BC ON
|
||||
BC.BVCUST = b.BILL_CUST
|
||||
BC.BVCUST = rtrim(substring(b.bill_cust_descr,1,8))
|
||||
LEFT OUTER JOIN LGDAT.CUST SC ON
|
||||
SC.BVCUST = b.SHIP_CUST
|
||||
LEFT OUTER JOIN RLARP.FFCHNL c ON
|
||||
c.BILL = bc.bvclas
|
||||
AND c.SHIP = sc.bvclas
|
||||
LEFT OUTER JOIN rlarp.ffterr t ON
|
||||
t.prov = sc.bvprcd AND
|
||||
t.ctry = sc.bvctry
|
||||
LEFT OUTER JOIN RLARP.FFCUST CG ON
|
||||
CG.CUSTN = BC.BVCUST
|
||||
LEFT OUTER JOIN RLARP.FFCUST SG ON
|
||||
SG.CUSTN = SC.BVCUST
|
||||
SC.BVCUST = rtrim(substring(b.ship_cust_descr,1,8))
|
||||
LEFT OUTER JOIN REPC ON
|
||||
REPC.RCODE = RTRIM(
|
||||
COALESCE(
|
||||
--retail items go to currep, or if null go to 90005
|
||||
CASE WHEN COALESCE(avgled,awgled) IN ('1RE','1CU') THEN
|
||||
CASE WHEN bc.bvctry = 'CAN' THEN
|
||||
--Rachel Bowman
|
||||
'50300'
|
||||
ELSE
|
||||
--retail chain got to Mark Wilkinson
|
||||
CASE COALESCE(cg.cgrp,bc.bvname)
|
||||
WHEN 'THE HOME DEPOT' THEN '90005'
|
||||
WHEN 'DO IT BEST' THEN '90005'
|
||||
WHEN 'ACE HARDWARE' THEN '90005'
|
||||
WHEN 'ALDI' THEN '90005'
|
||||
WHEN 'AMAZON.COM' THEN '90005'
|
||||
WHEN 'GARDEN RIDGE CORP' THEN '90005'
|
||||
--all other retail goes to Doran Marable
|
||||
ELSE '50200'
|
||||
END
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN COALESCE(avming,awming) = 'B52' THEN
|
||||
'PW'
|
||||
--gdir, ndir go to bill-to rep
|
||||
ELSE
|
||||
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
|
||||
bc.bvsalm
|
||||
ELSE
|
||||
sc.bvsalm
|
||||
END
|
||||
END
|
||||
END
|
||||
,''
|
||||
)
|
||||
)
|
||||
LEFT OUTER JOIN SI ON
|
||||
SI.BSMJCD = COALESCE(m.avmajs,p.awmajs)
|
||||
AND SI.BSMNCD = COALESCE(m.avmins,p.awmins)
|
||||
LEFT OUTER JOIN SJ ON
|
||||
SJ.BSMJCD = COALESCE(m.avmajs,p.awmajs)
|
||||
LEFT OUTER JOIN LGDAT.MAJG ON
|
||||
BQGRP = COALESCE(m.avmajg,p.awmajg)
|
||||
LEFT OUTER JOIN LGDAT.MMGP ON
|
||||
BRMGRP = COALESCE(m.avming,p.awming)
|
||||
AND BRGRP = COALESCE(m.avmajg,p.awmajg)
|
||||
--retail items go to currep, or if null go to 90005
|
||||
CASE WHEN i.glec IN ('1RE','1CU') THEN
|
||||
CASE WHEN bc.bvctry = 'CAN' THEN
|
||||
--Rachel Bowman
|
||||
'50300'
|
||||
ELSE
|
||||
--select customers go to select reps
|
||||
CASE CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END
|
||||
------Alecia Latini-------------------------------
|
||||
WHEN 'DO IT BEST' THEN '90006'
|
||||
WHEN 'ACE HARDWARE' THEN '90006'
|
||||
WHEN 'ALDI' THEN '90006'
|
||||
WHEN 'AMAZON.COM' THEN '90006'
|
||||
WHEN 'GARDEN RIDGE CORP' THEN '90006' --AKA "At Home"
|
||||
WHEN 'TRUE VALUE' THEN '90006'
|
||||
WHEN 'WAYFAIR' THEN '90006'
|
||||
WHEN 'GRIFFIN' THEN '90006'
|
||||
WHEN 'WAL-MART' THEN '90006'
|
||||
------Tony Landino--------------------------------
|
||||
WHEN 'THE HOME DEPOT' THEN '50802'
|
||||
WHEN 'FRED MEYER' THEN '50802'
|
||||
WHEN 'MENARDS' THEN '50802'
|
||||
WHEN 'KROGER' THEN '50802'
|
||||
WHEN 'OCEAN STATE JOBBERS' THEN '50802'
|
||||
WHEN 'AURORA WHOLESALE' THEN '50802'
|
||||
WHEN 'LEON KORRAL' THEN '50802'
|
||||
--all other retail goes to Doran Marable-----------
|
||||
ELSE '50200'
|
||||
END
|
||||
END
|
||||
--minor group b52 goes to dedicated rep
|
||||
ELSE
|
||||
CASE WHEN i.MING = 'B52' THEN
|
||||
'PW'
|
||||
--gdir, ndir go to bill-to rep
|
||||
ELSE
|
||||
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
|
||||
bc.bvsalm
|
||||
ELSE
|
||||
sc.bvsalm
|
||||
END
|
||||
END
|
||||
END
|
||||
)
|
||||
LEFT OUTER JOIN lgdat.icstm im ON
|
||||
im.cgpart = b.part
|
||||
AND im.cgplnt = a.v6plnt
|
||||
AND im.cgplnt = i.dplt
|
||||
LEFT OUTER JOIN lgdat.icstp ip ON
|
||||
ip.chpart = b.part
|
||||
AND ip.chplnt = a.v6plnt
|
||||
AND ip.chplnt = i.dplt
|
||||
LEFT OUTER JOIN lgdat.icstr ir ON
|
||||
ir.y0part = b.part
|
||||
AND ir.y0plnt = a.v6plnt
|
||||
AND ir.y0plnt = i.dplt
|
||||
LEFT OUTER JOIN lgdat.plnt ON
|
||||
yaplnt = a.v6plnt
|
||||
yaplnt = i.dplt
|
||||
LEFT OUTER JOIN copr ON
|
||||
copr.comp = yacomp::text
|
||||
LEFT OUTER JOIN rlarp.ffcret cx ON
|
||||
cx.perd = '1910'
|
||||
AND cx.rtyp = 'MA'
|
||||
cx.perd = '2101'
|
||||
AND cx.rtyp = 'BG'
|
||||
AND cx.fcur = copr.curr
|
||||
AND cx.tcur = 'US'
|
||||
LEFT OUTER JOIN rlarp.ffcret rx ON
|
||||
rx.perd = '1910'
|
||||
AND rx.rtyp = 'MA'
|
||||
AND rx.fcur = bc.bvcurr
|
||||
rx.perd = '2101'
|
||||
AND rx.rtyp = 'BG'
|
||||
AND rx.fcur = COALESCE(bc.bvcurr,b.r_currency)
|
||||
AND rx.tcur = 'US'
|
||||
LEFT OUTER JOIN LGDAT.ADRS AD ON
|
||||
AD.QZADR = plnt."yaadr#"
|
||||
)
|
||||
/*
|
||||
,clone_part_meta AS (
|
||||
SELECT
|
||||
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.segm
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.quota_rep
|
||||
,sum(fb_val_loc * r_rate) agg
|
||||
FROM
|
||||
rlarp.osm_fcpool b
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
--probably dont want to include adjustments that have blown away volume and good sources of dating info
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
GROUP BY
|
||||
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.segm
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.quota_rep
|
||||
ORDER BY
|
||||
agg desc
|
||||
)
|
||||
*/
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING *
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM final RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
@ -1,157 +1,85 @@
|
||||
WITH
|
||||
target AS (select target_increment incr)
|
||||
,basemix AS (
|
||||
SELECT
|
||||
plnt ---master data
|
||||
,0::numeric(11,0) "ddord#" --0
|
||||
,0::numeric(11,0) "dditm#" --0
|
||||
,0::numeric(11,0) "fgbol#" --0
|
||||
,0::numeric(11,0) "fgent#" --0
|
||||
,0::numeric(9,0) "diinv#" --0
|
||||
,0::numeric(3,0) "dilin#" --0
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,null::text return_reas --0
|
||||
,terms
|
||||
,''::text custpo --0
|
||||
,'I' dhincr --0
|
||||
,null::numeric diext
|
||||
,null::numeric ditdis
|
||||
,null::date dcodat --calculated date mix
|
||||
,null::date ddqdat --calculated date mix
|
||||
,null::date dcmdat --calculated date mix
|
||||
,null::date dhidat --calculated date mix
|
||||
,null::text fspr --calculated date mix
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,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
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,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
|
||||
,sum(coalesce(units,0)) units --history value
|
||||
,sum(coalesce(value_loc,0)) value_loc --history value
|
||||
,sum(coalesce(value_usd,0)) value_usd --0
|
||||
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
|
||||
,sum(coalesce(cost_usd,0)) cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,orderdate --history date mix
|
||||
,requestdate --history date mix
|
||||
,shipdate --history date mix
|
||||
,adj_orderdate --history
|
||||
,adj_requestdate --history
|
||||
,adj_shipdate --history
|
||||
,'b20' "version" --calculated
|
||||
,'adjustment' iter --calculated
|
||||
---------------ui columns-------------------------
|
||||
,order_season
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,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
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
plnt ---master data
|
||||
,promo
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,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
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -159,51 +87,29 @@ SELECT
|
||||
,c_rate --master data
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,orderdate --history date mix
|
||||
,requestdate --history date mix
|
||||
,shipdate --history date mix
|
||||
,adj_orderdate --history
|
||||
,adj_requestdate --history
|
||||
,adj_shipdate --history
|
||||
---------------ui columns-------------------------
|
||||
,order_season
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,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
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
)
|
||||
,scale AS (
|
||||
SELECT
|
||||
(SELECT incr::numeric FROM target) incr
|
||||
,(SELECT sum(fb_val_loc * r_rate) FROM basemix) base
|
||||
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM basemix) = 0 THEN
|
||||
,(SELECT sum(value_loc * r_rate) FROM basemix) base
|
||||
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN
|
||||
0
|
||||
ELSE
|
||||
(SELECT incr::numeric FROM target)/(SELECT sum(fb_val_loc * r_rate) FROM basemix)
|
||||
(SELECT incr::numeric FROM target)/(SELECT sum(value_loc * r_rate) FROM basemix)
|
||||
END factor
|
||||
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM basemix) = 0 THEN
|
||||
CASE WHEN ((SELECT incr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM basemix)) <> 0 THEN
|
||||
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN
|
||||
CASE WHEN ((SELECT incr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM basemix)) <> 0 THEN
|
||||
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply
|
||||
((SELECT incr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM basemix))/(SELECT sum(fb_qty) FROM basemix)
|
||||
((SELECT incr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM basemix))/(SELECT sum(units) FROM basemix)
|
||||
ELSE
|
||||
0
|
||||
END
|
||||
@ -211,193 +117,153 @@ SELECT
|
||||
0
|
||||
END mod_price
|
||||
)
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,final AS (
|
||||
SELECT
|
||||
b.plnt --master data
|
||||
,b."ddord#" --0
|
||||
,b."dditm#" --0
|
||||
,b."fgbol#" --0
|
||||
,b."fgent#" --0
|
||||
,b."diinv#" --0
|
||||
,b."dilin#" --0
|
||||
,b.promo --history date mix
|
||||
,b.return_reas --0
|
||||
,b.terms --history cust mix
|
||||
,b.custpo --0
|
||||
,b.dhincr --0
|
||||
,b.diext --0
|
||||
,b.ditdis --0
|
||||
,b.dcodat --calculated date mix
|
||||
,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*s.factor fb_val_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric fb_val_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc_pl*s.factor END)::numeric fb_val_loc_pl
|
||||
--,b.fb_val_loc_pl*s.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 --calculated
|
||||
-----------------------ui columns--------------------------------
|
||||
,'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_family
|
||||
,b.part_group
|
||||
,b.branding
|
||||
,b.color
|
||||
,b.segm
|
||||
,b.bill_cust_descr
|
||||
,b.billto_group
|
||||
,b.ship_cust_descr
|
||||
,b.shipto_group
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.mod_chan
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric value_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price ELSE b.fb_val_loc*s.factor*r_rate END)::numeric value_usd
|
||||
,0 cost_loc
|
||||
,0 cost_usd
|
||||
,0 units
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN scale s
|
||||
WHERE
|
||||
s.factor <> 0 or s.mod_price <> 0
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,0::numeric units
|
||||
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric value_usd
|
||||
,0::numeric cost_loc
|
||||
,0::numeric cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' price' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN scale s
|
||||
CROSS JOIN log
|
||||
WHERE
|
||||
s.factor <> 0 or s.mod_price <> 0
|
||||
)
|
||||
--select sum(value_usd), count(*) from final
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING *
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM final RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
@ -2,18 +2,17 @@ WITH
|
||||
target AS (select incr_qty qincr)
|
||||
,testv AS (
|
||||
SELECT
|
||||
sum(fb_qty) tot
|
||||
,sum(fb_qty) FILTER (WHERE iter = 'copy') base
|
||||
,sum(fb_qty) FILTER (WHERE iterdef->>'type' = 'new basket') newpart
|
||||
sum(units) tot
|
||||
,sum(units) FILTER (WHERE iter = 'copy') base
|
||||
,sum(units) FILTER (WHERE module = 'new basket') newpart
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool p
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
|
||||
AND order_date <= ship_date
|
||||
)
|
||||
,flagv AS (
|
||||
SELECT
|
||||
@ -38,115 +37,54 @@ target AS (select incr_qty qincr)
|
||||
)
|
||||
--ever need receive a target of -0- qty but value <> 0?
|
||||
,basemix AS (
|
||||
SELECT
|
||||
plnt ---master data
|
||||
,0::numeric(11,0) "ddord#" --0
|
||||
,0::numeric(11,0) "dditm#" --0
|
||||
,0::numeric(11,0) "fgbol#" --0
|
||||
,0::numeric(11,0) "fgent#" --0
|
||||
,0::numeric(9,0) "diinv#" --0
|
||||
,0::numeric(3,0) "dilin#" --0
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,null::text return_reas --0
|
||||
,terms
|
||||
,''::text custpo --0
|
||||
,'I' dhincr --0
|
||||
,null::numeric diext
|
||||
,null::numeric ditdis
|
||||
,null::date dcodat --calculated date mix
|
||||
,null::date ddqdat --calculated date mix
|
||||
,null::date dcmdat --calculated date mix
|
||||
,null::date dhidat --calculated date mix
|
||||
,null::text fspr --calculated date mix
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,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
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,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
|
||||
,sum(coalesce(units,0)) units --history value
|
||||
,sum(coalesce(value_loc,0)) value_loc --history value
|
||||
,sum(coalesce(value_usd,0)) value_usd --0
|
||||
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
|
||||
,sum(coalesce(cost_usd,0)) cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,orderdate --history date mix
|
||||
,requestdate --history date mix
|
||||
,shipdate --history date mix
|
||||
,adj_orderdate --history
|
||||
,adj_requestdate --history
|
||||
,adj_shipdate --history
|
||||
,null::text "version" --calculated
|
||||
,null::text iter --calculated
|
||||
---------------ui columns-------------------------
|
||||
,order_season
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,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
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
@ -154,46 +92,35 @@ SELECT
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
plnt ---master data
|
||||
,promo
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,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
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -201,229 +128,169 @@ SELECT
|
||||
,c_rate --master data
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,orderdate --history date mix
|
||||
,requestdate --history date mix
|
||||
,shipdate --history date mix
|
||||
,adj_orderdate --history
|
||||
,adj_requestdate --history
|
||||
,adj_shipdate --history
|
||||
---------------ui columns-------------------------
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
)
|
||||
--SELECT * FROM basemix
|
||||
,scale AS (
|
||||
SELECT
|
||||
(SELECT qincr::numeric FROM target) incr
|
||||
,(SELECT sum(value_loc *r_rate) FROM basemix) base
|
||||
,(SELECT qincr FROM target)/(SELECT SUM(units) FROM basemix) factor
|
||||
)
|
||||
--select * from scale
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,final AS (
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,units*s.factor
|
||||
,value_loc*s.factor value_loc
|
||||
,value_usd*s.factor value_usd
|
||||
,cost_loc*s.factor cost_loc
|
||||
,cost_usd*s.factor cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN scale s
|
||||
CROSS JOIN log
|
||||
)
|
||||
--select sum(value_usd), count(*) from final
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM final RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,part_descr
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,segm
|
||||
,bill_cust_descr
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
)
|
||||
--SELECT * FROM basemix
|
||||
,scale AS (
|
||||
SELECT
|
||||
(SELECT qincr::numeric FROM target) incr
|
||||
,(SELECT sum(fb_val_loc *r_rate) FROM basemix) base
|
||||
,(SELECT qincr FROM target)/(SELECT SUM(fb_qty) FROM basemix) factor
|
||||
)
|
||||
--select * from scale
|
||||
,final AS (
|
||||
SELECT
|
||||
b.plnt --master data
|
||||
,b."ddord#" --0
|
||||
,b."dditm#" --0
|
||||
,b."fgbol#" --0
|
||||
,b."fgent#" --0
|
||||
,b."diinv#" --0
|
||||
,b."dilin#" --0
|
||||
,b.promo --history date mix
|
||||
,b.return_reas --0
|
||||
,b.terms --history cust mix
|
||||
,b.custpo --0
|
||||
,b.dhincr --0
|
||||
,b.diext --0
|
||||
,b.ditdis --0
|
||||
,b.dcodat --calculated date mix
|
||||
,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 fb_qty
|
||||
,b.fb_cst_loc*s.factor fb_cst_loc
|
||||
,b.fb_cst_loc_cur*s.factor fb_cst_loc_cur
|
||||
,b.fb_cst_loc_fut*s.factor fb_cst_loc_fut
|
||||
,b.fb_val_loc*s.factor fb_val_loc
|
||||
,b.fb_val_loc_pl*s.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'||' volume' iter
|
||||
-----------------------ui columns--------------------------------
|
||||
,'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_family
|
||||
,b.part_group
|
||||
,b.branding
|
||||
,b.color
|
||||
,b.segm
|
||||
,b.bill_cust_descr
|
||||
,b.billto_group
|
||||
,b.ship_cust_descr
|
||||
,b.shipto_group
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.mod_chan
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,(b.fb_val_loc*s.factor)::numeric value_loc
|
||||
,(b.fb_val_loc*s.factor*r_rate)::numeric value_usd
|
||||
,(b.fb_cst_loc*s.factor)::numeric cost_loc
|
||||
,(b.fb_cst_loc*s.factor*c_rate)::numeric cost_usd
|
||||
,(b.fb_qty*s.factor)::numeric units
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN scale s
|
||||
)
|
||||
--select sum(value_usd), count(*) from final
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
@ -2,17 +2,17 @@ WITH
|
||||
target AS (select target_vol vincr, target_prc pincr)
|
||||
,testv AS (
|
||||
SELECT
|
||||
sum(fb_qty) tot
|
||||
,sum(fb_qty) FILTER (WHERE iter = 'copy') base
|
||||
,sum(fb_qty) FILTER (WHERE iterdef->>'type' = 'new basket') newpart
|
||||
sum(units) tot
|
||||
,sum(units) FILTER (WHERE iter = 'copy') base
|
||||
,sum(units) FILTER (WHERE module = 'new basket') newpart
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
|
||||
)
|
||||
,flagv AS (
|
||||
@ -38,114 +38,53 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
)
|
||||
,basemix AS (
|
||||
SELECT
|
||||
plnt ---master data
|
||||
,0::numeric(11,0) "ddord#" --0
|
||||
,0::numeric(11,0) "dditm#" --0
|
||||
,0::numeric(11,0) "fgbol#" --0
|
||||
,0::numeric(11,0) "fgent#" --0
|
||||
,0::numeric(9,0) "diinv#" --0
|
||||
,0::numeric(3,0) "dilin#" --0
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,null::text return_reas --0
|
||||
,terms
|
||||
,''::text custpo --0
|
||||
,'I' dhincr --0
|
||||
,null::numeric diext
|
||||
,null::numeric ditdis
|
||||
,null::date dcodat --calculated date mix
|
||||
,null::date ddqdat --calculated date mix
|
||||
,null::date dcmdat --calculated date mix
|
||||
,null::date dhidat --calculated date mix
|
||||
,null::text fspr --calculated date mix
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,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
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,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
|
||||
,sum(coalesce(units,0)) units --history value
|
||||
,sum(coalesce(value_loc,0)) value_loc --history value
|
||||
,sum(coalesce(value_usd,0)) value_usd --0
|
||||
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
|
||||
,sum(coalesce(cost_usd,0)) cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,orderdate --history date mix
|
||||
,requestdate --history date mix
|
||||
,shipdate --history date mix
|
||||
,adj_orderdate --history
|
||||
,adj_requestdate --history
|
||||
,adj_shipdate --history
|
||||
,null::text "version" --calculated
|
||||
,null::text iter --calculated
|
||||
---------------ui columns-------------------------
|
||||
,order_season
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,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
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
@ -153,46 +92,35 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
plnt ---master data
|
||||
,promo
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,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
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -200,174 +128,99 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
,c_rate --master data
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,orderdate --history date mix
|
||||
,requestdate --history date mix
|
||||
,shipdate --history date mix
|
||||
,adj_orderdate --history
|
||||
,adj_requestdate --history
|
||||
,adj_shipdate --history
|
||||
---------------ui columns-------------------------
|
||||
,order_season
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,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
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
)
|
||||
,vscale AS (
|
||||
SELECT
|
||||
(SELECT vincr::numeric FROM target) incr
|
||||
,(SELECT sum(fb_qty)::numeric FROM basemix) base
|
||||
,(SELECT vincr::numeric FROM target)/(SELECT sum(fb_qty)::numeric FROM basemix) factor
|
||||
,(SELECT sum(units)::numeric FROM basemix) base
|
||||
,(SELECT vincr::numeric FROM target)/(SELECT sum(units)::numeric FROM basemix) factor
|
||||
)
|
||||
--select * from vscale
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,volume AS (
|
||||
SELECT
|
||||
b.plnt --master data
|
||||
,b."ddord#" --0
|
||||
,b."dditm#" --0
|
||||
,b."fgbol#" --0
|
||||
,b."fgent#" --0
|
||||
,b."diinv#" --0
|
||||
,b."dilin#" --0
|
||||
,b.promo --history date mix
|
||||
,b.return_reas --0
|
||||
,b.terms --history cust mix
|
||||
,b.custpo --0
|
||||
,b.dhincr --0
|
||||
,b.diext --0
|
||||
,b.ditdis --0
|
||||
,b.dcodat --calculated date mix
|
||||
,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 fb_qty
|
||||
,b.fb_cst_loc*s.factor fb_cst_loc
|
||||
,b.fb_cst_loc_cur*s.factor fb_cst_loc_cur
|
||||
,b.fb_cst_loc_fut*s.factor fb_cst_loc_fut
|
||||
,b.fb_val_loc*s.factor fb_val_loc
|
||||
,b.fb_val_loc_pl*s.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'||' volume' iter
|
||||
-----------------------ui columns--------------------------------
|
||||
,'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_family
|
||||
,b.part_group
|
||||
,b.branding
|
||||
,b.color
|
||||
,b.segm
|
||||
,b.bill_cust_descr
|
||||
,b.billto_group
|
||||
,b.ship_cust_descr
|
||||
,b.shipto_group
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.mod_chan
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,(b.fb_val_loc*s.factor)::numeric value_loc
|
||||
,(b.fb_val_loc*s.factor*r_rate)::numeric value_usd
|
||||
,(b.fb_cst_loc*s.factor)::numeric cost_loc
|
||||
,(b.fb_cst_loc*s.factor*c_rate)::numeric cost_usd
|
||||
,(b.fb_qty*s.factor)::numeric units
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN vscale s
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,units*s.factor units
|
||||
,value_loc*s.factor value_loc
|
||||
,value_usd*s.factor value_usd
|
||||
,cost_loc*s.factor cost_loc
|
||||
,cost_usd*s.factor cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN vscale s
|
||||
CROSS JOIN log
|
||||
)
|
||||
,pscale AS (
|
||||
SELECT
|
||||
(SELECT pincr::numeric FROM target) incr
|
||||
,(SELECT sum(fb_val_loc * r_rate) FROM volume) base
|
||||
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN
|
||||
,(SELECT sum(value_loc * r_rate) FROM volume) base
|
||||
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
|
||||
--if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
|
||||
0
|
||||
ELSE
|
||||
--if the target $amount is not achieved, adjust further
|
||||
((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
|
||||
,CASE WHEN (SELECT sum(fb_val_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 sum(value_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
|
||||
((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
|
||||
0
|
||||
END
|
||||
@ -378,191 +231,148 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
--select * from pscale
|
||||
,pricing AS (
|
||||
SELECT
|
||||
b.plnt --master data
|
||||
,b."ddord#" --0
|
||||
,b."dditm#" --0
|
||||
,b."fgbol#" --0
|
||||
,b."fgent#" --0
|
||||
,b."diinv#" --0
|
||||
,b."dilin#" --0
|
||||
,b.promo --history date mix
|
||||
,b.return_reas --0
|
||||
,b.terms --history cust mix
|
||||
,b.custpo --0
|
||||
,b.dhincr --0
|
||||
,b.diext --0
|
||||
,b.ditdis --0
|
||||
,b.dcodat --calculated date mix
|
||||
,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*s.factor fb_val_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric fb_val_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc_pl*s.factor END)::numeric fb_val_loc_pl
|
||||
--,b.fb_val_loc_pl*s.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
|
||||
-----------------------ui columns--------------------------------
|
||||
,'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_family
|
||||
,b.part_group
|
||||
,b.branding
|
||||
,b.color
|
||||
,b.segm
|
||||
,b.bill_cust_descr
|
||||
,b.billto_group
|
||||
,b.ship_cust_descr
|
||||
,b.shipto_group
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.mod_chan
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric value_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price ELSE b.fb_val_loc*s.factor*b.r_rate END)::numeric value_usd
|
||||
,0 cost_loc
|
||||
,0 cost_usd
|
||||
,0 units
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,0::numeric units
|
||||
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric value_usd
|
||||
,0::numeric cost_loc
|
||||
,0::numeric cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' price' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
volume b
|
||||
CROSS JOIN pscale s
|
||||
CROSS JOIN log
|
||||
WHERE
|
||||
s.factor <> 0 or s.mod_price <> 0
|
||||
)
|
||||
--select sum(value_usd), sum(fb_qty) from pricing
|
||||
--select sum(value_usd), sum(units) from pricing
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_fcpool (SELECT * FROM pricing UNION ALL SELECT * FROM volume) RETURNING *
|
||||
INSERT INTO rlarp.osm_pool (SELECT * FROM pricing UNION ALL SELECT * FROM volume) RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,segm
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,part_descr
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
379
route_sql/scale_vupd_sales.sql
Normal file
379
route_sql/scale_vupd_sales.sql
Normal file
@ -0,0 +1,379 @@
|
||||
WITH
|
||||
target AS (select target_vol vincr, target_prc pincr)
|
||||
,testv AS (
|
||||
SELECT
|
||||
sum(units) tot
|
||||
,sum(units) FILTER (WHERE iter = 'copy') base
|
||||
,sum(units) FILTER (WHERE module = 'new basket') newpart
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
|
||||
)
|
||||
,flagv AS (
|
||||
SELECT
|
||||
tot
|
||||
,base
|
||||
,newpart
|
||||
,CASE WHEN tot = 0 THEN
|
||||
CASE WHEN base = 0 THEN
|
||||
CASE WHEN newpart = 0 THEN
|
||||
'unclean data. tested -> does not exist'
|
||||
ELSE
|
||||
'scale new part'
|
||||
END
|
||||
ELSE
|
||||
'scale copy'
|
||||
END
|
||||
ELSE
|
||||
'scale all'
|
||||
END flag
|
||||
FROM
|
||||
testv
|
||||
)
|
||||
,basemix AS (
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,sum(coalesce(units,0)) units --history value
|
||||
,sum(coalesce(value_loc,0)) value_loc --history value
|
||||
,sum(coalesce(value_usd,0)) value_usd --0
|
||||
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
|
||||
,sum(coalesce(cost_usd,0)) cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
AND ship_season = 2022
|
||||
-----------------additional params-------------------
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
)
|
||||
,vscale AS (
|
||||
SELECT
|
||||
(SELECT vincr::numeric FROM target) incr
|
||||
,(SELECT sum(units)::numeric FROM basemix) base
|
||||
,(SELECT vincr::numeric FROM target)/(SELECT sum(units)::numeric FROM basemix) factor
|
||||
)
|
||||
--select * from vscale
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,volume AS (
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,units*s.factor units
|
||||
,value_loc*s.factor value_loc
|
||||
,value_usd*s.factor value_usd
|
||||
,cost_loc*s.factor cost_loc
|
||||
,cost_usd*s.factor cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN vscale s
|
||||
CROSS JOIN log
|
||||
)
|
||||
,pscale AS (
|
||||
SELECT
|
||||
(SELECT pincr::numeric FROM target) incr
|
||||
,(SELECT sum(value_loc * r_rate) FROM volume) base
|
||||
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
|
||||
--if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
|
||||
0
|
||||
ELSE
|
||||
--if the target $amount is not achieved, adjust further
|
||||
((SELECT pincr::numeric FROM target)-(SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(value_loc * r_rate) FROM volume)
|
||||
END factor
|
||||
,CASE WHEN (SELECT sum(value_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
|
||||
((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume)
|
||||
ELSE
|
||||
0
|
||||
END
|
||||
ELSE
|
||||
0
|
||||
END mod_price
|
||||
)
|
||||
--select * from pscale
|
||||
,pricing AS (
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,0::numeric units
|
||||
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
|
||||
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric value_usd
|
||||
,0::numeric cost_loc
|
||||
,0::numeric cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' price' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
volume b
|
||||
CROSS JOIN pscale s
|
||||
CROSS JOIN log
|
||||
WHERE
|
||||
s.factor <> 0 or s.mod_price <> 0
|
||||
)
|
||||
--select sum(value_usd), sum(units) from pricing
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_pool (SELECT * FROM pricing UNION ALL SELECT * FROM volume) RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
@ -5,18 +5,18 @@ mseq AS (
|
||||
SELECT * FROM
|
||||
(
|
||||
VALUES
|
||||
('Jun',1)
|
||||
,('Jul',2)
|
||||
,('Aug',3)
|
||||
,('Sep',4)
|
||||
,('Oct',5)
|
||||
,('Nov',6)
|
||||
,('Dec',7)
|
||||
,('Jan',8)
|
||||
,('Feb',9)
|
||||
,('Mar',10)
|
||||
,('Apr',11)
|
||||
,('May',12)
|
||||
('01 - Jun',1)
|
||||
,('02 - Jul',2)
|
||||
,('03 - Aug',3)
|
||||
,('04 - Sep',4)
|
||||
,('05 - Oct',5)
|
||||
,('06 - Nov',6)
|
||||
,('07 - Dec',7)
|
||||
,('08 - Jan',8)
|
||||
,('09 - Feb',9)
|
||||
,('10 - Mar',10)
|
||||
,('11 - Apr',11)
|
||||
,('12 - May',12)
|
||||
|
||||
) x(m,s)
|
||||
)
|
||||
@ -33,10 +33,10 @@ SELECT
|
||||
,SUM(units) units
|
||||
,SUM(value_usd) value_usd
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
where_clause
|
||||
AND order_season IN (2019,2020)
|
||||
AND order_season IN (2021,2022)
|
||||
GROUP BY
|
||||
order_season
|
||||
,order_month
|
||||
@ -94,14 +94,14 @@ GROUP BY
|
||||
SELECT
|
||||
order_month
|
||||
,seq
|
||||
,SUM(units) FILTER (WHERE order_season = 2019) "2019 qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2020 AND iter IN ('copy','short ship','bad_ship')) "2020 base qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2020 AND iter NOT IN ('copy','short ship','bad_ship')) "2020 adj qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2020) "2020 tot qty"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2019) "2019 value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2020 AND iter IN ('copy','short ship','bad_ship')) "2020 base value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2020 AND iter NOT IN ('copy','short ship','bad_ship')) "2020 adj value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2020) "2020 tot value_usd"
|
||||
,SUM(units) FILTER (WHERE order_season = 2021) "2021 qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2022 AND iter IN ('copy','short ship','bad_ship')) "2022 base qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2022 AND iter NOT IN ('copy','short ship','bad_ship')) "2022 adj qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2022) "2022 tot qty"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2021) "2021 value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2022 AND iter IN ('copy','short ship','bad_ship')) "2022 base value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2022 AND iter NOT IN ('copy','short ship','bad_ship')) "2022 adj value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2022) "2022 tot value_usd"
|
||||
FROM
|
||||
months
|
||||
GROUP BY
|
||||
@ -113,14 +113,14 @@ GROUP BY
|
||||
,mlist AS (
|
||||
SELECT
|
||||
mseq.m order_month
|
||||
,"2019 qty"
|
||||
,"2020 base qty"
|
||||
,"2020 adj qty"
|
||||
,"2020 tot qty"
|
||||
,"2019 value_usd"
|
||||
,"2020 base value_usd"
|
||||
,"2020 adj value_usd"
|
||||
,"2020 tot value_usd"
|
||||
,"2021 qty"
|
||||
,"2022 base qty"
|
||||
,"2022 adj qty"
|
||||
,"2022 tot qty"
|
||||
,"2021 value_usd"
|
||||
,"2022 base value_usd"
|
||||
,"2022 adj value_usd"
|
||||
,"2022 tot value_usd"
|
||||
FROM
|
||||
mseq
|
||||
LEFT OUTER JOIN mpvt ON
|
||||
@ -142,6 +142,32 @@ GROUP BY
|
||||
,version
|
||||
,iter
|
||||
)
|
||||
,tags AS (
|
||||
SELECT DISTINCT
|
||||
doc->>'tag' tag
|
||||
FROM
|
||||
rlarp.osm_log
|
||||
WHERE
|
||||
doc ? 'tag'
|
||||
AND id <> 1
|
||||
UNION
|
||||
SELECT * FROM
|
||||
(VALUES
|
||||
('price'),
|
||||
('volume')
|
||||
) x(tag)
|
||||
)
|
||||
,custs AS (
|
||||
SELECT
|
||||
bill_cust_descr
|
||||
,ship_cust_descr
|
||||
,SUM(value_usd) value_usd
|
||||
FROM
|
||||
base
|
||||
GROUP BY
|
||||
bill_cust_descr
|
||||
,ship_cust_descr
|
||||
)
|
||||
SELECT
|
||||
jsonb_build_object(
|
||||
'months'
|
||||
@ -152,4 +178,8 @@ SELECT
|
||||
,(SELECT jsonb_agg(row_to_json(basket)::jsonb) FROM basket)
|
||||
,'totals'
|
||||
,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals)
|
||||
,'tags'
|
||||
,(SELECT jsonb_agg(tag) FROM tags)
|
||||
,'customers'
|
||||
,(SELECT jsonb_agg(row_to_json(custs)::jsonb) FROM custs)
|
||||
) package
|
311
route_sql/swap_cust.sql
Normal file
311
route_sql/swap_cust.sql
Normal file
@ -0,0 +1,311 @@
|
||||
WITH
|
||||
target AS (SELECT $$swap_doc$$::jsonb swap)
|
||||
,swap AS (
|
||||
SELECT
|
||||
rtrim(substring(bill,1,8)) billto
|
||||
,rtrim(substring(bill_r,1,8)) bill_r
|
||||
,rtrim(substring(ship,1,8)) shipto
|
||||
,rtrim(substring(ship_r,1,8)) ship_r
|
||||
FROM
|
||||
TARGET
|
||||
LEFT JOIN LATERAL jsonb_to_recordset(target.swap->'rows') AS x(bill text, bill_r text, ship text, ship_r text)ON TRUE
|
||||
WHERE
|
||||
rtrim(substring(bill_r,1,8)) IS NOT null
|
||||
OR rtrim(substring(ship_r,1,8)) IS NOT null
|
||||
)
|
||||
,cust AS (
|
||||
----------only return dba if being replaced-------------------------------------------------
|
||||
----------class and rep must always bew returned for both to determine new quota rep--------
|
||||
SELECT
|
||||
billto
|
||||
,bill_r
|
||||
,CASE WHEN bill_r IS NULL THEN NULL::text ELSE bc.bvadr6 END bill_dba
|
||||
,bc.bvclas bill_class
|
||||
,bc.bvsalm bill_rep
|
||||
,shipto
|
||||
,ship_r
|
||||
,CASE WHEN ship_r IS NULL THEN NULL::text ELSE sc.bvadr6 END ship_dba
|
||||
,sc.bvclas ship_class
|
||||
,sc.bvsalm ship_rep
|
||||
FROM
|
||||
swap
|
||||
----default to the replacement customer but join to original otherwise since still neeed
|
||||
----customer info for revised quote rep
|
||||
LEFT OUTER JOIN lgdat.cust bc ON
|
||||
bc.bvcust = COALESCE(swap.bill_r,billto)
|
||||
LEFT OUTER JOIN lgdat.cust sc ON
|
||||
sc.bvcust = COALESCE(swap.ship_r,shipto)
|
||||
)
|
||||
--put bill to and ship to back together and join in channel, terms, descriptions, etc
|
||||
,seg AS (
|
||||
SELECT
|
||||
x.glec
|
||||
,x.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)
|
||||
)
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,remove AS (
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,-units units
|
||||
,-value_loc value_loc
|
||||
,-value_usd value_usd
|
||||
,-cost_loc cost_loc
|
||||
,-cost_usd cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
CROSS JOIN log
|
||||
INNER JOIN cust c ON
|
||||
c.billto = SUBSTRING(o.bill_cust_descr,1,8)
|
||||
AND c.shipto = SUBSTRING(o.ship_cust_descr,1,8)
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
)
|
||||
,repl AS (
|
||||
SELECT
|
||||
o.fspr
|
||||
,o.plnt ---master data
|
||||
,o.promo --history date mix
|
||||
,o.terms
|
||||
,COALESCE(c.bill_r||' - '||c.bill_dba,o.bill_cust_descr) bill_cust_descr
|
||||
,COALESCE(c.ship_r||' - '||c.ship_dba,o.ship_cust_descr) ship_cust_descr
|
||||
,o.dsm
|
||||
,(regexp_match(r.repp,'.* - (.*)$'))[1] quota_rep_descr
|
||||
,r.director
|
||||
,COALESCE(c.bill_dba,o.billto_group) billto_group
|
||||
,COALESCE(c.ship_dba,o.shipto_group) shipto_group
|
||||
,CASE SUBSTRING(c.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(c.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 chan
|
||||
,CASE SUBSTRING(c.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(c.ship_class,2,3)
|
||||
WHEN 'DIS' THEN 'WHS'
|
||||
ELSE CASE SUBSTRING(c.ship_class,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
|
||||
END
|
||||
WHEN 'MAS' THEN 'RMN'
|
||||
WHEN 'NAT' THEN 'RMN'
|
||||
ELSE CASE SUBSTRING(c.ship_class,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
|
||||
END chansub
|
||||
,o.chan_retail
|
||||
,o.part
|
||||
,o.part_descr
|
||||
,o.part_group
|
||||
,o.branding
|
||||
,o.majg_descr
|
||||
,o.ming_descr
|
||||
,o.majs_descr
|
||||
,o.mins_descr
|
||||
,o.segm
|
||||
,o.substance
|
||||
,o.fs_line --master data
|
||||
,o.r_currency --history cust mix
|
||||
,o.r_rate --master data
|
||||
,o.c_currency --master data
|
||||
,o.c_rate --master data
|
||||
,-o.units units
|
||||
,-o.value_loc value_loc
|
||||
,-o.value_usd value_usd
|
||||
,-o.cost_loc cost_loc
|
||||
,-o.cost_usd cost_usd
|
||||
,o.calc_status --0
|
||||
,o.flag --0
|
||||
,o.order_date --history date mix
|
||||
,o.order_month
|
||||
,o.order_season
|
||||
,o.request_date --history date mix
|
||||
,o.request_month
|
||||
,o.request_season
|
||||
,o.ship_date --history date mix
|
||||
,o.ship_month
|
||||
,o.ship_season
|
||||
,o."version"
|
||||
,o.iter
|
||||
,o.id
|
||||
,o."tag"
|
||||
,o."comment"
|
||||
,o.module
|
||||
FROM
|
||||
remove o
|
||||
INNER JOIN cust c ON
|
||||
c.billto = SUBSTRING(o.bill_cust_descr,1,8)
|
||||
AND c.shipto = SUBSTRING(o.ship_cust_descr,1,8)
|
||||
LEFT OUTER JOIN rlarp.repc r ON
|
||||
r.rcode = CASE WHEN COALESCE(substring(ming_descr,1,3),'') = '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(o.segm,'') = 'Retail' AND COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = c.bill_r),'') <> ''
|
||||
THEN
|
||||
(SELECT currep FROM lgpgm.usrcust where cucust = c.bill_r)
|
||||
--default logic
|
||||
ELSE
|
||||
CASE SUBSTR(c.bill_class,2,3)
|
||||
WHEN 'DIS' THEN c.ship_rep
|
||||
ELSE c.bill_rep
|
||||
END
|
||||
END
|
||||
END
|
||||
)
|
||||
--select bill_cust_descr, ship_cust_descr, sum(value_usd) from (SELECT * FROM remove UNION ALL SELECT * FROM repl) x group by bill_cust_descr, ship_cust_descr
|
||||
,ins AS (
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM remove UNION ALL SELECT * FROM repl RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
77
route_sql/swap_fit.sql
Normal file
77
route_sql/swap_fit.sql
Normal file
@ -0,0 +1,77 @@
|
||||
WITH
|
||||
target AS (select 'replace_new_mold' new_mold)
|
||||
,basemix AS (
|
||||
SELECT
|
||||
part,
|
||||
stlc,
|
||||
colc,
|
||||
colgrp,
|
||||
coltier,
|
||||
sizc,
|
||||
SUM(value_usd) value_usd
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||
i.item = o.part
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
GROUP BY
|
||||
part,
|
||||
stlc,
|
||||
colc,
|
||||
colgrp,
|
||||
coltier,
|
||||
sizc
|
||||
)
|
||||
--SELECT * FROM basemix
|
||||
,tag AS (
|
||||
SELECT
|
||||
b.part
|
||||
,b.value_usd
|
||||
--,b.stlc
|
||||
--,b.sizc
|
||||
--,b.colgrp
|
||||
--,b.coltier
|
||||
--,b.colc
|
||||
,i.item
|
||||
,CASE WHEN b.sizc = i.sizc THEN '1' ELSE '0' END||
|
||||
CASE WHEN i.aplnt = 'I' THEN '0' ELSE '1' END||
|
||||
CASE WHEN b.colgrp = i.colgrp THEN '1' ELSE '0' END||
|
||||
CASE WHEN b.coltier = i.coltier THEN '1' ELSE '0' END||
|
||||
CASE WHEN b.colc = i.colc THEN '1' ELSE '0' END||
|
||||
CASE WHEN substring(b.part,9,12) = substring(i.item,9,12) THEN '1' ELSE 0 END fit
|
||||
FROM
|
||||
basemix b
|
||||
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||
i.stlc = (SELECT new_mold FROM target WHERE new_mold <> '')
|
||||
AND CASE WHEN b.sizc = i.sizc THEN '1' ELSE '0' END||
|
||||
CASE WHEN i.aplnt = 'I' THEN '0' ELSE '1' END||
|
||||
CASE WHEN b.colgrp = i.colgrp THEN '1' ELSE '0' END||
|
||||
CASE WHEN b.coltier = i.coltier THEN '1' ELSE '0' END||
|
||||
CASE WHEN b.colc = i.colc THEN '1' ELSE '0' END||
|
||||
CASE WHEN substring(b.part,9,12) = substring(i.item,9,12) THEN '1' ELSE 0 END >= '111110'
|
||||
)
|
||||
--SELECT * FROM tag
|
||||
,rsort AS (
|
||||
SELECT
|
||||
part,
|
||||
value_usd,
|
||||
item swap,
|
||||
fit,
|
||||
ROW_NUMBER() OVER (PARTITION BY tag.part ORDER BY fit DESC) ranked
|
||||
FROM
|
||||
tag
|
||||
ORDER BY
|
||||
part
|
||||
,fit desc
|
||||
)
|
||||
SELECT
|
||||
json_agg(row_to_json(rsort)) x
|
||||
FROM
|
||||
rsort
|
||||
WHERE
|
||||
ranked = 1
|
264
route_sql/swap_post.sql
Normal file
264
route_sql/swap_post.sql
Normal file
@ -0,0 +1,264 @@
|
||||
WITH
|
||||
target AS (SELECT $$swap_doc$$::jsonb swap)
|
||||
,pl AS (
|
||||
SELECT
|
||||
-----trim white space on CMS part numbers coming from spreadsheet master data----
|
||||
rtrim(x.original) AS original
|
||||
,sales
|
||||
,rtrim(x."replace") AS replace
|
||||
,rtrim(x.fit) fit
|
||||
FROM
|
||||
TARGET
|
||||
LEFT JOIN LATERAL jsonb_to_recordset(target.swap->'rows') AS x(original text, sales numeric, replace text, fit text)ON TRUE
|
||||
WHERE
|
||||
COALESCE(x.replace,'') <> ''
|
||||
)
|
||||
--select * from pl
|
||||
,seg AS (
|
||||
SELECT
|
||||
x.glec
|
||||
,x.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)
|
||||
)
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,remove AS (
|
||||
SELECT
|
||||
fspr
|
||||
,plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,part
|
||||
,part_descr
|
||||
,part_group
|
||||
,branding
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,-units units
|
||||
,-value_loc value_loc
|
||||
,-value_usd value_usd
|
||||
,-cost_loc cost_loc
|
||||
,-cost_usd cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
CROSS JOIN log
|
||||
INNER JOIN pl ON
|
||||
pl.original = o.part
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
)
|
||||
,repl AS (
|
||||
SELECT
|
||||
fspr
|
||||
,m.dplt plnt ---master data
|
||||
,promo --history date mix
|
||||
,terms
|
||||
,bill_cust_descr --history cust mix
|
||||
,ship_cust_descr --history cust mix
|
||||
,dsm
|
||||
,quota_rep_descr --master data
|
||||
,director
|
||||
,billto_group --master data
|
||||
,shipto_group
|
||||
,chan --master data
|
||||
,chansub
|
||||
,chan_retail
|
||||
,pl.replace part
|
||||
,m.item || ' - ' || m.descr partd
|
||||
,substring(pl.replace,1,8) part_group
|
||||
,m.branding branding
|
||||
,m.majg||' - '||m.majgd majg_descr
|
||||
,m.ming||' - '||m.mingd ming_descr
|
||||
,m.majs||' - '||m.majsd majs_descr
|
||||
,m.mins||' - '||m.minsd mins_descr
|
||||
,seg.segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,r.curr c_currency --master data
|
||||
,x.rate c_rate --master data
|
||||
,-units units
|
||||
,-value_loc value_loc
|
||||
,-value_usd value_usd
|
||||
,-units * c.std cost_loc
|
||||
,-units * c.std * x.rate cost_usd
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,order_date --history date mix
|
||||
,order_month
|
||||
,order_season
|
||||
,request_date --history date mix
|
||||
,request_month
|
||||
,request_season
|
||||
,ship_date --history date mix
|
||||
,ship_month
|
||||
,ship_season
|
||||
,o."version"
|
||||
,o.iter
|
||||
,o.id
|
||||
,o."tag"
|
||||
,o."comment"
|
||||
,o.module
|
||||
FROM
|
||||
remove o
|
||||
INNER JOIN pl ON
|
||||
pl.original = o.part
|
||||
INNER JOIN rlarp.itemmv m ON
|
||||
m.item = pl.replace
|
||||
LEFT OUTER JOIN rlarp.icstx c ON
|
||||
c.part = pl.replace
|
||||
AND c.plnt = m.dplt
|
||||
LEFT OUTER JOIN rlarp.plpr r ON
|
||||
yaplnt = m.dplt
|
||||
LEFT OUTER JOIN rlarp.ffcret x ON
|
||||
x.fcur = r.curr
|
||||
AND x.tcur = 'US'
|
||||
AND x.rtyp = 'BG'
|
||||
AND x.perd = '2101'
|
||||
LEFT OUTER JOIN seg ON
|
||||
seg.glec = m.glec
|
||||
)
|
||||
,ins AS (
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM remove UNION ALL SELECT * FROM repl RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
,ship_month
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
8
route_sql/undo.sql
Normal file
8
route_sql/undo.sql
Normal 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
28
sample_request.json
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user