From 1538e9ecf47642c4974693ff499c3e95e4d71977 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 29 Oct 2015 12:21:52 +0000 Subject: [PATCH] Bug 15084: Replace C4::Budgets::GetCurrencies with Koha::Acquisition::Currencies->search Most part of the code here is unnecessary complex. We should selected the currency if it is selected, that's all :) Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall Signed-off-by: Brendan A Gallagher --- C4/Biblio.pm | 9 ++-- C4/Budgets.pm | 42 ------------------- C4/Overdues.pm | 6 +-- Koha/Acquisition/Currencies.pm | 9 ++++ Koha/Number/Price.pm | 6 +-- about.pl | 3 +- acqui/addorder.pl | 5 ++- acqui/addorderiso2709.pl | 39 +++-------------- acqui/basket.pl | 6 +-- acqui/invoice.pl | 3 +- acqui/neworderempty.pl | 40 +++--------------- acqui/supplier.pl | 24 ++--------- admin/aqbudgetperiods.pl | 7 ++-- admin/aqbudgets.pl | 7 ++-- admin/aqplan.pl | 7 ++-- admin/preferences.pl | 6 +-- .../prog/en/modules/acqui/addorderiso2709.tt | 14 +++---- .../prog/en/modules/acqui/neworderempty.tt | 17 +++++--- .../prog/en/modules/acqui/supplier.tt | 26 +++++++----- .../prog/en/modules/admin/currency.tt | 2 + .../prog/en/modules/suggestion/suggestion.tt | 29 ++++++++----- misc/cronjobs/overdue_notices.pl | 1 + opac/sco/sco-main.pl | 5 ++- suggestion/suggestion.pl | 25 ++--------- t/Number/Price.t | 14 +++---- t/db_dependent/Biblio.t | 18 +++++--- t/db_dependent/MungeMarcPrice.t | 6 +-- 27 files changed, 143 insertions(+), 233 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 10faa8336d..a2b1d0a254 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -40,6 +40,7 @@ use C4::OAI::Sets; use Koha::Cache; use Koha::Authority::Types; +use Koha::Acquisition::Currencies; use vars qw($VERSION @ISA @EXPORT); @@ -1531,10 +1532,10 @@ sub MungeMarcPrice { my ( $price ) = @_; return unless ( $price =~ m/\d/ ); ## No digits means no price. # Look for the currency symbol and the normalized code of the active currency, if it's there, - my $active_currency = C4::Budgets->GetCurrency(); - my $symbol = $active_currency->{'symbol'}; - my $isocode = $active_currency->{'isocode'}; - $isocode = $active_currency->{'currency'} unless defined $isocode; + my $active_currency = Koha::Acquisition::Currencies->get_active; + my $symbol = $active_currency->symbol; + my $isocode = $active_currency->isocode; + $isocode = $active_currency->currency unless defined $isocode; my $localprice; if ( $symbol ) { my @matches =($price=~ / diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 1c30e1bf21..734eb6a679 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -59,8 +59,6 @@ BEGIN { &ModBudgetPlan - &GetCurrency - &GetCurrencies &ConvertCurrency &GetBudgetsPlanCell @@ -917,46 +915,6 @@ sub CanUserModifyBudget { # ------------------------------------------------------------------- -=head2 GetCurrencies - - @currencies = &GetCurrencies; - -Returns the list of all known currencies. - -C<$currencies> is a array; its elements are references-to-hash, whose -keys are the fields from the currency table in the Koha database. - -=cut - -sub GetCurrencies { - my $dbh = C4::Context->dbh; - my $query = " - SELECT * - FROM currency - "; - my $sth = $dbh->prepare($query); - $sth->execute; - my @results = (); - while ( my $data = $sth->fetchrow_hashref ) { - push( @results, $data ); - } - return @results; -} - -# ------------------------------------------------------------------- - -sub GetCurrency { - my $dbh = C4::Context->dbh; - my $query = " - SELECT * FROM currency where active = '1' "; - my $sth = $dbh->prepare($query); - $sth->execute; - my $r = $sth->fetchrow_hashref; - return $r; -} - -# ------------------------------------------------------------------- - =head2 ConvertCurrency $foreignprice = &ConvertCurrency($currency, $localprice); diff --git a/C4/Overdues.pm b/C4/Overdues.pm index e376798ab6..6c09f43824 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -33,7 +33,6 @@ use C4::Context; use C4::Accounts; use C4::Log; # logaction use C4::Debug; -use C4::Budgets qw(GetCurrency); use Koha::DateUtils; use Koha::Account::Line; use Koha::Account::Lines; @@ -1004,9 +1003,10 @@ sub parse_overdues_letter { $tables{'branches'} = $p; } - my $currencies = GetCurrency(); + my $active_currency = Koha::Acquisition::Currencies->get_active; + my $currency_format; - $currency_format = $currencies->{currency} if defined($currencies); + $currency_format = $active_currency->currency if defined($active_currency); my @item_tables; if ( my $i = $params->{'items'} ) { diff --git a/Koha/Acquisition/Currencies.pm b/Koha/Acquisition/Currencies.pm index 7f506a722e..cdbbfed98f 100644 --- a/Koha/Acquisition/Currencies.pm +++ b/Koha/Acquisition/Currencies.pm @@ -35,6 +35,15 @@ Koha::Acquisition::Currencies - Koha Acquisition Currency Object set class =cut +=head3 get_active + +=cut + +sub get_active { + my ( $self ) = @_; + return $self->SUPER::search( { active => 1 } )->next; +} + =head3 type =cut diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm index 2d563f9e8c..331e3c33e8 100644 --- a/Koha/Number/Price.pm +++ b/Koha/Number/Price.pm @@ -21,7 +21,7 @@ use Modern::Perl; use Number::Format qw( format_price ); use C4::Context; -use C4::Budgets qw( GetCurrency ); +use Koha::Acquisition::Currencies; use base qw( Class::Accessor ); __PACKAGE__->mk_accessors(qw( value )); @@ -82,7 +82,7 @@ sub _format_params { my $with_symbol = $params->{with_symbol} || 0; my $p_cs_precedes = $params->{p_cs_precedes}; my $p_sep_by_space = $params->{p_sep_by_space}; - my $currency = GetCurrency(); + my $currency = Koha::Acquisition::Currencies->get_active; my $currency_format = C4::Context->preference("CurrencyFormat"); my $int_curr_symbol = q||; @@ -94,7 +94,7 @@ sub _format_params { if ( $currency_format eq 'FR' ) { # FIXME This test should be done for all currencies - $int_curr_symbol = $currency->{symbol} if $with_symbol; + $int_curr_symbol = $currency->symbol if $with_symbol; %format_params = ( decimal_fill => '2', decimal_point => ',', diff --git a/about.pl b/about.pl index 4bf9779fc4..4587e27fc2 100755 --- a/about.pl +++ b/about.pl @@ -34,6 +34,7 @@ use C4::Context; use C4::Installer; use Koha; +use Koha::Acquisition::Currencies; use Koha::Borrowers; use Koha::Config::SysPrefs; @@ -88,7 +89,7 @@ my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode(); my $warnIsRootUser = (! $loggedinuser); -my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency()); +my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active); my @xml_config_warnings; my $context = new C4::Context; diff --git a/acqui/addorder.pl b/acqui/addorder.pl index f58e58dcb6..e5480ef9e3 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -129,6 +129,7 @@ use C4::Biblio; # AddBiblio TransformKohaToMarc use C4::Budgets; use C4::Items; use C4::Output; +use Koha::Acquisition::Currencies; ### "-------------------- addorder.pl ----------" @@ -188,11 +189,11 @@ unless($confirm_budget_exceeding) { if( ($budget_expenditure+0) && ($budget_used + $total) > $budget_expenditure && $total <= $budget_remaining ) { - my $currency = GetCurrency; + my $currency = Koha::Acquisition::Currencies->get_active; $template->param( expenditure_exceeded => 1, expenditure => sprintf("%.2f", $budget_expenditure), - currency => ($currency) ? $currency->{'symbol'} : '', + currency => ($currency) ? $currency->symbol : '', ); } if($total > $budget_remaining){ diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 5656d777e1..0f59a62a19 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -43,6 +43,7 @@ use C4::Branch; # GetBranches use C4::Members; use Koha::Number::Price; +use Koha::Acquisition::Currencies; use Koha::Acquisition::Order; use Koha::Acquisition::Bookseller; @@ -61,7 +62,6 @@ my $op = $cgiparams->{'op'} || ''; my $booksellerid = $input->param('booksellerid'); my $allmatch = $input->param('allmatch'); my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); -my $data; $template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl", booksellerid => $booksellerid, @@ -90,39 +90,12 @@ if ($op eq ""){ } elsif ($op eq "batch_details"){ #display lines inside the selected batch # get currencies (for change rates calcs if needed) - my $active_currency = GetCurrency(); - my $default_currency; - if (! $data->{currency} ) { # New order no currency set - if ( $bookseller->{listprice} ) { - $default_currency = $bookseller->{listprice}; - } - else { - $default_currency = $active_currency->{currency}; - } - } - my @rates = GetCurrencies(); - - # ## @rates - - my @loop_currency = (); - for my $curr ( @rates ) { - my $selected; - if ($data->{currency} ) { - $selected = $curr->{currency} eq $data->{currency}; - } - else { - $selected = $curr->{currency} eq $default_currency; - } - push @loop_currency, { - currcode => $curr->{currency}, - rate => $curr->{rate}, - selected => $selected, - } - } + my @currencies = Koha::Acquisition::Currencies->search; $template->param("batch_details" => 1, "basketno" => $cgiparams->{'basketno'}, - loop_currencies => \@loop_currency, + currencies => \@currencies, + bookseller => $bookseller, "allmatch" => $allmatch, ); import_biblios_list($template, $cgiparams->{'import_batch_id'}); @@ -167,7 +140,7 @@ if ($op eq ""){ my @discount = $input->param('discount'); my @sort1 = $input->param('sort1'); my @sort2 = $input->param('sort2'); - my $cur = GetCurrency(); + my $active_currency = Koha::Acquisition::Currencies->get_active; for my $biblio (@$biblios){ # Check if this import_record_id was selected next if not grep { $_ eq $$biblio{import_record_id} } @import_record_id_selected; @@ -251,7 +224,7 @@ if ($op eq ""){ $orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c ); } } - $orderinfo{listprice} = $orderinfo{rrp} / $cur->{rate}; + $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; $orderinfo{unitprice} = $orderinfo{ecost}; $orderinfo{total} = $orderinfo{ecost} * $c_quantity; } else { diff --git a/acqui/basket.pl b/acqui/basket.pl index 5fa94f86ef..b25426e938 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -290,9 +290,7 @@ if ( $op eq 'delete_confirm' ) { push @basketusers, $basketuser if $basketuser; } - #to get active currency - my $cur = GetCurrency(); - + my $active_currency = Koha::Acquisition::Currencies->get_active; my @orders = GetOrders( $basketno ); my @books_loop; @@ -384,7 +382,7 @@ if ( $op eq 'delete_confirm' ) { total_gste => sprintf( "%.2f", $total_gste ), total_gsti => sprintf( "%.2f", $total_gsti ), total_gstvalue => sprintf( "%.2f", $total_gstvalue ), - currency => $cur->{'currency'}, + currency => $active_currency->currency, listincgst => $bookseller->{listincgst}, basketgroups => $basketgroups, basketgroup => $basketgroup, diff --git a/acqui/invoice.pl b/acqui/invoice.pl index d2f649d38c..267d4fc9b4 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -36,6 +36,7 @@ use C4::Acquisition; use C4::Budgets; use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Currencies; use Koha::DateUtils; use Koha::Misc::Files; @@ -177,7 +178,7 @@ $template->param( total_gste_shipment => sprintf( $format, $total_gste + $details->{shipmentcost}), total_gsti_shipment => sprintf( $format, $total_gsti + $details->{shipmentcost}), invoiceincgst => $bookseller->{invoiceincgst}, - currency => GetCurrency()->{currency}, + currency => Koha::Acquisition::Currency->get_active->currency, budgets_loop => \@budgets_loop, ); diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index efd6648057..3885a7b347 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -89,6 +89,7 @@ use C4::Search qw/FindDuplicate/; use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Currencies; use Koha::ItemTypes; our $input = new CGI; @@ -206,37 +207,8 @@ else { #modify order my $suggestion; $suggestion = GetSuggestionInfo($suggestionid) if $suggestionid; -# get currencies (for change rates calcs if needed) -my $active_currency = GetCurrency(); -my $default_currency; -if (! $data->{currency} ) { # New order no currency set - if ( $bookseller->{listprice} ) { - $default_currency = $bookseller->{listprice}; - } - else { - $default_currency = $active_currency->{currency}; - } -} - -my @rates = GetCurrencies(); - -# ## @rates - -my @loop_currency = (); -for my $curr ( @rates ) { - my $selected; - if ($data->{currency} ) { - $selected = $curr->{currency} eq $data->{currency}; - } - else { - $selected = $curr->{currency} eq $default_currency; - } - push @loop_currency, { - currcode => $curr->{currency}, - rate => $curr->{rate}, - selected => $selected, - } -} +my @currencies = Koha::Acquisition::Currencies->search; +my $active_currency = Koha::Acquisition::Currencies->get_active; # build branches list my $onlymine = @@ -377,9 +349,9 @@ $template->param( listincgst => $bookseller->{'listincgst'}, invoiceincgst => $bookseller->{'invoiceincgst'}, name => $bookseller->{'name'}, - cur_active_sym => $active_currency->{'symbol'}, - cur_active => $active_currency->{'currency'}, - loop_currencies => \@loop_currency, + cur_active_sym => $active_currency->symbol, + cur_active => $active_currency->currency, + currencies => \@currencies, orderexists => ( $new eq 'yes' ) ? 0 : 1, title => $data->{'title'}, author => $data->{'author'}, diff --git a/acqui/supplier.pl b/acqui/supplier.pl index 2d1a223454..493c8af82e 100755 --- a/acqui/supplier.pl +++ b/acqui/supplier.pl @@ -53,6 +53,7 @@ use C4::Bookseller::Contact; use C4::Budgets; use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Currencies; my $query = CGI->new; my $op = $query->param('op') || 'display'; @@ -76,7 +77,6 @@ if ($booksellerid) { } $template->{'VARS'}->{'contacts'} = C4::Bookseller::Contact->new() unless $template->{'VARS'}->{'contacts'}; -#build array for currencies if ( $op eq 'display' ) { my $contracts = GetContracts( { booksellerid => $booksellerid } ); @@ -98,25 +98,7 @@ if ( $op eq 'display' ) { print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl'); exit; } else { - my @currencies = GetCurrencies(); - my $loop_currency; - my $active_currency = GetCurrency(); - my $active_listprice = $supplier->{'listprice'}; - my $active_invoiceprice = $supplier->{'invoiceprice'}; - if (!$supplier->{listprice}) { - $active_listprice = $active_currency->{currency}; - } - if (!$supplier->{invoiceprice}) { - $active_invoiceprice = $active_currency->{currency}; - } - for (@currencies) { - push @{$loop_currency}, - { - currency => $_->{currency}, - listprice => ( $_->{currency} eq $active_listprice ), - invoiceprice => ( $_->{currency} eq $active_invoiceprice ), - }; - } + my @currencies = Koha::Acquisition::Currencies->search; # get option values from gist syspref my @gst_values = map { @@ -128,7 +110,7 @@ if ( $op eq 'display' ) { active => $booksellerid ? $supplier->{'active'} : 1, gstrate => $supplier->{gstrate} ? $supplier->{'gstrate'}+0.0 : 0, gst_values => \@gst_values, - loop_currency => $loop_currency, + currencies => \@currencies, enter => 1, ); } diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index 93cef8a8eb..653f9161b1 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -57,6 +57,7 @@ use C4::Output; use C4::Acquisition; use C4::Budgets; use C4::Debug; +use Koha::Acquisition::Currencies; my $dbh = C4::Context->dbh; @@ -91,9 +92,9 @@ my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user( # This is used in incbudgets-active-currency.inc -my $cur = GetCurrency(); -$template->param( symbol => $cur->{symbol}, - currency => $cur->{currency} +my $active_currency = Koha::Acquisition::Currencies->get_active; +$template->param( symbol => $active_currency->symbol, + currency => $active_currency->currency ); # ADD OR MODIFY A BUDGET PERIOD - BUILD SCREEN diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 3e7e14f80a..0d18131eb8 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -35,6 +35,7 @@ use C4::Context; use C4::Output; use C4::Koha; use C4::Debug; +use Koha::Acquisition::Currencies; my $input = new CGI; my $dbh = C4::Context->dbh; @@ -49,9 +50,9 @@ my ($template, $borrowernumber, $cookie, $staffflags ) = get_template_and_user( } ); -my $cur = GetCurrency(); -$template->param( symbol => $cur->{symbol}, - currency => $cur->{currency} +my $active_currency = Koha::Acquisition::Currencies->get_active; +$template->param( symbol => $active_currency->symbol, + currency => $active_currency->currency ); my $op = $input->param('op') || 'list'; diff --git a/admin/aqplan.pl b/admin/aqplan.pl index 7374428983..20a8b004a3 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -35,6 +35,7 @@ use C4::Output; use C4::Koha; use C4::Auth; use C4::Debug; +use Koha::Acquisition::Currencies; my $input = new CGI; #### $input @@ -56,9 +57,9 @@ my $budget_period_id = $input->param('budget_period_id'); # IF PERIOD_ID IS DEFINED, GET THE PERIOD - ELSE GET THE ACTIVE PERIOD BY DEFAULT my $period = GetBudgetPeriod($budget_period_id); my $count = GetPeriodsCount(); -my $cur = GetCurrency; -$template->param( symbol => $cur->{symbol}, - currency => $cur->{currency} +my $active_currency = Koha::Acquisition::Currencies->get_active; +$template->param( symbol => $active_currency->symbol, + currency => $active_currency->currency, ); $template->param( period_button_only => 1 ) if $count == 0; diff --git a/admin/preferences.pl b/admin/preferences.pl index d9683f125c..24bffce83e 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -28,7 +28,7 @@ use C4::ClassSource; use C4::Log; use C4::Output; use C4::Templates; -use C4::Budgets qw(GetCurrency); +use Koha::Acquisition::Currencies; use File::Spec; use IO::File; use YAML::Syck qw(); @@ -45,10 +45,10 @@ sub GetTab { my $tab_template = C4::Templates::gettemplate( 'admin/preferences/' . $tab . '.pref', 'intranet', $input ); - my $active_currency = GetCurrency(); + my $active_currency = Koha::Acquisition::Currencies->get_active; my $local_currency; if ($active_currency) { - $local_currency = $active_currency->{currency}; + $local_currency = $active_currency->currency; } $tab_template->param( local_currency => $local_currency, # currency code is used, because we do not know how a given currency is formatted. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt index 31822d98a3..36bf23d387 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -199,10 +199,6 @@ - [% FOREACH cur IN loop_currencies %] - - [% END %] - [% FOREACH biblio IN biblio_list %]
@@ -358,11 +354,11 @@
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index 7638f0289e..dbb2b02315 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -302,8 +302,8 @@ $(document).ready(function() - [% FOREACH loop_currencie IN loop_currencies %] - + [% FOREACH currency IN currencies %] + [% END %]
    1. @@ -522,10 +522,15 @@ $(document).ready(function() [% currency %] [% ELSE %] - + [% END %]
    2. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt index a1be60fdbd..74ff5f7050 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt @@ -221,20 +221,26 @@ function delete_contact(ev) {
    1. - + [% FOREACH currency IN currencies %] + [% IF booksellerid and currency.currency == listprice or not booksellerid and currency.active %] + + [% ELSIF not currency.archived %] + + [% END %] [% END %] - +
    2. - + [% FOREACH currency IN currencies %] + [% IF booksellerid and currency.currency == invoiceprice or not booksellerid and currency.active %] + + [% ELSIF not currency.archived %] + + [% END %] [% END %] - +
      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 812a0043da..99557a21f9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt @@ -176,6 +176,7 @@ ISO code Last updated Active + Archived Actions @@ -188,6 +189,7 @@ [% currency.isocode |html %] [% currency.timestamp | $KohaDates %] [% IF currency.active %]✓[% END %] + [% IF currency.archived %]Yes[% END %] Edit | diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index e518afab96..233269465c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -420,16 +420,25 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o
    1. -
    2. - [% FOREACH loop_currenc IN loop_currency %] - - - [% END %] - -
    3. +
    4. +
    5. + + [% FOREACH c IN currencies %] + + + [% END %] + + +
    6. +
    7. diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 1774b29b91..b6c643df02 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -42,6 +42,7 @@ use Koha::Borrower::Debarments qw(AddUniqueDebarment); use Koha::DateUtils; use Koha::Calendar; use Koha::Libraries; +use Koha::Acquisition::Currencies; =head1 NAME diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl index eff549d57b..b345c7c873 100755 --- a/opac/sco/sco-main.pl +++ b/opac/sco/sco-main.pl @@ -45,6 +45,7 @@ use C4::Output; use C4::Members; use C4::Biblio; use C4::Items; +use Koha::Acquisition::Currencies; my $query = new CGI; @@ -113,8 +114,8 @@ if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { my $borrower = GetMemberDetails(undef,$patronid); my $currencySymbol = ""; -if ( defined C4::Budgets->GetCurrency() ) { - $currencySymbol = C4::Budgets->GetCurrency()->{symbol}; +if ( my $active_currency = Koha::Acquisition::Currencies->get_active ) { + $currencySymbol = $active_currency->symbol; } my $branch = $issuer->{branchcode}; diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 936149f723..15c73a4ef3 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -32,6 +32,7 @@ use C4::Members; use C4::Debug; use Koha::DateUtils qw( dt_from_string ); +use Koha::Acquisition::Currencies; use URI::Escape; @@ -352,28 +353,10 @@ foreach my $budget ( @{$budgets} ) { $template->param( budgetsloop => \@budgets_loop); $template->param( "statusselected_$$suggestion_ref{'STATUS'}" =>1) if ($$suggestion_ref{'STATUS'}); -# get currencies and rates -my @rates = GetCurrencies(); -my $count = scalar @rates; -my $active_currency = GetCurrency(); -my $selected_currency; -if ($$suggestion_ref{'currency'}) { - $selected_currency = $$suggestion_ref{'currency'}; -} -else { - $selected_currency = $active_currency->{currency}; -} - -my @loop_currency = (); -for ( my $i = 0 ; $i < $count ; $i++ ) { - my %line; - $line{currcode} = $rates[$i]->{'currency'}; - $line{rate} = $rates[$i]->{'rate'}; - $line{selected} = 1 if ($line{'currcode'} eq $selected_currency); - push @loop_currency, \%line; -} +my @currencies = Koha::Acquisition::Currencies->search; $template->param( - loop_currency => \@loop_currency, + currencies => \@currencies, + suggestion => $suggestion_ref, price => sprintf("%.2f", $$suggestion_ref{'price'}||0), total => sprintf("%.2f", $$suggestion_ref{'total'}||0), ); diff --git a/t/Number/Price.t b/t/Number/Price.t index 3191e4d13f..060b183e69 100644 --- a/t/Number/Price.t +++ b/t/Number/Price.t @@ -5,10 +5,10 @@ use Test::More tests => 19; use Test::MockModule; use t::lib::Mocks; -use C4::Budgets; -my $budget_module = Test::MockModule->new('C4::Budgets'); +use Koha::Acquisition::Currencies; +my $budget_module = Test::MockModule->new('Koha::Acquisition::Currencies'); my $currency; -$budget_module->mock( 'GetCurrency', sub { return $currency; } ); +$budget_module->mock( 'get_active', sub { return $currency; } ); use_ok('Koha::Number::Price'); my $format = { @@ -16,12 +16,12 @@ my $format = { p_sep_by_space => 0, # Force to not add a space between the symbol and the number }; t::lib::Mocks::mock_preference( 'CurrencyFormat', 'US' ); -$currency = { +$currency = Koha::Acquisition::Currency->new({ currency => 'USD', symbol => '$', rate => 1, active => 1, -}; +}); is( Koha::Number::Price->new->format( $format ), '0.00', 'US: format 0' ); is( Koha::Number::Price->new(3)->format( $format ), '3.00', 'US: format 3' ); @@ -45,12 +45,12 @@ is( Koha::Number::Price->new(1234567890)->unformat, '1234567890', 'US: unformat 1234567890' ); t::lib::Mocks::mock_preference( 'CurrencyFormat', 'FR' ); -$currency = { +$currency = Koha::Acquisition::Currency->new({ currency => 'EUR', symbol => '€', rate => 1, active => 1, -}; +}); # Actually,the price formating for France is 3,00€ # How put the symbol at the end with Number::Format? diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index 31bd958a75..10237981cc 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -37,11 +37,19 @@ my $context = new Test::MockModule('C4::Context'); mock_marcfromkohafield(); -my $currency = new Test::MockModule('C4::Budgets'); -$currency->mock( 'GetCurrency', sub { - return { symbol => '$', isocode => 'USD', - currency => 'USD', active => 1 }; -}); +my $currency = new Test::MockModule('Koha::Acquisition::Currencies'); +$currency->mock( + 'get_active', + sub { + return Koha::Acquisition::Currency->new( + { symbol => '$', + isocode => 'USD', + currency => 'USD', + active => 1, + } + ); + } +); sub run_tests { diff --git a/t/db_dependent/MungeMarcPrice.t b/t/db_dependent/MungeMarcPrice.t index f661323e78..78a599f088 100755 --- a/t/db_dependent/MungeMarcPrice.t +++ b/t/db_dependent/MungeMarcPrice.t @@ -3,7 +3,7 @@ use strict; use warnings; use C4::Biblio; -use C4::Budgets; +use Koha::Acquisition::Currencies; use Test::More; use utf8; @@ -39,10 +39,10 @@ my $ISOCODE = 'USD'; my $RATE= 1; # disables existing active currency if necessary. -my $active_currency = C4::Budgets->GetCurrency(); +my $active_currency = Koha::Acquisition::Currencies->get_active; my $curr; if ($active_currency) { - $curr = $active_currency->{'currency'}; + $curr = $active_currency->currency; $dbh->do("UPDATE currency set active = 0 where currency = '$curr'"); } -- 2.39.5