// Handle soft credit and / or link to personal campaign page
$softIDs = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id);
+
+ //Delete PCP against this contribution and create new on submitted PCP information
+ $pcpId = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id, TRUE);
+ if ($pcpId) {
+ $deleteParams = array('id' => $pcpId);
+ CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
+ }
if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
- if ($pcpId = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id, TRUE)) {
- $deleteParams = array('id' => $pcpId);
- CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
- }
$softParams = array();
$softParams['contribution_id'] = $contribution->id;
$softParams['pcp_id'] = $pcp['pcp_made_through_id'];
if ($isPCP) {
$query .= " AND pcp_id IS NOT NULL";
}
+ else {
+ $query .= " AND pcp_id IS NULL";
+ }
$params = array(1 => array($contributionID, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization',
);
- $contactType = $contactTypes[$contactTypeId];
+ $contactType = isset($contactTypes[$contactTypeId]) ? $contactTypes[$contactTypeId] : '';
// get importable fields for contact type
$contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
'used' => 'Unsupervised',
);
$fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
- $softCreditFields = array();
- if (is_array($fieldsArray)) {
- foreach ($fieldsArray as $value) {
- //skip if there is no dupe rule
- if ($value == 'none') {
- continue;
- }
- $softCreditFields[$value] = $contactFields[trim($value)]['title'];
- }
- }
$softCreditFields['contact_id'] = ts('Contact ID');
$softCreditFields['external_identifier'] = ts('External Identifier');
$sel2['soft_credit'] = $softCreditFields;
+ $sel3['soft_credit']['contact_id'] = $sel3['soft_credit']['external_identifier'] = CRM_Core_OptionGroup::values('soft_credit_type');
+ $sel4 = NULL;
// end of soft credit section
);
}
}
- $sel->setOptions(array($sel1, $sel2, (isset($sel3)) ? $sel3 : "", (isset($sel4)) ? $sel4 : ""));
+ $sel->setOptions(array($sel1, $sel2, $sel3,$sel4));
}
$js .= "</script>\n";
$this->assign('initHideBoxes', $js);
static function formRule($fields, $files, $self) {
$errors = array();
$fieldMessage = NULL;
-
+ $contactORContributionId = $self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE ? 'contribution_id' : 'contribution_contact_id';
if (!array_key_exists('savedMapping', $fields)) {
$importKeys = array();
foreach ($fields['mapper'] as $mapperPart) {
);
$params = array(
'used' => 'Unsupervised',
- 'contact_type' => $contactTypes[$contactTypeId],
+ 'contact_type' => isset($contactTypes[$contactTypeId]) ? $contactTypes[$contactTypeId] : '',
);
list($ruleFields, $threshold) = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($params);
$weightSum = 0;
if (array_key_exists($val, $ruleFields)) {
$weightSum += $ruleFields[$val];
}
+ if ($val == "soft_credit") {
+ $mapperKey = CRM_Utils_Array::key('soft_credit', $importKeys);
+ if (!empty($fields['mapper'][$mapperKey][1])) {
+ if (empty($errors['_qf_default'])) {
+ $errors['_qf_default'] = '';
+ }
+ $errors['_qf_default'] .= ts('Missing required fields: Soft Credit') . '<br />';
+ }
+ }
}
foreach ($ruleFields as $field => $weight) {
$fieldMessage .= ' ' . $field . '(weight ' . $weight . ')';
// FIXME: should use the schema titles, not redeclare them
$requiredFields = array(
- 'contribution_contact_id' => ts('Contact ID'),
+ $contactORContributionId == 'contribution_id' ? 'contribution_id' : 'contribution_contact_id' => $contactORContributionId == 'contribution_id' ? ts('Contribution ID') : ts('Contact ID'),
'total_amount' => ts('Total Amount'),
'financial_type' => ts('Financial Type')
);
foreach ($requiredFields as $field => $title) {
if (!in_array($field, $importKeys)) {
- if ($field == 'contribution_contact_id') {
+ if (empty($errors['_qf_default'])) {
+ $errors['_qf_default'] = '';
+ }
+ if ($field == $contactORContributionId) {
if (!($weightSum >= $threshold || in_array('external_identifier', $importKeys)) &&
$self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE
) {
}
}
else {
- if ($self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
- $errors['_qf_default'] .= ts('Missing required field: %1', array(
- 1 => $title
- )) . '<br />';
- }
+ $errors['_qf_default'] .= ts('Missing required field: %1', array(
+ 1 => $title
+ )) . '<br />';
}
}
}
$assignError = new CRM_Core_Page();
$assignError->assign('mappingDetailsError', $_flag);
}
+ CRM_Core_Session::setStatus($errors['_qf_default'], ts("Error"), "error");
return $errors;
}
$config = CRM_Core_Config::singleton();
$seperator = $config->fieldSeparator;
- $mapper = $mapperKeys = $mapperKeysMain = $mapperSoftCredit = $softCreditFields = $mapperPhoneType = array();
+ $mapper = $mapperKeys = $mapperKeysMain = $mapperSoftCredit = $softCreditFields = $mapperPhoneType = $mapperSoftCreditType = array();
$mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
+ $softCreditTypes = CRM_Core_OptionGroup::values('soft_credit_type');
+
for ($i = 0; $i < $this->_columnCount; $i++) {
$mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
$mapperKeysMain[$i] = $mapperKeys[$i][0];
$mapperSoftCredit[$i] = $mapperKeys[$i][1];
list($first, $second) = explode('_', $mapperSoftCredit[$i]);
$softCreditFields[$i] = ucwords($first . " " . $second);
+ $mapperSoftCreditType[$i] = array(
+ 'value' => isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : '',
+ 'label' => isset($softCreditTypes[$mapperKeys[$i][2]]) ? $softCreditTypes[$mapperKeys[$i][2]] : '',
+ );
}
else {
- $mapperSoftCredit[$i] = $softCreditFields[$i] = NULL;
- $softCreditFields[$i] = NULL;
+ $mapperSoftCredit[$i] = $softCreditFields[$i] = $mapperSoftCreditType[$i] = NULL;
}
}
$this->set('mapper', $mapper);
$this->set('softCreditFields', $softCreditFields);
+ $this->set('mapperSoftCreditType', $mapperSoftCreditType);
// store mapping Id to display it in the preview page
$this->set('loadMappingId', CRM_Utils_Array::value('mappingId', $params));
$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
//get the data from the session
- $dataValues = $this->get('dataValues');
- $mapper = $this->get('mapper');
- $softCreditFields = $this->get('softCreditFields');
- $invalidRowCount = $this->get('invalidRowCount');
- $conflictRowCount = $this->get('conflictRowCount');
- $mismatchCount = $this->get('unMatchCount');
+ $dataValues = $this->get('dataValues');
+ $mapper = $this->get('mapper');
+ $softCreditFields = $this->get('softCreditFields');
+ $mapperSoftCreditType = $this->get('mapperSoftCreditType');
+ $invalidRowCount = $this->get('invalidRowCount');
+ $conflictRowCount = $this->get('conflictRowCount');
+ $mismatchCount = $this->get('unMatchCount');
//get the mapping name displayed if the mappingId is set
$mappingId = $this->get('loadMappingId');
$properties = array(
'mapper', 'softCreditFields',
+ 'mapperSoftCreditType',
'dataValues', 'columnCount',
'totalRowCount', 'validRowCount',
'invalidRowCount', 'conflictRowCount',
$invalidRowCount = $this->get('invalidRowCount');
$conflictRowCount = $this->get('conflictRowCount');
$onDuplicate = $this->get('onDuplicate');
+ $mapperSoftCreditType = $this->get('mapperSoftCreditType');
$config = CRM_Core_Config::singleton();
$seperator = $config->fieldSeparator;
foreach ($mapper as $key => $value) {
$mapperKeys[$key] = $mapper[$key][0];
- if (isset($mapper[$key][0]) && $mapper[$key][0] == 'soft_credit') {
- $mapperSoftCredit[$key] = $mapper[$key][1];
+ if (isset($mapper[$key][0]) && $mapper[$key][0] == 'soft_credit' && isset($mapper[$key])) {
+ $mapperSoftCredit[$key] = isset($mapper[$key][1]) ? $mapper[$key][1] : '';
+ $mapperSoftCreditType[$key] = $mapperSoftCreditType[$key]['value'];
}
else {
- $mapperSoftCredit[$key] = NULL;
+ $mapperSoftCredit[$key] = $mapperSoftCreditType[$key] = NULL;
}
}
- $parser = new CRM_Contribute_Import_Parser_Contribution($mapperKeys, $mapperSoftCredit, $mapperPhoneType);
+ $parser = new CRM_Contribute_Import_Parser_Contribution($mapperKeys, $mapperSoftCredit, $mapperPhoneType, $mapperSoftCreditType);
$mapFields = $this->get('fields');
}
}
+ function setActiveFieldSoftCreditType($elements) {
+ for ($i = 0; $i < count($elements); $i++) {
+ $this->_activeFields[$i]->_softCreditType = $elements[$i];
+ }
+ }
/**
* function to format the field values for input to the api
*
if (!isset($params[$this->_activeFields[$i]->_name])) {
$params[$this->_activeFields[$i]->_name] = array();
}
- $params[$this->_activeFields[$i]->_name][$this->_activeFields[$i]->_softCreditField] = $this->_activeFields[$i]->_value;
+ $params[$this->_activeFields[$i]->_name][$i][$this->_activeFields[$i]->_softCreditField] = $this->_activeFields[$i]->_value;
+ if(isset($this->_activeFields[$i]->_softCreditType)){
+ $params[$this->_activeFields[$i]->_name][$i]['soft_credit_type_id'] = $this->_activeFields[$i]->_softCreditType;
+ }
}
if (!isset($params[$this->_activeFields[$i]->_name])) {
foreach ($data as $datum) {
foreach ($datum as $key => $value) {
- if (is_array($value[0])) {
+ if (isset($value[0]) && is_array($value)) {
foreach ($value[0] as $k1 => $v1) {
if ($k1 == 'location_type_id') {
continue;
/**
* class constructor
*/
- function __construct(&$mapperKeys, $mapperSoftCredit = NULL, $mapperPhoneType = NULL) {
+ function __construct(&$mapperKeys, $mapperSoftCredit = NULL, $mapperPhoneType = NULL, $mapperSoftCreditType = NULL) {
parent::__construct();
$this->_mapperKeys = &$mapperKeys;
$this->_mapperSoftCredit = &$mapperSoftCredit;
+ $this->_mapperSoftCreditType = &$mapperSoftCreditType;
}
/**
$this->setActiveFields($this->_mapperKeys);
$this->setActiveFieldSoftCredit($this->_mapperSoftCredit);
+ $this->setActiveFieldSoftCreditType($this->_mapperSoftCreditType);
// FIXME: we should do this in one place together with Form/MapField.php
$this->_contactIdIndex = -1;
$paramValues['contact_type'] = $this->_contactType;
}
elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE &&
- ($paramValues['contribution_id'] || $values['trxn_id'] || $paramValues['invoice_id'])
+ (!empty($paramValues['contribution_id']) || !empty($values['trxn_id']) || !empty($paramValues['invoice_id']))
) {
$paramValues['contact_type'] = $this->_contactType;
}
$paramValues['onDuplicate'] = $onDuplicate;
}
require_once 'CRM/Utils/DeprecatedUtils.php';
- $formatError = _civicrm_api3_deprecated_formatted_param($paramValues, $formatted, TRUE);
+ $formatError = _civicrm_api3_deprecated_formatted_param($paramValues, $formatted, TRUE, $onDuplicate);
if ($formatError) {
array_unshift($values, $formatError['error_message']);
else {
//fix for CRM-2219 - Update Contribution
// onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
- if (!empty($paramValues['invoice_id']) || !empty($paramValues['trxn_id']) || $paramValues['contribution_id']) {
+ if (!empty($paramValues['invoice_id']) || !empty($paramValues['trxn_id']) || !empty($paramValues['contribution_id'])) {
$dupeIds = array(
'id' => CRM_Utils_Array::value('contribution_id', $paramValues),
'trxn_id' => CRM_Utils_Array::value('trxn_id', $paramValues),
}
//need to check existing soft credit contribution, CRM-3968
- if (!empty($formatted['soft_credit_to'])) {
+ if (!empty($formatted['soft_credit'])) {
$dupeSoftCredit = array(
- 'contact_id' => $formatted['soft_credit_to'],
+ 'contact_id' => $formatted['soft_credit'],
'contribution_id' => $ids['contribution'],
);
- //FIX ME: Need to fix this logic
+ //Delete all existing soft Contribution from contribution_soft table for pcp_id is_null
$existingSoftCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dupeSoftCredit['contribution_id']);
- if (!empty($existingSoftCredit['soft_credit_id'])) {
- $formatted['softID'] = $existingSoftCredit['soft_credit_id'];
+ if(isset($existingSoftCredit['soft_credit']) && !empty($existingSoftCredit['soft_credit'])){
+ foreach($existingSoftCredit['soft_credit'] as $key => $existingSoftCreditValues){
+ if (!empty($existingSoftCreditValues['soft_credit_id'])) {
+ $deleteParams = array(
+ 'id' => $existingSoftCreditValues['soft_credit_id'],
+ 'pcp_id' => NULL,
+ );
+ CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
+ }
+ }
}
}
$this->_newContributions[] = $newContribution->id;
//return soft valid since we need to show how soft credits were added
- if (!empty($formatted['soft_credit_to'])) {
+ if (!empty($formatted['soft_credit'])) {
return CRM_Contribute_Import_Parser::SOFT_CREDIT;
}
$formatted['contribution_id'] = $newContribution['id'];
//return soft valid since we need to show how soft credits were added
- if (!empty($formatted['soft_credit_to'])) {
+ if (!empty($formatted['soft_credit'])) {
return CRM_Contribute_Import_Parser::SOFT_CREDIT;
}
'used' => 'Unsupervised',
);
$fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
-
+ $disp = NULL;
foreach ($fieldsArray as $value) {
if (array_key_exists(trim($value), $params)) {
$paramValue = $params[trim($value)];
$formatted['contribution_id'] = $newContribution['id'];
//return soft valid since we need to show how soft credits were added
- if (!empty($formatted['soft_credit_to'])) {
+ if (!empty($formatted['soft_credit'])) {
return CRM_Contribute_Import_Parser::SOFT_CREDIT;
}
* @return array|CRM_Error
* @access public
*/
-function _civicrm_api3_deprecated_formatted_param($params, &$values, $create = FALSE) {
+function _civicrm_api3_deprecated_formatted_param($params, &$values, $create = FALSE, $onDuplicate = Null) {
// copy all the contribution fields as is
$fields = CRM_Contribute_DAO_Contribution::fields();
}
break;
- case 'honor_type_id':
- require_once 'CRM/Core/OptionGroup.php';
- $values['honor_type_id'] = CRM_Core_OptionGroup::getValue('honor_type', $value);
- if (empty($values['honor_type_id'])) {
- return civicrm_api3_create_error("Honor Type is not valid: $value");
- }
- break;
-
case 'soft_credit':
//import contribution record according to select contact type
-
// validate contact id and external identifier.
- $contactId = CRM_Utils_Array::value('contact_id', $params['soft_credit']);
- $externalId = CRM_Utils_Array::value('external_identifier', $params['soft_credit']);
- if ($contactId || $externalId) {
- require_once 'CRM/Contact/DAO/Contact.php';
- $contact = new CRM_Contact_DAO_Contact();
- $contact->id = $contactId;
- $contact->external_identifier = $externalId;
-
- $errorMsg = NULL;
- if (!$contact->find(TRUE)) {
- $errorMsg = ts("No match found for specified Soft Credit contact data. Row was skipped.");
- }
-
- if ($errorMsg) {
- return civicrm_api3_create_error($errorMsg, 'soft_credit');
- }
-
- // finally get soft credit contact id.
- $values['soft_credit_to'] = $contact->id;
+ $value[$key] = '';
+ if (!isset($params['contribution_id']) && empty($params['contribution_id']) && $onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
+ $errorMsg = ts("Empty Contribution Id. Row was skipped.");
+ return civicrm_api3_create_error($errorMsg, $value[$key]);
}
- else {
- // get the contact id from duplicate contact rule, if more than one contact is returned
- // we should return error, since current interface allows only one-one mapping
-
- $softParams = $params['soft_credit'];
- $softParams['contact_type'] = $params['contact_type'];
-
- $error = _civicrm_api3_deprecated_duplicate_formatted_contact($softParams);
+ elseif (!isset($params['contribution_contact_id']) && empty($params['contribution_contact_id']) && $onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
+ $errorMsg = ts("Empty Contact Id. Row was skipped.");
+ return civicrm_api3_create_error($errorMsg, $value[$key]);
+ }
+ if (isset($params[$key]) && is_array($params[$key])) {
+ foreach ($params[$key] as $softKey => $softParam) {
+ $contactId = CRM_Utils_Array::value('contact_id', $softParam);
+ $externalId = CRM_Utils_Array::value('external_identifier', $softParam);
+ if (isset($softParam['contact_id']) && !empty($softParam['contact_id'])) {
+ $softCreditContactIds = implode(', ', array_map(function ($entry) {
+ return $entry['contact_id'];
+ }, $params[$key]));
+ }
+ else {
+ $softCreditContactIds='';
+ }
+ if ($contactId || $externalId) {
+ require_once 'CRM/Contact/DAO/Contact.php';
+ $contact = new CRM_Contact_DAO_Contact();
+ $contact->id = $contactId;
+ $contact->external_identifier = $externalId;
+
+ $errorMsg = NULL;
+ if (!$contact->find(TRUE)) {
+ $errorMsg = (isset($softCreditContactIds) && $softCreditContactIds) ? ts("Invalid ContactId ($softCreditContactIds) specified for Soft Credit contact data. Row was skipped.") : ts("Empty ContactId specified for Soft Credit contact data. Row was skipped.");
+ }
- if (isset($error['error_message']['params'][0])) {
- $matchedIDs = explode(',', $error['error_message']['params'][0]);
+ if ($errorMsg) {
+ return civicrm_api3_create_error($errorMsg, $value[$key]);
+ }
- // check if only one contact is found
- if (count($matchedIDs) > 1) {
- return civicrm_api3_create_error($error['error_message']['message'], 'soft_credit');
+ // finally get soft credit contact id.
+ $values[$key][$softKey] = $softParam;
+ $values[$key][$softKey]['contact_id'] = $contact->id;
}
else {
- $values['soft_credit_to'] = $matchedIDs[0];
+ // get the contact id from duplicate contact rule, if more than one contact is returned
+ // we should return error, since current interface allows only one-one mapping
+ $softParams = $params['soft_credit'];
+ $softParams['contact_type'] = $params['contact_type'];
+
+ $error = _civicrm_api3_deprecated_duplicate_formatted_contact($softParams);
+
+ if (isset($error['error_message']['params'][0])) {
+ $matchedIDs = explode(',', $error['error_message']['params'][0]);
+
+ // check if only one contact is found
+ if (count($matchedIDs) > 1) {
+ return civicrm_api3_create_error($error['error_message']['message'], $value[$key]);
+ }
+ else {
+ $values['soft_credit'] = $matchedIDs[0];
+ }
+ }
+ else {
+ $errorMsg = (isset($softCreditContactIds) && $softCreditContactIds) ? ts("Invalid ContactId ($softCreditContactIds) specified for Soft Credit contact data. Row was skipped.") : ts("Empty ContactId specified for Soft Credit contact data. Row was skipped.");
+ return civicrm_api3_create_error($errorMsg, $value[$key]);
+ }
}
}
- else {
- return civicrm_api3_create_error('No match found for specified Soft Credit contact data. Row was skipped.', 'soft_credit');
- }
}
break;
})
// This is just a cheap trick to store the name in case of a formrule error
.on('change', function() {
- $('[name=pcp_made_through]', $form).val($(this).select2('data').text || '');
+ //$('[name=pcp_made_through]', $form).val($(this).select2('data').text || '');
});
$('.crm-soft-credit-block tr span').each(function () {
<td class="form-item even-row{if $wizard.currentStepName == 'Preview'} labels{/if}">
{if $wizard.currentStepName == 'Preview'}
{if $softCreditFields && $softCreditFields[$i] != ''}
- {$mapper[$i]} - {$softCreditFields[$i]}
+ {$mapper[$i]} - {$softCreditFields[$i]} {if $mapperSoftCreditType[$i]}({$mapperSoftCreditType[$i].label}){/if}
{else}
{$mapper[$i]}
{/if}