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

Extract getContributionBalance function, use that rather than wrapper… #13151

Merged
merged 1 commit into from
Nov 30, 2018

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Nov 22, 2018

Overview

Minor code cleanup to extract the guts of an overloaded function so just the relevant part can be called. These are internal functions only.

Before

Complex function function getPartialPaymentWithType doing multiple things

After

Get balance part callable by itself

Technical Details

@monishdeb @pradpnayak this function is only called from a few places and I couldn't find any evidence that the 'full_paid' parameter is ever used so I dropped that. I feel like this 'getByType' stuff is a bit silly & we should determine that before calling it but for now I haven't touched that.

I also updated the payment only bit from the contribution form to call this function - this came off trying to understand https://github.com/civicrm/civicrm-core/pull/12319/files#diff-e59ea24da123edeec35a0c498d02874fR1322 & feeling that we just need to know the amount owing whatever the status

Comments

@civibot
Copy link

civibot bot commented Nov 22, 2018

(Standard links)

AND ft.status_id IN ({$statusId}, {$refundStatusId})
";

$ftTotalAmt = CRM_Core_DAO::singleValueQuery($sqlFtTotalAmt);
Copy link
Member

Choose a reason for hiding this comment

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

you can further optimize it via:

$ftTotalAmt = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contributionId);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@monishdeb ok - wanna do that as a follow up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@monishdeb I just revisited this to see if I should make this suggested change in this PR (now it's Monday :-))

But there is a minor change between this and the function you suggest calling - this function looks at completed & refunded whereas that one only looks at completed.

The getTotalPayments function is called from 2 places & my feeling is that those places would be better served by also looking at refunds - per this - but I think we should analyse that so a follow up PR makes more sense. I think @jitendrapurohit had actually suggested changing one of those places in his recent PR

Copy link
Member

Choose a reason for hiding this comment

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

Submitted followup PR #13187

@eileenmcnaughton
Copy link
Contributor Author

@monishdeb can we merge this?

@@ -494,9 +478,6 @@ public static function getPartialPaymentWithType($entityId, $entityName = 'parti
elseif ($paymentVal > 0) {
$value['amount_owed'] = $paymentVal;
}
elseif ($lineItemTotal == $ftTotalAmt) {
$value['full_paid'] = $ftTotalAmt;
}
Copy link
Member

Choose a reason for hiding this comment

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

lol and I didn't relaised it's not used anwhere in Civi but still we are having a separate attribute.

$ grep -irn "full_paid" CRM/
CRM//Core/BAO/FinancialTrxn.php:498:          $value['full_paid'] = $ftTotalAmt;

Agree with this change

@@ -207,16 +207,15 @@ public function testAddPartialPayment() {
$amtPaid = 60;
$balance = $feeAmt - $amtPaid;
$result = $this->addParticipantWithPayment($feeAmt, $amtPaid);
extract($result);
$paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($participant['id'], 'event');
$paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($result['participant']['id'], 'event');
Copy link
Member

Choose a reason for hiding this comment

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

better :)

@monishdeb
Copy link
Member

Agree with the overall change and existing UTs ensure no fee-change is broken by this patch. Though there's a scope for optimization that I'll will bring in a separate followup PR.

@monishdeb monishdeb merged commit c08e3ee into civicrm:master Nov 30, 2018
@eileenmcnaughton eileenmcnaughton deleted the payment_function branch November 30, 2018 08:54
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.

2 participants