Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Minor
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.7.27, 4.7.30
-
Fix Version/s: 5.1
-
Component/s: CiviContribute
-
Labels:
-
Versioning Impact:Patch (backwards-compatible bug fixes)
-
Documentation Required?:None
-
Funding Source:Needs Funding
-
Verified?:No
Description
This has been recreated on 4.7.27 and on a clean install of 4.7.30
To recreate:
- Create a contribution with status "Pending" (I chose "total amount" = 300.00usd which makes this easy to see) and save.
- Record a payment on this contribution of 299.99 (or 1 cent less than your original contribution. Note that I couldn't reproduce this with 100.00 and 99.99, but I could with 400.00 and 399.99)
- Attempt to record a payment on this contribution for the remaining 0.01 owed, and observe the error "Payment amount cannot be greater than owed amount"
- Attempt to record a payment on this contribution for the amount "0.009" and observe that the contribution is rounded to 0.01 and the contribution is marked as "completed"
Investigated so far:
- If you comment out the line that forces two decimal places to be displayed for default, (https://github.com/civicrm/civicrm-core/blob/40a86fc916ea2916d37bc2705b42198c0ea34ec8/CRM/Contribute/Form/AdditionalPayment.php#L184) you can see that my example is pulling up 0.0099999999999909 as the amount owed (should be 0.01) - so that's why the 'amt > owed' error is triggered.
- The incorrect value above appears to be returned by CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType
- I believe the issue may be with the float precision of this equation (The two variables subtracted here, in my example, are correctly returning 300.00 and 299.99, but when subtracted result in 0.0099999999999909): https://github.com/civicrm/civicrm-core/blob/8c06bc25b235f82bcf2fe4e145f911ef3ade0324/CRM/Core/BAO/FinancialTrxn.php#L489