From 8838fdbcbcd86ffda74c628b62bef631653e9e2c Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Wed, 26 Feb 2020 17:07:49 -0500 Subject: [PATCH] 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 (