From af97d79148cd44cc71bc0a8168e55d3a52e0cdc5 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Mon, 12 Dec 2022 16:49:58 +0100 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/modules/members/maninvoice.tt | 5 ++--- .../prog/en/modules/members/paycollect.tt | 8 ++++---- members/maninvoice.pl | 1 + members/pay.pl | 3 +++ members/paycollect.pl | 8 +++++--- 6 files changed, 33 insertions(+), 10 deletions(-) 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/modules/members/maninvoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt index 7f46f5dcaf..89918cd608 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt @@ -94,9 +94,8 @@
  • -
  • - -
  • 5[% decimal_delimiter | html %]12
  • +
  • +
  • 5[% decimal_delimiter | html %]12
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt index c5bc2ed26b..17ed3f25e1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -175,11 +175,11 @@
  • - +
  • - +
  • @@ -328,12 +328,12 @@ [% ELSE %] [% END %] - +
  • [% IF type != 'WRITEOFF' %]
  • - +
  • diff --git a/members/maninvoice.pl b/members/maninvoice.pl index e220a6cb91..3d8ea82126 100755 --- a/members/maninvoice.pl +++ b/members/maninvoice.pl @@ -80,6 +80,7 @@ output_and_exit_if_error( my $library_id = C4::Context->userenv->{'branch'}; my $desc = $input->param('desc'); my $amount = $input->param('amount'); +$amount = Koha::Number::Price->new( $amount )->format(); my $note = $input->param('note'); my $debit_type = $input->param('type'); my $barcode = $input->param('barcode'); diff --git a/members/pay.pl b/members/pay.pl index 27181164ad..d2da46178c 100755 --- a/members/pay.pl +++ b/members/pay.pl @@ -43,6 +43,7 @@ use Koha::Items; use Koha::Patron::Categories; use URI::Escape qw( uri_escape_utf8 uri_unescape ); +use Koha::Number::Price; our $input = CGI->new; @@ -100,6 +101,8 @@ elsif ( $input->param('confirm_writeoff') ) { my $accountline = Koha::Account::Lines->find( $accountlines_id ); + $amount = Koha::Number::Price->new( $amount )->unformat(); + $amount = $accountline->amountoutstanding if (abs($amount - $accountline->amountoutstanding) < 0.01) && C4::Context->preference('RoundFinesAtPayment'); if ( $amount > $accountline->amountoutstanding ) { print $input->redirect( "/cgi-bin/koha/members/paycollect.pl?" diff --git a/members/paycollect.pl b/members/paycollect.pl index 17dcd7646b..d4a240c4e5 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -37,6 +37,7 @@ use Koha::AdditionalFields; use Koha::Token; use Koha::DateUtils qw( output_pref ); use Koha::Number::Price; +use Number::Format qw( unformat_number ); my $input = CGI->new(); @@ -137,6 +138,8 @@ if ( $selected_accts ) { $total_due = $sum->_resultset->first->get_column('total_amountoutstanding'); } +$total_paid = Koha::Number::Price->new( $total_paid )->unformat(); + if ( $total_paid and $total_paid ne '0.00' ) { $total_paid = $total_due if (abs($total_paid - $total_due) < 0.01) && C4::Context->preference('RoundFinesAtPayment'); if ( $total_paid < 0 or $total_paid > $total_due ) { @@ -273,11 +276,10 @@ if ( $total_paid and $total_paid ne '0.00' ) { } if ( $input->param('error_over') ) { - $template->param( error_over => 1, total_due => scalar $input->param('amountoutstanding') ); + my $amountoutstanding = Koha::Number::Price->new($input->param('amountoutstanding'))->format(); + $template->param( error_over => 1, total_due => scalar $amountoutstanding ); } -$total_due = Koha::Number::Price->new( $total_due )->format({mon_decimal_point => '-'}); - $template->param( payment_id => $payment_id, -- 2.25.1