From 6eb592cca1cb5cd67ad81f9557663f9a19bb001a Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 21 Jun 2019 18:03:29 -0400 Subject: [PATCH] Copy assignProportional Line items back into Payment.create function This is a case where (unintuitively) I feel reducing code sharing and extraction makes sense. The reason being I think the 'needs' of adding a payment are not obviously the same as the needs of 'changing a payment instrument' and the code feels confusion and like the extractions make less sense now than they did. In the interests of improving it bringing it back together seems the right path to me here. We can then edit for the purposes of payment create code very specifically (and all functions that add payments need to call that) --- CRM/Financial/BAO/Payment.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index 7217637710..d3f5dc3119 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -118,7 +118,17 @@ class CRM_Financial_BAO_Payment { } } elseif (!empty($trxn)) { - CRM_Contribute_BAO_Contribution::assignProportionalLineItems($params, $trxn->id, $contribution['total_amount']); + $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($params['contribution_id']); + if (!empty($lineItems)) { + // get financial item + list($ftIds, $taxItems) = CRM_Contribute_BAO_Contribution::getLastFinancialItemIds($params['contribution_id']); + $entityParams = [ + 'contribution_total_amount' => $contribution['total_amount'], + 'trxn_total_amount' => $params['total_amount'], + 'trxn_id' => $trxn->id, + ]; + CRM_Contribute_BAO_Contribution::createProportionalFinancialEntries($entityParams, $lineItems, $ftIds, $taxItems); + } } } elseif ($params['total_amount'] < 0) { -- 2.25.1