From 169225b1e9400b32681e2c0d1f4f7c7fc6f34c14 Mon Sep 17 00:00:00 2001 From: Sagar Date: Thu, 14 Jun 2012 14:09:23 +0530 Subject: [PATCH] [SIGNED-OFF] Bug 7571 Maintain exchange rate history Content-Type: text/plain; charset="utf-8" Keep track of changes to exchange rates for accounting purposes. History is displayed with each currency. Behaviour is as expected. Signed-off-by: Marc Veron --- admin/currency.pl | 23 ++++++++++++++++++++ installer/data/mysql/updatedatabase.pl | 7 ++++++ .../prog/en/modules/admin/currency.tt | 15 +++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-) diff --git a/admin/currency.pl b/admin/currency.pl index e24f6b6..381e8ce 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -175,6 +175,21 @@ sub add_form { $template->param( 'timestamp' => format_date($date) ); } + my $dbh = C4::Context->dbh; + my $query = " + SELECT currency,timestamp,rate + FROM ex_rates where currency=?; + "; + my $sth = $dbh->prepare($query); + $sth->execute($curr); + my @results = (); + while ( my $data = $sth->fetchrow_hashref ) { + push( @results, $data ); + } + $template->param( + ex_result => \@results, + ); + return; } @@ -188,6 +203,13 @@ sub add_validate { currency => $input->param('currency'), }; + $dbh->do( +q|INSERT INTO ex_rates (currency, rate, timestamp) VALUES (?,?,now()) |, + {}, + $rec->{currency}, + $rec->{rate} + ); + if ( $rec->{active} == 1 ) { $dbh->do('UPDATE currency SET active = 0'); } @@ -204,6 +226,7 @@ q|UPDATE currency SET rate = ?, symbol = ?, active = ? WHERE currency = ? |, $rec->{active}, $rec->{currency} ); + } else { $dbh->do( q|INSERT INTO currency (currency, rate, symbol, active) VALUES (?,?,?,?) |, diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index d06a188..ebe6042 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5392,6 +5392,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.09.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("create table ex_rates(currency varchar(10) not null REFERENCES currency(currency) ON UPDATE CASCADE ON DELETE CASCADE,rate float(15,5) default null,timestamp timestamp not null,UNIQUE(currency,timestamp));"); + print "Upgrade to $DBversion done (Insert currency details into ex_rates for exchage rate history)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt index 4834ff3..d98ab3e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt @@ -133,6 +133,21 @@ + [% IF ( searchfield ) %] +

Exchange rates History [% searchfield %]

+ + + + + + [% FOREACH loo IN ex_result %] + + + + + [% END %] +
DateRate
[% loo.timestamp %][% loo.rate %]
+ [% END %] [% END %] [% IF ( delete_confirm ) %] -- 1.7.2.5