Skip to content

Commit

Permalink
PROD-180: Resolve Issue with Payment Allocation to Contribution Line …
Browse files Browse the repository at this point in the history
…Item

Applying PR civicrm#29823

Partially Included in 5.74
  • Loading branch information
Muhammad Shahrukh authored and shahrukh-compuco committed Jul 10, 2024
1 parent 1fc7352 commit 8e5d6bd
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ protected static function getPayableItems(array $params, array $contribution): a
}
}

$isPaymentCompletesContribution = self::isPaymentCompletesContribution($params['contribution_id'], $params['total_amount'], '');
$items = LineItem::get(FALSE)
->addSelect('*', 'financial_item.status_id:name', 'financial_item.id', 'financial_item.financial_account_id', 'financial_item_id.currency', 'financial_item.financial_account_id.is_tax', 'financial_item.entity_id', 'financial_item.amount', 'allocated.amount')
->addJoin(
Expand Down Expand Up @@ -579,15 +580,32 @@ protected static function getPayableItems(array $params, array $contribution): a
}
else {
if (empty($item['balance']) && !empty($ratio) && $params['total_amount'] < 0) {
$item['allocation'] = $item['item_total'] * $ratio;
$item['allocation'] = round($item['item_total'] * $ratio, 2);
}
elseif ($isPaymentCompletesContribution) {
$item['allocation'] = $item['balance'];
}
else {
$item['allocation'] = $item['balance'] * $ratio;
$item['allocation'] = round($item['balance'] * $ratio, 2);
}

if (!empty($item['tax_amount'])) {
$item['tax_allocation'] = round($item['tax_amount'] * ($params['total_amount'] / $contribution['total_amount']), 2);
}
}
$payableItems[$payableItemIndex] = $item;
}

if (empty($lineItemOverrides) && !empty($ratio)) {
$totalTaxAllocation = array_sum(array_column($payableItems, 'tax_allocation'));
$totalAllocation = array_sum(array_column($payableItems, 'allocation'));
$total = $totalTaxAllocation + $totalAllocation;
$leftPayment = $params['total_amount'] - $total;

// assign any leftover amount, to the last lineitem
$payableItems[$payableItemIndex]['allocation'] += $leftPayment;
}

return $payableItems;
}

Expand Down

0 comments on commit 8e5d6bd

Please sign in to comment.