From 879319b8899843b1130674ff53973934fb8054db Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Tue, 25 Feb 2020 10:01:09 -0500 Subject: [PATCH] change how currency is handled and add sort to month --- README.md | 3 ++- route_sql/new_basket.sql | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fbd932d..6a09ce7 100644 --- a/README.md +++ b/README.md @@ -50,4 +50,5 @@ Walk Issues Things to Demo * product swap out * pivot re-org -* don't use filters \ No newline at end of file +* don't use filters +* assumes all changes target USD \ No newline at end of file diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index 09e9c58..3fa47ff 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -18,6 +18,7 @@ target AS (select $$replace_request$$::json def) ,N1ED01 - N1SD01 +1 NDAYS ,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR ,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR + ,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') || ' - '|| TO_CHAR(n1ed01,'Mon') SORTMO FROM LGDAT.GLDATREF INNER JOIN LGDAT.GLDATE ON @@ -235,15 +236,15 @@ SELECT ,jr.part_descr ,substring(jr.part_descr,1,8) part_group ,mxm.qty*mxm.momix*jr.mix units - ,mxm.amount*mxm.momix*jr.mix value_loc + ,mxm.amount*mxm.momix*jr.mix value_usd --assume that target dollars are USD ,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) order_date - ,to_char(make_date(mxm.yr + 2021,mxm.cal,mxm.odom),'Mon') order_month + ,od.sortmo order_month ,od.ssyr order_season ,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag request_date - ,to_char(make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag,'Mon') request_month + ,rd.sortmo request_month ,rd.ssyr request_season ,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag ship_date - ,to_char(make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag,'Mon') ship_month + ,sd.sortmo ship_month ,sd.ssyr ship_season ,jr.mix FROM @@ -315,10 +316,10 @@ SELECT ,copr.curr c_currency --master data ,cx.rate c_rate --master data ,b.units - ,b.value_loc - ,b.value_loc * rx.rate value_usd + ,b.value_usd / rx.rate --b.value is denominated in USD, need to apply currency to get to local + ,b.value_usd value_usd --b.value is already denominated in usd ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units cost_loc - ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_loc + ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_usd ,'CLOSED' calc_status ,'SHIPMENT' flag ,b.order_date