Skip to content

Commit 97d7a53

Browse files
PROD-229: Resolve Issue with Payment Allocation to Contribution Line Item
Correction of the Patch introduced in this commit 7507726
1 parent 1d1d186 commit 97d7a53

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

CRM/Financial/BAO/Payment.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,22 +588,32 @@ protected static function getPayableItems(array $params, array $contribution): a
588588
else {
589589
$item['allocation'] = round($item['balance'] * $ratio, 2);
590590
}
591-
592-
if (!empty($item['tax_amount'])) {
593-
$item['tax_allocation'] = round($item['tax_amount'] * ($params['total_amount'] / $contribution['total_amount']), 2);
594-
}
595591
}
596592
$payableItems[$payableItemIndex] = $item;
597593
}
598594

595+
// Custom patch to correct roundoff errors
599596
if (empty($lineItemOverrides) && !empty($ratio) && isset($payableItems[$payableItemIndex])) {
600-
$totalTaxAllocation = array_sum(array_column($payableItems, 'tax_allocation'));
601-
$totalAllocation = array_sum(array_column($payableItems, 'allocation'));
597+
$totalTaxAllocation = 0;
598+
$totalAllocation = 0;
599+
$lastNonTaxKey = $payableItemIndex;
600+
601+
foreach ($payableItems as $key => $item) {
602+
if ($item['financial_item.financial_account_id.is_tax']) {
603+
$totalTaxAllocation += $item['allocation'];
604+
}
605+
else {
606+
$totalAllocation += $item['allocation'];
607+
$lastNonTaxKey = $key;
608+
}
609+
}
610+
602611
$total = $totalTaxAllocation + $totalAllocation;
603612
$leftPayment = $params['total_amount'] - $total;
604-
605-
// assign any leftover amount, to the last lineitem
606-
$payableItems[$payableItemIndex]['allocation'] += $leftPayment;
613+
614+
if ($lastNonTaxKey !== NULL) {
615+
$payableItems[$lastNonTaxKey]['allocation'] += $leftPayment;
616+
}
607617
}
608618

609619
return $payableItems;

0 commit comments

Comments
 (0)