From d80dbc1447d6ec915986643d4d666de0c5f74a26 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Tue, 6 May 2014 23:39:01 +0530 Subject: [PATCH] CRM-13981, Handling Soft Credit for Gift Membership ---------------------------------------- * CRM-13981: Migrate "In Honor of" to Soft Credits https://issues.civicrm.org/jira/browse/CRM-13981 --- CRM/Member/BAO/Membership.php | 15 ++++---- CRM/Member/Form/Membership.php | 28 ++++++++------- CRM/Member/Form/MembershipRenewal.php | 6 ++-- templates/CRM/Member/Form/Membership.tpl | 44 +++++++++++------------- 4 files changed, 48 insertions(+), 45 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 98accda3d6..6ea25cfa8d 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -2689,8 +2689,8 @@ WHERE civicrm_membership.is_test = 0"; $contributionParams['currency'] = $config->defaultCurrency; $contributionParams['receipt_date'] = (CRM_Utils_Array::value('receipt_date', $params)) ? $params['receipt_date'] : 'null'; $contributionParams['source'] = CRM_Utils_Array::value('contribution_source', $params); - $contributionParams['soft_credit'] = CRM_Utils_Array::value('soft_credit', $params); $contributionParams['non_deductible_amount'] = 'null'; + $contributionSoftParams = CRM_Utils_Array::value('soft_credit', $params); $recordContribution = array( 'contact_id', 'total_amount', 'receive_date', 'financial_type_id', 'payment_instrument_id', 'trxn_id', 'invoice_id', 'is_test', @@ -2705,11 +2705,6 @@ 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']) ) { @@ -2718,6 +2713,14 @@ WHERE civicrm_membership.is_test = 0"; $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); + //CRM-13981, create new soft-credit record as to record payment from differnt person for this membership + if (!empty($contributionSoftParams)) { + $contributionSoftParams['contribution_id'] = $contribution->id; + $contributionSoftParams['currency'] = $contribution->currency; + $contributionSoftParams['amount'] = $contribution->total_amount; + CRM_Contribute_BAO_ContributionSoft::add($contributionSoftParams); + } + // store contribution id $params['contribution_id'] = $contribution->id; diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index f8881395b6..0f7f31dd17 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -767,13 +767,13 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType() ); - if ($this->_context != 'standalone') { - //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->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft')); - $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE)); - } + + //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->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft')); + $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE)); + $this->addElement('checkbox', 'send_receipt', @@ -933,8 +933,8 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; if (empty($params['soft_credit_type_id'])) { $errors['soft_credit_type_id'] = ts('Please Select a Soft Credit Type'); } - if (empty($params['contribution_contact'][1])) { - $errors['contribution_contact[1]'] = ts('Please select a contact'); + if (empty($params['soft_credit_contact_id'])) { + $errors['soft_credit_contact_id'] = ts('Please select a contact'); } } @@ -1262,12 +1262,11 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; // Retrieve the name and email of the current user - this will be the FROM for the receipt email list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']); - //CRM-10223 - allow contribution to be recorded against different contact + //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'] = $params['contact_id']; + $softParams['contact_id'] = $this->_contributorContactID; } } if (!empty($formValues['record_contribution'])) { @@ -1631,6 +1630,11 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; } $membershipParams['init_amount'] = $init_amount; } + + if (!empty($softParams)) { + $membershipParams['soft_credit'] = $softParams; + } + $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids); $this->_membershipIDs[] = $membership->id; diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 04201b87e9..c644242dff 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -770,12 +770,10 @@ 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( + $formValues['soft_credit'] = array( 'soft_credit_type_id' => $this->_params['soft_credit_type_id'], - 'contact_id' => $this->_contactID, - 'amount' => $formValues['total_amount'], + 'contact_id' => $this->_contributorContactID, ); } } diff --git a/templates/CRM/Member/Form/Membership.tpl b/templates/CRM/Member/Form/Membership.tpl index 61d4e24750..3e21138fe3 100644 --- a/templates/CRM/Member/Form/Membership.tpl +++ b/templates/CRM/Member/Form/Membership.tpl @@ -177,27 +177,25 @@ {$form.total_amount.html}
{ts}Membership payment amount.{/ts} - {if $context neq 'standalone'} - - {$form.is_different_contribution_contact.label} - {$form.is_different_contribution_contact.html}  {help id="id-contribution_contact"} - - -   - - - - - - - - - - -
{$form.soft_credit_type.label}{$form.soft_credit_type.html}
{$form.soft_credit_contact_id.label}{$form.soft_credit_contact_id.html}
- - - {/if} + + {$form.is_different_contribution_contact.label} + {$form.is_different_contribution_contact.html}  {help id="id-contribution_contact"} + + +   + + + + + + + + + + +
{$form.soft_credit_type.label}{$form.soft_credit_type.html}
{$form.soft_credit_contact_id.label}{$form.soft_credit_contact_id.html}
+ + {include file='CRM/Core/BillingBlock.tpl'} @@ -212,7 +210,7 @@
{ts}Membership Payment and Receipt{/ts} - {if $context neq 'standalone'} +
@@ -231,7 +229,7 @@
{$form.is_different_contribution_contact.label} {$form.is_different_contribution_contact.html}  {help id="id-contribution_contact"}
- {/if} + {$form.financial_type_id.label} {$form.financial_type_id.html}
-- 2.25.1