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

[REF] simplify recordAdjustedAmt function #16135

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions CRM/Price/BAO/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ protected function _getRelatedCancelFinancialTrxn($financialItemID) {
* @return bool|\CRM_Core_BAO_FinancialTrxn
*/
protected function _recordAdjustedAmt($updatedAmount, $contributionId, $taxAmount = NULL, $updateAmountLevel = NULL) {
$paidAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contributionId);
$paidAmount = (float) CRM_Core_BAO_FinancialTrxn::getTotalPayments($contributionId);
$balanceAmt = $updatedAmount - $paidAmount;

$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
Expand All @@ -1181,26 +1181,21 @@ protected function _recordAdjustedAmt($updatedAmount, $contributionId, $taxAmoun
$completedStatusId = array_search('Completed', $contributionStatuses);

$updatedContributionDAO = new CRM_Contribute_BAO_Contribution();
$adjustedTrxn = $skip = FALSE;
$adjustedTrxn = FALSE;
if ($balanceAmt) {
if ($balanceAmt > 0 && $paidAmount != 0) {
$contributionStatusVal = $partiallyPaidStatusId;
}
elseif ($balanceAmt < 0 && $paidAmount != 0) {
$contributionStatusVal = $pendingRefundStatusId;
}
elseif ($paidAmount == 0) {
if ($paidAmount === 0.0) {
//skip updating the contribution status if no payment is made
$skip = TRUE;
$updatedContributionDAO->cancel_date = 'null';
$updatedContributionDAO->cancel_reason = NULL;
}
else {
$updatedContributionDAO->contribution_status_id = $balanceAmt > 0 ? $partiallyPaidStatusId : $pendingRefundStatusId;
}

// update contribution status and total amount without trigger financial code
// as this is handled in current BAO function used for change selection
$updatedContributionDAO->id = $contributionId;
if (!$skip) {
$updatedContributionDAO->contribution_status_id = $contributionStatusVal;
}

$updatedContributionDAO->total_amount = $updatedContributionDAO->net_amount = $updatedAmount;
$updatedContributionDAO->fee_amount = 0;
$updatedContributionDAO->tax_amount = $taxAmount;
Expand Down