From 133e2c99199891058cbe252dcd4d8e85b22554eb Mon Sep 17 00:00:00 2001 From: monishdeb Date: Wed, 15 Jan 2014 18:30:34 +0530 Subject: [PATCH] CRM-13981 fix - Migrate "In Honor of" to Soft Credits http://issues.civicrm.org/jira/browse/CRM-13981 Conflicts: CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl templates/CRM/Contribute/Form/SoftCredit.js ---------------------------------------- * CRM-13981: Migrate "In Honor of" to Soft Credits http://issues.civicrm.org/jira/browse/CRM-13981 --- CRM/Contact/Form/ProfileContact.php | 150 ++++++++++++++++++ CRM/Contribute/BAO/Contribution.php | 54 +------ CRM/Contribute/BAO/Query.php | 69 -------- CRM/Contribute/Form/AdditionalInfo.php | 13 -- CRM/Contribute/Form/Contribution.php | 64 +------- CRM/Contribute/Form/Contribution/Confirm.php | 119 +++++--------- CRM/Contribute/Form/Contribution/Main.php | 104 ++++++------ CRM/Contribute/Form/Contribution/ThankYou.php | 67 ++++---- CRM/Contribute/Form/ContributionBase.php | 17 +- CRM/Contribute/Form/ContributionPage.php | 8 +- .../Form/ContributionPage/Settings.php | 114 ++++++++++--- CRM/Contribute/Form/SoftCredit.php | 40 ++++- CRM/Core/BAO/UFGroup.php | 21 ++- CRM/Member/BAO/Membership.php | 1 - CRM/Member/Form/Membership.php | 50 ++++-- CRM/Member/Form/MembershipRenewal.php | 14 +- CRM/Pledge/Form/Pledge.php | 57 ------- CRM/Report/Form/Contribute/Detail.php | 91 ----------- CRM/Report/Form/Member/ContributionDetail.php | 84 ---------- CRM/UF/Page/ProfileEditor.php | 8 + .../Incremental/sql/4.5.alpha1.mysql.tpl | 34 ++++ sql/GenerateData.php | 8 +- .../Contribute/Form/Contribution/Confirm.tpl | 17 +- .../Contribute/Form/Contribution/Honor.tpl | 37 ----- .../CRM/Contribute/Form/Contribution/Main.tpl | 47 +----- .../Contribute/Form/Contribution/ThankYou.tpl | 14 +- .../Form/ContributionPage/Settings.tpl | 60 ++++++- templates/CRM/Contribute/Form/SoftCredit.js | 6 +- templates/CRM/Contribute/Form/SoftCredit.tpl | 19 ++- .../CRM/Contribute/Page/ContributionHonor.tpl | 57 ------- templates/CRM/Contribute/Page/Tab.tpl | 7 - templates/CRM/Member/Form/Membership.tpl | 8 +- .../CRM/Member/Form/MembershipRenewal.tpl | 4 +- templates/CRM/UF/Form/Block.tpl | 8 +- xml/schema/Contribute/Contribution.xml | 31 ---- xml/schema/Contribute/ContributionPage.xml | 22 --- xml/schema/Core/UFJoin.xml | 7 + xml/schema/Pledge/Pledge.xml | 31 ---- xml/templates/civicrm_data.tpl | 23 +++ xml/templates/civicrm_sample.tpl | 8 +- 40 files changed, 682 insertions(+), 911 deletions(-) create mode 100644 CRM/Contact/Form/ProfileContact.php delete mode 100644 templates/CRM/Contribute/Form/Contribution/Honor.tpl delete mode 100644 templates/CRM/Contribute/Page/ContributionHonor.tpl diff --git a/CRM/Contact/Form/ProfileContact.php b/CRM/Contact/Form/ProfileContact.php new file mode 100644 index 0000000000..746c0564cc --- /dev/null +++ b/CRM/Contact/Form/ProfileContact.php @@ -0,0 +1,150 @@ +get('userID'); + + $ufJoinParams = array( + 'module' => 'soft_credit', + 'entity_table' => 'civicrm_contribution_page', + 'entity_id' => $form->_id, + ); + $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); + $form->_honoreeProfileId = $profileId[0]; + + if (!$form->_honoreeProfileId || + !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_honoreeProfileId, 'is_active') + ) { + CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.')); + } + + $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_honoreeProfileId); + $requiredProfileFields = array( + 'Individual' => array('first_name', 'last_name'), + 'Organization' => array('organization_name', 'email'), + 'Household' => array('household_name', 'email') + ); + $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_honoreeProfileId, $requiredProfileFields[$profileContactType]); + if (!$validProfile) { + CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.')); + } + } + + /** + * Function to build form for honoree contact / on behalf of organization. + * + * @param $form object invoking Object + * @param $contactType string contact type + * @param $title string fieldset title + * + * @static + */ + static function buildQuickForm(&$form) { + $ufGroup = new CRM_Core_DAO_UFGroup(); + $ufGroup->id = $form->_honoreeProfileId; + if (!$ufGroup->find(TRUE)) { + CRM_Core_Error::fatal(ts('Chosen honoree profile is for this contribution is disabled')); + } + + $prefix = 'honor'; + $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($form->_honoreeProfileId, FALSE, NULL, + NULL, NULL, + FALSE, NULL, + TRUE, NULL, + CRM_Core_Permission::CREATE + ); + $form->addElement('hidden', 'honoree_profile_id', $form->_honoreeProfileId); + $form->assign('honoreeProfileFields', $honoreeProfileFields); + + // add the form elements + foreach ($honoreeProfileFields as $name => $field) { + // If soft credit type is not chosen then make omit requiredness from honoree profile fields + if (count($form->_submitValues) && + !CRM_Utils_Array::value('soft_credit_type_id', $form->_submitValues) && + CRM_Utils_Array::value('is_required', $field) + ) { + $field['is_required'] = FALSE; + } + CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, $prefix); + } + } + + static function postProcess($form) { + $params = $form->_params; + $values = $form->_values; + if ($form->get('honor_block_is_active') && CRM_Utils_Array::value('soft_credit_type_id', $params)) { + $honorId = null; + + //check if there is any duplicate contact + $profileContactType = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); + CRM_Core_Error::debug( '$profileContactType', $profileContactType ); + $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); + } + } +} + diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index c6e1efea20..2fcd78da33 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -342,10 +342,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { foreach ($softParams as $softParam) { $softParam['contribution_id'] = $contribution->id; $softParam['currency'] = $contribution->currency; - $softParam['pcp_id'] = 'null'; - $softParam['pcp_display_in_roll'] = 'null'; - $softParam['pcp_roll_nickname'] = 'null'; - $softParam['pcp_personal_note'] = 'NULL'; CRM_Contribute_BAO_ContributionSoft::add($softParam); } } @@ -909,44 +905,6 @@ GROUP BY p.id } } - /** - * Function to create is honor of - * - * @param array $params associated array of fields (by reference) - * @param int $honorId honor Id - * @param array $honorParams any params that should be send to the create function - * - * @return contact id - */ - static function createHonorContact(&$params, $honorId = NULL, $honorParams = array()) { - $honorParams = array_merge( - array( - 'first_name' => $params['honor_first_name'], - 'last_name' => $params['honor_last_name'], - 'prefix_id' => $params['honor_prefix_id'], - 'email-Primary' => $params['honor_email'], - ), - $honorParams - ); - if (!$honorId) { - $honorParams['email'] = $params['honor_email']; - - $dedupeParams = CRM_Dedupe_Finder::formatParams($honorParams, 'Individual'); - $dedupeParams['check_permission'] = FALSE; - $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); - - // if we find more than one contact, use the first one - $honorId = CRM_Utils_Array::value(0, $ids); - } - - $contactID = CRM_Contact_BAO_Contact::createProfileContact( - $honorParams, - CRM_Core_DAO::$_nullArray, - $honorId - ); - return $contactID; - } - /** * Function to get list of contribution In Honor of contact Ids * @@ -1697,7 +1655,7 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ return $componentDetails; } - static function contributionCount($contactId, $includeSoftCredit = TRUE, $includeHonoree = TRUE) { + static function contributionCount($contactId, $includeSoftCredit = TRUE) { if (!$contactId) { return 0; } @@ -1707,11 +1665,6 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ FROM civicrm_contribution contribution WHERE contribution.is_test = 0 AND contribution.contact_id = {$contactId} "; - $contactHonoreeContributionsSQL = " - SELECT contribution.id - FROM civicrm_contribution contribution - WHERE contribution.is_test = 0 AND contribution.honor_contact_id = {$contactId} "; - $contactSoftCreditContributionsSQL = " SELECT contribution.id FROM civicrm_contribution contribution INNER JOIN civicrm_contribution_soft softContribution @@ -1725,11 +1678,6 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ $query .= $contactSoftCreditContributionsSQL; } - if ($includeHonoree) { - $query .= " UNION "; - $query .= $contactHonoreeContributionsSQL; - } - $query .= ") x"; return CRM_Core_DAO::singleValueQuery($query); diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 7d9255329f..1d0e57d4e6 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -127,38 +127,6 @@ class CRM_Contribute_BAO_Query { $query->_tables['contribution_payment_instrument'] = 1; } - // get honor contact name - if (CRM_Utils_Array::value('honor_contact_name', $query->_returnProperties)) { - $query->_select['contribution_honor_contact_name'] = "civicrm_contact_c.display_name as contribution_honor_contact_name"; - $query->_element['contribution_honor_contact_name'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['contribution_honor_contact_name'] = 1; - } - - // get honor type label - if (CRM_Utils_Array::value('honor_type_label', $query->_returnProperties)) { - $query->_select['contribution_honor_type_label'] = "honor_type.label as contribution_honor_type_label"; - $query->_element['contribution_honor_type_label'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['contribution_honor_type_label'] = 1; - } - - // get honor contact email - if (CRM_Utils_Array::value('honor_contact_email', $query->_returnProperties)) { - $query->_select['contribution_honor_contact_email'] = "honor_email.email as contribution_honor_contact_email"; - $query->_element['contribution_honor_contact_email'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['contribution_honor_contact_email'] = 1; - } - - // get honor contact id - if (CRM_Utils_Array::value('honor_contact_id', $query->_returnProperties)) { - $query->_select['contribution_honor_contact_id'] = "civicrm_contribution.honor_contact_id as contribution_honor_contact_id"; - $query->_element['contribution_honor_contact_id'] = 1; - $query->_tables['civicrm_contribution'] = 1; - } - - if (CRM_Utils_Array::value('check_number', $query->_returnProperties)) { $query->_select['contribution_check_number'] = "civicrm_contribution.check_number as contribution_check_number"; $query->_element['contribution_check_number'] = 1; @@ -373,22 +341,6 @@ class CRM_Contribute_BAO_Query { $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; return; - case 'contribution_in_honor_of': - $name = trim($value); - $newName = str_replace(',', " ", $name); - $pieces = explode(' ', $newName); - foreach ($pieces as $piece) { - $value = $strtolower(CRM_Core_DAO::escapeString(trim($piece))); - $value = "'%$value%'"; - $sub[] = " ( contact_b.sort_name LIKE $value )"; - } - - $query->_where[$grouping][] = ' ( ' . implode(' OR ', $sub) . ' ) '; - $query->_qill[$grouping][] = ts('Honor name like - \'%1\'', array(1 => $name)); - $query->_tables['civicrm_contact_b'] = $query->_whereTables['civicrm_contact_b'] = 1; - $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; - return; - case 'contribution_status': case 'contribution_status_id': if (is_array($value)) { @@ -665,10 +617,6 @@ class CRM_Contribute_BAO_Query { AND option_group_payment_instrument.id = payment_instrument.option_group_id ) "; break; - case 'civicrm_contact_b': - $from .= " $side JOIN civicrm_contact contact_b ON (civicrm_contribution.honor_contact_id = contact_b.id )"; - break; - case 'contribution_status': $from = " $side JOIN civicrm_option_group option_group_contribution_status ON (option_group_contribution_status.name = 'contribution_status')"; $from .= " $side JOIN civicrm_option_value contribution_status ON (civicrm_contribution.contribution_status_id = contribution_status.value @@ -680,20 +628,6 @@ class CRM_Contribute_BAO_Query { civicrm_contribution.id = civicrm_note.entity_id )"; break; - case 'contribution_honor_contact_name': - $from .= " $side JOIN civicrm_contact civicrm_contact_c ON (civicrm_contribution.honor_contact_id = civicrm_contact_c.id )"; - break; - - case 'contribution_honor_contact_email': - $from .= " $side JOIN civicrm_email as honor_email ON (civicrm_contribution.honor_contact_id = honor_email.contact_id AND honor_email.is_primary = 1 )"; - break; - - case 'contribution_honor_type_label': - $from = " $side JOIN civicrm_option_group option_group_honor_type ON ( option_group_honor_type.name = 'honor_type')"; - $from .= " $side JOIN civicrm_option_value honor_type ON (civicrm_contribution.honor_type_id = honor_type.value - AND option_group_honor_type.id = honor_type.option_group_id ) "; - break; - case 'contribution_membership': $from = " $side JOIN civicrm_membership_payment ON civicrm_membership_payment.contribution_id = civicrm_contribution.id"; $from .= " $side JOIN civicrm_membership ON civicrm_membership_payment.membership_id = civicrm_membership.id "; @@ -866,9 +800,6 @@ class CRM_Contribute_BAO_Query { $form->addYesNo('contribution_thankyou_date_is_not_null', ts('Thank-you sent?')); $form->addYesNo('contribution_receipt_date_is_not_null', ts('Receipt sent?')); - // Add fields for honor search - $form->addElement('text', 'contribution_in_honor_of', ts("In Honor Of")); - $form->addYesNo('contribution_pay_later', ts('Contribution is Pay Later?')); $form->addYesNo('contribution_recurring', ts('Contribution is Recurring?')); diff --git a/CRM/Contribute/Form/AdditionalInfo.php b/CRM/Contribute/Form/AdditionalInfo.php index 3d92a50b50..ead4c9c4f9 100644 --- a/CRM/Contribute/Form/AdditionalInfo.php +++ b/CRM/Contribute/Form/AdditionalInfo.php @@ -311,19 +311,6 @@ class CRM_Contribute_Form_AdditionalInfo { $params['receipt_date'] = $formatted['receipt_date'] = date('YmdHis'); } - if (CRM_Utils_Array::value('honor_type_id', $params)) { - if ($form->_honorID) { - $honorId = CRM_Contribute_BAO_Contribution::createHonorContact($params, $form->_honorID); - } - else { - $honorId = CRM_Contribute_BAO_Contribution::createHonorContact($params); - } - $formatted["honor_contact_id"] = $honorId; - } - else { - $formatted["honor_contact_id"] = 'null'; - } - //special case to handle if all checkboxes are unchecked $customFields = CRM_Core_BAO_CustomField::getFields('Contribution', FALSE, diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 401e51e2e3..007994119e 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -104,14 +104,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP */ public $_options; - /** - * stores the honor id - * - * @var int - * @public - */ - public $_honorID = NULL; - /** * Store the contribution Type ID * @@ -289,8 +281,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP //set defaults for pledge payment. if ($this->_ppID) { $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']); - $defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues); - $defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues); $defaults['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_pledgeValues); $defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues); $defaults['option_type'] = 1; @@ -349,7 +339,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP if ($this->_contributionType) { $defaults['financial_type_id'] = $this->_contributionType; } - + if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) { $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); } @@ -358,23 +348,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->assign('is_test', TRUE); } - if (isset($defaults['honor_contact_id'])) { - $honorDefault = $ids = array(); - $this->_honorID = $defaults['honor_contact_id']; - $honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id'); - $idParams = array( - 'id' => $defaults['honor_contact_id'], - 'contact_id' => $defaults['honor_contact_id'], - ); - CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids); - - $defaults['honor_prefix_id'] = CRM_Utils_Array::value('prefix_id', $honorDefault); - $defaults['honor_first_name'] = CRM_Utils_Array::value('first_name', $honorDefault); - $defaults['honor_last_name'] = CRM_Utils_Array::value('last_name', $honorDefault); - $defaults['honor_email'] = CRM_Utils_Array::value('email', $honorDefault['email'][1]); - $defaults['honor_type'] = $honorType[$defaults['honor_type_id']]; - } - $this->assign('showOption', TRUE); // for Premium section if ($this->_premiumID) { @@ -493,25 +466,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } - $honorFields = array( - 'honor_type_id', - 'honor_prefix_id', - 'honor_first_name', - 'honor_lastname', - 'honor_email', - ); - foreach ($honorFields as $key) { - if (!empty($defaults[$key])) { - $defaults['hidden_Honoree'] = 1; - break; - } - } - - //check for honoree pane. - if ($this->_ppID && CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues)) { - $defaults['hidden_Honoree'] = 1; - } - if ($this->_productDAO) { if ($this->_productDAO->product_id) { $defaults['hidden_Premium'] = 1; @@ -526,7 +480,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $paneNames = array( ts('Additional Details') => 'AdditionalDetail', - ts('Honoree Information') => 'Honoree' ); //Add Premium pane only if Premium is exists. @@ -895,17 +848,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $errors['contact[1]'] = ts('Please select a contact or create new contact'); } - if (isset($fields['honor_type_id'])) { - if (!((CRM_Utils_Array::value('honor_first_name', $fields) && - CRM_Utils_Array::value('honor_last_name', $fields) - ) || - CRM_Utils_Array::value('honor_email', $fields) - ) - ) { - $errors['honor_first_name'] = ts('Honor First Name and Last Name OR an email should be set.'); - } - } - //check for Credit Card Contribution. if ($self->_mode) { if (empty($fields['payment_processor_id'])) { @@ -938,7 +880,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id'])) { $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType; } - + // $trxn_id must be unique CRM-13919 if (!empty($fields['trxn_id'])) { $queryParams = array(1 => array($fields['trxn_id'], 'String')); @@ -950,7 +892,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $tCnt = CRM_Core_DAO::singleValueQuery($query, $queryParams); if ($tCnt) { $errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id'])); - } + } } $errors = array_merge($errors, $softErrors); diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 2f7aeea141..974ee3ff0f 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -376,21 +376,39 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $params = $this->_params; $honor_block_is_active = $this->get('honor_block_is_active'); // make sure we have values for it - if ($honor_block_is_active && - ((!empty($params['honor_first_name']) && !empty($params['honor_last_name'])) || - (!empty($params['honor_email'])) - ) - ) { + if ($honor_block_is_active && CRM_Utils_Array::value('soft_credit_type_id', $params)) { + $honorName = null; + $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); + $this->assign('honor_block_is_active', $honor_block_is_active); - $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values)); + $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); + $profileContactType = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); + switch ($profileContactType) { + case 'Individual': + if (array_key_exists('prefix_id', $params['honor'])) { + $honorName = CRM_Utils_Array::value(CRM_Utils_Array::value('prefix_id',$params['honor']), + CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id') + ); + } + $honorName .= ' ' . $params['honor']['first_name'] . ' ' . $params['honor']['last_name']; + if (array_key_exists('suffix_id', $params['honor'])) { + $honorName .= ' ' . CRM_Utils_Array::value(CRM_Utils_Array::value('suffix_id',$params['honor']), + CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id') + ); + } + break; + case 'Organization': + $honorName = $params['honor']['organization_name']; + break; + case 'Household': + $honorName = $params['honor']['household_name']; + break; + } + $this->assign('honorName', $honorName); - $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); - $honor = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id'); - $this->assign('honor_type', CRM_Utils_Array::value($params['honor_type_id'], $honor)); - $this->assign('honor_prefix', CRM_Utils_Array::value($params['honor_prefix_id'], $prefix)); - $this->assign('honor_first_name', $params['honor_first_name']); - $this->assign('honor_last_name', $params['honor_last_name']); - $this->assign('honor_email', $params['honor_email']); + $fieldTypes = array('Contact'); + $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); + $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); } $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); $amount_block_is_active = $this->get('amount_block_is_active'); @@ -444,7 +462,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $fieldTypes = array_merge($fieldTypes, array('Contribution')); } - $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes); + $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); @@ -507,12 +525,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $defaults = array(); $fields = array(); foreach ($this->_fields as $name => $dontCare) { - if ($name == 'onbehalf') { - foreach ($dontCare as $key => $value) { - $fields['onbehalf'][$key] = 1; - } - } - else { + if ($name != 'onbehalf' || $name != 'honor') { $fields[$name] = 1; } } @@ -520,17 +533,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $contact = $this->_params; foreach ($fields as $name => $dontCare) { - if ($name == 'onbehalf') { - foreach ($dontCare as $key => $value) { - if (isset($contact['onbehalf'][$key])) { - $defaults[$key] = $contact['onbehalf'][$key]; - } - if (isset($contact['onbehalf']["{$key}_id"])) { - $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"]; - } - } - } - elseif (isset($contact[$name])) { + if (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; @@ -971,6 +974,9 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $fieldTypes ); } + + //processing honor contact into soft-credit contribution + CRM_Contact_Form_ProfileContact::postProcess($this); } /** @@ -1124,11 +1130,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr ) { $transaction = new CRM_Core_Transaction(); $className = get_class($form); - $honorCId = $recurringContributionID = NULL; - - if ($online && $form->get('honor_block_is_active')) { - $honorCId = $form->createHonorContact(); - } + $recurringContributionID = NULL; // add these values for the recurringContrib function ,CRM-10188 $params['financial_type_id'] = $contributionType->id; @@ -1143,10 +1145,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } $recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $contributionType, $online); - if (!$online && isset($params['honor_contact_id'])) { - $honorCId = $params['honor_contact_id']; - } - $config = CRM_Core_Config::singleton(); // CRM-11885 // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it. @@ -1264,11 +1262,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr ); } - if (isset($honorCId)) { - $contribParams['honor_contact_id'] = $honorCId; - $contribParams['honor_type_id'] = $params['honor_type_id']; - } - if ($recurringContributionID) { $contribParams['contribution_recur_id'] = $recurringContributionID; } @@ -1569,42 +1562,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr return $recurring->id; } - /** - * Create the Honor contact - * - * @return void - * @access public - */ - function createHonorContact() { - $params = $this->controller->exportValues('Main'); - - // email is enough to create a contact - if (! CRM_Utils_Array::value('honor_email', $params) && - // or we need first name AND last name - (! CRM_Utils_Array::value('honor_first_name', $params) - || ! CRM_Utils_Array::value('honor_last_name', $params))) { - //don't create contact - possibly the form was left blank - return null; - } - - //assign to template for email receipt - $honor_block_is_active = $this->get('honor_block_is_active'); - - $this->assign('honor_block_is_active', $honor_block_is_active); - $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values)); - - $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); - $honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id'); - $this->assign('honor_type', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $params), $honorType)); - $this->assign('honor_prefix', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_prefix_id', $params), $prefix)); - $this->assign('honor_first_name', CRM_Utils_Array::value('honor_first_name', $params)); - $this->assign('honor_last_name', CRM_Utils_Array::value('honor_last_name', $params)); - $this->assign('honor_email', CRM_Utils_Array::value('honor_email', $params)); - - //create honoree contact - return CRM_Contribute_BAO_Contribution::createHonorContact($params); - } - /** * Function to add on behalf of organization and it's location * diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 88191c7406..64b90320fc 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -114,6 +114,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } $this->assign('onBehalfRequired', $this->_onBehalfRequired); + if (CRM_Utils_Array::value('honor_block_is_active', $this->_values)) { + CRM_Contact_Form_ProfileContact::preprocess($this); + } + if (!empty($this->_pcpInfo['id']) && !empty($this->_pcpInfo['intro_text'])) { $this->assign('intro_text', $this->_pcpInfo['intro_text']); } @@ -231,23 +235,47 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu //build set default for pledge overdue payment. if (CRM_Utils_Array::value('pledge_id', $this->_values)) { - //get all payment statuses. - $statuses = array(); - $returnProperties = array('status_id'); - CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $this->_values['pledge_id'], - $statuses, $returnProperties - ); + //get all pledge payment records of current pledge id. + $pledgePayments = array(); + + //used to record completed pledge payment ids used later for honor default + $completedContributionIds = array(); + + $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($this->_values['pledge_id']); - $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $duePayment = FALSE; - foreach ($statuses as $payId => $value) { - if ($paymentStatusTypes[$value['status_id']] == 'Overdue') { + foreach ($pledgePayments as $payId => $value) { + if ($value['status'] == 'Overdue') { $this->_defaults['pledge_amount'][$payId] = 1; } - elseif (!$duePayment && $paymentStatusTypes[$value['status_id']] == 'Pending') { + elseif (!$duePayment && $value['status'] == 'Pending') { $this->_defaults['pledge_amount'][$payId] = 1; $duePayment = TRUE; } + elseif ($value['status'] == 'Completed' && $value['contribution_id']) { + $completedContributionIds[] = $value['contribution_id']; + } + } + + if (CRM_Utils_Array::value('honor_block_is_active', $this->_values) && count($completedContributionIds)) { + $softCredit = array(); + foreach ($completedContributionIds as $id) { + $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id); + } + if (isset($softCredit['soft_credit'])) { + $this->_defaults['soft_credit_type_id'] = $softCredit['soft_credit'][1]['soft_credit_type']; + + //since honoree profile fieldname of fields are prefixed with 'honor' + //we need to reformat the fieldname to append prefix during setting default values + CRM_Core_BAO_UFGroup::setProfileDefaults( + $softCredit['soft_credit'][1]['contact_id'], + CRM_Core_BAO_UFGroup::getFields($this->_honoreeProfileId), + $defaults + ); + foreach ($defaults as $fieldName => $value) { + $this->_defaults['honor[' . $fieldName . ']'] = $value; + } + } } } elseif (CRM_Utils_Array::value('pledge_block_id', $this->_values)) { @@ -460,8 +488,15 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE); } + //add honor block if ($this->_values['honor_block_is_active']) { - $this->buildHonorBlock(); + $this->assign('honor_block_is_active', TRUE); + $this->set('honor_block_is_active', TRUE); + + //build soft-credit section + CRM_Contribute_Form_SoftCredit::buildQuickForm($this); + //build honoree profile section + CRM_Contact_Form_ProfileContact::buildQuickForm($this); } @@ -571,42 +606,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this); } - /** - * Function to add the honor block - * - * @return void - * @access public - */ - function buildHonorBlock() { - $this->assign('honor_block_is_active', TRUE); - $this->set('honor_block_is_active', TRUE); - - $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values)); - $this->assign('honor_block_text', CRM_Utils_Array::value('honor_block_text', $this->_values)); - - $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); - $extraOption = array('onclick' => "enableHonorType();"); - // radio button for Honor Type - $honorOptions = array(); - $honor = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id'); - foreach ($honor as $key => $var) { - $honorTypes[$key] = $this->createElement('radio', NULL, NULL, $var, $key, $extraOption); - } - $this->addGroup($honorTypes, 'honor_type_id', NULL); - - // prefix - $this->addElement('select', 'honor_prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id')); - // first_name - $this->addElement('text', 'honor_first_name', ts('First Name'), $attributes['first_name']); - - //last_name - $this->addElement('text', 'honor_last_name', ts('Last Name'), $attributes['last_name']); - - //email - $this->addElement('text', 'honor_email', ts('Email Address'), array('class' => 'email')); - $this->addRule('honor_email', ts('Honoree Email is not valid.'), 'email'); - } - /** * build elements to enable pay on behalf of an organization. * @@ -898,17 +897,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } } - if ($self->_values['honor_block_is_active'] && CRM_Utils_Array::value('honor_type_id', $fields)) { - // make sure there is a first name and last name if email is not there - if (!CRM_Utils_Array::value('honor_email', $fields)) { - if (!CRM_Utils_Array::value('honor_first_name', $fields) || - !CRM_Utils_Array::value('honor_last_name', $fields) - ) { - $errors['honor_last_name'] = ts('In Honor Of - First Name and Last Name, OR an Email Address is required.'); - } - } - } - if ( CRM_Utils_Array::value( 'is_recur', $fields ) ) { if ($fields['frequency_interval'] <= 0) { $errors['frequency_interval'] = ts('Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months).'); diff --git a/CRM/Contribute/Form/Contribution/ThankYou.php b/CRM/Contribute/Form/Contribution/ThankYou.php index c1fbad5fba..5591e3e0c4 100644 --- a/CRM/Contribute/Form/Contribution/ThankYou.php +++ b/CRM/Contribute/Form/Contribution/ThankYou.php @@ -120,21 +120,39 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont $params = $this->_params; $honor_block_is_active = $this->get('honor_block_is_active'); - if ($honor_block_is_active && - ((!empty($params["honor_first_name"]) && !empty($params["honor_last_name"])) || - (!empty($params["honor_email"])) - ) - ) { + if ($honor_block_is_active && CRM_Utils_Array::value('soft_credit_type_id', $params)) { + $honorName = null; + $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); + $this->assign('honor_block_is_active', $honor_block_is_active); - $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values)); + $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); + $profileContactType = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); + switch ($profileContactType) { + case 'Individual': + if (array_key_exists('prefix_id', $params['honor'])) { + $honorName = CRM_Utils_Array::value(CRM_Utils_Array::value('prefix_id',$params['honor']), + CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id') + ); + } + $honorName .= ' ' . $params['honor']['first_name'] . ' ' . $params['honor']['last_name']; + if (array_key_exists('suffix_id', $params['honor'])) { + $honorName .= ' ' . CRM_Utils_Array::value(CRM_Utils_Array::value('suffix_id',$params['honor']), + CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id') + ); + } + break; + case 'Organization': + $honorName = $params['honor']['organization_name']; + break; + case 'Household': + $honorName = $params['honor']['household_name']; + break; + } + $this->assign('honorName', $honorName); - $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); - $honor = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id'); - $this->assign('honor_type', $honor[$params["honor_type_id"]]); - $this->assign('honor_prefix', ($params["honor_prefix_id"]) ? $prefix[$params["honor_prefix_id"]] : ' '); - $this->assign('honor_first_name', $params["honor_first_name"]); - $this->assign('honor_last_name', $params["honor_last_name"]); - $this->assign('honor_email', $params["honor_email"]); + $fieldTypes = array('Contact'); + $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); + $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); } $qParams = "reset=1&id={$this->_id}"; @@ -194,7 +212,7 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont $fieldTypes = array_merge($fieldTypes, array('Contribution')); } - $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes); + $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); } $this->assign('trxn_id', @@ -209,12 +227,7 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont $defaults = array(); $fields = array(); foreach ($this->_fields as $name => $dontCare) { - if ($name == 'onbehalf') { - foreach ($dontCare as $key => $value) { - $fields['onbehalf'][$key] = 1; - } - } - else { + if ($name != 'onbehalf' || $name != 'honor') { $fields[$name] = 1; } } @@ -222,19 +235,7 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont $contact = $this->_params = $this->controller->exportValues('Main'); foreach ($fields as $name => $dontCare) { - if ($name == 'onbehalf') { - foreach ($dontCare as $key => $value) { - //$defaults[$key] = $contact['onbehalf'][$key]; - if (isset($contact['onbehalf'][$key])) { - $defaults[$key] = $contact['onbehalf'][$key]; - } - if (isset($contact['onbehalf']["{$key}_id"])) { - $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"]; - } - - } - } - elseif (isset($contact[$name])) { + if (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 1f05911ecd..f0763ae5aa 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -640,7 +640,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { * @return void * @access public */ - function buildCustom($id, $name, $viewOnly = FALSE, $onBehalf = FALSE, $fieldTypes = NULL) { + function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL) { $stateCountryMap = array(); if ($id) { @@ -709,7 +709,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $stateCountryMap[$index][$prefixName] = $key; if ($prefixName == "state_province") { - if ($onBehalf) { + if ($profileContactType == 'onbehalf') { //CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page //as already done during Contribution registration via onBehalf's quickForm $field['is_required'] = FALSE; @@ -728,16 +728,23 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } - if ($onBehalf) { + if ($profileContactType) { + //Since we are showing honoree name separately so we are removing it from honoree profile just for display + $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name'); + if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) { + unset($fields[$field['name']]); + continue; + } if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) { CRM_Core_BAO_UFGroup::buildProfile( $this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, - TRUE + TRUE, + $profileContactType ); - $this->_fields['onbehalf'][$key] = $field; + $this->_fields[$profileContactType][$key] = $field; } else { unset($fields[$key]); diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index 9fa9d093ef..6107c73625 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -133,7 +133,7 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { } // Preload libraries required by the "Profiles" tab - $schemas = array('IndividualModel', 'ContributionModel'); + $schemas = array('IndividualModel', 'OrganizationModel', 'ContributionModel'); if (in_array('CiviMember', CRM_Core_Config::singleton()->enableComponents)) { $schemas[] = 'MembershipModel'; } @@ -218,16 +218,16 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'")); } - + // don't show option for contribution amounts section if membership price set // this flag is sent to template - + $membershipBlock = new CRM_Member_DAO_MembershipBlock(); $membershipBlock->entity_table = 'civicrm_contribution_page'; $membershipBlock->entity_id = $this->_id; $membershipBlock->is_active = 1; $hasMembershipBlk = FALSE; - if ($membershipBlock->find(TRUE) && + if ($membershipBlock->find(TRUE) && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, NULL, 1)) ) { $extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends'); diff --git a/CRM/Contribute/Form/ContributionPage/Settings.php b/CRM/Contribute/Form/ContributionPage/Settings.php index 2af10e33e0..8c7605a7b0 100644 --- a/CRM/Contribute/Form/ContributionPage/Settings.php +++ b/CRM/Contribute/Form/ContributionPage/Settings.php @@ -74,11 +74,28 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ // get the first one only $defaults['onbehalf_profile_id'] = $onBehalfIDs[0]; } + + $ufJoinDAO = new CRM_Core_DAO_UFJoin(); + $ufJoinDAO->module = 'soft_credit'; + $ufJoinDAO->entity_id = $this->_id; + if ($ufJoinDAO->find(TRUE)) { + $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id; + $jsonData = json_decode($ufJoinDAO->module_data); + if ($jsonData) { + foreach ($jsonData->soft_credit as $index => $value){ + $defaults[$index] = $value; + } + } + } } else { CRM_Utils_System::setTitle(ts('Title and Settings')); } + if (!CRM_Utils_Array::value('soft_credit_types', $defaults)) { + $defaults['soft_credit_types'] = array(1, 2); + } + return $defaults; } @@ -171,9 +188,33 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ // should the honor be enabled $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()")); - $this->add('text', 'honor_block_title', ts('Honoree Section Title'), $attributes['honor_block_title']); + $this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45)); - $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), $attributes['honor_block_text']); + $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50)); + + $softCreditTypes = &$this->add('select', 'soft_credit_types', + ts('Honor Types'), + CRM_Core_OptionGroup::values("soft_credit_type", FALSE), + FALSE, + array( + 'id' => 'soft_credit_types', + 'multiple' => 'multiple', + 'title' => '- ' . ts('select') . ' -', + ) + ); + + $entities = array(); + $entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'); + //$entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'OrganizationModel'); + $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType::subTypes('Individual')); + $allowSubTypes = array(); + + $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities); + + if (CRM_Utils_Array::value('honor_block_is_active', $this->_submitValues)) { + $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required'); + $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required'); + } // add optional start and end dates $this->addDateTime('start_date', ts('Start Date')); @@ -213,12 +254,12 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ if (($end < $start) && ($end != 0)) { $errors['end_date'] = ts('End date should be after Start date.'); } - - if (CRM_Utils_Array::value('payment_processor', $self->_values) + + if (CRM_Utils_Array::value('payment_processor', $self->_values) && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($values['financial_type_id'])) { - $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType; + $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType; } - + //dont allow on behalf of save when //pre or post profile consists of membership fields if ($contributionPageId && CRM_Utils_Array::value('is_organization', $values)) { @@ -239,7 +280,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ $conProfileType = "'Includes Profile (top of page)'"; } } - + if ($contributionProfiles['custom_post_id']) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_post_id']); if ($postProfileType == 'Membership') { @@ -291,24 +332,61 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ $params['honor_block_title'] = NULL; $params['honor_block_text'] = NULL; } + else { + $sctJSON = json_encode(array( + 'soft_credit' => array( + 'soft_credit_types' => $params['soft_credit_types'], + 'honor_block_title' => $params['honor_block_title'], + 'honor_block_text' => $params['honor_block_text'] + ) + ) + ); + } $dao = CRM_Contribute_BAO_ContributionPage::create($params); - // make entry in UF join table for onbehalf of org profile $ufJoinParams = array( - 'is_active' => 1, - 'module' => 'OnBehalf', - 'entity_table' => 'civicrm_contribution_page', - 'entity_id' => $dao->id, + 'onbehalf_profile_id' => + array( + 'is_active' => 1, + 'module' => 'OnBehalf', + 'entity_table' => 'civicrm_contribution_page', + 'entity_id' => $dao->id, + ), + 'honor_block_is_active' => + array( + 'module' => 'soft_credit', + 'entity_table' => 'civicrm_contribution_page', + 'entity_id' => $dao->id, + ) ); - // first delete all past entries - CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); - if (CRM_Utils_Array::value('onbehalf_profile_id', $params)) { - $ufJoinParams['weight'] = 1; - $ufJoinParams['uf_group_id'] = $params['onbehalf_profile_id']; - CRM_Core_BAO_UFJoin::create($ufJoinParams); + foreach ($ufJoinParams as $index => $ufJoinParam) { + if (CRM_Utils_Array::value($index, $params)) { + $ufJoinParam['weight'] = 1; + if ($index == 'honor_block_is_active') { + $ufJoinParam['is_active'] = 1; + $ufJoinParam['uf_group_id'] = $params['honoree_profile']; + $ufJoinParam['module_data'] = $sctJSON; + } + else { + // first delete all past entries + CRM_Core_BAO_UFJoin::deleteAll($ufJoinParam); + $ufJoinParam['uf_group_id'] = $params[$index]; + } + CRM_Core_BAO_UFJoin::create($ufJoinParam); + } + elseif ($index == 'honor_block_is_active') { + //On subsequent honor_block_is_active uncheck, disable(don't delete) + //that particular honoree profile entry in UFjoin table, CRM-13981 + $ufId = CRM_Core_BAO_UFJoin::findJoinEntryId($ufJoinParam); + if ($ufId) { + $ufJoinParam['uf_group_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParam); + $ufJoinParam['is_active'] = 0; + CRM_Core_BAO_UFJoin::create($ufJoinParam); + } + } } $this->set('id', $dao->id); diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index 896d3dfa8b..7a89a959fa 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -47,6 +47,29 @@ class CRM_Contribute_Form_SoftCredit { * @return void */ static function buildQuickForm(&$form) { + if ($form->_mode == 'live' && CRM_Utils_Array::value('honor_block_is_active', $form->_values)) { + $ufJoinDAO = new CRM_Core_DAO_UFJoin(); + $ufJoinDAO->module = 'soft_credit'; + $ufJoinDAO->entity_id = $form->_id; + if ($ufJoinDAO->find(TRUE)) { + $jsonData = json_decode($ufJoinDAO->module_data); + if ($jsonData) { + $form->assign('honor_block_title', $jsonData->soft_credit->honor_block_title); + $form->assign('honor_block_text', $jsonData->soft_credit->honor_block_text); + + $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); + $extraOption = array('onclick' => "enableHonorType();"); + + // radio button for Honor Type + foreach ($jsonData->soft_credit->soft_credit_types as $value) { + $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value, $extraOption); + } + $form->addGroup($honorTypes, 'soft_credit_type_id', NULL); + } + } + return $form; + } + $prefix = 'soft_credit_'; // by default generate 5 blocks $item_count = 6; @@ -55,6 +78,22 @@ class CRM_Contribute_Form_SoftCredit { $showCreateNew = TRUE; if ($form->_action & CRM_Core_Action::UPDATE) { $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE); + } + elseif ($form->_pledgeID) { + //Check and select most recent completed contrubtion and use it to retrieve + //soft-credit information to use as default for current pledge payment, CRM-13981 + $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID); + foreach ($pledgePayments as $id => $record) { + if ($record['contribution_id']) { + $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE); + if ($record['status'] == 'Completed' && count($softCredits) > 0) { + $form->_softCreditInfo = $softCredits; + } + } + } + } + + if (property_exists($form, "_softCreditInfo")) { if (!empty($form->_softCreditInfo['soft_credit'])) { $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']); $showSoftCreditRow++; @@ -119,7 +158,6 @@ class CRM_Contribute_Form_SoftCredit { $defaults["soft_credit_type[$key]"] = $value['soft_credit_type']; } } - elseif (CRM_Utils_Array::value('pcp_id', $form->_softCreditInfo)) { $pcpInfo = $form->_softCreditInfo; $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo); diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 637f4ee788..e0d8fbd9d6 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -1695,6 +1695,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) * @params array $field array field properties * @params int $mode profile mode * @params int $contactID contact id + * @params string $usedFor for building up prefixed fieldname for special cases (e.g. onBehalf, Honor) * * @return null * @static @@ -1706,7 +1707,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) $mode, $contactId = NULL, $online = FALSE, - $onBehalf = FALSE, + $usedFor = NULL, $rowNumber = NULL , $prefix = '' ) { @@ -1726,9 +1727,12 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) return; } - if ($onBehalf) { + if ($usedFor == 'onbehalf') { $name = "onbehalf[$fieldName]"; } + elseif ($usedFor == 'honor') { + $name = "honor[$fieldName]"; + } elseif ($contactId && !$online) { $name = "field[$contactId][$fieldName]"; } @@ -1814,7 +1818,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) elseif (substr($fieldName, 0, 2) === 'im') { $form->add('text', $name, $title, $attributes, $required); if (!$contactId) { - if ($onBehalf) { + if ($usedFor) { if (substr($name, -1) == ']') { $providerName = substr($name, 0, -1) . '-provider_id]'; } @@ -1884,9 +1888,12 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) } elseif ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); - if ($onBehalf) { + if ($usedFor == 'onbehalf') { $profileType = 'Organization'; } + elseif ($usedFor == 'honor') { + $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']); + } else { $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL; if ($profileType == 'Contact') { @@ -1993,7 +2000,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) $form->addRule($name, ts('Enter a valid Website.'), 'url'); //Website type select - if ($onBehalf) { + if ($usedFor) { if (substr($name, -1) == ']') { $websiteTypeName = substr($name, 0, -1) . '-website_type_id]'; } @@ -2169,8 +2176,8 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. - if ($onBehalf) { - $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']); + if ($usedFor) { + $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']); } else { $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 321d2e332b..9ca03859f7 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -2662,7 +2662,6 @@ WHERE civicrm_membership.is_test = 0"; $recordContribution = array( 'contact_id', 'total_amount', 'receive_date', 'financial_type_id', 'payment_instrument_id', 'trxn_id', 'invoice_id', 'is_test', - 'honor_contact_id', 'honor_type_id', 'contribution_status_id', 'check_number', 'campaign_id', 'is_pay_later', ); foreach ($recordContribution as $f) { diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 63bb3b6788..d1b90814a9 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -359,7 +359,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { } } } - + if (CRM_Utils_Array::value('record_contribution', $defaults) && !$this->_mode) { $contributionParams = array('id' => $defaults['record_contribution']); $contributionIds = array(); @@ -771,8 +771,8 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //CRM-10223 - allow contribution to be recorded against different contact // causes a conflict in standalone mode so skip in standalone for now $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?')); - $this->add('select', 'honor_type_id', ts('Membership payment is : '), - array('' => ts('-')) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id')); + $this->add('select', 'soft_credit_type_id', ts('Membership payment is : '), + array('' => ts('- Select - ')) + CRM_Core_OptionGroup::values("soft_credit_type", FALSE)); CRM_Contact_Form_NewContact::buildQuickForm($this, 1, NULL, FALSE, 'contribution_'); } @@ -930,11 +930,20 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; if (!$priceSetId && $self->_mode && !CRM_Utils_Array::value('financial_type_id', $params)) { $errors['financial_type_id'] = ts('Please enter the financial Type.'); } - + if (CRM_Utils_Array::value('record_contribution', $params) && !CRM_Utils_Array::value('payment_instrument_id', $params)) { $errors['payment_instrument_id'] = ts('Paid By is a required field.'); } + if (CRM_Utils_Array::value('is_different_contribution_contact', $params)) { + if (!CRM_Utils_Array::value('soft_credit_type_id', $params)) { + $errors['soft_credit_type_id'] = ts('Please Select a Soft Credit Type'); + } + if (!CRM_Utils_Array::value(1, $params['contribution_contact'])) { + $errors['contribution_contact[1]'] = ts('Please select a contact'); + } + } + if (CRM_Utils_Array::value('payment_processor_id', $params)) { // make sure that credit card number and cvv are valid CRM_Core_Payment_Form::validateCreditCard($params, $errors); @@ -1074,7 +1083,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $this->_params = $formValues = $this->controller->exportValues($this->_name); $this->convertDateFieldsToMySQL($formValues); - $params = $ids = array(); + $params = $softParams = $ids = array(); $membershipTypeValues = array(); foreach ($this->_memTypeSelected as $memType) { @@ -1249,15 +1258,14 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //CRM-10223 - allow contribution to be recorded against different contact if ($this->_contributorContactID != $this->_contactID) { $params['contribution_contact_id'] = $this->_contributorContactID; - if (CRM_Utils_Array::value('honor_type_id', $this->_params)) { - $params['honor_type_id'] = $this->_params['honor_type_id']; - $params['honor_contact_id'] = $params['contact_id']; + if (CRM_Utils_Array::value('soft_credit_type_id', $this->_params)) { + $softParams['soft_credit_type_id'] = $this->_params['soft_credit_type_id']; + $softParams['contact_id'] = $params['contact_id']; } } if (CRM_Utils_Array::value('record_contribution', $formValues)) { $recordContribution = array( 'total_amount', - 'honor_type_id', 'financial_type_id', 'payment_instrument_id', 'trxn_id', @@ -1395,9 +1403,9 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //CRM-10377 if payment is by an alternate contact then we need to set that person // as the contact in the payment params if ($this->_contributorContactID != $this->_contactID) { - if (CRM_Utils_Array::value('honor_type_id', $this->_params)) { - $paymentParams['honor_contact_id'] = $this->_contactID; - $paymentParams['honor_type_id'] = $this->_params['honor_type_id']; + if (CRM_Utils_Array::value('soft_credit_type_id', $this->_params)) { + $softParams['contact_id'] = $params['contact_id']; + $softParams['soft_credit_type_id'] = $this->_params['soft_credit_type_id']; } } if (CRM_Utils_Array::value('send_receipt', $this->_params)) { @@ -1427,6 +1435,13 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; TRUE, FALSE ); + + //create new soft-credit record, CRM-13981 + $softParams['contribution_id'] = $contribution->id; + $softParams['currency'] = $contribution->currency; + $softParams['amount'] = $contribution->total_amount; + CRM_Contribute_BAO_ContributionSoft::add($softParams); + $paymentParams['contactID'] = $contactID; $paymentParams['contributionID'] = $contribution->id; $paymentParams['contributionTypeID'] = $contribution->financial_type_id; @@ -1547,6 +1562,17 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $lineItems[$itemId]['id'] = $itemId; $lineItem[$priceSetId] = $lineItems; CRM_Price_BAO_LineItem::processPriceSet($params['contribution_id'], $lineItem); + + //create new soft-credit record, CRM-13981 + $softParams['contribution_id'] = $params['contribution_id']; + $dao = new CRM_Contribute_DAO_Contribution(); + $dao->id = $params['contribution_id']; + $dao->find(); + while ($dao->fetch()) { + $softParams['currency'] = $dao->currency; + $softParams['amount'] = $dao->total_amount; + } + CRM_Contribute_BAO_ContributionSoft::add($softParams); } //carry updated membership object. diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 537e6a5e4f..02ccc85eaa 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -244,7 +244,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { } $defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id'); - + //CRM-13420 if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) { $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); @@ -515,8 +515,8 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //CRM-10223 - allow contribution to be recorded against different contact // causes a conflict in standalone mode so skip in standalone for now $this->addElement('checkbox', 'contribution_contact', ts('Record Payment from a Different Contact?')); - $this->add( 'select', 'honor_type_id', ts('Membership payment is : '), - array( '' => ts( '-') ) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id') ); + $this->add('select', 'soft_credit_type_id', ts('Membership payment is : '), + array('' => ts('- Select - ')) + CRM_Core_OptionGroup::values("soft_credit_type", FALSE)); require_once 'CRM/Contact/Form/NewContact.php'; CRM_Contact_Form_NewContact::buildQuickForm($this,1, null, false,'contribution_'); } @@ -781,8 +781,12 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //assign contribution contact id to the field expected by recordMembershipContribution if($this->_contributorContactID != $this->_contactID){ $formValues['contribution_contact_id'] = $this->_contributorContactID; - if(CRM_Utils_Array::value('honor_type_id', $this->_params)){ - $formValues['honor_contact_id'] = $this->_contactID; + if(CRM_Utils_Array::value('soft_credit_type_id', $this->_params)){ + $formValues['soft_credit'][] = array( + 'soft_credit_type_id' => $this->_params['soft_credit_type_id'], + 'contact_id' => $this->_contactID, + 'amount' => $formValues['total_amount'], + ); } } $formValues['contact_id'] = $this->_contactID; diff --git a/CRM/Pledge/Form/Pledge.php b/CRM/Pledge/Form/Pledge.php index ad2ac46cee..def9c51291 100644 --- a/CRM/Pledge/Form/Pledge.php +++ b/CRM/Pledge/Form/Pledge.php @@ -62,14 +62,6 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { */ public $_values; - /** - * stores the honor id - * - * @var int - * @public - */ - public $_honorID = NULL; - /** * The Pledge frequency Units * @public @@ -134,9 +126,6 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { $params = array('id' => $this->_id); CRM_Pledge_BAO_Pledge::getValues($params, $this->_values); - //get the honorID - $this->_honorID = CRM_Utils_Array::value('honor_contact_id', $this->_values); - $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); //check for pending pledge. @@ -252,19 +241,6 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { $defaultPledgeStatus )); - //honoree contact. - if ($this->_honorID) { - $honorDefault = array(); - $idParams = array('contact_id' => $this->_honorID); - CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault); - $honorType = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id'); - $defaults['honor_prefix_id'] = $honorDefault['prefix_id']; - $defaults['honor_first_name'] = CRM_Utils_Array::value('first_name', $honorDefault); - $defaults['honor_last_name'] = CRM_Utils_Array::value('last_name', $honorDefault); - $defaults['honor_email'] = CRM_Utils_Array::value('email', $honorDefault['email'][1]); - $defaults['honor_type'] = $honorType[$defaults['honor_type_id']]; - } - if (isset($this->userEmail)) { $this->assign('email', $this->userEmail); } @@ -306,14 +282,9 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { $showAdditionalInfo = FALSE; $this->_formType = CRM_Utils_Array::value('formType', $_GET); - //fix to load honoree pane on edit. $defaults = array(); - if ($this->_honorID) { - $defaults['hidden_Honoree'] = 1; - } $paneNames = array( - 'Honoree Information' => 'Honoree', 'Payment Reminders' => 'PaymentReminders', ); foreach ($paneNames as $name => $type) { @@ -527,15 +498,6 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { $errors['contact[1]'] = ts('Please select a contact or create new contact'); } - if (isset($fields['honor_type_id'])) { - if (!((CRM_Utils_Array::value('honor_first_name', $fields) && - CRM_Utils_Array::value('honor_last_name', $fields) - ) || - CRM_Utils_Array::value('honor_email', $fields) - )) { - $errors['honor_first_name'] = ts('Honor First Name and Last Name OR an email should be set.'); - } - } if ($fields['amount'] <= 0) { $errors['amount'] = ts('Total Pledge Amount should be greater than zero.'); } @@ -592,11 +554,6 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { 'initial_reminder_day', 'max_reminders', 'additional_reminder_day', - 'honor_type_id', - 'honor_prefix_id', - 'honor_first_name', - 'honor_last_name', - 'honor_email', 'contribution_page_id', 'campaign_id', ); @@ -647,20 +604,6 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { $params['contact_id'] = $this->_contactID; - //handle Honoree contact. - if (CRM_Utils_Array::value('honor_type_id', $params)) { - if ($this->_honorID) { - $honorID = CRM_Contribute_BAO_Contribution::createHonorContact($params, $this->_honorID); - } - else { - $honorID = CRM_Contribute_BAO_Contribution::createHonorContact($params); - } - $params['honor_contact_id'] = $honorID; - } - else { - $params['honor_contact_id'] = 'null'; - } - //format custom data if (CRM_Utils_Array::value('hidden_custom', $formValues)) { $params['hidden_custom'] = 1; diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 3f59c3a600..e5c38a3ee1 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -36,9 +36,6 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { protected $_addressField = FALSE; protected $_emailField = FALSE; - protected $_emailFieldHonor = FALSE; - - protected $_nameFieldHonor = FALSE; protected $_summary = NULL; protected $_allBatches = NULL; @@ -133,41 +130,6 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { ), 'grouping' => 'contact-fields', ), - 'civicrm_contact_honor' => - array( - 'dao' => 'CRM_Contact_DAO_Contact', - 'fields' => - array( - 'sort_name_honor' => - array('title' => ts('Honoree Name'), - 'name' => 'sort_name', - 'alias' => 'contacthonor', - 'default' => FALSE, - ), - 'id_honor' => - array( - 'no_display' => TRUE, - 'title' => ts('Honoree ID'), - 'name' => 'id', - 'alias' => 'contacthonor', - 'required' => TRUE, - ), - ), - ), - 'civicrm_email_honor' => - array( - 'dao' => 'CRM_Core_DAO_Email', - 'fields' => - array( - 'email_honor' => - array('title' => ts('Honoree Email'), - 'name' => 'email', - 'alias' => 'emailhonor', - 'default' => FALSE, - ), - ), - 'grouping' => 'contact-fields', - ), 'civicrm_contribution' => array( 'dao' => 'CRM_Contribute_DAO_Contribution', @@ -214,9 +176,6 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { 'trxn_id' => NULL, 'receive_date' => array('default' => TRUE), 'receipt_date' => NULL, - 'honor_type_id' => array('title' => ts('Honor Type'), - 'default' => FALSE, - ), 'fee_amount' => NULL, 'net_amount' => NULL, 'total_amount' => array('title' => ts('Amount'), @@ -406,22 +365,6 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { function select() { $this->_columnHeaders = array(); - foreach ($this->_columns as $tableName => $table) { - if (array_key_exists('fields', $table)) { - foreach ($table['fields'] as $fieldName => $field) { - if (CRM_Utils_Array::value('required', $field) || - CRM_Utils_Array::value($fieldName, $this->_params['fields']) - ) { - if ($tableName == 'civicrm_email_honor') { - $this->_emailFieldHonor = TRUE; - } - if ($tableName == 'civicrm_contact_honor') { - $this->_nameFieldHonor = TRUE; - } - } - } - } - } parent::select(); } @@ -486,20 +429,6 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n"; } - - // include Honor name field - if ($this->_nameFieldHonor) { - $this->_from .= " - LEFT JOIN civicrm_contact contacthonor - ON contacthonor.id = {$this->_aliases['civicrm_contribution']}.honor_contact_id"; - } - // include Honor email field - if ($this->_emailFieldHonor) { - $this->_from .= " - LEFT JOIN civicrm_email emailhonor - ON emailhonor.contact_id = {$this->_aliases['civicrm_contribution']}.honor_contact_id - AND emailhonor.is_primary = 1\n"; - } // include contribution note if (CRM_Utils_Array::value('contribution_note', $this->_params['fields']) || CRM_Utils_Array::value('note_value', $this->_params)) { @@ -701,8 +630,6 @@ UNION ALL $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); $contributionPages = CRM_Contribute_PseudoConstant::contributionPage(); - $honorTypes = CRM_Core_OptionGroup::values('honor_type', FALSE, FALSE, FALSE, NULL, 'label'); - foreach ($rows as $rowNum => $row) { if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') { @@ -751,20 +678,6 @@ UNION ALL $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact."); } - // convert honoree sort name to link - if (array_key_exists('civicrm_contact_honor_sort_name_honor', $row) && - CRM_Utils_Array::value('civicrm_contact_honor_sort_name_honor', $rows[$rowNum]) && - array_key_exists('civicrm_contact_honor_id_honor', $row) - ) { - - $url = CRM_Utils_System::url("civicrm/contact/view", - 'reset=1&cid=' . $row['civicrm_contact_honor_id_honor'], - $this->_absoluteUrl - ); - $rows[$rowNum]['civicrm_contact_honor_sort_name_honor_link'] = $url; - $rows[$rowNum]['civicrm_contact_honor_sort_name_honor_hover'] = ts("View Contact Summary for Honoree."); - } - if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) { $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value]; $entryFound = TRUE; @@ -781,10 +694,6 @@ UNION ALL $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value]; $entryFound = TRUE; } - if ($value = CRM_Utils_Array::value('civicrm_contribution_honor_type_id', $row)) { - $rows[$rowNum]['civicrm_contribution_honor_type_id'] = $honorTypes[$value]; - $entryFound = TRUE; - } if (array_key_exists('civicrm_batch_batch_id', $row)) { if ($value = $row['civicrm_batch_batch_id']) { $rows[$rowNum]['civicrm_batch_batch_id'] = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $value, 'title'); diff --git a/CRM/Report/Form/Member/ContributionDetail.php b/CRM/Report/Form/Member/ContributionDetail.php index 442c6f856c..a0c8a5385d 100644 --- a/CRM/Report/Form/Member/ContributionDetail.php +++ b/CRM/Report/Form/Member/ContributionDetail.php @@ -37,9 +37,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { protected $_addressField = FALSE; protected $_emailField = FALSE; - protected $_emailFieldHonor = FALSE; - - protected $_nameFieldHonor = FALSE; protected $_summary = NULL; protected $_allBatches = NULL; @@ -138,43 +135,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { ), 'grouping' => 'contact-fields', ), - 'civicrm_contact_honor' => - array( - 'dao' => 'CRM_Contact_DAO_Contact', - 'fields' => - array( - 'sort_name_honor' => - array('title' => ts('Honoree Name'), - 'name' => 'sort_name', - 'alias' => 'contacthonor', - 'default' => FALSE, - 'no_repeat' => TRUE, - ), - 'id_honor' => - array( - 'no_display' => TRUE, - 'title' => ts('Honoree ID'), - 'name' => 'id', - 'alias' => 'contacthonor', - 'required' => TRUE, - ), - ), - ), - 'civicrm_email_honor' => - array( - 'dao' => 'CRM_Core_DAO_Email', - 'fields' => - array( - 'email_honor' => - array('title' => ts('Honoree Email'), - 'name' => 'email', - 'alias' => 'emailhonor', - 'default' => FALSE, - 'no_repeat' => TRUE, - ), - ), - 'grouping' => 'contact-fields', - ), 'first_donation' => array( 'dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => @@ -227,9 +187,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { 'trxn_id' => NULL, 'receive_date' => array('default' => TRUE), 'receipt_date' => NULL, - 'honor_type_id' => array('title' => ts('Honor Type'), - 'default' => FALSE, - ), 'fee_amount' => NULL, 'net_amount' => NULL, 'total_amount' => array('title' => ts('Amount'), @@ -479,13 +436,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { if ($tableName == 'civicrm_email') { $this->_emailField = TRUE; } - elseif ($tableName == 'civicrm_email_honor') { - $this->_emailFieldHonor = TRUE; - } - - if ($tableName == 'civicrm_contact_honor') { - $this->_nameFieldHonor = TRUE; - } // only include statistics columns if set if (CRM_Utils_Array::value('statistics', $field)) { @@ -601,21 +551,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n"; } - - // include Honor name field - if ($this->_nameFieldHonor) { - $this->_from .= " - LEFT JOIN civicrm_contact contacthonor - ON contacthonor.id = {$this->_aliases['civicrm_contribution']}.honor_contact_id"; - } - - // include Honor email field - if ($this->_emailFieldHonor) { - $this->_from .= " - LEFT JOIN civicrm_email emailhonor - ON emailhonor.contact_id = {$this->_aliases['civicrm_contribution']}.honor_contact_id - AND emailhonor.is_primary = 1\n"; - } } function tempTable($applyLimit = TRUE) { @@ -720,7 +655,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); - $honorTypes = CRM_Core_OptionGroup::values('honor_type', FALSE, FALSE, FALSE, NULL, 'label'); //altering the csv display adding additional fields if ($this->_outputMode == 'csv') { @@ -840,20 +774,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View Contact Summary for this Contact.'); } - // convert honoree sort name to link - if (array_key_exists('civicrm_contact_honor_sort_name_honor', $row) && - CRM_Utils_Array::value('civicrm_contact_honor_sort_name_honor', $rows[$rowNum]) && - array_key_exists('civicrm_contact_honor_id_honor', $row) - ) { - - $url = CRM_Utils_System::url('civicrm/contact/view', - 'reset=1&cid=' . $row['civicrm_contact_honor_id_honor'], - $this->_absoluteUrl - ); - $rows[$rowNum]['civicrm_contact_honor_sort_name_honor_link'] = $url; - $rows[$rowNum]['civicrm_contact_honor_sort_name_honor_hover'] = ts('View Contact Summary for Honoree.'); - } - if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) { $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value]; $entryFound = TRUE; @@ -866,10 +786,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value]; $entryFound = TRUE; } - if ($value = CRM_Utils_Array::value('civicrm_contribution_honor_type_id', $row)) { - $rows[$rowNum]['civicrm_contribution_honor_type_id'] = $honorTypes[$value]; - $entryFound = TRUE; - } if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount_sum', $row)) && CRM_Core_Permission::check('access CiviContribute') ) { diff --git a/CRM/UF/Page/ProfileEditor.php b/CRM/UF/Page/ProfileEditor.php index 2f4fbb25a0..b412922689 100644 --- a/CRM/UF/Page/ProfileEditor.php +++ b/CRM/UF/Page/ProfileEditor.php @@ -67,6 +67,8 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page { * @param array $entityTypes strings, e.g. "IndividualModel", "ActivityModel" */ static function registerSchemas($entityTypes) { + /* CRM_Core_Error::backtrace(); */ + /* CRM_Core_Error::debug( '$entityTypes', $entityTypes ); */ // TODO in cases where registerSchemas is called multiple times for same entity, be more efficient CRM_Core_Resources::singleton()->addSettingsFactory(function () use ($entityTypes) { return array( @@ -111,6 +113,12 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page { $availableFields ); break; + case 'OrganizationModel': + $civiSchema[$entityType] = self::convertCiviModelToBackboneModel( + 'Organization', + ts('Organization'), + $availableFields + ); case 'ActivityModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel( 'Activity', diff --git a/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl index baee09572e..7916644a0e 100644 --- a/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl @@ -119,3 +119,37 @@ VALUES ALTER TABLE civicrm_action_schedule ADD sms_provider_id int(10) unsigned NULL COMMENT 'FK to civicrm_sms_provider id '; ALTER TABLE civicrm_action_schedule ADD CONSTRAINT FK_civicrm_action_schedule_sms_provider_id FOREIGN KEY (`sms_provider_id`) REFERENCES `civicrm_sms_provider` (`id`) ON DELETE SET NULL; + +--CRM-13981 migrate 'In Honor of' to Soft Credits +INSERT INTO `civicrm_uf_group` + (`name`, `group_type`, {localize field='title'}`title`{/localize}, `is_cms_user`, `is_reserved`) +VALUES + ('honoree_individual', 'Individual, Contact', {localize}'{ts escape="sql"}Honoree Individual{/ts}'{/localize}, 0, 1); + +SELECT @uf_group_id_honoree_individual := max(id) from civicrm_uf_group where name = 'honoree_individual'; + +INSERT INTO `civicrm_uf_field` + (`uf_group_id`, `field_name`, `is_required`, `is_reserved`, `weight`, `visibility`, `in_selector`, `is_searchable`, {localize field='label'}`label`{/localize}, field_type) +VALUES + (@uf_group_id_honoree_individual, 'honor_prefix_id', 0, 1, 1, 'User and User Admin Only', 0, 1, '{ts escape="sql"}Individual Prefix{/ts}', 'Individual'), + (@uf_group_id_honoree_individual, 'honor_first_name', 0, 1, 2, 'User and User Admin Only', 0, 1, '{ts escape="sql"}First Name{/ts}', 'Individual'), + (@uf_group_id_honoree_individual, 'honor_last_name', 0, 1, 3, 'User and User Admin Only', 0, 1, '{ts escape="sql"}Last Name{/ts}', 'Individual'); + +ALTER TABLE `civicrm_uf_join` + ADD COLUMN `module_data` varchar(255) COMMENT 'Json serialized array of data used by the ufjoin.module'; + +{if $multilingual} + {foreach from=$locales item=loc} + ALTER TABLE civicrm_contribution_page DROP honor_block_title_{$loc}; + ALTER TABLE civicrm_contribution_page DROP honor_block_text_{$loc}; + {/foreach} +{else} + ALTER TABLE civicrm_contribution_page DROP honor_block_title; + ALTER TABLE civicrm_contribution_page DROP honor_block_text; +{/if} + +ALTER TABLE civicrm_contribution DROP honor_contact_id; +ALTER TABLE civicrm_contribution DROP honor_type_id; + +ALTER TABLE civicrm_pledge DROP honor_contact_id; +ALTER TABLE civicrm_pledge DROP honor_type_id; diff --git a/sql/GenerateData.php b/sql/GenerateData.php index 56263a8a3c..3a5214abc8 100644 --- a/sql/GenerateData.php +++ b/sql/GenerateData.php @@ -1731,11 +1731,11 @@ VALUES private function addPledge() { $pledge = "INSERT INTO civicrm_pledge - (contact_id, financial_type_id, contribution_page_id, amount, original_installment_amount, currency,frequency_unit, frequency_interval, frequency_day, installments, start_date, create_date, acknowledge_date, modified_date, cancel_date, end_date, honor_contact_id, honor_type_id, status_id, is_test) + (contact_id, financial_type_id, contribution_page_id, amount, original_installment_amount, currency,frequency_unit, frequency_interval, frequency_day, installments, start_date, create_date, acknowledge_date, modified_date, cancel_date, end_date, status_id, is_test) VALUES - (71, 1, 1, 500.00, '500', 'USD', 'month', 1, 1, 1, '2009-07-01 00:00:00', '2009-06-26 00:00:00', NULL, NULL, NULL,'2009-07-01 00:00:00', NULL, NULL, 1, 0), - (43, 1, 1, 800.00, '200', 'USD', 'month', 3, 1, 4, '2009-07-01 00:00:00', '2009-06-23 00:00:00', '2009-06-23 00:00:00', NULL, NULL, '2009-04-01 10:11:40', NULL, NULL, 5, 0), - (32, 1, 1, 600.00, '200', 'USD', 'month', 1, 1, 3, '2009-10-01 00:00:00', '2009-09-14 00:00:00', '2009-09-14 00:00:00', NULL, NULL, '2009-12-01 00:00:00', NULL, NULL, 5, 0); + (71, 1, 1, 500.00, '500', 'USD', 'month', 1, 1, 1, '2009-07-01 00:00:00', '2009-06-26 00:00:00', NULL, NULL, NULL,'2009-07-01 00:00:00', 1, 0), + (43, 1, 1, 800.00, '200', 'USD', 'month', 3, 1, 4, '2009-07-01 00:00:00', '2009-06-23 00:00:00', '2009-06-23 00:00:00', NULL, NULL, '2009-04-01 10:11:40', 5, 0), + (32, 1, 1, 600.00, '200', 'USD', 'month', 1, 1, 3, '2009-10-01 00:00:00', '2009-09-14 00:00:00', '2009-09-14 00:00:00', NULL, NULL, '2009-12-01 00:00:00', 5, 0); "; $this->_query($pledge); } diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index e00f7da8f1..315c7cccdc 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -121,7 +121,20 @@ {/if} - {include file="CRM/Contribute/Form/Contribution/Honor.tpl"} + + {if $honor_block_is_active} +
+
+ {$soft_credit_type} +
+
+
+ {$honorName}

