Bugzilla – Attachment 144537 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), 16.51 KB, created by
Thibaud Guillot
on 2022-12-12 15:57:48 UTC
(
hide
)
Description:
Bug 21507 : Set decimal separator according to currency format syspref
Filename:
MIME Type:
Creator:
Thibaud Guillot
Created:
2022-12-12 15:57:48 UTC
Size:
16.51 KB
patch
obsolete
>From 034183f94e3397c38954e4ade18863b0e24b839d Mon Sep 17 00:00:00 2001 >From: Victor Grousset <victor.grousset@biblibre.com> >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 %] >+ >+<script type="text/javascript"> >+ var currency_format = "[% Koha.Preference('CurrencyFormat') %]"; >+ if (currency_format === "US" || currency_format === "CH") { >+ var decimal_separator = "."; >+ } else if (currency_format === "FR") { >+ var decimal_separator = ","; >+ } else { >+ console.error("Unhandled value for currency_format: \"" + currency_format +"\" You should report this issue to avoid unexpected behavior with numbers. Note that you should also check the code displaying the example value in manual invoice and credit pages.") >+ var decimal_separator = "."; >+ } >+ >+ // allow only non-decimal numbers and decimal numbers containing a dot or a comma >+ jQuery.validator.addMethod("is_decimal_number", function(value, element){ >+ return /^\d+(\.|,)?\d*$/.test(value); >+ }, _("Please input a decimal number without thousands separators")); >+ >+ jQuery.validator.addMethod("uses_correct_decimal_separator", function(value, element){ >+ var non_decimal_number = /^\d+$/.test(value); >+ var correct_decimal_number = value.indexOf(decimal_separator) !== -1; >+ return non_decimal_number || correct_decimal_number; >+ }, _("Please do not use thousands separators and only the decimal separator shown in the example: ")); >+</script> >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 @@ > <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li> > <li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li> > <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li> >- <li><label for="amount" class="required">Amount: </label><input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" name="amount" id="amount" required="required" min="0" value=""/> Example: 5.00</li> >+ <li><label for="amount" class="required">Amount: </label><input type="text" inputmode="decimal" pattern=[% decimal_input_pattern %] name="amount" id="amount" required="required" value=""/> Example: 5[% decimal_delimiter | html %]12</li> > [% INCLUDE 'transaction_types.inc' type="credit" %] > [% IF Koha.Preference('UseCashRegisters') %] > <li> >@@ -135,10 +135,21 @@ > [% MACRO jsinclude BLOCK %] > [% INCLUDE 'str/members-menu.inc' %] > [% Asset.js("js/members-menu.js") | $raw %] >+ [% INCLUDE 'decimal-input-js.inc' %] >+ > <script> > $(document).ready(function(){ > $('#mancredit').preventDoubleFormSubmit(); > $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit"); >+ // decimal input >+ $("#mancredit").validate({ >+ rules: { >+ amount: { >+ is_decimal_number: true, >+ uses_correct_decimal_separator: true >+ }, >+ } >+ }); > [% UNLESS Koha.Preference('RequireCashRegister') %] > $('#credit_type').on('change', function() { > let val = $(this).val(); >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 876ca88c22..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,8 +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="^\d+(\.\d{2})?$" name="amount" id="amount" required="required" min="0" value="[% amount | $Price on_editing => 1 %]" /> Example: 5.00</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> > >@@ -127,6 +127,7 @@ > [% MACRO jsinclude BLOCK %] > [% INCLUDE 'str/members-menu.inc' %] > [% Asset.js("js/members-menu.js") | $raw %] >+ [% INCLUDE 'decimal-input-js.inc' %] > <script> > var type_fees = {}; > [% FOREACH debit_type IN debit_types %] >@@ -135,6 +136,15 @@ > $(document).ready(function(){ > $('#maninvoice').preventDoubleFormSubmit(); > $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit"); >+ // decimal input >+ $("#maninvoice").validate({ >+ rules: { >+ amount: { >+ is_decimal_number: true, >+ uses_correct_decimal_separator: true >+ }, >+ } >+ }); > $("#invoice_type").on("change",function(){ > this.form.desc.value = this.options[this.selectedIndex].value; > this.form.amount.value = type_fees[this.options[this.selectedIndex].value]; >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/mancredit.pl b/members/mancredit.pl >index e77c82defc..88f1a36a76 100755 >--- a/members/mancredit.pl >+++ b/members/mancredit.pl >@@ -68,6 +68,17 @@ output_and_exit_if_error( > my $library_id = > C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; > >+my $decimal_delimiter = >+ C4::Context->preference('CurrencyFormat') eq 'FR' ? ',' : '.'; >+my $decimal_input_pattern = >+ C4::Context->preference('CurrencyFormat') eq 'FR' >+ ? '^\d+(\,\d{2})?$' >+ : '^\d+(\.\d{2})?$'; >+$template->param( >+ decimal_delimiter => $decimal_delimiter, >+ decimal_input_pattern => $decimal_input_pattern, >+); >+ > my $add = $input->param('add'); > if ($add) { > output_and_exit( $input, $cookie, $template, 'wrong_csrf_token' ) >@@ -89,6 +100,7 @@ if ($add) { > my $description = $input->param('desc'); > my $note = $input->param('note'); > my $amount = $input->param('amount') || 0; >+ $amount = Koha::Number::Price->new($amount)->unformat(); > my $type = $input->param('type'); > my $credit_type = $input->param('credit_type'); > my $cash_register_id = $input->param('cash_register'); >diff --git a/members/maninvoice.pl b/members/maninvoice.pl >index 01464cf3a4..3d8ea82126 100755 >--- a/members/maninvoice.pl >+++ b/members/maninvoice.pl >@@ -42,6 +42,8 @@ use Koha::Old::Checkouts; > use Koha::Patron::Categories; > use Koha::Account::DebitTypes; > use Koha::AdditionalFields; >+use Koha::Number::Price; >+use C4::Context; > > my $input = CGI->new; > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >@@ -78,17 +80,27 @@ 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'); >+my $decimal_delimiter = >+ C4::Context->preference('CurrencyFormat') eq 'FR' ? ',' : '.'; >+my $decimal_input_pattern = >+ C4::Context->preference('CurrencyFormat') eq 'FR' >+ ? '^\d+(\,\d{2})?$' >+ : '^\d+(\.\d{2})?$'; > $template->param( >- desc => $desc, >- amount => $amount, >- note => $note, >- type => $debit_type, >- barcode => $barcode >+ desc => $desc, >+ amount => $amount, >+ note => $note, >+ type => $debit_type, >+ barcode => $barcode, >+ decimal_delimiter => $decimal_delimiter, >+ decimal_input_pattern => $decimal_input_pattern, > ); > >+ > my $add = $input->param('add'); > if ($add) { > output_and_exit( $input, $cookie, $template, 'wrong_csrf_token' ) >@@ -101,10 +113,12 @@ if ($add) { > > # Note: If the logged in user is not allowed to see this patron an invoice can be forced > # Here we are trusting librarians not to hack the system >- my $desc = $input->param('desc'); >- my $amount = $input->param('amount'); >- my $note = $input->param('note'); >- my $debit_type = $input->param('type'); >+ my $desc = $input->param('desc'); >+ my $amount = $input->param('amount'); >+ $amount = Koha::Number::Price->new($amount)->unformat(); >+ my $note = $input->param('note'); >+ my $debit_type = $input->param('type'); >+ > > # If barcode is passed, attempt to find the associated item > my $failed; >@@ -133,7 +147,7 @@ if ($add) { > my $checkouts = Koha::Checkouts->search( > { > itemnumber => $item_id, >- borrowernumber => $borrowernumber >+ borrowernumber => $borrowernumber > } > ); > my $checkout = >@@ -162,7 +176,7 @@ if ($add) { > library_id => $library_id, > type => $debit_type, > ( $olditem ? () : ( item_id => $item_id ) ), >- issue_id => $issue_id >+ issue_id => $issue_id, > } > ); > >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 b189107f25..d4a240c4e5 100755 >--- a/members/paycollect.pl >+++ b/members/paycollect.pl >@@ -36,6 +36,8 @@ use Koha::Account::Lines; > 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(); > >@@ -136,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 ) { >@@ -272,7 +276,8 @@ 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 ); > } > > $template->param( >-- >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