From 036136e2da223c4ec3dbeec0fe1de456bb4118c8 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Tue, 1 Dec 2020 16:38:38 +1100 Subject: [PATCH] CIVICRM-1617: Only make line_item array if it doesn't exist already. --- CRM/Contribute/BAO/Contribution.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 236c1c203e..24fd0f4091 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -168,6 +168,16 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { unset($params['revenue_recognition_date']); } + // Get Line Items if we don't have them already. + if (empty($params['line_item'])) { + if (isset($params['id'])) { + CRM_Price_BAO_LineItem::getLineItemArray($params, [$params['id']]); + } + else { + CRM_Price_BAO_LineItem::getLineItemArray($params); + } + } + if (!isset($params['tax_amount']) && $setPrevContribution && (isset($params['total_amount']) || isset($params['financial_type_id']))) { $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params); @@ -4111,7 +4121,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac // Assign tax Amount on update of contribution if (!empty($params['prevContribution']->tax_amount)) { $params['tax_amount'] = 'null'; - CRM_Price_BAO_LineItem::getLineItemArray($params, [$params['id']]); foreach ($params['line_item'] as $setID => $priceField) { foreach ($priceField as $priceFieldID => $priceFieldValue) { $params['line_item'][$setID][$priceFieldID]['tax_amount'] = $params['tax_amount']; @@ -4128,13 +4137,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount(CRM_Utils_Array::value('total_amount', $params), $taxRateParams); $params['tax_amount'] = round($taxAmount['tax_amount'], 2); - // Get Line Item on update of contribution - if (isset($params['id'])) { - CRM_Price_BAO_LineItem::getLineItemArray($params, [$params['id']]); - } - else { - CRM_Price_BAO_LineItem::getLineItemArray($params); - } foreach ($params['line_item'] as $setID => $priceField) { foreach ($priceField as $priceFieldID => $priceFieldValue) { $params['line_item'][$setID][$priceFieldID]['tax_amount'] = $params['tax_amount']; -- 2.25.1