Bug 15084: Replace C4::Budgets::GetCurrencies with Koha::Acquisition::Currencies...
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 29 Oct 2015 12:21:52 +0000 (12:21 +0000)
committerBrendan A Gallagher <brendan@bywatersolutions.com>
Thu, 3 Mar 2016 20:39:01 +0000 (20:39 +0000)
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 <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>

27 files changed:
C4/Biblio.pm
C4/Budgets.pm
C4/Overdues.pm
Koha/Acquisition/Currencies.pm
Koha/Number/Price.pm
about.pl
acqui/addorder.pl
acqui/addorderiso2709.pl
acqui/basket.pl
acqui/invoice.pl
acqui/neworderempty.pl
acqui/supplier.pl
admin/aqbudgetperiods.pl
admin/aqbudgets.pl
admin/aqplan.pl
admin/preferences.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt
koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt
misc/cronjobs/overdue_notices.pl
opac/sco/sco-main.pl
suggestion/suggestion.pl
t/Number/Price.t
t/db_dependent/Biblio.t
t/db_dependent/MungeMarcPrice.t

index 10faa83..a2b1d0a 100644 (file)
@@ -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=~ /
index 1c30e1b..734eb6a 100644 (file)
@@ -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);
index e376798..6c09f43 100644 (file)
@@ -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'} ) {
index 7f506a7..cdbbfed 100644 (file)
@@ -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
index 2d563f9..331e3c3 100644 (file)
@@ -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     => ',',
index 4bf9779..4587e27 100755 (executable)
--- 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;
index f58e58d..e5480ef 100755 (executable)
@@ -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){
index 5656d77..0f59a62 100755 (executable)
@@ -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 {
index 5fa94f8..b25426e 100755 (executable)
@@ -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,
index d2f649d..267d4fc 100755 (executable)
@@ -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,
 );
 
index efd6648..3885a7b 100755 (executable)
@@ -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'},
index 2d1a223..493c8af 100755 (executable)
@@ -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,
     );
 }
index 93cef8a..653f916 100755 (executable)
@@ -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
index 3e7e14f..0d18131 100755 (executable)
@@ -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';
index 7374428..20a8b00 100755 (executable)
@@ -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;
 
index d9683f1..24bffce 100755 (executable)
@@ -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.
index 31822d9..36bf23d 100644 (file)
                         <input type="hidden" name="import_batch_id" value="[%import_batch_id %]" />
                         <input type="hidden" name="ordernumber" value="[% ordernumber %]" />
 
-                        [% FOREACH cur IN loop_currencies %]
-                            <input type="hidden" name="[% cur.currency %]" value="[% cur.rate %]" />
-                        [% END %]
-
                         [% FOREACH biblio IN biblio_list %]
                         <fieldset class="biblio unselected rows" style="float:none;">
                           <legend>
                                         <li>
                                             <label for="all_currency">Currency:</label>
                                             <select name="all_currency" id="all_currency">
-                                            [% FOREACH loop_currencie IN loop_currencies %]
-                                                [% IF ( loop_currencie.selected ) %]
-                                                    <option value="[% loop_currencie.currcode %]" selected="selected">[% loop_currencie.currcode %]</option>
-                                                [% ELSE %]
-                                                    <option value="[% loop_currencie.currcode %]">[% loop_currencie.currcode %]</option>
+                                            [% FOREACH currency IN currencies %]
+                                                [% IF currency.currency == bookseller.listprice %]
+                                                    <option value="[% currency.currency %]" selected="selected">[% currency.currency %]</option>
+                                                [% ELSIF not currency.archived %]
+                                                    <option value="[% currency.currency %]">[% currency.currency %]</option>
                                                 [% END %]
                                             [% END %]
                                             </select>
