From: yashodha Date: Wed, 1 May 2013 01:19:41 +0000 (+0530) Subject: more BAO work(CRM-12463) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=cd0a30ac0fa5fa158ae13d3397db396763c36cac;p=civicrm-core.git more BAO work(CRM-12463) --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 934345c191..d6210fca67 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -158,13 +158,13 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { if (CRM_Utils_Array::value('contribution', $ids)) { $contributionId['id'] = $ids['contribution']; $params['prevContribution'] = self::getValues($contributionId, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray); - if (CRM_Utils_Array::value('soft_credit_to', $params)) { + /*if (CRM_Utils_Array::value('soft_credit_to', $params)) { foreach (array('financial_type_id', 'total_amount') as $field) { if (!isset($contribution->$field)) { $contribution->$field = $params['prevContribution']->$field; } } - } + }*/ } $result = $contribution->save(); @@ -178,7 +178,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { self::recordFinancialAccounts($params, $ids); // Add soft_contribution details as part of fix for CRM-8908 - $contribution->soft_credit_to = CRM_Utils_Array::value('soft_credit_to', $params); + //$contribution->soft_credit_to = CRM_Utils_Array::value('soft_credit_to', $params); // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); @@ -241,18 +241,18 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } } - if (CRM_Utils_Array::value('contribution', $ids) && + /*if (CRM_Utils_Array::value('contribution', $ids) && !CRM_Utils_Array::value('softID', $params) ) { if ($softID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionSoft', $ids['contribution'], 'id', 'contribution_id')) { $params['softID'] = $softID; } - } + }*/ $transaction = new CRM_Core_Transaction(); // delete the soft credit record if no soft credit contact ID AND no PCP is set in the form - if (CRM_Utils_Array::value('contribution', $ids) && + /*if (CRM_Utils_Array::value('contribution', $ids) && (!CRM_Utils_Array::value('soft_credit_to', $params) && !CRM_Utils_Array::value('pcp_made_through_id', $params) ) && @@ -261,10 +261,34 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $softCredit = new CRM_Contribute_DAO_ContributionSoft(); $softCredit->id = $params['softID']; $softCredit->delete(); - } + }*/ $contribution = self::add($params, $ids); + if (CRM_Utils_Array::value('deleteSoftCredit', $params, TRUE)) { + // first delete soft credits if any + CRM_Contribute_BAO_ContributionSoft::del($contribution->id); + + if (CRM_Utils_Array::value('pcp_made_through_id', $params)) { + $softParams = array(); + $softParams['contribution_id'] = $contribution->id; + $softParams['pcp_id'] = $params['pcp_made_through_id']; + $softParams['contact_id'] = $params['soft_credit_to']; + $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $params); + $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $params); + $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $params); + CRM_Contribute_BAO_ContributionSoft::add($softParams); + } + elseif (CRM_Utils_Array::value('soft_credit', $params)) { + $softParams = $params['soft_credit']; + foreach ($softParams as $softParam) { + $softParam['contribution_id'] = $contribution->id; + $softParam['currency'] = $contribution->currency; + CRM_Contribute_BAO_ContributionSoft::add($softParam); + } + } + } + if (is_a($contribution, 'CRM_Core_Error')) { $transaction->rollback(); return $contribution; diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 73e539c477..e8a3d800fa 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1019,6 +1019,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP // get the submitted form values. $submittedValues = $this->controller->exportValues($this->_name); + if (CRM_Utils_Array::value('price_set_id', $submittedValues) && $this->_action & CRM_Core_Action::UPDATE ) { $line = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution'); $lineID = key($line); @@ -1101,9 +1102,28 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } $this->assign('lineItem', !empty($lineItem) && !$isQuickConfig ? $lineItem : FALSE); - if (CRM_Utils_Array::value('soft_credit_to', $submittedValues)) { - $submittedValues['soft_credit_to'] = $submittedValues['soft_contact_id']; + if (CRM_Utils_Array::value('pcp_made_through_id', $submittedValues)) { + + } + else { + //build soft credit params + if (!empty($submittedValues['soft_credit_contact_select_id'])) + $softParams = array(); + foreach( $submittedValues['soft_credit_contact_select_id'] as $key => $val) { + if ($val && $submittedValues['soft_credit_amount'][$key]) { + $softParams[$key]['contact_id'] = $val; + $softParams[$key]['amount'] = $submittedValues['soft_credit_amount'][$key]; + $softCredit = TRUE; + } + } } + if (!empty($softParams)) { + $params['soft_credit'] = $softParams; + } + + /* if (CRM_Utils_Array::value('soft_credit_to', $submittedValues)) { + $submittedValues['soft_credit_to'] = $submittedValues['soft_contact_id']; + }*/ // set the contact, when contact is selected if (CRM_Utils_Array::value('contact_select_id', $submittedValues)) { @@ -1135,19 +1155,21 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP 'cancel_reason', 'source', 'check_number', - 'soft_credit_to', + /*'soft_credit_to', 'pcp_made_through_id', 'pcp_display_in_roll', 'pcp_roll_nickname', - 'pcp_personal_note', + 'pcp_personal_note',*/ ); foreach ($fields as $f) { $params[$f] = CRM_Utils_Array::value($f, $formValues); } - - if ($softID = CRM_Utils_Array::value('softID', $this->_values)) { - $params['softID'] = $softID; + if (!empty($softParams)) { + $params['soft_credit'] = $softParams; } + /*if ($softID = CRM_Utils_Array::value('softID', $this->_values)) { + $params['softID'] = $softID; + }*/ //if priceset is used, no need to cleanup money //CRM-5740 if ($priceSetId) { @@ -1175,7 +1197,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } else { - $params['cancel_date'] = $params['cancel_reason'] = 'null'; + $params['cancel_date'] = $params['cancel_reason'] = 'null'; } // Set is_pay_later flag for back-office offline Pending status contributions CRM-8996