From cb579c663f8d5ba33b3c06eb7a501551112f8ae3 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sat, 30 Aug 2014 19:30:30 +0530 Subject: [PATCH] --CRM-15055, CRM-15178, fixed code to save line items when a contribution is saved for contribution ---------------------------------------- * CRM-15178: Correct line_item entity reference for memberships when Separate Payments is true https://issues.civicrm.org/jira/browse/CRM-15178 --- CRM/Contribute/BAO/Contribution.php | 8 ++++++-- CRM/Contribute/Form/Contribution.php | 26 ++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 90e05757fd..e5d86ed448 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2583,7 +2583,7 @@ WHERE contribution_id = %1 "; * @static */ static function recordFinancialAccounts(&$params, $financialTrxnValues = NULL) { - $skipRecords = $update = $return = FALSE; + $skipRecords = $update = $return = $isRelatedId = FALSE; $additionalParticipantId = array(); $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); @@ -2604,6 +2604,10 @@ WHERE contribution_id = %1 "; $entityTable = 'civicrm_contribution'; } + if (CRM_Utils_Array::value('contribution_mode', $params) == 'membership') { + $isRelatedId = TRUE; + } + $entityID[] = $entityId; if (!empty($additionalParticipantId)) { $entityID += $additionalParticipantId; @@ -2654,7 +2658,7 @@ WHERE contribution_id = %1 "; // build line item array if its not set in $params if (empty($params['line_item']) || $additionalParticipantId) { - CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable)); + CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable), $isRelatedId); } if (CRM_Utils_Array::value('contribution_status_id', $params) != array_search('Failed', $contributionStatuses) && diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 1a48047519..bc42f27862 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -988,7 +988,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP */ public function postProcess() { $session = CRM_Core_Session::singleton(); - $sendReceipt = $pId = $contribution = FALSE; + $sendReceipt = $pId = $contribution = $isRelatedId = FALSE; $softParams = $softIDs =array(); if ($this->_action & CRM_Core_Action::DELETE) { @@ -1030,8 +1030,23 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $submittedValues['total_amount'] = CRM_Utils_Array::value('amount', $submittedValues); } if ($this->_id) { - //CRM-10964 - $pId = ($this->_compId && $this->_context == 'participant') ? $this->_compId : CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'participant_id', 'contribution_id'); + if ($this->_compId) { + if ($this->_context == 'participant') { + $pId = $this->_compId; + } + elseif ($this->_context == 'membership') { + $isRelatedId = TRUE; + } + } + else { + $contributionDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id); + if (array_key_exists('membership', $contributionDetails)) { + $isRelatedId = TRUE; + } + elseif (array_key_exists('participant', $contributionDetails)) { + $pId = current($contributionDetails['participant']); + } + } } if (!$priceSetId && !empty($submittedValues['total_amount']) && $this->_id) { // 10117 update th line items for participants @@ -1052,7 +1067,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $entityID = $this->_id; } - $lineItems = CRM_Price_BAO_LineItem::getLineItems($entityID, $entityTable); + $lineItems = CRM_Price_BAO_LineItem::getLineItems($entityID, NULL, TRUE, $isRelatedId); foreach (array_keys($lineItems) as $id) { $lineItems[$id]['id'] = $id; } @@ -1212,6 +1227,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $params['participant_id'] = $pId; $params['skipLineItem'] = 1; } + elseif ($isRelatedId) { + $params['contribution_mode'] = 'membership'; + } $params['line_item'] = $lineItem; $params['payment_processor_id'] = $params['payment_processor'] = CRM_Utils_Array::value('id', $this->_paymentProcessor); //create contribution. -- 2.25.1