index 7638f02..dbb2b02 100644 (file)
@@ -302,8 +302,8 @@ $(document).ready(function()
         <input type="hidden" name="suggestionid" value="[% suggestionid %]" />
         <input type="hidden" name="import_batch_id" value="[% import_batch_id %]" />
 
-        [% FOREACH loop_currencie IN loop_currencies %]
-            <input type="hidden" id="currency_rate_[% loop_currencie.currcode %]"  name="[% loop_currencie.currcode %]" value="[% loop_currencie.rate %]" />
+        [% FOREACH currency IN currencies %]
+            <input type="hidden" id="currency_rate_[% currency.currency %]"  name="[% currency.currency %]" value="[% currency.rate %]" />
         [% END %]
 
         <ol><li>
@@ -522,10 +522,15 @@ $(document).ready(function()
             <input type="hidden" name="currency" id="currency" value="[% currency %]" />[% currency %]
                 [% ELSE %]
                        <label for="currency">Currency:</label>
-                       <select name="currency" id="currency" onchange="updateCosts();">
-                       [% FOREACH loop_currencie IN loop_currencies %]
-                       [% IF ( loop_currencie.selected ) %]<option value="[% loop_currencie.currcode %]" selected="selected">[% loop_currencie.currcode %]</option>[% ELSE %]<option value="[% loop_currencie.currcode %]">[% loop_currencie.currcode %]</option>[% END %][% END %]
-                       </select>
+            <select name="currency" id="currency" onchange="updateCosts();">
+                [% FOREACH currency IN currencies %]
+                    [% IF ordernumber and currency.currency == listprice or not ordernumber and currency.active %]
+                        <option value="[% currency.currency %]" selected="selected">[% currency.currency %]</option>
+                    [% ELSIF not currency.archived %]
+                        <option value="[% currency.currency %]">[% currency.currency %]</option>
+                    [% END %]
+                [% END %]
+            </select>
                [% END %]
                 </li>
             <li>
index a1be60f..74ff5f7 100644 (file)
@@ -221,20 +221,26 @@ function delete_contact(ev) {
             </ol>
             <ol>
             <li><label for="list_currency">List prices are: </label>
-                    <select name="list_currency" id="list_currency">
-                    [% FOREACH loop_currenc IN loop_currency %]
-                        [% IF ( loop_currenc.listprice ) %]<option value="[% loop_currenc.currency %]" selected="selected">[% loop_currenc.currency %]</option>
-                        [% ELSE %]<option value="[% loop_currenc.currency %]">[% loop_currenc.currency %]</option>[% END %]
+                <select name="list_currency" id="list_currency">
+                    [% FOREACH currency IN currencies %]
+                        [% IF booksellerid and currency.currency == listprice or not booksellerid and currency.active %]
+                            <option value="[% currency.currency %]" selected="selected">[% currency.currency %]</option>
+                        [% ELSIF not currency.archived %]
+                            <option value="[% currency.currency %]" selected="selected">[% currency.currency %]</option>
+                        [% END %]
                     [% END %]
-                    </select>
+                </select>
             </li>
             <li><label for="invoice_currency">Invoice prices are: </label>
-                    <select name="invoice_currency" id="invoice_currency">
-                    [% FOREACH loop_currenc IN loop_currency %]
-                        [% IF ( loop_currenc.invoiceprice ) %]<option value="[% loop_currenc.currency %]" selected="selected">[% loop_currenc.currency %]</option>
-                        [% ELSE %]<option value="[% loop_currenc.currency %]">[% loop_currenc.currency %]</option>[% END %]
+                <select name="invoice_currency" id="invoice_currency">
+                    [% FOREACH currency IN currencies %]
+                        [% IF booksellerid and currency.currency == invoiceprice or not booksellerid and currency.active %]
+                            <option value="[% currency.currency %]" selected="selected">[% currency.currency %]</option>
+                        [% ELSIF not currency.archived %]
+                            <option value="[% currency.currency %]" selected="selected">[% currency.currency %]</option>
+                        [% END %]
                     [% END %]
-                    </select>
+                </select>
             </li>
             </ol>
             <ol class="radio">
index 812a004..99557a2 100644 (file)
             <th>ISO code</th>
             <th class="title-string">Last updated</th>
             <th>Active</th>
+            <th>Archived</th>
             <th>Actions</th>
         </tr>
       </thead>
             <td>[% currency.isocode |html %]</td>
             <td><span title="[% currency.timestamp %]">[% currency.timestamp | $KohaDates %]</span></td>
             <td style="color:green;">[% IF currency.active %]✓[% END %]</td>
+            <td>[% IF currency.archived %]Yes[% END %]</td>
             <td>
               <a href="/cgi-bin/koha/admin/currency.pl?op=add_form&amp;currency_code=[% currency.currency %]">Edit</a>
               |
index e518afa..2332694 100644 (file)
@@ -420,16 +420,25 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o
             </select>
                </li><li><label for="quantity">Copies:</label>
                        <input type="text" size="10" id="quantity" name="quantity" value="[% quantity %]" onchange="calcNewsuggTotal();" />
-                </li><li><label for="currency">Currency:</label>
-                       [% FOREACH loop_currenc IN loop_currency %]
-                    <input type="hidden" value="[% loop_currenc.rate %]" id="currency_rate_[% loop_currenc.currcode %]" name="currency_rate_[% loop_currenc.currcode %]" />
-                           <input type="hidden" id="[% loop_currenc.currcode %]" name="[% loop_currenc.currcode %]" value="[% loop_currenc.rate %]" />
-                       [% END %]
-            <select name="currency" id="currency" onchange="calcNewsuggTotal();">
-                [% FOREACH loop_currenc IN loop_currency %]
-                [% IF ( loop_currenc.selected ) %]<option value="[% loop_currenc.currcode %]" selected="selected">[% loop_currenc.currcode %]</option>[% ELSE %]<option value="[% loop_currenc.currcode %]">[% loop_currenc.currcode %]</option>[% END %][% END %]
-            </select>
-                </li><li><label for="price">Price:</label>
+                </li>
+                <li>
+                    <label for="currency">Currency:</label>
+                    [% FOREACH c IN currencies %]
+                        <input type="hidden" value="[% c.rate %]" id="currency_rate_[% c.currency %]" name="currency_rate_[% c.currency %]" />
+                        <input type="hidden" id="[% c.currency %]" name="[% c.currency %]" value="[% c.rate %]" />
+                    [% END %]
+
+                    <select name="currency" id="currency" onchange="calcNewsuggTotal();">
+                        [% FOREACH c IN currencies %]
+                            [% IF suggestionid and suggestion.currency == c.currency or not suggestionid and c.active %]
+                                <option value="[% c.currency %]" selected="selected">[% c.currency %]</option>
+                            [% ELSIF not c.archived %]
+                                <option value="[% c.currency %]">[% c.currency %]</option>
+                            [% END %]
+                        [% END %]
+                    </select>
+                </li>
+                <li><label for="price">Price:</label>
                        <input type="text" size="20" name="price" id="price" value="[% price %]" onchange="calcNewsuggTotal();" />
                 </li><li><label for="total">Total: </label>
                        <input type="text" readonly="readonly" id="total" name="total" size="10" value="[% total %]"/>
index 1774b29..b6c643d 100755 (executable)
@@ -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
 
index eff549d..b345c7c 100755 (executable)
@@ -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};
index 936149f..15c73a4 100755 (executable)
@@ -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),
 );
index 3191e4d..060b183 100644 (file)
@@ -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?
index 31bd958..1023798 100755 (executable)
@@ -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 {
 
index f661323..78a599f 100755 (executable)
@@ -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'");
 }