add in currency

This commit is contained in:
Trowbridge 2020-02-26 17:07:49 -05:00
parent 43a194b116
commit 8838fdbcbc

View File

@ -106,6 +106,7 @@ target AS (select $$replace_request$$::json def)
SELECT SELECT
promo promo
,terms ,terms
,r_currency
,order_month ,order_month
,mseq.s seq ,mseq.s seq
,order_date ,order_date
@ -126,6 +127,7 @@ target AS (select $$replace_request$$::json def)
GROUP BY GROUP BY
promo promo
,terms ,terms
,r_currency
,order_month ,order_month
,mseq.s ,mseq.s
,order_date ,order_date
@ -152,6 +154,7 @@ target AS (select $$replace_request$$::json def)
,seq ,seq
,promo ,promo
,terms ,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? --should terms be included here?
,sum(extract(day from order_date)*value_usd) dom_wa ,sum(extract(day from order_date)*value_usd) dom_wa
--,request_date-order_date rlag --,request_date-order_date rlag
@ -193,6 +196,7 @@ target AS (select $$replace_request$$::json def)
,seq ,seq
,promo ,promo
,terms ,terms
,r_currency
,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom ,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom
,round((rlag_wa/value_usd)::numeric,0)::int rlag ,round((rlag_wa/value_usd)::numeric,0)::int rlag
,round((slag_wa/value_usd)::numeric,0)::int slag ,round((slag_wa/value_usd)::numeric,0)::int slag
@ -217,6 +221,7 @@ SELECT
,x.slag ,x.slag
,x.promo ,x.promo
,x.terms ,x.terms
,x.r_currency
FROM FROM
targm t targm t
LEFT OUTER JOIN mmixp x ON LEFT OUTER JOIN mmixp x ON
@ -237,6 +242,7 @@ SELECT
sd.fspr sd.fspr
,mxm.promo ,mxm.promo
,mxm.terms ,mxm.terms
,mxm.r_currency
,jr.bill_cust_descr ,jr.bill_cust_descr
,jr.ship_cust_descr ,jr.ship_cust_descr
,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part ,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part
@ -318,7 +324,7 @@ SELECT
,seg.segm ,seg.segm
,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance ,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
,'41010' fs_line --master data ,'41010' fs_line --master data
,bc.bvcurr r_currency --history cust mix ,mxm.r_currency --history cust mix
,rx.rate r_rate --master data ,rx.rate r_rate --master data
,copr.curr c_currency --master data ,copr.curr c_currency --master data
,cx.rate c_rate --master data ,cx.rate c_rate --master data
@ -423,7 +429,7 @@ FROM
LEFT OUTER JOIN rlarp.ffcret rx ON LEFT OUTER JOIN rlarp.ffcret rx ON
rx.perd = '2008' rx.perd = '2008'
AND rx.rtyp = 'MA' AND rx.rtyp = 'MA'
AND rx.fcur = bc.bvcurr AND rx.fcur = COALESCE(bc.bvcurr,mxm.r_currency)
AND rx.tcur = 'US' AND rx.tcur = 'US'
) )
, ins AS ( , ins AS (