CRM-14377 fix - http://issues.civicrm.org/jira/browse/CRM-14377
authormonishdeb <monish.deb@webaccess.co.in>
Sat, 29 Mar 2014 12:42:23 +0000 (18:12 +0530)
committermonishdeb <monish.deb@webaccess.co.in>
Sat, 29 Mar 2014 12:42:23 +0000 (18:12 +0530)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/ContributionView.php
CRM/Contribute/Form/SoftCredit.php
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Form/ContributionView.tpl
templates/CRM/Contribute/Form/SoftCredit.tpl
templates/CRM/Contribute/Page/Tab.hlp

index d19728a1a9a719c5c7f5b3a3d14b8e94a9130811..68514a7e1e2809d9898d0e4b6560282941ff0a1d 100644 (file)
@@ -318,10 +318,10 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
     }
 
     // Handle soft credit and / or link to personal campaign page
-    list($type, $softIDs) = CRM_Contribute_BAO_ContributionSoft::getSoftCreditType($contribution->id);
+    $softIDs = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id);
     if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
-      if (!empty($type) && $type == 'soft') {
-        $deleteParams = array('contribution_id' => $contribution->id);
+      if ($pcpId = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id, TRUE)) {
+        $deleteParams = array('id' => $pcpId);
         CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
       }
       $softParams = array();
@@ -338,7 +338,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
       $softParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name');
       CRM_Contribute_BAO_ContributionSoft::add($softParams);
     }
