From 878ed265ca45f20e06390e7ef1417ef9e23b9679 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 25 Mar 2019 00:42:10 -0400 Subject: [PATCH] change status so that only true open orders show as such --- route_sql/build/copy_orders.sql | 6 ++-- route_sql/build/increment_orders.sql | 0 route_sql/build/open_timing.sql | 43 +++++++++++--------------- route_sql/{ => build}/set_fspr_gld.sql | 0 4 files changed, 20 insertions(+), 29 deletions(-) delete mode 100644 route_sql/build/increment_orders.sql rename route_sql/{ => build}/set_fspr_gld.sql (100%) diff --git a/route_sql/build/copy_orders.sql b/route_sql/build/copy_orders.sql index 60adba8..bc3045a 100644 --- a/route_sql/build/copy_orders.sql +++ b/route_sql/build/copy_orders.sql @@ -255,8 +255,8 @@ gld AS ( ,sum(o.fb_cst_loc_fut) fb_cst_loc_fut ,sum(o.fb_val_loc) fb_val_loc ,sum(o.fb_val_loc_pl) fb_val_loc_pl - ,o.calc_status - ,o.flag + ,'CLOSED' calc_status + ,'SHIPMENT' flag ,o.orderdate ,o.requestdate ,greatest(least(o.shipdate,gld.edat),gld.sdat) shipdate @@ -336,8 +336,6 @@ gld AS ( ,o.ddqtsi ,o.fgqshp ,o.diqtsh - ,o.calc_status - ,o.flag ,o.orderdate ,o.requestdate ,greatest(least(o.shipdate,gld.edat),gld.sdat) diff --git a/route_sql/build/increment_orders.sql b/route_sql/build/increment_orders.sql deleted file mode 100644 index e69de29..0000000 diff --git a/route_sql/build/open_timing.sql b/route_sql/build/open_timing.sql index ca296d0..c8772cd 100644 --- a/route_sql/build/open_timing.sql +++ b/route_sql/build/open_timing.sql @@ -1,3 +1,5 @@ +BEGIN; + WITH mseq AS ( SELECT * FROM @@ -74,30 +76,21 @@ GROUP BY ORDER BY value_usd DESC ) -,rbld AS ( -SELECT - o.shipgrp - ,o.orderdate - ,o.requestdate - ,o.shipdate - ,o.orderm - ,o.rmo - ,o.value_usd - ,lag.wav_lag - ,o.requestdate + lag.wav_lag + 15 rship +,upd AS ( +UPDATE rlarp.osmfs o SET + adj_shipdate = greatest(shipdate + lag.wav_lag + 5 ,shipdate) FROM - opord o - LEFT OUTER JOIN lag ON - lag.shipgrp = o.shipgrp - AND lag.orderm = o.orderm - AND lag.rmo = o.rmo -ORDER BY - value_usd desc + lag +WHERE + lag.shipgrp = o.shipgrp + AND lag.orderm = to_char(o.orderdate,'Mon') + AND lag.rmo = extract(month FROM age(o.requestdate,o.orderdate)) + AND o.calc_status in ('BACKORDER','OPEN') +RETURNING * ) -select - sum(value_usd) filter (where rship >= '2019-04-01') - ,sum(value_usd) filter (where rship < '2019-04-01') -from - rbld -where - shipdate < '2019-04-01' \ No newline at end of file +SELECT + sum(fb_val_loc *r_rate) filter (where adj_shipdate < '2019-04-01') + ,sum(fb_val_loc *r_rate) filter (where adj_shipdate >= '2019-04-01') +from upd; + +COMMIT; \ No newline at end of file diff --git a/route_sql/set_fspr_gld.sql b/route_sql/build/set_fspr_gld.sql similarity index 100% rename from route_sql/set_fspr_gld.sql rename to route_sql/build/set_fspr_gld.sql