coalesce DBA and coalesce FX for local

This commit is contained in:
Paul Trowbridge 2020-02-26 10:35:41 -05:00
parent ebc169e34a
commit fb1fcabb00

View File

@ -275,8 +275,8 @@ SELECT
,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm ,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm
,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr ,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr
,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director ,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director
,CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END billto_group ,COALESCE(CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END,b.bill_cust_descr) billto_group
,CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE bc.BVADR6 END shipto_group ,COALESCE(CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE bc.BVADR6 END,b.ship_cust_descr) shipto_group
,CASE SUBSTRING(bc.bvclas,2,3) ,CASE SUBSTRING(bc.bvclas,2,3)
--if the bill to class is ditsributor, then it's either warehouse or drop --if the bill to class is ditsributor, then it's either warehouse or drop
WHEN 'DIS' THEN WHEN 'DIS' THEN
@ -317,7 +317,7 @@ SELECT
,copr.curr c_currency --master data ,copr.curr c_currency --master data
,cx.rate c_rate --master data ,cx.rate c_rate --master data
,b.units ,b.units
,b.value_usd / rx.rate --b.value is denominated in USD, need to apply currency to get to local ,b.value_usd / COALESCE(rx.rate,1) --b.value is denominated in USD, need to apply currency to get to local, assume 1 if using a fake customer
,b.value_usd value_usd --b.value is already denominated in usd ,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 cost_loc
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_usd ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_usd