update building of forecast to integrate last price paid

This commit is contained in:
Paul Trowbridge 2019-03-25 02:31:31 -04:00
parent 878ed265ca
commit 4907170629
2 changed files with 568 additions and 534 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
BEGIN; BEGIN;
with p AS ( with p AS (
SELECT SELECT
part part
@ -22,7 +23,7 @@ with p AS (
,orderdate ,orderdate
) )
--SELECT * FROM p WHERE rn = 1 --SELECT * FROM p WHERE rn = 1
,ins AS ( ,incr AS (
SELECT SELECT
b.plnt b.plnt
,b."ddord#" ,b."ddord#"
@ -84,12 +85,12 @@ with p AS (
,b.ddqtsi ,b.ddqtsi
,b.fgqshp ,b.fgqshp
,b.diqtsh ,b.diqtsh
,b.fb_qty ,0 fb_qty
,b.fb_cst_loc ,0 fb_cst_loc
,b.fb_cst_loc_cur ,0 fb_cst_loc_cur
,b.fb_cst_loc_fut ,0 fb_cst_loc_fut
,b.fb_qty * p.price - b.fb_val_loc fb_val_loc ,b.fb_qty * p.price - b.fb_val_loc fb_val_loc
,b.fb_val_loc_pl ,0 fb_val_loc_pl
,b.calc_status ,b.calc_status
,b.flag ,b.flag
,b.orderdate ,b.orderdate
@ -99,24 +100,21 @@ with p AS (
,b.adj_requestdate ,b.adj_requestdate
,b.adj_shipdate ,b.adj_shipdate
,b."version" ,b."version"
,b.iter ,'last price paid' 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
FROM 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 WHERE
p.part = f.part b.orderdate BETWEEN '2019-03-25' AND '2019-05-31'
AND p.bill_cust = f.bill_cust OR b.orderdate BETWEEN '2020-03-25' AND '2020-05-31'
AND p.ship_cust = f.ship_cust
) )
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;