CRM-13981, Handling Soft Credit for Gift Membership
authormonishdeb <monish.deb@webaccess.co.in>
Tue, 6 May 2014 18:09:01 +0000 (23:39 +0530)
committermonishdeb <monish.deb@webaccess.co.in>
Tue, 6 May 2014 18:09:01 +0000 (23:39 +0530)
----------------------------------------
* CRM-13981: Migrate "In Honor of" to Soft Credits
  https://issues.civicrm.org/jira/browse/CRM-13981

CRM/Member/BAO/Membership.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php
templates/CRM/Member/Form/Membership.tpl

index 98accda3d65df9c5c68a3fa153e7403bd10df5da..6ea25cfa8d1ea0740f49bbd86d4deeaee744328a 100644 (file)
@@ -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;
 
index f8881395b6beff8500c149764902f6ee2c00eef7..0f7f31dd17a717b10e9a145de0659c028baabdcf 100644 (file)
@@ -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;
index 04201b87e9806a5e98dcd2a0d4e96fac094361fb..c644242dff8b9305939fa275d1eab35488563999 100644 (file)
@@ -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,
           );
         }
       }
index 61d4e247506d1e750522c25652ed82fc348256f5..3e21138fe3933d537c7a3af3114a0f1780da31e9 100644 (file)
             <td>{$form.total_amount.html}<br />
               <span class="description">{ts}Membership payment amount.{/ts}</span></td>
           </tr>
-          {if $context neq 'standalone'}
-            <tr class="crm-membership-form-block-contribution-contact">
-              <td class="label">{$form.is_different_contribution_contact.label}</td>
-              <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
-            </tr>
-            <tr id="record-different-contact">
-              <td>&nbsp;</td>
-              <td>
-                <table class="compressed">
-                  <tr class="crm-membership-form-block-soft-credit-type">
-                    <td class="label">{$form.soft_credit_type.label}</td>
-                    <td>{$form.soft_credit_type.html}</td>
-                  </tr>
-                  <tr class="crm-membership-form-block-soft-credit-contact-id">
-                    <td class="label">{$form.soft_credit_contact_id.label}</td>
-                    <td>{$form.soft_credit_contact_id.html}</td>
-                  </tr>
-                </table>
-              </td>
-            </tr>
-          {/if}
+          <tr class="crm-membership-form-block-contribution-contact">
+            <td class="label">{$form.is_different_contribution_contact.label}</td>
+            <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
+          </tr>
+          <tr id="record-different-contact">
+            <td>&nbsp;</td>
+            <td>
+              <table class="compressed">
+                <tr class="crm-membership-form-block-soft-credit-type">
+                  <td class="label">{$form.soft_credit_type.label}</td>
+                  <td>{$form.soft_credit_type.html}</td>
+                </tr>
+                <tr class="crm-membership-form-block-soft-credit-contact-id">
+                  <td class="label">{$form.soft_credit_contact_id.label}</td>
+                  <td>{$form.soft_credit_contact_id.html}</td>
+                </tr>
+              </table>
+            </td>
+          </tr>
           <tr class="crm-membership-form-block-billing">
             <td colspan="2">
             {include file='CRM/Core/BillingBlock.tpl'}
           </tr>
           <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
             <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
-              <table>{if $context neq 'standalone'}
+              <table>
                 <tr class="crm-membership-form-block-contribution-contact">
                   <td class="label">{$form.is_different_contribution_contact.label}</td>
                   <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
                       </tr>
                     </table>
                   </td>
-                </tr>{/if}
+                </tr>
                   <tr class="crm-membership-form-block-financial_type_id">
                       <td class="label">{$form.financial_type_id.label}</td>
                       <td>{$form.financial_type_id.html}<br />