Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug where Payment Balance is sometimes miscalculated #16546

Merged
merged 1 commit into from
Mar 16, 2020

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Feb 14, 2020

Overview

Fixes a bug where Add Refund is displayed instead of Add Payment on partially paid event contributions

Before

Notice that when viewing a partially paid transaction getPaymentInfo is called twice - the first time is with usingLineTotal = TRUE & results in the Record Payment button about half way up.

The second is at the bottom & the mystery param is not passed i - resulting in RecordRefund

Screen Shot 2020-02-15 at 10 56 22 AM

After

Screen Shot 2020-02-15 at 11 10 58 AM

Technical Details

I observed that when this function is called without the mystical the paymentBalance is miscalculated

The payment balance is calculated as the Contribution Total less the amount paid (for less queries the
total is passed into getContributionBalance & used if passed in). We were passing in the Balance
as the total causing the balance to be calculated as the Balance less any amount paid.

From what I can tell this function has been honed & cleaned up but because the parameter never made much sense
the impact of different variants was not really tested. This removes & fixes

Comments

@monishdeb @pradpnayak

@civibot
Copy link

civibot bot commented Feb 14, 2020

(Standard links)

@civibot civibot bot added the master label Feb 14, 2020
@seamuslee001
Copy link
Contributor

@seamuslee001
Copy link
Contributor

This seems to be fine to me but would appreciate others to comment @monishdeb @mattwire

@@ -4043,19 +4045,13 @@ public static function getPaymentInfo($id, $component = 'contribution', $getTrxn
$contributionId = $id;
}

$total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
$baseTrxnId = !empty($total['trxn_id']) ? $total['trxn_id'] : NULL;
$oldCalculation = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton It would be helpful to have a comment explaining why this variable is called oldCalculation as it's a mystery to me. Non-blocking to merging of this PR but if you get chance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - because I think it is weird & should go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire - I've expanded the code comments

@mattwire
Copy link
Contributor

I'm happy with this from an r-code perspective. Could really do with an r-run from someone like @monishdeb @pradpnayak @elcapo

I observed that when this function is called without the mystical  the paymentBalance is miscalculated

The payment balance is calculated as the Contribution Total less the amount paid (for less queries the
total is passed into getContributionBalance & used if passed in). We were passing in the Balance
as the total causing the balance to be calculated as the Balance less any amount paid.

From what I can tell this function has been honed & cleaned up but because the parameter never made much sense
the impact of different variants was not really tested. This removes & fixes
@jaapjansma
Copy link
Contributor

Betty and I are reviewing PR's and we came across this PR.

  • General standards
    • Explain (r-explain)
      • FAIL We missed a step by step instruction of how to reproduce this as a user. We managed to find it out ourselves but that was quite a bit of work. We have given this a FAIL because we do think @eileenmcnaughton can do better. However we don't think this blocks the merging.
    • User impact (r-user)
      • PASS: The change would be intuitive or unnoticeable for a majority of users who work with this feature.
    • Documentation (r-doc)
      • PASS: The changes do not require documentation.
      • COMMENTS: Although this a pass we discovered that the user guide does not have a section on how to handle partial payments. We have added an issue for updating the user guide: https://lab.civicrm.org/documentation/docs/user-en/issues/1 However it is not blocking for this PR.
    • Run it (r-run)
      • PASS: We registered for an event (Rain Forest Cup) as Tiny Tots and paid the $ 800 fee by credit card. We then changed the registration in the back end to Junior Stars. We saw the button record payment, record credit card payment appear. We also tested this in dmaster and the buttons did not appear.
  • Developer standards
    • Technical impact (r-tech)
      • PASS: The change preserves compatibility with existing callers/code/downstream.
    • Code quality (r-code)
      • PASS: The functionality, purpose, and style of the code seems clear+sensible.
    • Maintainability (r-maint)
      • PASS: The change is trivial enough that it does not require tests.
      • COMMENTS: We have given this a PASS however based on the feedback from previous reviewing we have a gut feeling @eileenmcnaughton might say this needs a test as it involves payments ;-)
    • Test results (r-test)
      • PASS: The test results are all-clear.

@mattwire or @eileenmcnaughton could one of you merge this PR?

@mattwire
Copy link
Contributor

Thanks @jaapjansma

@mattwire mattwire merged commit 3f93233 into civicrm:master Mar 16, 2020
@eileenmcnaughton eileenmcnaughton deleted the part_end2 branch March 16, 2020 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants