-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Optimize CRM_Core_BAO_FinancialTrxn::getTotalPayment #13187
Optimize CRM_Core_BAO_FinancialTrxn::getTotalPayment #13187
Conversation
(Standard links)
|
a87fff9
to
ff4407a
Compare
And I wonder what CRM_Core_BAO_ActionScheduleTest.testRepetitionFrequencyUnit test fail has to do with this patch :/ |
Jenkins re test this please |
Refund amount is not properly calculated after this change. Balance amount still equals the refund amount after the payment is refunded. To replicate -
Payment already refunded - |
@jitendrapurohit thanks for your review. But this PR is meant only to optimize the getTotalPayment() by reusing the code of I am expecting it shouldn't break any scenario nor should fix any issue for partial and refund. After merging this PR can you bring necessary change in #12319 ? |
Hi @eileenmcnaughton , did you get a chance to review this PR? |
@monishdeb I just checked & the issue @jitendrapurohit raises is in fact a regression - here is how the query winds up
Note the apostrophes around '1, 7' - that is invalid, I think you need to use string concatenation not CRM_Core_DAO interpolation here - I guess you can validate as commaSeparatedIntegers for good practice - although it's not immediately obvious how someone could get a user value into that field |
@monishdeb I'm marking this WIP until you get the chance to make the suggested changes. |
ff4407a
to
76ada6c
Compare
Hi @colemanw @eileenmcnaughton sorry for the delay. I have updated this PR, please have a look now. |
CRM/Core/BAO/FinancialTrxn.php
Outdated
return CRM_Core_DAO::singleValueQuery($sql, $params); | ||
return CRM_Core_DAO::singleValueQuery($sql, [ | ||
1 => [$contributionID, 'Integer'], | ||
2 => [implode(', ', $statusIDs), 'CommaSeparatedIntegers'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the test fail is due to the space here - not sure if we should fix the rule to permit but easy to change here for now
76ada6c
to
89bfb10
Compare
Jenkins test this please |
@eileenmcnaughton can you please merge it? |
public static function getTotalPayments($contributionID, $includeRefund = FALSE) { | ||
$statusIDs = [CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed')]; | ||
|
||
if ($includeRefund) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have we split out this parameter? There are no places calling it as yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton this is old followup PR of #13151 where we agreed here to have this function modified to include refunded payments rather than only Completed. The need is to get correct contribution balance that earlier considers only Completed payments and is used in the patch at L4178 at Contribution BAO.
I've run through this in a test & am satisified the result is the same with this change - I'll push my test up separately |
Add unit test on getContributionBalance fn (#13187)
Overview
This patch optimizes the
getContributionBalance()
function to useCRM_Core_BAO_FinancialTrxn::getTotalPayments
to fetch the total paid amount.Before
getContributionBalance() uses codes already present in
CRM_Core_BAO_FinancialTrxn::getTotalPayments
After
CRM_Core_BAO_FinancialTrxn::getTotalPayments
consider refund trxnsgetContributionBalance()
Comments
This is a followup PR of #13151
ping @eileenmcnaughton @jitendrapurohit @seamuslee001