In our application we store multiple project fundings of different donors that they insert in their respective currency, e.g. EUR for Germany, SEK for Sweden etc.
The idea is to provide reports for these projects in one currency.. We are currently storing the amount of funding together with it's currency in a table like this:
development=> \d funding_forecasts
Table "public.funding_forecasts"
Column | Type | Modifiers
-------------+------------------------+----------------------------------------------------------------
id | integer | not null default nextval('funding_forecasts_id_seq'::regclass)
project_id | integer |
year | integer |
currency | character varying(255) |
payments | integer |
commitments | integer |
We are further having an exchange_rates table that stores exchange rates from a base currency to a specific currency for each year.
Now the problem is that when we are creating reports, we need to query a lot of funding tables for each project and are thus having a huuuuge amount of queries + numerous currency conversions and aggregations on the application side.
What I think would be cool because Rails isn't very flexible with custom SQL (I know it can be but it is a hassle) is to do the conversion more or less transparently, maybe using a custom data type that allows easy aggregation (using sum and +/- etc. operators).. I'm not sure about this at all anyway so all comments are very much appreciated!