From 034183f94e3397c38954e4ade18863b0e24b839d Mon Sep 17 00:00:00 2001 From: Victor Grousset Date: Wed, 17 Oct 2018 11:07:05 +0200 Subject: [PATCH] Bug 21507 : Set decimal separator according to currency format syspref This is always a WIP, but I push some code to let the subject open to any advice Test plan : 1) Go on 'cgi-bin/koha/members/mancredit.pl?borrowernumber={patron_id}' 2) Create manual invoice or credit and see differents input pattern and example 3) You can also test payment feature with 'total due' transformation --- Koha/Number/Price.pm | 18 ++++++++++ .../prog/en/includes/decimal-input-js.inc | 24 +++++++++++++ .../prog/en/modules/members/mancredit.tt | 13 ++++++- .../prog/en/modules/members/maninvoice.tt | 14 ++++++-- .../prog/en/modules/members/paycollect.tt | 8 ++--- members/mancredit.pl | 12 +++++++ members/maninvoice.pl | 36 +++++++++++++------ members/pay.pl | 3 ++ members/paycollect.pl | 7 +++- 9 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm index e9a6aa748e..369c5fd2db 100644 --- a/Koha/Number/Price.pm +++ b/Koha/Number/Price.pm @@ -53,6 +53,8 @@ sub format_for_editing { return unless defined $self->value; my $format_params = $self->_format_params( $params ); + my $currency_format = C4::Context->preference("CurrencyFormat"); + $format_params = { %$format_params, int_curr_symbol => '', @@ -60,6 +62,22 @@ sub format_for_editing { mon_decimal_point => '.', }; + if ( $currency_format eq 'FR' ) { + %$format_params = ( + int_curr_symbol => '', + mon_thousands_sep => ' ', + mon_decimal_point => ',' + ); + } + + if ( $currency_format eq 'CH' ) { + %$format_params = ( + int_curr_symbol => '', + mon_thousands_sep => '\'', + mon_decimal_point => '.' + ); + } + # To avoid the system to crash, we will not format big number # We divide per 100 because we want to keep the default DECIMAL_DIGITS (2) # error - round() overflow. Try smaller precision or use Math::BigFloat diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc new file mode 100644 index 0000000000..2e3836c5af --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc @@ -0,0 +1,24 @@ +[% USE Koha %] + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt index 71479bd2a0..3dd2270dc0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt @@ -83,7 +83,7 @@
  • -
  • Example: 5.00
  • +
  • Example: 5[% decimal_delimiter | html %]12
  • [% INCLUDE 'transaction_types.inc' type="credit" %] [% IF Koha.Preference('UseCashRegisters') %]
  • @@ -135,10 +135,21 @@ [% MACRO jsinclude BLOCK %] [% INCLUDE 'str/members-menu.inc' %] [% Asset.js("js/members-menu.js") | $raw %] + [% INCLUDE 'decimal-input-js.inc' %] +