From 7d5fb2a7f61d0fd73e64138aac60bf64cbb79c7f Mon Sep 17 00:00:00 2001 From: Sagar Date: Thu, 14 Jun 2012 14:09:23 +0530 Subject: [PATCH] Bug 7571 Maintain exchange rate history 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(+) diff --git a/admin/currency.pl b/admin/currency.pl index f62f761..2c4a236 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -169,6 +169,21 @@ sub add_form { } } + 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; } @@ -183,6 +198,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'); } @@ -200,6 +222,7 @@ q|UPDATE currency SET rate = ?, symbol = ?, isocode = ?, active = ? WHERE curren $rec->{active}, $rec->{currency} ); + } else { $dbh->do( q|INSERT INTO currency (currency, rate, symbol, isocode, active) VALUES (?,?,?,?,?) |, diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 13c03d5..c88def1 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -10425,6 +10425,13 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.19.00.XXX"; +if ( CheckVersion($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); +} + # DEVELOPER PROCESS, search for anything to execute in the db_update directory # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. 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 57c38cf..f5e010b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt @@ -122,6 +122,21 @@ + [% IF ( searchfield ) %] +

Exchange rates History [% searchfield %]

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