update building of forecast to integrate last price paid
This commit is contained in:
parent
878ed265ca
commit
4907170629
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
with p AS (
|
||||
SELECT
|
||||
part
|
||||
@ -22,7 +23,7 @@ with p AS (
|
||||
,orderdate
|
||||
)
|
||||
--SELECT * FROM p WHERE rn = 1
|
||||
,ins AS (
|
||||
,incr AS (
|
||||
SELECT
|
||||
b.plnt
|
||||
,b."ddord#"
|
||||
@ -84,12 +85,12 @@ with p AS (
|
||||
,b.ddqtsi
|
||||
,b.fgqshp
|
||||
,b.diqtsh
|
||||
,b.fb_qty
|
||||
,b.fb_cst_loc
|
||||
,b.fb_cst_loc_cur
|
||||
,b.fb_cst_loc_fut
|
||||
,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
|
||||
,b.fb_val_loc_pl
|
||||
,0 fb_val_loc_pl
|
||||
,b.calc_status
|
||||
,b.flag
|
||||
,b.orderdate
|
||||
@ -99,24 +100,21 @@ with p AS (
|
||||
,b.adj_requestdate
|
||||
,b.adj_shipdate
|
||||
,b."version"
|
||||
,b.iter
|
||||
WHERE
|
||||
orderdate BETWEEN '2019-03-25' AND '2019-05-31'
|
||||
AND version = '9p3'
|
||||
AND iter = 'forecast'
|
||||
)
|
||||
,
|
||||
|
||||
/*
|
||||
,upd AS (
|
||||
UPDATE rlarp.osmfs SET
|
||||
fb_val_loc = fb_qty * p.price
|
||||
,'last price paid' iter
|
||||
FROM
|
||||
p
|
||||
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
|
||||
p.part = f.part
|
||||
AND p.bill_cust = f.bill_cust
|
||||
AND p.ship_cust = f.ship_cust
|
||||
b.orderdate BETWEEN '2019-03-25' AND '2019-05-31'
|
||||
OR b.orderdate BETWEEN '2020-03-25' AND '2020-05-31'
|
||||
)
|
||||
ROLLBACK;
|
||||
*/
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osmfs SELECT * FROM incr RETURNING *
|
||||
)
|
||||
SELECT fspr, sum(fb_val_loc *r_rate) FROM ins GROUP BY fspr;
|
||||
|
||||
COMMIT;
|
Loading…
Reference in New Issue
Block a user