change status so that only true open orders show as such

This commit is contained in:
Paul Trowbridge 2019-03-25 00:42:10 -04:00
parent df8f63fcfb
commit 878ed265ca
4 changed files with 20 additions and 29 deletions

View File

@ -255,8 +255,8 @@ gld AS (
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut ,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
,sum(o.fb_val_loc) fb_val_loc ,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_pl) fb_val_loc_pl ,sum(o.fb_val_loc_pl) fb_val_loc_pl
,o.calc_status ,'CLOSED' calc_status
,o.flag ,'SHIPMENT' flag
,o.orderdate ,o.orderdate
,o.requestdate ,o.requestdate
,greatest(least(o.shipdate,gld.edat),gld.sdat) shipdate ,greatest(least(o.shipdate,gld.edat),gld.sdat) shipdate
@ -336,8 +336,6 @@ gld AS (
,o.ddqtsi ,o.ddqtsi
,o.fgqshp ,o.fgqshp
,o.diqtsh ,o.diqtsh
,o.calc_status
,o.flag
,o.orderdate ,o.orderdate
,o.requestdate ,o.requestdate
,greatest(least(o.shipdate,gld.edat),gld.sdat) ,greatest(least(o.shipdate,gld.edat),gld.sdat)

View File

@ -1,3 +1,5 @@
BEGIN;
WITH WITH
mseq AS ( mseq AS (
SELECT * FROM SELECT * FROM
@ -74,30 +76,21 @@ GROUP BY
ORDER BY ORDER BY
value_usd DESC value_usd DESC
) )
,rbld AS ( ,upd AS (
SELECT UPDATE rlarp.osmfs o SET
o.shipgrp adj_shipdate = greatest(shipdate + lag.wav_lag + 5 ,shipdate)
,o.orderdate
,o.requestdate
,o.shipdate
,o.orderm
,o.rmo
,o.value_usd
,lag.wav_lag
,o.requestdate + lag.wav_lag + 15 rship
FROM FROM
opord o lag
LEFT OUTER JOIN lag ON WHERE
lag.shipgrp = o.shipgrp lag.shipgrp = o.shipgrp
AND lag.orderm = o.orderm AND lag.orderm = to_char(o.orderdate,'Mon')
AND lag.rmo = o.rmo AND lag.rmo = extract(month FROM age(o.requestdate,o.orderdate))
ORDER BY AND o.calc_status in ('BACKORDER','OPEN')
value_usd desc RETURNING *
) )
select SELECT
sum(value_usd) filter (where rship >= '2019-04-01') sum(fb_val_loc *r_rate) filter (where adj_shipdate < '2019-04-01')
,sum(value_usd) filter (where rship < '2019-04-01') ,sum(fb_val_loc *r_rate) filter (where adj_shipdate >= '2019-04-01')
from from upd;
rbld
where COMMIT;
shipdate < '2019-04-01'