-    elseif (isset($params['soft_credit'])) {
+    if (isset($params['soft_credit'])) {
       $softParams = $params['soft_credit'];
 
       if (!empty($softIDs)) {
index af23c793c0661904f33cd441eae90774c9040645..39436c64091ee6f87b752a7141f818df55619977 100644 (file)
@@ -147,14 +147,16 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
   static function getSoftContribution($contributionID, $all = FALSE) {
     $pcpFields = array(
       'pcp_id',
+      'pcp_title',
       'pcp_display_in_roll',
       'pcp_roll_nickname',
       'pcp_personal_note',
     );
 
     $query = '
-    SELECT ccs.id, pcp_id, pcp_display_in_roll, pcp_roll_nickname, pcp_personal_note, currency, amount, contact_id, c.display_name, ccs.soft_credit_type_id
+    SELECT ccs.id, pcp_id, cpcp.title as pcp_title, pcp_display_in_roll, pcp_roll_nickname, pcp_personal_note, ccs.currency as currency, amount, ccs.contact_id as contact_id, c.display_name, ccs.soft_credit_type_id
     FROM civicrm_contribution_soft ccs INNER JOIN civicrm_contact c on c.id = ccs.contact_id
+    LEFT JOIN civicrm_pcp cpcp ON ccs.pcp_id = cpcp.id
     WHERE contribution_id = %1;
     ';
 
@@ -165,74 +167,54 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
     $softContribution = array();
     $count = 1;
     while ($dao->fetch()) {
-      if ($all) {
-        foreach ($pcpFields as $val) {
-          $softContribution[$val] = $dao->$val;
-        }
-      }
-
-      $softContribution['soft_credit'][$count] = array(
-        'contact_id' => $dao->contact_id,
-        'soft_credit_id' => $dao->id,
-        'currency' => $dao->currency,
-        'amount' => $dao->amount,
-        'contact_name' => $dao->display_name,
-        'soft_credit_type' => $dao->soft_credit_type_id,
-        'soft_credit_type_label' => CRM_Core_OptionGroup::getLabel('soft_credit_type', $dao->soft_credit_type_id)
-      );
-      $count++;
-    }
-
-    /*
-     * FIX API before deleting this
-    $cs = new CRM_Contribute_DAO_ContributionSoft();
-    $cs->copyValues($params);
-    $softContribution = array();
-    $cs->find();
-
-    if ($cs->N > 0) {
-      $count = 1;
-      while ($cs->fetch()) {
+      if ($dao->pcp_id) {
         if ($all) {
           foreach ($pcpFields as $val) {
-            $softContribution['pcp'][$val] = $cs->$val;
+            $softContribution[$val] = $dao->$val;
           }
+          $softContribution['pcp_soft_credit_to_name'] = $dao->display_name;
+          $softContribution['pcp_soft_credit_to_id'] = $dao->contact_id;
         }
-
+      }
+      else {
         $softContribution['soft_credit'][$count] = array(
-          'soft_credit_to' => $cs->contact_id,
-          'soft_credit_id' => $cs->id,
-          'soft_credit_amount' => $cs->amount,
+          'contact_id' => $dao->contact_id,
+          'soft_credit_id' => $dao->id,
+          'currency' => $dao->currency,
+          'amount' => $dao->amount,
+          'contact_name' => $dao->display_name,
+          'soft_credit_type' => $dao->soft_credit_type_id,
+          'soft_credit_type_label' => CRM_Core_OptionGroup::getLabel('soft_credit_type', $dao->soft_credit_type_id)
         );
         $count++;
       }
     }
-    */
 
     return $softContribution;
   }
 
-  static function getSoftCreditType($contributionID) {
+  static function getSoftCreditIds($contributionID , $isPCP = FALSE) {
     $query = "
-  SELECT id, pcp_id
+  SELECT id
   FROM  civicrm_contribution_soft
   WHERE contribution_id = %1
   ";
+
+    if ($isPCP) {
+      $query .= " AND pcp_id IS NOT NULL";
+    }
     $params = array(1 => array($contributionID, 'Integer'));
 
     $dao = CRM_Core_DAO::executeQuery($query, $params);
     $id = array();
     $type = '';
     while ($dao->fetch()) {
-      if ($dao->pcp_id) {
-        $type = 'pcp';
-      }
-      else {
-        $type = 'soft';
+      if ($isPCP) {
+        return $dao->id;
       }
       $id[] = $dao->id;
     }
-    return array($type, $id);
+    return $id;
   }
 
   /**
index b1dc39ade945e1ccc7796e394bf06b86d05b0fd4..cdb5d94e7f136015b70ce522c63925ff6515aa58 100644 (file)
@@ -655,7 +655,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
         unset($status[CRM_Utils_Array::key('Overdue', $statusName)]);
       }
     }
-    
+
     if ($this->_id) {
       $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id');
       $name = CRM_Utils_Array::value($contributionStatus, $statusName);
@@ -1031,23 +1031,22 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
         $pcp[$f] = CRM_Utils_Array::value($f, $submittedValues);
       }
     }
+
+    $isEmpty = array_keys(array_flip($submittedValues['soft_credit_contact_id']));
+    if ($this->_id && count($isEmpty) == 1 && key($isEmpty) == NULL) {
+      //Delete existing soft credit records if soft credit list is empty on update
+      CRM_Contribute_BAO_ContributionSoft::del(array('contribution_id' => $this->_id));
+    }
     else {
-      $isEmpty = array_keys(array_flip($submittedValues['soft_credit_contact_id']));
-      if ($this->_id && count($isEmpty) == 1 && key($isEmpty) == NULL) {
-        //Delete existing soft credit records if soft credit list is empty on update
-        CRM_Contribute_BAO_ContributionSoft::del(array('contribution_id' => $this->_id));
-      }
-      else {
-        //build soft credit params
-        $softParams = $softIDs =array();
-        foreach ($submittedValues['soft_credit_contact_id'] as $key => $val) {
-          if ($val && $submittedValues['soft_credit_amount'][$key]) {
-            $softParams[$key]['contact_id'] = $val;
-            $softParams[$key]['amount'] = CRM_Utils_Rule::cleanMoney($submittedValues['soft_credit_amount'][$key]);
-            $softParams[$key]['soft_credit_type_id'] = $submittedValues['soft_credit_type'][$key];
-            if (!empty($submittedValues['soft_credit_id'][$key])) {
-              $softIDs[] = $softParams[$key]['id'] = $submittedValues['soft_credit_id'][$key];
-            }
+      //build soft credit params
+      $softParams = $softIDs =array();
+      foreach ($submittedValues['soft_credit_contact_id'] as $key => $val) {
+        if ($val && $submittedValues['soft_credit_amount'][$key]) {
+          $softParams[$key]['contact_id'] = $val;
+          $softParams[$key]['amount'] = CRM_Utils_Rule::cleanMoney($submittedValues['soft_credit_amount'][$key]);
+          $softParams[$key]['soft_credit_type_id'] = $submittedValues['soft_credit_type'][$key];
+          if (!empty($submittedValues['soft_credit_id'][$key])) {
+            $softIDs[] = $softParams[$key]['id'] = $submittedValues['soft_credit_id'][$key];
           }
         }
       }
index 735c4616446b43a004634c4b1a837cbafdd987aa..f003909004e59d0a06a50ee1857264f07f179fdc 100644 (file)
@@ -116,8 +116,15 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
       $values['billing_address'] = $addressDetails[0]['display'];
     }
 
-    //get soft credit record if exists.
-    $values['softContributions'] = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id']);
+    //assign soft credit record if exists.
+    $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE);
+    $this->assign('softContributions', $SCRecords['soft_credit']);
+    unset($SCRecords['soft_credit']);
+
+    //assign pcp record if exists
+    foreach ($SCRecords as $name => $value) {
+      $this->assign($name, $value);
+    }
 
     $lineItems = array();
     if ($id) {
index db9170ba9f387370291f83d81e4c0586c4e86a6a..cd9bd77406c7b28b77d6c6742be864f526ebf9f8 100644 (file)
@@ -153,11 +153,6 @@ class CRM_Contribute_Form_SoftCredit {
       CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"),
       array('id' => 'sct_default_id')
     );
-
-    // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page
-    if (!empty($form->_values['pcp_made_through_id'])) {
-      $form->assign('pcpLinked', 1);
-    }
   }
 
   /**
@@ -171,7 +166,7 @@ class CRM_Contribute_Form_SoftCredit {
         $defaults["soft_credit_type[$key]"] = $value['soft_credit_type'];
       }
     }
-    elseif (!empty($form->_softCreditInfo['pcp_id'])) {
+    if (!empty($form->_softCreditInfo['pcp_id'])) {
       $pcpInfo = $form->_softCreditInfo;
       $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo);
       $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
index 79f05effbfe6881349539d0e771ddd0d4ae6a3e9..99105694662219774705891b044421017d8b4450 100644 (file)
       </div>
       <div class="crm-accordion-body">
         <table class="form-layout-compressed">
-          {if $siteHasPCPs}
-            <tr class="crm-contribution-pcp-block-link">
-              <td colspan="2">
-                <div id="showPCP">
-                  <a href='#'>{ts}credit this contribution to a personal campaign page{/ts}</a>
-                </div>
-              </td>
-            </tr>
-            <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id hiddenElement">
+          <tr class="crm-contribution-form-block-soft_credit_to">
+            <td colspan="2">
+              {include file="CRM/Contribute/Form/SoftCredit.tpl"}
+            </td>
+          </tr>
+        </table>
+      </div>
+    </div>
+    <!-- end of soft credit -->
+
+    <!-- start of PCP -->
+    {if $siteHasPCPs}
+      <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="softCredit">
+        <div class="crm-accordion-header">
+          {ts}Personal Campaign Page{/ts}&nbsp;{help id="id-pcp"}
+        </div>
+        <div class="crm-accordion-body">
+          <table class="form-layout-compressed">
+            <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id">
               <td class="label">{$form.pcp_made_through_id.label}</td>
               <td>
                 {$form.pcp_made_through_id.html} &nbsp;
-                <span class="showSoftCreditLink">
-                  <a href="#" id="showSoftCredit">{ts}unlink from personal campaign page{/ts}</a>
-                </span><br/>
                 <span class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or
                  email address.{/ts}</span>
 
                 <div class="spacer"></div>
-                <div class="crm-contribution-form-block-pcp_details">
+                 <div class="crm-contribution-form-block-pcp_details">
                   <table class="crm-contribution-form-table-credit_to_pcp">
                     <tr id="pcpDisplayRollID" class="crm-contribution-form-block-pcp_display_in_roll">
                       <td class="label">{$form.pcp_display_in_roll.label}</td>
                 </div>
               </td>
             </tr>
-          {/if}
-          <tr class="crm-contribution-form-block-soft_credit_to">
-            <td colspan="2">
-              {include file="CRM/Contribute/Form/SoftCredit.tpl"}
-            </td>
-          </tr>
-        </table>
+          </table>
+        </div>
       </div>
-    </div>
-    <!-- end of soft credit -->
+    {/if}
+    <!-- end of PCP -->
+
     {if !$contributionMode}
     <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="paymentDetails_Information">
       <div class="crm-accordion-header">
index 985e7e37cd4393a90a71d4e05a492ef11a0caa1b..d13cf73fb3e053793e5c198e6f12d1c7195e035a 100644 (file)
   {/if}
 </table>
 
-{if $softContributions and !$pcp_id} {* We show soft credit name with PCP section if contribution is linked to a PCP. *}
+{if count($softContributions)} {* We show soft credit name with PCP section if contribution is linked to a PCP. *}
   <div class="crm-accordion-wrapper crm-soft-credit-pane">
     <div class="crm-accordion-header">
       {ts}Soft Credit{/ts}
     </div>
     <div class="crm-accordion-body">
       <table class="crm-info-panel crm-soft-credit-listing">
-        {foreach from=$softContributions.soft_credit item="softCont"}
+        {foreach from=$softContributions item="softCont"}
           <tr>
             <td>
               <a href="{crmURL p="civicrm/contact/view" q="reset=1&cid=`$softCont.contact_id`"}"
       <table class="crm-info-panel">
         <tr>
           <td class="label">{ts}Personal Campaign Page{/ts}</td>
-          <td><a href="{crmURL p="civicrm/pcp/info" q="reset=1&id=`$pcp_id`"}">{$pcp}</a><br/>
+          <td><a href="{crmURL p="civicrm/pcp/info" q="reset=1&id=`$pcp_id`"}">{$pcp_title}</a><br/>
             <span class="description">{ts}Contribution was made through this personal campaign page.{/ts}</span>
           </td>
         </tr>
         <tr>
           <td class="label">{ts}Soft Credit To{/ts}</td>
-          <td><a href="{crmURL p="civicrm/contact/view" q="reset=1&cid=`$soft_credit_to`"}" id="view_contact"
-                 title="{ts}View contact record{/ts}">{$softCreditToName}</a></td>
+          <td><a href="{crmURL p="civicrm/contact/view" q="reset=1&cid=`$pcp_soft_credit_to_id`"}" id="view_contact"
+                 title="{ts}View contact record{/ts}">{$pcp_soft_credit_to_name}</a></td>
         </tr>
         <tr>
           <td class="label">{ts}In Public Honor Roll?{/ts}</td>
index 43ba52e2ca1b7b6f7cfd22b2b8d9855d5cb35685..b9e762e6f9f4905daf89ced8e9d720edda333f4c 100644 (file)
     });
 
     $('.soft-credit-delete-link').click(function(){
+      $(this).closest('tr').find('input').val('');
       $(this).closest('tr').addClass('hiddenElement').removeAttr('style');
       $('#addMoreSoftCredit').show();
       return false;
index 5f010733876ad345c602df067fcb51ee28945506..a2a6c66d9318f02c2321210f7f88bad10b83f75d 100644 (file)
 <p>
 {ts}When a contribution is made via a Personal Campaign Page, a soft credit for that contribution is automatically assigned to the contact who created the Personal Campaign Page.{/ts}
 </p>
+{/htxt}
+
+{htxt id="id-pcp-title"}
+  {ts}Personal Campaign Page{/ts}
+{/htxt}
+{htxt id="id-pcp"}
+<p>
+{ts}Use to indicate that a contact has a relationship with the actual donor and / or was indirectly responsible for the contribution. For example, if one family member makes a large contribution - it is often useful to record a Soft Credit for the other family member(s). You can record a soft credit while adding or editing a contribution record from this tab.{/ts}
+</p>
+<p>
+{ts}When a contribution is made via a Personal Campaign Page, a soft credit for that contribution is automatically assigned to the contact who created the Personal Campaign Page.{/ts}
+</p>
 {/htxt} 
 
 {htxt id="adjust-payment-amount-title"}