RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / edit / process / currency_exchange.html
1 %if ( $error ) {
2 %  errorpage($error); #also not super ideal
3 %} else { #or this
4 <% include('/elements/header.html', 'Exchange rates updated') %>
5 <% include('/elements/footer.html') %>
6 %}
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
11
12 my $conf = new FS::Conf;
13
14 my $to_currency = $conf->config('currency') || 'USD';
15
16 my @currencies = sort { $a cmp $b } $conf->config('currencies');
17
18 #in the best of all possible worlds, i would be a single database transaction
19 # but here it isn't terribly important other than offending my sense of elegance
20 my $error = '';
21 foreach my $currency (@currencies) {
22
23   my %hash = ( 'from_currency' => $currency,
24                'to_currency'   => $to_currency,
25              );
26
27   my $currency_exchange = qsearchs('currency_exchange', \%hash)
28                          || new FS::currency_exchange   \%hash;
29
30   $currency_exchange->rate( $cgi->param("$currency-$to_currency") );
31
32   my $method = $currency_exchange->currencyratenum ? 'replace' : 'insert';
33   $error = $currency_exchange->$method() and last;
34 }
35
36 </%init>