From 8307b7c8ea3372a780cd2d1567d8486e29cf58c1 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 5 Apr 2021 12:06:49 -0400 Subject: [PATCH] retain dsm and fx rates, couple date fixes --- build/build_forecast.sql | 48 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/build/build_forecast.sql b/build/build_forecast.sql index ded2084..8c5cbb6 100644 --- a/build/build_forecast.sql +++ b/build/build_forecast.sql @@ -54,7 +54,7 @@ gld AS ( ,null::numeric ditdis ,null::jsonb discj ,null::text dhincr - ,plnt + ,o.plnt ,COALESCE(o.promo,'') promo ,null::text return_reas ,o.terms @@ -65,10 +65,10 @@ gld AS ( ,null::text bill_rep ,null::text bill_terr ,null::text ship_class - ,ship_cust + ,o.ship_cust ,null::text ship_rep ,null::text ship_terr - ,null::text dsm + ,o.dsm ,null::text account ,null::text shipgrp ,null::text geo @@ -111,9 +111,9 @@ gld AS ( ,null::text plcd ,o.fs_line ,o.r_currency - ,null::numeric r_rate + ,o.r_rate ,o.c_currency - ,null::numeric c_rate + ,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 @@ -145,26 +145,31 @@ gld AS ( WHERE ( --base period orders booked.... - o.odate BETWEEN '2020-06-01' AND '2021-04-11' + 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-11') + 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 '2011' + 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 - ,plnt + ,o.plnt ,COALESCE(o.promo,'') ,o.terms ,o.bill_cust - ,ship_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 @@ -216,7 +221,7 @@ gld AS ( ,ship_cust ,null::text ship_rep ,null::text ship_terr - ,null::text dsm + ,o.dsm ,null::text account ,null::text shipgrp ,null::text geo @@ -259,9 +264,9 @@ gld AS ( ,null::text plcd ,o.fs_line ,o.r_currency - ,null::numeric r_rate + ,o.r_rate ,o.c_currency - ,null::numeric c_rate + ,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 @@ -289,22 +294,25 @@ gld AS ( 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' + o.odate BETWEEN '2020-04-05' 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 false + AND version = 'ACTUALS' GROUP BY o.fspr ,plnt ,COALESCE(o.promo,'') ,o.terms ,o.bill_cust - ,ship_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 @@ -429,11 +437,11 @@ gld AS ( LEFT OUTER JOIN gld ss ON greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat WHERE - o.odate BETWEEN '2020-03-01' AND '2020-05-31' - AND fs_line = '41010' - AND calc_status <> 'CANCELED' + 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-- - AND false GROUP BY o.fspr ,plnt