From 91ef9be0d24eb2134b8af7f6a8e1cbc1756991e1 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 9 May 2014 18:49:25 +0530 Subject: [PATCH] CRM-13981 handling SC on Gift Membership minor fix ---------------------------------------- * CRM-13981: Migrate "In Honor of" to Soft Credits https://issues.civicrm.org/jira/browse/CRM-13981 --- CRM/Contribute/BAO/ContributionSoft.php | 19 +++++++++++++------ CRM/Contribute/Page/Tab.php | 2 +- CRM/Member/BAO/Membership.php | 5 +++++ CRM/Member/Form/Membership.php | 3 ++- CRM/Member/Form/MembershipRenewal.php | 3 ++- CRM/Member/Page/Tab.php | 11 +++++++++++ .../CRM/Contribute/Page/ContributionSoft.tpl | 18 ++++++++++-------- templates/CRM/Member/Form/MembershipView.tpl | 4 ++++ 8 files changed, 48 insertions(+), 17 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index 3ee042d6f5..72ee3e7651 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -227,14 +227,14 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio /** * Function to retrieve the list of soft contributions for given contact. * - * @param int $contact_id contact id - * - * @param int $isTest + * @param int $contact_id contact id + * @param int $isTest + * @param string $filter additional filter criteria, later used in where clause * * @return array * @static */ - static function getSoftContributionList($contact_id, $isTest = 0) { + static function getSoftContributionList($contact_id, $filter = NULL, $isTest = 0) { $query = ' SELECT ccs.id, ccs.amount as amount, ccs.contribution_id, @@ -258,8 +258,15 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio LEFT JOIN civicrm_contact contact ON ccs.contribution_id = cc.id AND cc.contact_id = contact.id LEFT JOIN civicrm_financial_type cct ON cc.financial_type_id = cct.id - WHERE cc.is_test = %2 AND ccs.contact_id = %1 - ORDER BY cc.receive_date DESC'; + '; + + $where = " + WHERE cc.is_test = %2 AND ccs.contact_id = %1"; + if ($filter) { + $where .= $filter; + } + + $query .= "{$where} ORDER BY cc.receive_date DESC"; $params = array( 1 => array($contact_id, 'Integer'), diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index 30cc65e36f..bac070363a 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -179,7 +179,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { } $this->assign('isTest', $isTest); - $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $isTest); + $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, NULL, $isTest); if (!empty($softCreditList)) { $softCreditTotals = array(); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 6569226b6c..7f1d8ca764 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -2736,6 +2736,11 @@ WHERE civicrm_membership.is_test = 0"; $contributionParams['batch_id'] = $params['batch_id']; } + if (!empty($params['contribution_contact_id'])) { + // deal with possibility of a different person paying for contribution + $contributionParams['contact_id'] = $params['contribution_contact_id']; + } + if (!empty($params['processPriceSet']) && !empty($params['lineItems']) ) { diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 98ecd10985..d17da29d02 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1268,9 +1268,10 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //CRM-13981, allow different person as a soft-contributor of chosen type if ($this->_contributorContactID != $this->_contactID) { + $params['contribution_contact_id'] = $this->_contributorContactID; if (!empty($this->_params['soft_credit_type_id'])) { $softParams['soft_credit_type_id'] = $this->_params['soft_credit_type_id']; - $softParams['contact_id'] = $this->_contributorContactID; + $softParams['contact_id'] = $this->_contactID; } } if (!empty($formValues['record_contribution'])) { diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index c644242dff..a624d31d39 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -770,10 +770,11 @@ 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 (!empty($this->_params['soft_credit_type_id'])){ $formValues['soft_credit'] = array( 'soft_credit_type_id' => $this->_params['soft_credit_type_id'], - 'contact_id' => $this->_contributorContactID, + 'contact_id' => $this->_contactID, ); } } diff --git a/CRM/Member/Page/Tab.php b/CRM/Member/Page/Tab.php index d39d3b660e..412850068e 100644 --- a/CRM/Member/Page/Tab.php +++ b/CRM/Member/Page/Tab.php @@ -323,10 +323,21 @@ class CRM_Member_Page_Tab extends CRM_Core_Page { if (CRM_Core_Permission::access('CiviContribute')) { $this->_accessContribution = TRUE; $this->assign('accessContribution', TRUE); + + //show associated soft credit when contribution payment is paid by different person + if ($this->_id && $this->_contactId) { + $filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})"; + $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter); + if (!empty($softCreditList)) { + $this->assign('softCredit', TRUE); + $this->assign('softCreditRows', $softCreditList); + } + } } else { $this->_accessContribution = FALSE; $this->assign('accessContribution', FALSE); + $this->assign('softCredit', FALSE); } if ($this->_action & CRM_Core_Action::VIEW) { diff --git a/templates/CRM/Contribute/Page/ContributionSoft.tpl b/templates/CRM/Contribute/Page/ContributionSoft.tpl index b85a22230c..27f6200316 100644 --- a/templates/CRM/Contribute/Page/ContributionSoft.tpl +++ b/templates/CRM/Contribute/Page/ContributionSoft.tpl @@ -25,14 +25,16 @@ *} {if $softCreditRows} {strip} - - - - - - -
{ts}Total Soft Credits{/ts} - {$softCreditTotals.amount|crmMoney:$softCreditTotals.currency}     {ts}Avg Soft Credits{/ts} - {$softCreditTotals.avg|crmMoney:$softCreditTotals.currency}
-

+{if $context neq 'membership'} + + + + + + +
{ts}Total Soft Credits{/ts} - {$softCreditTotals.amount|crmMoney:$softCreditTotals.currency}     {ts}Avg Soft Credits{/ts} - {$softCreditTotals.avg|crmMoney:$softCreditTotals.currency}
+

+{/if} diff --git a/templates/CRM/Member/Form/MembershipView.tpl b/templates/CRM/Member/Form/MembershipView.tpl index 7950339329..2e26bb1aaf 100644 --- a/templates/CRM/Member/Form/MembershipView.tpl +++ b/templates/CRM/Member/Form/MembershipView.tpl @@ -68,6 +68,10 @@ {include file="CRM/Contribute/Form/Selector.tpl" context="Search"} {/if} + {if $softCredit} + {include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"} + {/if} + {if $has_related} {include file="CRM/Member/Form/MembershipRelated.tpl" context="Search"} {/if} -- 2.25.1