Our librarians discovered recently that recording payments for some specific fine amounts (64.60, for example) are not working properly - they are getting errors like: You must pay a value less than or equal to 64.60 It's not just 64.60, same thing happens for: 1.14 1.36 1.39 1.57 1.59 1.61 1.64 1.66 1.68 1.82 1.84 1.86 1.89 1.91 1.93 2.01 2.03 2.28 2.47 2.53 2.72 2.78 2.97 ... 32.30 64.10 64.60 65.10 128.20 128.70 129.20 129.70 130.20 130.70 ... and so on. This error seems to be caused by incorrect rounding in C4::Members::GetMemberAccountRecords(). To replicate: 1) Create manual invoice for 64.60 (or 1.14, 1.36, ...) 2) Try to pay it using "Pay amount" or "Pay selected" buttons As a temporary workaround, one may: - pay such amount in 2+ steps (eg. 64.00 + 0.60) - pay individual fines using 'Pay' button[s] on the left but, at first glance at least, an underlying problem for this error may possibly have some more severe consequences than just minor troubles with making payments - eg., if patron has 12+ fines (or credits) of such kind, total account balance calculation may be wrong as well.
Created attachment 48776 [details] [review] Bug 15741: Fix rounding in total fines calculations C4::Members::GetMemberAccountRecords wrongly casts float to integer It's common to use sprintf in Perl to do this job. % perl -e 'print int(1000*64.60)."\n"'; 64599 % perl -e 'print sprintf("%.0f", 1000*64.60)."\n"'; 64600 Test plan: 1) Create manual invoice for 64.60 (or 1.14, 1.36, ...) 2) Try to pay it using "Pay amount" or "Pay selected" buttons
I was keen to sign this patch off, as this causes terrible problems for us. Test plan: 1) Create manual invoice for 64.60 (or 1.14, 1.36, ...) 2) Try to pay it using "Pay amount" or "Pay selected" buttons Using 'Pay Amount' button: 1) Create manual invoice for a single payment: 64.60 (or 1.14, 1.36, ...) 2) Pay it using 'Pay Amount' button Pass: this works as expected. 1) Create manual invoice for multiple lines which total: 64.60 (or 1.14, 1.36, ...) 2) Pay all lines using 'Pay Amount' button Pass: this works as expected. 1) Create manual invoice for multiple lines. 2) Decide to pay an amount which totals: 64.60 (or 1.14, 1.36, ...) 3) Pay using 'Pay Amount' button Pass: this works as expected. Using 'Pay Selected' button: 1) Create manual invoice for a single payment: 64.60 (or 1.14, 1.36, ...) 2) Pay it using 'Pay Selected' button Fail: 'You must pay a value less than or equal to 64.60 (or 1.14, 1.36, ...)' displays 1) Create manual invoice for multiple lines which total: 64.60 (or 1.14, 1.36, ...) 2) Pay all lines using 'Pay Selected' button Pass: this works as expected 1) Create manual invoice for multiple lines. 2) Choose some lines which total: 64.60 (or 1.14, 1.36, ...) 3) Pay chosen lines using 'Pay Selected' button Pass: the error line does not appear. However, there seems to be a major error with the 'Pay Selected' function, which is reported in the following bug: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15397 Can we sign off this patch as it mends the functionality of the 'Pay Amount' button and focus on the 'Pay Selected' issue in a different bug - which appears to be a much bigger problem?
(In reply to Sally Healey from comment #2) > Can we sign off this patch as it mends the functionality of the 'Pay Amount' > button and focus on the 'Pay Selected' issue in a different bug - which > appears to be a much bigger problem? Yes, definitely.
Patch tested with a sandbox, by Sally Healey <sally.healey@cheshiresharedservices.gov.uk>
Created attachment 49087 [details] [review] Bug 15741: Fix rounding in total fines calculations C4::Members::GetMemberAccountRecords wrongly casts float to integer It's common to use sprintf in Perl to do this job. % perl -e 'print int(1000*64.60)."\n"'; 64599 % perl -e 'print sprintf("%.0f", 1000*64.60)."\n"'; 64600 Test plan: 1) Create manual invoice for 64.60 (or 1.14, 1.36, ...) 2) Try to pay it using "Pay amount" or "Pay selected" buttons Signed-off-by: Sally Healey <sally.healey@cheshiresharedservices.gov.uk>
Created attachment 49484 [details] [review] [PASSED QA] Bug 15741: Fix rounding in total fines calculations C4::Members::GetMemberAccountRecords wrongly casts float to integer It's common to use sprintf in Perl to do this job. % perl -e 'print int(1000*64.60)."\n"'; 64599 % perl -e 'print sprintf("%.0f", 1000*64.60)."\n"'; 64600 Test plan: 1) Create manual invoice for 64.60 (or 1.14, 1.36, ...) 2) Try to pay it using "Pay amount" or "Pay selected" buttons Signed-off-by: Sally Healey <sally.healey@cheshiresharedservices.gov.uk> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Created attachment 49495 [details] [review] Bug 15741: (regression tests) Rounding is not calculated correctly Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 49496 [details] [review] Bug 15741: Fix rounding in total fines calculations C4::Members::GetMemberAccountRecords wrongly casts float to integer It's common to use sprintf in Perl to do this job. % perl -e 'print int(1000*64.60)."\n"'; 64599 % perl -e 'print sprintf("%.0f", 1000*64.60)."\n"'; 64600 Test plan: 1) Create manual invoice for 64.60 (or 1.14, 1.36, ...) 2) Try to pay it using "Pay amount" or "Pay selected" buttons Signed-off-by: Sally Healey <sally.healey@cheshiresharedservices.gov.uk> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Pushed to Master - Should be in May 2016 release. Thanks!
Patches pushed to 3.22.x, will be in 3.22.6
Pushed to 3.20.x, will be in 3.20.11.
This bug still appears in master at "Pay amount" and "Pay selected" for payment of 1.14, but not with 64.60. To replicate: 1. Go to patron's fines tab, make sure there are no outstanding payments. 2. Via "Create manual invoice" tab, create one fine of 1.14 3. Go to Pay fines tab 4. Click "Pay amount" and confirm. 5. Observe error message "You must pay a value less than or equal to 1.14." 6. Go to Pay fines tab 7. Click "Pay selected" and confirm 8. Observe error message "You must pay a value less than or equal to 1.14." However, via individual row's "Pay" button it seems to work.