-
-
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
Extract getContributionBalance function, use that rather than wrapper… #13151
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,26 +466,10 @@ public static function getPartialPaymentWithType($entityId, $entityName = 'parti | |
$financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'financial_type_id'); | ||
|
||
if ($contributionId && $financialTypeId) { | ||
$statusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); | ||
$refundStatusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Refunded'); | ||
|
||
if (empty($lineItemTotal)) { | ||
$lineItemTotal = CRM_Price_BAO_LineItem::getLineTotal($contributionId); | ||
} | ||
$sqlFtTotalAmt = " | ||
SELECT SUM(ft.total_amount) | ||
FROM civicrm_financial_trxn ft | ||
INNER JOIN civicrm_entity_financial_trxn eft ON (ft.id = eft.financial_trxn_id AND eft.entity_table = 'civicrm_contribution' AND eft.entity_id = {$contributionId}) | ||
WHERE ft.is_payment = 1 | ||
AND ft.status_id IN ({$statusId}, {$refundStatusId}) | ||
"; | ||
|
||
$ftTotalAmt = CRM_Core_DAO::singleValueQuery($sqlFtTotalAmt); | ||
if (!$ftTotalAmt) { | ||
$ftTotalAmt = 0; | ||
} | ||
$currency = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'currency'); | ||
$value = $paymentVal = CRM_Utils_Money::subtractCurrencies($lineItemTotal, $ftTotalAmt, $currency); | ||
$value = CRM_Contribute_BAO_Contribution::getContributionBalance($contributionId, $lineItemTotal); | ||
|
||
$paymentVal = $value; | ||
if ($returnType) { | ||
$value = array(); | ||
if ($paymentVal < 0) { | ||
|
@@ -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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Agree with this change |
||
} | ||
} | ||
return $value; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line 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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better :) |
||
|
||
// amount checking | ||
$this->assertEquals(round($paymentInfo['total']), $feeAmt, 'Total amount recorded is not proper'); | ||
$this->assertEquals(round($paymentInfo['paid']), $amtPaid, 'Amount paid is not proper'); | ||
$this->assertEquals(round($paymentInfo['balance']), $balance, 'Balance amount is not proper'); | ||
|
||
// status checking | ||
$this->assertEquals($participant['participant_status_id'], 14, 'Status record is not proper for participant'); | ||
$this->assertEquals($result['participant']['participant_status_id'], 14, 'Status record is not proper for participant'); | ||
$this->assertEquals($result['contribution']['contribution_status_id'], 8, 'Status record is not proper for contribution'); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you can further optimize it via:
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.
@monishdeb ok - wanna do that as a follow up?
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.
@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
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.
Submitted followup PR #13187