Skip to content

Commit

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

Correction of the Patch introduced in this commit 7507726
  • Loading branch information
olayiwola-compucorp committed Nov 7, 2024
1 parent 1d1d186 commit 97d7a53
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,22 +588,32 @@ protected static function getPayableItems(array $params, array $contribution): a
else {
$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;
}

// Custom patch to correct roundoff errors
if (empty($lineItemOverrides) && !empty($ratio) && isset($payableItems[$payableItemIndex])) {
$totalTaxAllocation = array_sum(array_column($payableItems, 'tax_allocation'));
$totalAllocation = array_sum(array_column($payableItems, 'allocation'));
$totalTaxAllocation = 0;
$totalAllocation = 0;
$lastNonTaxKey = $payableItemIndex;

foreach ($payableItems as $key => $item) {
if ($item['financial_item.financial_account_id.is_tax']) {
$totalTaxAllocation += $item['allocation'];
}
else {
$totalAllocation += $item['allocation'];
$lastNonTaxKey = $key;
}
}

$total = $totalTaxAllocation + $totalAllocation;
$leftPayment = $params['total_amount'] - $total;

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

if ($lastNonTaxKey !== NULL) {
$payableItems[$lastNonTaxKey]['allocation'] += $leftPayment;
}
}

return $payableItems;
Expand Down

0 comments on commit 97d7a53

Please sign in to comment.