From e96a2a6fd3a8885b0fb035ecc55bdf50dbe5a4aa Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sat, 8 Jun 2013 01:30:52 -0700 Subject: multi-currency, RT#21565 --- httemplate/edit/process/currency_exchange.html | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 httemplate/edit/process/currency_exchange.html (limited to 'httemplate/edit/process/currency_exchange.html') diff --git a/httemplate/edit/process/currency_exchange.html b/httemplate/edit/process/currency_exchange.html new file mode 100644 index 000000000..1f6852299 --- /dev/null +++ b/httemplate/edit/process/currency_exchange.html @@ -0,0 +1,36 @@ +%if ( $error ) { +% errorpage($error); #also not super ideal +%} else { #or this +<% include('/elements/header.html', 'Exchange rates updated') %> +<% include('/elements/footer.html') %> +%} +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $conf = new FS::Conf; + +my $to_currency = $conf->config('currency') || 'USD'; + +my @currencies = sort { $a cmp $b } $conf->config('currencies'); + +#in the best of all possible worlds, i would be a single database transaction +# but here it isn't terribly important other than offending my sense of elegance +my $error = ''; +foreach my $currency (@currencies) { + + my %hash = ( 'from_currency' => $currency, + 'to_currency' => $to_currency, + ); + + my $currency_exchange = qsearchs('currency_exchange', \%hash) + || new FS::currency_exchange \%hash; + + $currency_exchange->rate( $cgi->param("$currency-$to_currency") ); + + my $method = $currency_exchange->currencyratenum ? 'replace' : 'insert'; + $error = $currency_exchange->$method() and last; +} + + -- cgit v1.2.1