CRM-13981 handling SC on Gift Membership minor fix
authormonishdeb <monish.deb@webaccess.co.in>
Fri, 9 May 2014 13:19:25 +0000 (18:49 +0530)
committermonishdeb <monish.deb@webaccess.co.in>
Fri, 9 May 2014 13:19:25 +0000 (18:49 +0530)
----------------------------------------
* CRM-13981: Migrate "In Honor of" to Soft Credits
  https://issues.civicrm.org/jira/browse/CRM-13981

CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Page/Tab.php
CRM/Member/BAO/Membership.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php
CRM/Member/Page/Tab.php
templates/CRM/Contribute/Page/ContributionSoft.tpl
templates/CRM/Member/Form/MembershipView.tpl

index 3ee042d6f570507fc1e64488d45933440e20363b..72ee3e765177d9858481598647acdfda108c6e2e 100644 (file)
@@ -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'),
index 30cc65e36f8ec0e92c27edba54068e18d30d709e..bac070363ac614b8db955f7d30f930bd0c3596b5 100644 (file)
@@ -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();
index 6569226b6c497288903d5d3f443bc481bff36bd3..7f1d8ca764dcf26848d62cf5d23848890211dbdb 100644 (file)
@@ -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'])
     ) {
index 98ecd10985c71900c276f17ed0295d1f6e25c01f..d17da29d02ee1459a629bf88a4c2018c395a1433 100644 (file)
@@ -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'])) {
index c644242dff8b9305939fa275d1eab35488563999..a624d31d39b1f568b07976814f414767a6d2d4f5 100644 (file)
@@ -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,
           );
         }
       }
index d39d3b660edf3a1668bb72e46cf20249053c5687..412850068e140b01cfc1247c2885e55d9bb8c781 100644 (file)
@@ -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) {
index b85a22230cd5dde86709500b9cf716dc2741091f..27f6200316ddd98f240dc12381972e451b676f7a 100644 (file)
 *}
 {if $softCreditRows}
 {strip}
-<table class="form-layout-compressed">
-    <tr>
-        <th class="contriTotalLeft">{ts}Total Soft Credits{/ts} - {$softCreditTotals.amount|crmMoney:$softCreditTotals.currency}</th>
-        <th class="right" width="10px"> &nbsp; </th>
-        <th class="right contriTotalRight"> &nbsp; {ts}Avg Soft Credits{/ts} - {$softCreditTotals.avg|crmMoney:$softCreditTotals.currency}</th>
-    </tr>
-</table> 
-<p></p>
+{if $context neq 'membership'}
+    <table class="form-layout-compressed">
+        <tr>
+            <th class="contriTotalLeft">{ts}Total Soft Credits{/ts} - {$softCreditTotals.amount|crmMoney:$softCreditTotals.currency}</th>
+            <th class="right" width="10px"> &nbsp; </th>
+            <th class="right contriTotalRight"> &nbsp; {ts}Avg Soft Credits{/ts} - {$softCreditTotals.avg|crmMoney:$softCreditTotals.currency}</th>
+        </tr>
+    </table>
+    <p></p>
+{/if}
 
 <table class="selector row-highlight">
     <tr class="columnheader">
index 7950339329d1ee105d31090db96c8394a9a77969..2e26bb1aaf086d985bfb1563efb0df0e14bd6828 100644 (file)
         {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}