Display total cancelled soft credits in summary
authorunknown <mathavan@vedaconsulting.co.uk>
Fri, 4 Mar 2016 17:08:15 +0000 (17:08 +0000)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Wed, 9 Mar 2016 06:01:34 +0000 (11:31 +0530)
CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Page/Tab.php
templates/CRM/Contribute/Page/ContributionSoft.tpl

index aecf78541a7646e5352a2ed3aa400c863817465a..0d6e85ee5a696e6343625753582ef85b1973f417 100644 (file)
@@ -243,12 +243,15 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
    * @return array
    */
   public static function getSoftContributionTotals($contact_id, $isTest = 0) {
-    $query = '
+    
+    $whereClause = "AND cc.cancel_date IS NULL";
+    
+    $query = "
     SELECT SUM(amount) as amount, AVG(total_amount) as average, cc.currency
     FROM civicrm_contribution_soft  ccs
       LEFT JOIN civicrm_contribution cc ON ccs.contribution_id = cc.id
-    WHERE cc.is_test = %2 AND ccs.contact_id = %1
-    GROUP BY currency';
+    WHERE cc.is_test = %2 AND ccs.contact_id = %1 {$whereClause}
+    GROUP BY currency";
 
     $params = array(
       1 => array($contact_id, 'Integer'),
@@ -258,7 +261,7 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
     $cs = CRM_Core_DAO::executeQuery($query, $params);
 
     $count = 0;
-    $amount = $average = array();
+    $amount = $average = $cancelAmount = array();
 
     while ($cs->fetch()) {
       if ($cs->amount > 0) {
@@ -268,12 +271,23 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
         $currency[] = $cs->currency;
       }
     }
-
+    
+    //to get cancel amount
+    $cancelAmountWhereClause = "AND cc.cancel_date IS NOT NULL";
+    $query = str_replace($whereClause, $cancelAmountWhereClause, $query);
+    $cancelAmountSQL  = CRM_Core_DAO::executeQuery($query, $params);
+    while ($cancelAmountSQL->fetch()) {
+      if ($cancelAmountSQL->amount > 0) {
+        $cancelAmount[] = $cancelAmountSQL->amount;
+      }
+    }
+    
     if ($count > 0) {
       return array(
         implode(',&nbsp;', $amount),
         implode(',&nbsp;', $average),
         implode(',&nbsp;', $currency),
+        implode(',&nbsp;', $cancelAmount),
       );
     }
     return array(0, 0);
index b284ed0118ac1efe2e8436849909767752f65770..e7ee1f2cfd3a32215bd09132e23f0a64e72023ce 100644 (file)
@@ -180,7 +180,8 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
 
       list($softCreditTotals['amount'],
         $softCreditTotals['avg'],
-        $softCreditTotals['currency']
+        $softCreditTotals['currency'],
+        $softCreditTotals['cancelAmount'] //to get cancel amount
         ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest);
 
       $this->assign('softCredit', TRUE);
index 05af80f83d0eb1cf930764fa9e6e13d4213e5593..3723de3d708668e50def5f724c65b26b51ea1bf8 100644 (file)
             <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>
+            
+            {if $softCreditTotals.cancelAmount}
+            <th class="right contriTotalRight"> &nbsp; {ts}Total Cancelled Soft Credits{/ts} - {$softCreditTotals.cancelAmount|crmMoney:$softCreditTotals.currency}</th>
+            {/if}
+            
         </tr>
     </table>
     <p></p>