From 9c8e4540b6ed607dee03c215efac008c19554c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Sun, 11 Oct 2015 01:25:19 +0200 Subject: [PATCH] Bug 4078 - Display active currency symbol on currency output and input Display active currency using international formatting patterns and active currency symbol withplugin price. The patch inlcudes an example on Opac. To test: Without patch: - Log in to the Opac with an user who has credits or fines. - Go to 'Your summary'. The amount appears in the tab 'Credits'rsp. 'Fines' - Apply patch - Make sure that you have defined an active currency in Home > Administration > Currency & Exchange rates - Search for Syspref 'Currency Format' - Select a formatting pattern from the drop down list - Go back to the Opac and verify that the amount is properly formatted, including the position of the currency symbol. --- Koha/Number/Price.pm | 71 ++++++++++++++++---- .../en/modules/admin/preferences/acquisitions.pref | 19 +++++- .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 5 +- 3 files changed, 76 insertions(+), 19 deletions(-) diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm index 2d563f9..1ff3c8b 100644 --- a/Koha/Number/Price.pm +++ b/Koha/Number/Price.pm @@ -79,7 +79,7 @@ sub round { sub _format_params { my ( $self, $params ) = @_; - my $with_symbol = $params->{with_symbol} || 0; + my $with_symbol = $params->{with_symbol}; my $p_cs_precedes = $params->{p_cs_precedes}; my $p_sep_by_space = $params->{p_sep_by_space}; my $currency = GetCurrency(); @@ -92,21 +92,64 @@ sub _format_params { mon_decimal_point => '.' ); - if ( $currency_format eq 'FR' ) { - # FIXME This test should be done for all currencies - $int_curr_symbol = $currency->{symbol} if $with_symbol; - %format_params = ( - decimal_fill => '2', - decimal_point => ',', - int_curr_symbol => $int_curr_symbol, - mon_thousands_sep => ' ', - thousands_sep => ' ', - mon_decimal_point => ',' - ); + if ( $currency_format =~ m/(_LEAD)/ ) { + $p_cs_precedes = 1 unless ( defined $p_cs_precedes ); + } + + if ( $currency_format =~ m/(_TRAIL)/ ) { + $p_cs_precedes = 0 unless ( defined $p_cs_precedes ); + } + + $format_params{'p_cs_precedes'} = $p_cs_precedes + if ( defined $p_cs_precedes ); + + if ( $currency_format =~ m/(_SPACE)/ ) { + $p_sep_by_space = 1 unless ( $p_sep_by_space ); + } + else { + $p_sep_by_space = 0 unless ( $p_sep_by_space ); + } + + $format_params{'p_sep_by_space'} = $p_sep_by_space; + + if ( $currency_format =~ m/(SYMB)/ ) { + $with_symbol = 1 unless ( defined $with_symbol ); + } + + $format_params{'int_curr_symbol'} = $currency->{symbol} + if ( $with_symbol ); + + # $format_params{'int_curr_symbol'} = "xxxxxxxxxxxxxx"; + + # TODO Add more currency formats (Syspref CurrencyFormat) + + # syspref FR: 360 000,00 + if ( $currency_format =~ m/(^FR)/ ) { + $format_params{'decimal_fill'} = '2'; + $format_params{'decimal_point'} = ','; + $format_params{'mon_decimal_point'} = ','; + $format_params{'thousands_sep'} = ' '; + $format_params{'mon_thousands_sep'} = ' '; + } + + # syspref US: 360,000.00 + if ( $currency_format =~ m/(^US)/ ) { + $format_params{'decimal_fill'} = '2'; + $format_params{'decimal_point'} = '.'; + $format_params{'mon_decimal_point'} = '.'; + $format_params{'thousands_sep'} = ','; + $format_params{'mon_thousands_sep'} = ','; + } + + # syspref CH: 360'000.00 + if ( $currency_format =~ m/(^CH)/ ) { + $format_params{'decimal_fill'} = '2'; + $format_params{'decimal_point'} = '.'; + $format_params{'mon_decimal_point'} = '.'; + $format_params{'thousands_sep'} = '\''; + $format_params{'mon_thousands_sep'} = '\''; } - $format_params{p_cs_precedes} = $p_cs_precedes if defined $p_cs_precedes; - $format_params{p_sep_by_space} = ( $int_curr_symbol and defined $p_sep_by_space ) ? $p_sep_by_space : 0; return \%format_params; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref index b52b5a9..d719c19 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref @@ -27,11 +27,24 @@ Acquisitions: branch: from staff member's library. all: in system, regardless of owner. - - - Display currencies using the following format + - "Display currencies using the following format (¤ = symbol of active currency as defined in Currency and exchange rates.)" - pref: CurrencyFormat choices: - US: 360,000.00 (US) - FR: 360 000,00 (FR) + US: "360,000.00" + US_SYMB_LEAD_SPACE: ¤ 360,000.00 + US_SYMB_LEAD: ¤360,000.00 + US_SYMB_TRAIL_SPACE: 360,000.00 ¤ + US_SYMB_TRAIL: 360,000.00¤ + FR: "360 000,00" + FR_SYMB_LEAD_SPACE: ¤ 360 000,00 + FR_SYMB_LEAD: ¤360 000,00 + FR_SYMB_TRAIL_SPACE: 360 000,00 ¤ + FR_SYMB_TRAIL: 360 000,00¤ + CH: "360'000.00" + CH_SYMB_LEAD_SPACE: ¤ 360'000.00 + CH_SYMB_LEAD: ¤360'000.00 + CH_SYMB_TRAIL_SPACE: 360'000.00 ¤ + CH_SYMB_TRAIL: 360'000.00¤ - - Tax rates are - pref: gist diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index 1a200e6..37c0191 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -1,5 +1,6 @@ [% USE Koha %] [% USE KohaDates %] +[% USE Price %] [% INCLUDE 'doc-head-open.inc' %] [% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Your library home @@ -115,7 +116,7 @@ [% IF ( OPACFinesTab ) %] [% IF ( BORROWER_INF.amountoverfive ) %]
  • Fines ([% BORROWER_INF.amountoutstanding %])
  • [% END %] [% IF ( BORROWER_INF.amountoverzero ) %]
  • Fines ([% BORROWER_INF.amountoutstanding %])
  • [% END %] - [% IF ( BORROWER_INF.amountlessthanzero ) %]
  • Credits ([% BORROWER_INF.amountoutstanding %])
  • [% END %] + [% IF ( BORROWER_INF.amountlessthanzero ) %]
  • Credits ([% BORROWER_INF.amountoutstanding | $Price %])
  • [% END %] [% END %] [% IF ( waiting_count ) %][% IF ( BORROWER_INF.atdestination ) %]
  • Waiting ([% waiting_count %])
  • [% END %][% END %] [% IF ( reserves_count ) %]
  • Holds ([% reserves_count %])
  • [% END %] @@ -324,7 +325,7 @@ Amount - You have a credit of:[% BORROWER_INF.amountoutstanding %] + You have a credit of:[% BORROWER_INF.amountoutstanding | $Price %] -- 1.7.10.4