* @param $form
* @param array $params Parameters from the form.
*/
- public static function postProcess($form, $params) {
- if (!empty($form->_honor_block_is_active) && !empty($params['soft_credit_type_id'])) {
- $honorId = NULL;
-
- //check if there is any duplicate contact
- $profileContactType = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
- $dedupeParams = CRM_Dedupe_Finder::formatParams($params['honor'], $profileContactType);
- $dedupeParams['check_permission'] = FALSE;
- $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $profileContactType);
- if (count($ids)) {
- $honorId = CRM_Utils_Array::value(0, $ids);
- }
-
- $honorId = CRM_Contact_BAO_Contact::createProfileContact(
- $params['honor'], CRM_Core_DAO::$_nullArray,
- $honorId, NULL,
- $params['honoree_profile_id']
- );
- $softParams = array();
- $softParams['contribution_id'] = $form->_contributionID;
- $softParams['contact_id'] = $honorId;
- $softParams['soft_credit_type_id'] = $params['soft_credit_type_id'];
- $contribution = new CRM_Contribute_DAO_Contribution();
- $contribution->id = $form->_contributionID;
- $contribution->find();
- while ($contribution->fetch()) {
- $softParams['currency'] = $contribution->currency;
- $softParams['amount'] = $contribution->total_amount;
- }
- CRM_Contribute_BAO_ContributionSoft::add($softParams);
-
- if (CRM_Utils_Array::value('is_email_receipt', $form->_values)) {
- $form->_values['honor'] = array(
- 'soft_credit_type' => CRM_Utils_Array::value(
- $params['soft_credit_type_id'],
- CRM_Core_OptionGroup::values("soft_credit_type")
- ),
- 'honor_id' => $honorId,
- 'honor_profile_id' => $params['honoree_profile_id'],
- 'honor_profile_values' => $params['honor'],
- );
- }
- }
+ public static function postProcess($form) {
}
}
}
}
- // Handle soft credit and / or link to personal campaign page
- $softIDs = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id);
-
- $pcpId = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id, TRUE);
-
- if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
- $softParams = array();
- $softParams['id'] = $pcpId ? $pcpId : NULL;
- $softParams['contribution_id'] = $contribution->id;
- $softParams['pcp_id'] = $pcp['pcp_made_through_id'];
- $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
- $pcp['pcp_made_through_id'], 'contact_id'
- );
- $softParams['currency'] = $contribution->currency;
- $softParams['amount'] = $contribution->total_amount;
- $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
- $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
- $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
- $softParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name');
- $contributionSoft = CRM_Contribute_BAO_ContributionSoft::add($softParams);
- //Send notification to owner for PCP
- if ($contributionSoft->pcp_id && empty($pcpId)) {
- CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
- }
- }
- //Delete PCP against this contribution and create new on submitted PCP information
- elseif (array_key_exists('pcp', $params) && $pcpId) {
- $deleteParams = array('id' => $pcpId);
- CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
- }
- if (isset($params['soft_credit'])) {
- $softParams = $params['soft_credit'];
- foreach ($softParams as $softParam) {
- if (!empty($softIDs)) {
- $key = key($softIDs);
- $softParam['id'] = $softIDs[$key];
- unset($softIDs[$key]);
- }
- $softParam['contribution_id'] = $contribution->id;
- $softParam['currency'] = $contribution->currency;
- //case during Contribution Import when we assign soft contribution amount as contribution's total_amount by default
- if (empty($softParam['amount'])) {
- $softParam['amount'] = $contribution->total_amount;
- }
- CRM_Contribute_BAO_ContributionSoft::add($softParam);
- }
-
- if (!empty($softIDs)) {
- foreach ($softIDs as $softID) {
- if (!in_array($softID, $params['soft_credit_ids'])) {
- $deleteParams = array('id' => $softID);
- CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
- }
- }
- }
- }
+ CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
$transaction->commit();
return $contributionSoft->save();
}
+ /**
+ * Process the soft contribution and/or link to personal campaign page.
+ *
+ * @param array $params
+ * @param object $contribution CRM_Contribute_DAO_Contribution
+ *
+ */
+ public static function processSoftContribution($params, $contribution) {
+ //retrieve existing soft-credit and pcp id(s) if any against $contribution
+ $softIDs = self::getSoftCreditIds($contribution->id);
+ $pcpId = self::getSoftCreditIds($contribution->id, TRUE);
+
+ if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
+ $softParams = array();
+ $softParams['id'] = $pcpId ? $pcpId : NULL;
+ $softParams['contribution_id'] = $contribution->id;
+ $softParams['pcp_id'] = $pcp['pcp_made_through_id'];
+ $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
+ $pcp['pcp_made_through_id'], 'contact_id'
+ );
+ $softParams['currency'] = $contribution->currency;
+ $softParams['amount'] = $contribution->total_amount;
+ $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
+ $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
+ $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
+ $softParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name');
+ $contributionSoft = self::add($softParams);
+ //Send notification to owner for PCP
+ if ($contributionSoft->pcp_id && empty($pcpId)) {
+ CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
+ }
+ }
+ //Delete PCP against this contribution and create new on submitted PCP information
+ elseif (array_key_exists('pcp', $params) && $pcpId) {
+ $deleteParams = array('id' => $pcpId);
+ CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
+ }
+ if (isset($params['soft_credit'])) {
+ $softParams = $params['soft_credit'];
+ foreach ($softParams as $softParam) {
+ if (!empty($softIDs)) {
+ $key = key($softIDs);
+ $softParam['id'] = $softIDs[$key];
+ unset($softIDs[$key]);
+ }
+ $softParam['contribution_id'] = $contribution->id;
+ $softParam['currency'] = $contribution->currency;
+ //case during Contribution Import when we assign soft contribution amount as contribution's total_amount by default
+ if (empty($softParam['amount'])) {
+ $softParam['amount'] = $contribution->total_amount;
+ }
+ CRM_Contribute_BAO_ContributionSoft::add($softParam);
+ }
+
+ // delete any extra soft-credit while updating back-office contribution
+ foreach ((array) $softIDs as $softID) {
+ if (!in_array($softID, $params['soft_credit_ids'])) {
+ $deleteParams = array('id' => $softID);
+ CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
+ }
+ }
+ }
+ }
+
+ /**
+ * Function used to save pcp / soft credit entry.
+ *
+ * This is used by contribution and also event pcps
+ *
+ * @param array $params
+ * @param object $form
+ * Form object.
+ */
+ public static function formatSoftCreditParams(&$params, &$form) {
+ $pcp = $softParams = $softIDs = array();
+ if (!empty($params['pcp_made_through_id'])) {
+ $fields = array(
+ 'pcp_made_through_id',
+ 'pcp_display_in_roll',
+ 'pcp_roll_nickname',
+ 'pcp_personal_note',
+ );
+ foreach ($fields as $f) {
+ $pcp[$f] = CRM_Utils_Array::value($f, $params);
+ }
+ }
+
+ if (!empty($form->_honor_block_is_active) && !empty($params['soft_credit_type_id'])) {
+ $honorId = NULL;
+
+ $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name');
+ //check if there is any duplicate contact
+ $profileContactType = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
+ $dedupeParams = CRM_Dedupe_Finder::formatParams($params['honor'], $profileContactType);
+ $dedupeParams['check_permission'] = FALSE;
+ $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $profileContactType);
+ if (count($ids)) {
+ $honorId = CRM_Utils_Array::value(0, $ids);
+ }
+
+ $honorId = CRM_Contact_BAO_Contact::createProfileContact(
+ $params['honor'], CRM_Core_DAO::$_nullArray,
+ $honorId, NULL,
+ $params['honoree_profile_id']
+ );
+ $softParams[] = array(
+ 'contact_id' => $honorId,
+ 'soft_credit_type_id' => $params['soft_credit_type_id'],
+ );
+
+ if (CRM_Utils_Array::value('is_email_receipt', $form->_values)) {
+ $form->_values['honor'] = array(
+ 'soft_credit_type' => CRM_Utils_Array::value(
+ $params['soft_credit_type_id'],
+ CRM_Core_OptionGroup::values("soft_credit_type")
+ ),
+ 'honor_id' => $honorId,
+ 'honor_profile_id' => $params['honoree_profile_id'],
+ 'honor_profile_values' => $params['honor'],
+ );
+ }
+ }
+ elseif (!empty($params['soft_credit_contact_id'])) {
+ //build soft credit params
+ foreach ($params['soft_credit_contact_id'] as $key => $val) {
+ if ($val && $params['soft_credit_amount'][$key]) {
+ $softParams[$key]['contact_id'] = $val;
+ $softParams[$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]);
+ $softParams[$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
+ if (!empty($params['soft_credit_id'][$key])) {
+ $softIDs[] = $softParams[$key]['id'] = $params['soft_credit_id'][$key];
+ }
+ }
+ }
+ }
+
+ $params['pcp'] = !empty($pcp) ? $pcp : NULL;
+ $params['soft_credit'] = $softParams;
+ $params['soft_credit_ids'] = $softIDs;
+ }
+
/**
* Fetch object based on array of properties.
*
$this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date'], $this->_params['receive_date_time']);
}
- if (!empty($params['soft_credit_to'])) {
- $this->_params['soft_credit_to'] = $params['soft_credit_to'];
- $this->_params['pcp_made_through_id'] = $params['pcp_made_through_id'];
- }
-
$this->_params['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $params);
$this->_params['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $params);
$this->_params['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $params);
}
$this->assign('lineItem', !empty($lineItem) && !$isQuickConfig ? $lineItem : FALSE);
- if (!empty($submittedValues['pcp_made_through_id'])) {
- $pcp = array();
- $fields = array(
- 'pcp_made_through_id',
- 'pcp_display_in_roll',
- 'pcp_roll_nickname',
- 'pcp_personal_note',
- );
- foreach ($fields as $f) {
- $pcp[$f] = CRM_Utils_Array::value($f, $submittedValues);
- }
- }
-
$isEmpty = array_keys(array_flip($submittedValues['soft_credit_contact_id']));
if ($this->_id && count($isEmpty) == 1 && key($isEmpty) == NULL) {
//Delete existing soft credit records if soft credit list is empty on update
CRM_Contribute_BAO_ContributionSoft::del(array('contribution_id' => $this->_id, 'pcp_id' => 0));
}
- else {
- //build soft credit params
- foreach ($submittedValues['soft_credit_contact_id'] as $key => $val) {
- if ($val && $submittedValues['soft_credit_amount'][$key]) {
- $softParams[$key]['contact_id'] = $val;
- $softParams[$key]['amount'] = CRM_Utils_Rule::cleanMoney($submittedValues['soft_credit_amount'][$key]);
- $softParams[$key]['soft_credit_type_id'] = $submittedValues['soft_credit_type'][$key];
- if (!empty($submittedValues['soft_credit_id'][$key])) {
- $softIDs[] = $softParams[$key]['id'] = $submittedValues['soft_credit_id'][$key];
- }
- }
- }
- }
// set the contact, when contact is selected
if (!empty($submittedValues['contact_id'])) {
$this->_contactID = $submittedValues['contact_id'];
}
+
$formValues = $submittedValues;
// Credit Card Contribution.
$params['contact_id'] = $this->_contactID;
$params['currency'] = $this->getCurrency($submittedValues);
+ //format soft-credit/pcp param first
+ CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($submittedValues, $this);
+ $params = array_merge($params, $submittedValues);
+
$fields = array(
'financial_type_id',
'contribution_status_id',
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
- if (!empty($pcp)) {
- $params['pcp'] = $pcp;
- }
- $params['soft_credit'] = !empty($softParams) ? $softParams : array();
- $params['soft_credit_ids'] = !empty($softIDs) ? $softIDs : array();
-
// CRM-5740 if priceset is used, no need to cleanup money.
if ($priceSetId) {
$params['skipCleanMoney'] = 1;
$receiptDate = $now;
}
- // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
- if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
- // if its due to pcp
- if (!empty($params['pcp_made_through_id'])) {
- $contributionParams['soft_credit_to'] = CRM_Core_DAO::getFieldValue(
- 'CRM_PCP_DAO_PCP',
- $params['pcp_made_through_id'],
- 'contact_id'
- );
- // Pass these details onto with the contribution to make them
- // available at hook_post_process, CRM-8908
- // @todo - obsolete?
- $params['soft_credit_to'] = $contributionParams['soft_credit_to'];
- }
- else {
- $contributionParams['soft_credit_to'] = CRM_Utils_Array::value('soft_credit_to', $params);
- }
- }
-
if (isset($params['amount'])) {
$contributionParams = array_merge(self::getContributionParams(
$params, $financialType->id, $nonDeductibleAmount, TRUE,
$form->_contributionID = $contribution->id;
}
- //CRM-13981, processing honor contact into soft-credit contribution
- CRM_Contact_Form_ProfileContact::postProcess($form, $params);
+ // process soft credit / pcp params first
+ CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($params, $form);
- // process soft credit / pcp pages
- CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
+ //CRM-13981, processing honor contact into soft-credit contribution
+ CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
//handle pledge stuff.
if ($isPledge) {
}
}
- /**
- * Function used to save pcp / soft credit entry.
- *
- * This is used by contribution and also event pcps
- *
- * @param array $params
- * @param object $contribution
- * Contribution object.
- */
- public static function processPcpSoft(&$params, &$contribution) {
- // Add soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
- if (!empty($params['soft_credit_to'])) {
- $contributionSoftParams = array();
- foreach (array(
- 'pcp_display_in_roll',
- 'pcp_roll_nickname',
- 'pcp_personal_note',
- 'amount',
- ) as $val) {
- if (!empty($params[$val])) {
- $contributionSoftParams[$val] = $params[$val];
- }
- }
-
- $contributionSoftParams['contact_id'] = $params['soft_credit_to'];
- // add contribution id
- $contributionSoftParams['contribution_id'] = $contribution->id;
- // add pcp id
- $contributionSoftParams['pcp_id'] = $params['pcp_made_through_id'];
-
- $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name');
-
- $contributionSoft = CRM_Contribute_BAO_ContributionSoft::add($contributionSoftParams);
-
- //Send notification to owner for PCP
- if ($contributionSoft->id && $contributionSoft->pcp_id) {
- CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
- }
- }
- }
-
/**
* Function used to send notification mail to pcp owner.
*
$contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
}
- // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
- if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
-
- // if its due to pcp
- if (!empty($params['pcp_made_through_id'])) {
- $contribSoftContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
- $params['pcp_made_through_id'],
- 'contact_id'
- );
- }
- else {
- $contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
- }
-
- // Pass these details onto with the contribution to make them
- // available at hook_post_process, CRM-8908
- $contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
- }
$contribParams['payment_processor'] = CRM_Utils_Array::value('payment_processor', $params);
$contribParams['skipLineItem'] = 1;
// create contribution record
CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, CRM_Utils_Array::value('amount_priceset_level_radio', $params, NULL));
// process soft credit / pcp pages
- CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
+ if (!empty($params['pcp_made_through_id'])) {
+ CRM_Contribute_Form_Contribution_Confirm::formatSoftCreditParams($params, $form);
+ CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
+ }
$transaction->commit();