Bugzilla – Attachment 144535 Details for
Bug 21507
Decimal separators issues in patrons payments/fines, simplified
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21507 : Set decimal separator according to currency format syspref
Bug-21507--Set-decimal-separator-according-to-curr.patch (text/plain), 8.06 KB, created by
Thibaud Guillot
on 2022-12-12 15:54:23 UTC
(
hide
)
Description:
Bug 21507 : Set decimal separator according to currency format syspref
Filename:
MIME Type:
Creator:
Thibaud Guillot
Created:
2022-12-12 15:54:23 UTC
Size:
8.06 KB
patch
obsolete
>From af97d79148cd44cc71bc0a8168e55d3a52e0cdc5 Mon Sep 17 00:00:00 2001 >From: Thibaud Guillot <thibaud.guillot@biblibre.com> >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 @@ > </li> > <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" value="[% barcode | html %]" /></li> > <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" value="[% desc | html %]" /></li> >- <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" value="[% note | html %]" /></li> >- >- <li><label for="amount">Amount: </label><input type="text" inputmode="decimal" pattern=[% decimal_input_pattern %] name="amount" id="amount" required="required" value="[% amount | $Price on_editing => 1 %]" /> 5[% decimal_delimiter | html %]12</li> >+ <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" value="[% note | html %]" /></li> >+ <li><label for="amount">Amount: </label><input type="text" inputmode="decimal" pattern=[% decimal_input_pattern %] name="amount" id="amount" required="required" value="[% amount | $Price on_editing => 1 %]" /> 5[% decimal_delimiter | html %]12</li> > </ol> > </fieldset> > >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 @@ > > <li> > <label for="paid">Amount being paid: </label> >- <input name="paid" id="paid" type="text" step="0.01" min="0" value="[% amountoutstanding | $Price on_editing => 1 %]"/> >+ <input name="paid" id="paid" type="text" value="[% amountoutstanding | $Price on_editing => 1 %]"/> > </li> > <li> > <label for="collected">Amount tendered: </label> >- <input name="collected" id="collected" type="text" step="0.01" min="0" value="[% amountoutstanding | $Price on_editing => 1 %]"/> >+ <input name="collected" id="collected" type="text" value="[% amountoutstanding | $Price on_editing => 1 %]"/> > </li> > <li> > <label>Change to give: </label> >@@ -328,12 +328,12 @@ > [% ELSE %] > <label for="paid">Amount being paid: </label> > [% END %] >- <input name="paid" id="paid" type="text" step="0.01" min="0" value="[% total | $Price on_editing => 1 %]"/> >+ <input name="paid" id="paid" type="text" value="[% total | $Price on_editing => 1 %]"/> > </li> > [% IF type != 'WRITEOFF' %] > <li> > <label for="collected">Amount tendered: </label> >- <input name="collected" id="collected" type="text" step="0.01" min="0" value="[% total | $Price on_editing => 1 %]"/> >+ <input name="collected" id="collected" type="text" value="[% total | $Price on_editing => 1 %]"/> > </li> > <li> > <label>Change to give: </label> >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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21507
:
95734
|
95735
|
144502
|
144535
|
144536
|
144537