+ {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields prefix='honor'} +
+
+
+ {/if} {if $customPre}
@@ -157,7 +170,7 @@ {if $onbehalfProfile}
- {include file="CRM/UF/Form/Block.tpl" fields=$onbehalfProfile} + {include file="CRM/UF/Form/Block.tpl" fields=$onbehalfProfile prefix='onbehalf'}
{ts}Organization Email{/ts}
{$onBehalfEmail}
diff --git a/templates/CRM/Contribute/Form/Contribution/Honor.tpl b/templates/CRM/Contribute/Form/Contribution/Honor.tpl deleted file mode 100644 index 9664a8a937..0000000000 --- a/templates/CRM/Contribute/Form/Contribution/Honor.tpl +++ /dev/null @@ -1,37 +0,0 @@ -{* - +--------------------------------------------------------------------+ - | CiviCRM version 4.4 | - +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2013 | - +--------------------------------------------------------------------+ - | This file is a part of CiviCRM. | - | | - | CiviCRM is free software; you can copy, modify, and distribute it | - | under the terms of the GNU Affero General Public License | - | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | - | | - | CiviCRM is distributed in the hope that it will be useful, but | - | WITHOUT ANY WARRANTY; without even the implied warranty of | - | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | - | See the GNU Affero General Public License for more details. | - | | - | You should have received a copy of the GNU Affero General Public | - | License and the CiviCRM Licensing Exception along | - | with this program; if not, contact CiviCRM LLC | - | at info[AT]civicrm[DOT]org. If you have questions about the | - | GNU Affero General Public License or the licensing of CiviCRM, | - | see the CiviCRM license FAQ at http://civicrm.org/licensing | - +--------------------------------------------------------------------+ -*} -{if $honor_block_is_active} -
-
- {$honor_block_title} -
-
- {$honor_type} : - {$honor_prefix} {$honor_first_name} {$honor_last_name}
- Email : {$honor_email}
-
-
-{/if} diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 9d1b101a69..18bbb0233e 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -192,44 +192,9 @@ {if $honor_block_is_active}
- {$honor_block_title} -
- {$honor_block_text} -
- {if $form.honor_type_id.html} -
-
- {$form.honor_type_id.html} - ({ts}clear{/ts}) -
{ts}Select an option to reveal honoree information fields.{/ts}
-
-
- {/if} + {include file="CRM/Contribute/Form/SoftCredit.tpl"}
-
-
{$form.honor_prefix_id.html}
-
-
-
{$form.honor_first_name.label}
-
- {$form.honor_first_name.html} -
-
-
-
-
{$form.honor_last_name.label}
-
- {$form.honor_last_name.html} -
-
-
-
-
{$form.honor_email.label}
-
- {$form.honor_email.html} -
-
-
+ {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields mode=8 prefix='honor'}
{/if} @@ -373,13 +338,13 @@ showOnBehalf(true); {/if} - {if $honor_block_is_active AND $form.honor_type_id.html} + {if $honor_block_is_active AND $form.soft_credit_type_id.html} enableHonorType(); {/if} {literal} function enableHonorType( ) { - var element = document.getElementsByName("honor_type_id"); + var element = document.getElementsByName("soft_credit_type_id"); for (var i = 0; i < element.length; i++ ) { var isHonor = false; if ( element[i].checked == true ) { @@ -392,10 +357,6 @@ cj('#honorTypeEmail').show(); } else { - document.getElementById('honor_first_name').value = ''; - document.getElementById('honor_last_name').value = ''; - document.getElementById('honor_email').value = ''; - document.getElementById('honor_prefix_id').value = ''; cj('#honorType').hide(); cj('#honorTypeEmail').hide(); } diff --git a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl index 70e2ab8934..ef73f373db 100644 --- a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl +++ b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl @@ -173,7 +173,19 @@
{/if} - {include file="CRM/Contribute/Form/Contribution/Honor.tpl"} + {if $honor_block_is_active} +
+
+ {$soft_credit_type} +
+
+
+ {$honorName}

+ {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields prefix='honor'} +
+
+
+ {/if} {if $customPre}
diff --git a/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl b/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl index 5d73e02f67..6a2542f66b 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl +++ b/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl @@ -108,13 +108,46 @@ - + + + + + + + - - + + + + + +
{$form.honor_block_title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_contribution_page' field='honor_block_title' id=$contributionPageID}{/if}{$form.honor_block_title.html}
- {ts}Title for the Honoree section (e.g. "Honoree Information").{/ts}
+ {$form.honor_block_title.label} + {if $action == 2} + {include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_contribution_page' field='honor_block_title' id=$contributionPageID} + {/if} + + {$form.honor_block_title.html}
+ {ts}Title for the Honoree section (e.g. "Honoree Information").{/ts} +
+ {crmAPI var='result' entity='OptionGroup' action='get' sequential=1 name='soft_credit_type'} + {$form.honor_block_text.label} + {if $action == 2} + {include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_contribution_page' field='honor_block_text' id=$contributionPageID} + {/if} + + {$form.honor_block_text.html}
+ {ts}Optional explanatory text for the Honoree section (displayed above the Honoree fields).{/ts} +
{$form.honor_block_text.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_contribution_page' field='honor_block_text' id=$contributionPageID}{/if}{$form.honor_block_text.html}
- {ts}Optional explanatory text for the Honoree section (displayed above the Honoree fields).{/ts}
+ + {$form.soft_credit_types.label}{$form.soft_credit_types.html} +
+ {$form.honoree_profile.label} + + {$form.honoree_profile.html} + {ts}Profile to be included in the honoree section{/ts} +
@@ -171,6 +204,23 @@ document.getElementById("honor").style.display = "none"; } } + cj('.optionvalue-link').click(function() { + {/literal}"{crmAPI var='result' entity='OptionGroup' action='get' sequential=1 name='soft_credit_type'}"{literal}; + var postURL = {/literal}"{crmURL p='civicrm/admin/optionValue' q="gid="}{$result.id}"{literal}; + CRM.loadForm(postURL).on('crmFormSuccess', function(e, data) { + cj('.ui-dialog a').click(function(){ + //Todo: inline edit facility for soft_credit_type option group in jquery popup dialog + }); + }); + return false; + }) + + cj("select#soft_credit_types").crmasmSelect({ + addItemTarget: 'bottom', + animate: false, + highlight: true, + respectParents: true + }); {/literal} diff --git a/templates/CRM/Contribute/Form/SoftCredit.js b/templates/CRM/Contribute/Form/SoftCredit.js index b0ac108d72..b8159a47c2 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.js +++ b/templates/CRM/Contribute/Form/SoftCredit.js @@ -11,9 +11,9 @@ cj(function($) { return false; } - $('#addMoreSoftCredit').click(function(){ + $('#addMoreSoftCredit').live('click', function () { $('.crm-contribution-form-block-soft_credit_to tr.hiddenElement').filter(':first').show().removeClass('hiddenElement'); - if ( $('.crm-soft-credit-block tr.hiddenElement').length < 1 ) { + if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) { $('#addMoreSoftCredit').hide(); } return false; @@ -58,7 +58,7 @@ cj(function($) { }); $('input[name^="soft_credit_contact["]').change(function(){ - var rowNum = $(this).attr('id').replace('soft_credit_contact_',''); + var rowNum = $(this).prop('id').replace('soft_credit_contact_',''); var totalAmount = $('#total_amount').val(); //assign total amount as default soft credit amount $('#soft_credit_amount_'+ rowNum).val(totalAmount); diff --git a/templates/CRM/Contribute/Form/SoftCredit.tpl b/templates/CRM/Contribute/Form/SoftCredit.tpl index 35e0e30e09..f75c5883f8 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.tpl +++ b/templates/CRM/Contribute/Form/SoftCredit.tpl @@ -24,7 +24,23 @@ +--------------------------------------------------------------------+ *} {* template for adding form elements for soft credit form*} - +{if $honor_block_is_active} + {crmRegion name="contribution-soft-credit-block"} + {$honor_block_title} +
+ {$honor_block_text} +
+ {if $form.soft_credit_type_id.html} +
+
+ {$form.soft_credit_type_id.html} + ({ts}clear{/ts}) +
{ts}Select an option to reveal honoree information fields.{/ts}
+
+
+ {/if} + {/crmRegion} +{else}
{section name='i' start=1 loop=$rowCount} {assign var='rowNumber' value=$smarty.section.i.index} @@ -55,3 +71,4 @@
+{/if} diff --git a/templates/CRM/Contribute/Page/ContributionHonor.tpl b/templates/CRM/Contribute/Page/ContributionHonor.tpl deleted file mode 100644 index aa5eff7c34..0000000000 --- a/templates/CRM/Contribute/Page/ContributionHonor.tpl +++ /dev/null @@ -1,57 +0,0 @@ -{* - +--------------------------------------------------------------------+ - | CiviCRM version 4.4 | - +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2013 | - +--------------------------------------------------------------------+ - | This file is a part of CiviCRM. | - | | - | CiviCRM is free software; you can copy, modify, and distribute it | - | under the terms of the GNU Affero General Public License | - | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | - | | - | CiviCRM is distributed in the hope that it will be useful, but | - | WITHOUT ANY WARRANTY; without even the implied warranty of | - | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | - | See the GNU Affero General Public License for more details. | - | | - | You should have received a copy of the GNU Affero General Public | - | License and the CiviCRM Licensing Exception along | - | with this program; if not, contact CiviCRM LLC | - | at info[AT]civicrm[DOT]org. If you have questions about the | - | GNU Affero General Public License or the licensing of CiviCRM, | - | see the CiviCRM license FAQ at http://civicrm.org/licensing | - +--------------------------------------------------------------------+ -*} -{if $action eq 1 or $action eq 2 or $action eq 8} {* add, update or view *} - {include file="CRM/Contribute/Form/Contribution.tpl"} -{elseif $action eq 4} - {include file="CRM/Contribute/Form/ContributionView.tpl"} -{/if} -{if $honorRows} - {strip} - - - - - - - - - - - {foreach from=$honorRows item=row} - - - - - - - - - - {/foreach} -
{ts}Contributor{/ts}{ts}Amount{/ts}{ts}Type{/ts}{ts}Source{/ts}{ts}Received{/ts}{ts}Status{/ts} 
{$row.display_name}{$row.amount}{$row.type}{$row.source}{$row.receive_date|truncate:10:''|crmDate}{$row.contribution_status}{$row.action|replace:'xx':$row.honorId}
- {/strip} -{/if} - diff --git a/templates/CRM/Contribute/Page/Tab.tpl b/templates/CRM/Contribute/Page/Tab.tpl index 27c32d46da..b946e5d1ff 100644 --- a/templates/CRM/Contribute/Page/Tab.tpl +++ b/templates/CRM/Contribute/Page/Tab.tpl @@ -74,13 +74,6 @@ {include file="CRM/Contribute/Page/ContributionRecur.tpl"} {/if} - {if $honor} -
-
-
- {include file="CRM/Contribute/Page/ContributionHonor.tpl"} - {/if} - {if $softCredit}

diff --git a/templates/CRM/Member/Form/Membership.tpl b/templates/CRM/Member/Form/Membership.tpl index fd73e63bd7..a02eb03e4a 100644 --- a/templates/CRM/Member/Form/Membership.tpl +++ b/templates/CRM/Member/Form/Membership.tpl @@ -184,8 +184,8 @@ - - + + {include file="CRM/Contact/Form/NewContact.tpl"} @@ -218,8 +218,8 @@
{$form.honor_type_id.label}{$form.honor_type_id.html}{$form.soft_credit_type.label}{$form.soft_credit_type.html}
- - + + {include file="CRM/Contact/Form/NewContact.tpl"} diff --git a/templates/CRM/Member/Form/MembershipRenewal.tpl b/templates/CRM/Member/Form/MembershipRenewal.tpl index 554366162a..b3da8fc1d5 100644 --- a/templates/CRM/Member/Form/MembershipRenewal.tpl +++ b/templates/CRM/Member/Form/MembershipRenewal.tpl @@ -138,8 +138,8 @@
{$form.honor_type_id.label}{$form.honor_type_id.html}{$form.soft_credit_type_id.label}{$form.soft_credit_type_id.html}
- - + + {include file="CRM/Contact/Form/NewContact.tpl"} diff --git a/templates/CRM/UF/Form/Block.tpl b/templates/CRM/UF/Form/Block.tpl index d526339941..a789951303 100644 --- a/templates/CRM/UF/Form/Block.tpl +++ b/templates/CRM/UF/Form/Block.tpl @@ -47,7 +47,7 @@
{$field.groupTitle} {/if} - {if $form.formName eq 'Confirm' OR $form.formName eq 'ThankYou'} + {if ($form.formName eq 'Confirm' OR $form.formName eq 'ThankYou') AND $prefix neq 'honor'}
{$field.groupTitle}
{/if} {assign var=fieldset value=`$field.groupTitle`} @@ -103,7 +103,7 @@ {else}
- {$form.$n.label} + {if $prefix}{$form.$prefix.$n.label}{else}{$form.$n.label}{/if}
{if $n|substr:0:3 eq 'im-'} @@ -125,12 +125,12 @@ {include file="CRM/common/jcalendar.tpl" elementName=$n} {elseif $n|substr:0:5 eq 'phone'} {assign var="phone_ext_field" value=$n|replace:'phone':'phone_ext'} - {$form.$n.html} + {if $prefix}{$form.$prefix.$n.html}{else}{$form.$n.html}{/if} {if $form.$phone_ext_field.html}  {$form.$phone_ext_field.html} {/if} {else} - {$form.$n.html} + {if $prefix}{$form.$prefix.$n.html}{else}{$form.$n.html}{/if} {if $n eq 'gender' && $form.$fieldName.frozen neq true} ({ts}clear{/ts}) {/if} diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index 64d1aff602..b74263329e 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -353,23 +353,6 @@ 1.4 SET NULL - - honor_contact_id - Honor Contact - int unsigned - FK to contact ID - 1.3 - - Autocomplete-Select - - - - honor_contact_id -
{$form.honor_type_id.label}{$form.honor_type_id.html}{$form.soft_credit_type_id.label}{$form.soft_credit_type_id.html}
civicrm_contact
- id - 1.6 - SET NULL - is_test Test @@ -407,20 +390,6 @@ 1.6 - - honor_type_id - Honor Type - int unsigned - Implicit FK to civicrm_option_value. - 2.0 - SET NULL - - honor_type - - - Select - - index_contribution_status contribution_status_id diff --git a/xml/schema/Contribute/ContributionPage.xml b/xml/schema/Contribute/ContributionPage.xml index e9dd38d11d..1384ffa6d8 100644 --- a/xml/schema/Contribute/ContributionPage.xml +++ b/xml/schema/Contribute/ContributionPage.xml @@ -352,28 +352,6 @@ Should this contribution have the honor block enabled? 1.6 - - honor_block_title - Contribution Page Honor Block Title - varchar - 255 - true - Title for honor block. - 1.5 - - - honor_block_text - Contribution Page Honor Block Text - text - - TextArea - 2 - 50 - - true - text for honor block. - 1.5 - start_date datetime diff --git a/xml/schema/Core/UFJoin.xml b/xml/schema/Core/UFJoin.xml index ee55d05766..ba37a03a0d 100644 --- a/xml/schema/Core/UFJoin.xml +++ b/xml/schema/Core/UFJoin.xml @@ -87,4 +87,11 @@ id 1.3 + + module_data + varchar + 255 + Json serialized array of data used by the ufjoin.module + 4.5 +
diff --git a/xml/schema/Pledge/Pledge.xml b/xml/schema/Pledge/Pledge.xml index 41ff7f2dd1..d4cd98446b 100644 --- a/xml/schema/Pledge/Pledge.xml +++ b/xml/schema/Pledge/Pledge.xml @@ -240,37 +240,6 @@ Select Date - - honor_contact_id - int unsigned - Pledge Honor Contact - FK to contact ID. Used when pledge is made in honor of another contact. This is propagated to contribution records when pledge payments are made. - 2.1 - - Autocomplete-Select - - - - honor_contact_id - civicrm_contact
- id - 2.1 - SET NULL -
- - honor_type_id - Honor Type - int unsigned - Implicit FK to civicrm_option_value. - 2.1 - SET NULL - - honor_type - - - Select - - max_reminders Maximum Number of Reminders diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index ca6a66ca1e..e2c07db5cb 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -1349,6 +1349,7 @@ INSERT INTO civicrm_uf_group (11, 'membership_batch_entry', 'Membership', '{ts escape="sql"}Membership Bulk Entry{/ts}' , 0, 1, NULL), (12, 'event_registration', 'Individual, Contact', '{ts escape="sql"}Your Registration Info{/ts}', 0, 0, NULL); + INSERT INTO civicrm_uf_join (is_active,module,entity_table,entity_id,weight,uf_group_id) VALUES @@ -1597,3 +1598,25 @@ VALUES INSERT INTO civicrm_uf_field ( uf_group_id, field_name, is_required, is_reserved, weight, visibility, in_selector, is_searchable, location_type_id, label, field_type, help_post, phone_type_id ) VALUES ( 10, 'soft_credit_type', 0, 1, 11, 'User and User Admin Only', 0, 1, NULL, '{ts escape="sql"}Soft Credit Type{/ts}', 'Contribution', NULL, NULL ); + +-- CRM-13981 +INSERT INTO civicrm_uf_group + (name, group_type, title, is_cms_user, is_reserved, help_post) +VALUES + ('honoree_individual', 'Individual, Contact', '{ts escape="sql"}Honoree Individual{/ts}', 0, 1, NULL); + +SELECT @uf_group_id_honoree_individual := max(id) from civicrm_uf_group where name = 'honoree_individual'; + +INSERT INTO civicrm_uf_field + ( uf_group_id, field_name, is_required, is_reserved, weight, visibility, in_selector, is_searchable, location_type_id, label, field_type) +VALUES + (@uf_group_id_honoree_individual, 'honor_prefix_id', 0, 1, 1, 'User and User Admin Only', 0, 1, NULL, '{ts escape="sql"}Individual Prefix{/ts}', 'Individual'), + (@uf_group_id_honoree_individual, 'honor_first_name', 1, 1, 2, 'User and User Admin Only', 0, 1, NULL, '{ts escape="sql"}First Name{/ts}', 'Individual'), + (@uf_group_id_honoree_individual, 'honor_last_name', 1, 1, 3, 'User and User Admin Only', 0, 1, NULL, '{ts escape="sql"}Last Name{/ts}', 'Individual'), + (@uf_group_id_honoree_individual, 'honor_first_name', 1, 1, 2, 'User and User Admin Only', 0, 1, NULL, '{ts escape="sql"}First Name{/ts}', 'Individual'), + (@uf_group_id_honoree_individual, 'honor_email', 0, 1, 3, 'User and User Admin Only', 0, 1, 1, '{ts escape="sql"}Last Name{/ts}', 'Individual'); + +INSERT INTO civicrm_uf_join + (is_active, module, weight, uf_group_id) +VALUES + (1, 'Profile', 1, @uf_group_id_honoree_individual); diff --git a/xml/templates/civicrm_sample.tpl b/xml/templates/civicrm_sample.tpl index 3179303092..83f909e86a 100644 --- a/xml/templates/civicrm_sample.tpl +++ b/xml/templates/civicrm_sample.tpl @@ -60,11 +60,11 @@ VALUES (@priceFieldID, 'other_amount', 'Other Amount', 1, 3, 1, 0, 1); INSERT INTO civicrm_contribution_page - (title,intro_text,financial_type_id,is_monetary,is_allow_other_amount,default_amount_id,min_amount,max_amount,goal_amount,thankyou_title,thankyou_text,thankyou_footer,receipt_from_name,receipt_from_email,cc_receipt,bcc_receipt,receipt_text,is_active,footer_text,amount_block_is_active,honor_block_is_active,honor_block_title,honor_block_text,currency,is_email_receipt) + (title,intro_text,financial_type_id,is_monetary,is_allow_other_amount,default_amount_id,min_amount,max_amount,goal_amount,thankyou_title,thankyou_text,thankyou_footer,receipt_from_name,receipt_from_email,cc_receipt,bcc_receipt,receipt_text,is_active,footer_text,amount_block_is_active,honor_block_is_active,currency,is_email_receipt) VALUES - ('Help Support CiviCRM!','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Contribute NOW by trying out our new online contribution features!',1,1,1,137,'10.00','10000.00','100000.00','Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools.

Please tell your friends and colleagues about CiviCRM!

','

Back to CiviCRM Home Page

','CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1, NULL, 1,NULL, NULL, NULL, 'USD', 1), - ('Member Signup and Renewal', 'Members are the life-blood of our organization. If you''re not already a member - please consider signing up today. You can select the membership level the fits your budget and needs below.', 2, 1, NULL, NULL, NULL, NULL, NULL, 'Thanks for Your Support!', 'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.', NULL, 'Membership Department', 'memberships@civicrm.org', NULL, NULL, 'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.\r\n\r\nKeep this receipt for your records.', 1, NULL, 0, NULL, NULL,NULL, 'USD', 1), - ('Pledge for CiviCRM!','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Pledge NOW by trying out our online contribution features!',1,1,1,NULL,'10.00','10000.00','100000.00','Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools like Pledge.

Please tell your friends and colleagues about CiviPledge!

','

Back to CiviCRM Home Page

','CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1, NULL, 1,NULL, NULL, NULL, 'USD', 1); + ('Help Support CiviCRM!','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Contribute NOW by trying out our new online contribution features!',1,1,1,137,'10.00','10000.00','100000.00','Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools.

Please tell your friends and colleagues about CiviCRM!

','

Back to CiviCRM Home Page

','CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1, NULL, 1,NULL, 'USD', 1), + ('Member Signup and Renewal', 'Members are the life-blood of our organization. If you''re not already a member - please consider signing up today. You can select the membership level the fits your budget and needs below.', 2, 1, NULL, NULL, NULL, NULL, NULL, 'Thanks for Your Support!', 'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.', NULL, 'Membership Department', 'memberships@civicrm.org', NULL, NULL, 'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.\r\n\r\nKeep this receipt for your records.', 1, NULL, 0, NULL, 'USD', 1), + ('Pledge for CiviCRM!','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Pledge NOW by trying out our online contribution features!',1,1,1,NULL,'10.00','10000.00','100000.00','Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools like Pledge.

Please tell your friends and colleagues about CiviPledge!

','

Back to CiviCRM Home Page

','CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1, NULL, 1,NULL, 'USD', 1); INSERT INTO `civicrm_tell_friend` (`entity_table`, `entity_id`, `title`, `intro`, `suggested_message`, `general_link`, `thankyou_title`, `thankyou_text`, `is_active`) -- 2.25.1