From 43a194b1162a44612e35404a68228221212ab62f Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Wed, 26 Feb 2020 17:07:35 -0500 Subject: [PATCH 1/3] add terms to base mix --- route_sql/new_basket.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index a2426bd..72f848c 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -151,6 +151,8 @@ target AS (select $$replace_request$$::json def) to_char(order_date,'Mon') _month ,seq ,promo + ,terms + --should terms be included here? ,sum(extract(day from order_date)*value_usd) dom_wa --,request_date-order_date rlag ,sum((request_date-order_date)*(value_usd)) rlag_wa @@ -163,6 +165,7 @@ target AS (select $$replace_request$$::json def) to_char(order_date,'Mon') ,seq ,promo + ,terms --,extract(day from order_date) --,request_date-order_date --,ship_date - request_date @@ -189,6 +192,7 @@ target AS (select $$replace_request$$::json def) _month ,seq ,promo + ,terms ,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom ,round((rlag_wa/value_usd)::numeric,0)::int rlag ,round((slag_wa/value_usd)::numeric,0)::int slag @@ -212,6 +216,7 @@ SELECT ,x.rlag ,x.slag ,x.promo + ,x.terms FROM targm t LEFT OUTER JOIN mmixp x ON @@ -231,6 +236,7 @@ FROM SELECT sd.fspr ,mxm.promo + ,mxm.terms ,jr.bill_cust_descr ,jr.ship_cust_descr ,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part @@ -269,7 +275,7 @@ SELECT b.fspr ,i.dplt plnt ,b.promo - ,bc.bvterm terms + ,b.terms ,b.bill_cust_descr ,b.ship_cust_descr ,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm From 8838fdbcbcd86ffda74c628b62bef631653e9e2c Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Wed, 26 Feb 2020 17:07:49 -0500 Subject: [PATCH 2/3] add in currency --- route_sql/new_basket.sql | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index 72f848c..b5da1f0 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -106,6 +106,7 @@ target AS (select $$replace_request$$::json def) SELECT promo ,terms + ,r_currency ,order_month ,mseq.s seq ,order_date @@ -126,6 +127,7 @@ target AS (select $$replace_request$$::json def) GROUP BY promo ,terms + ,r_currency ,order_month ,mseq.s ,order_date @@ -152,6 +154,7 @@ target AS (select $$replace_request$$::json def) ,seq ,promo ,terms + ,(SELECT r_currency FROM alldates GROUP BY r_currency ORDER BY SUM(value_usd) DESC LIMIT 1) r_currency --should terms be included here? ,sum(extract(day from order_date)*value_usd) dom_wa --,request_date-order_date rlag @@ -193,6 +196,7 @@ target AS (select $$replace_request$$::json def) ,seq ,promo ,terms + ,r_currency ,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom ,round((rlag_wa/value_usd)::numeric,0)::int rlag ,round((slag_wa/value_usd)::numeric,0)::int slag @@ -217,6 +221,7 @@ SELECT ,x.slag ,x.promo ,x.terms + ,x.r_currency FROM targm t LEFT OUTER JOIN mmixp x ON @@ -237,6 +242,7 @@ SELECT sd.fspr ,mxm.promo ,mxm.terms + ,mxm.r_currency ,jr.bill_cust_descr ,jr.ship_cust_descr ,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part @@ -318,7 +324,7 @@ SELECT ,seg.segm ,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance ,'41010' fs_line --master data - ,bc.bvcurr r_currency --history cust mix + ,mxm.r_currency --history cust mix ,rx.rate r_rate --master data ,copr.curr c_currency --master data ,cx.rate c_rate --master data @@ -423,7 +429,7 @@ FROM LEFT OUTER JOIN rlarp.ffcret rx ON rx.perd = '2008' AND rx.rtyp = 'MA' - AND rx.fcur = bc.bvcurr + AND rx.fcur = COALESCE(bc.bvcurr,mxm.r_currency) AND rx.tcur = 'US' ) , ins AS ( From 10d20e050ea712ca2d5e57406f3d9bea1ea96343 Mon Sep 17 00:00:00 2001 From: pt Date: Wed, 26 Feb 2020 23:55:20 -0500 Subject: [PATCH 3/3] use basline fx and new budget period fx rates --- route_sql/new_basket.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index b5da1f0..721f5f4 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -281,7 +281,7 @@ SELECT b.fspr ,i.dplt plnt ,b.promo - ,b.terms + ,COALESCE(b.terms,bc.bvterm) terms ,b.bill_cust_descr ,b.ship_cust_descr ,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm @@ -324,7 +324,7 @@ SELECT ,seg.segm ,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance ,'41010' fs_line --master data - ,mxm.r_currency --history cust mix + ,b.r_currency --history cust mix ,rx.rate r_rate --master data ,copr.curr c_currency --master data ,cx.rate c_rate --master data @@ -422,14 +422,14 @@ FROM LEFT OUTER JOIN copr ON copr.comp = yacomp::text LEFT OUTER JOIN rlarp.ffcret cx ON - cx.perd = '2008' - AND cx.rtyp = 'MA' + cx.perd = '2101' + AND cx.rtyp = 'BG' AND cx.fcur = copr.curr AND cx.tcur = 'US' LEFT OUTER JOIN rlarp.ffcret rx ON - rx.perd = '2008' - AND rx.rtyp = 'MA' - AND rx.fcur = COALESCE(bc.bvcurr,mxm.r_currency) + rx.perd = '2101' + AND rx.rtyp = 'BG' + AND rx.fcur = COALESCE(bc.bvcurr,b.r_currency) AND rx.tcur = 'US' ) , ins AS (