CRM-17032 - Add totals for Fees and Net Amount to Contribution Detail Report.
authorDave Greenberg <dave@civicrm.org>
Thu, 29 Oct 2015 00:21:40 +0000 (17:21 -0700)
committerDave Greenberg <dave@civicrm.org>
Thu, 29 Oct 2015 00:21:40 +0000 (17:21 -0700)
----------------------------------------
* CRM-17032: Add Fees and Net to Statistics of Contribution Detail Report
  https://issues.civicrm.org/jira/browse/CRM-17032

CRM/Report/Form/Contribute/Detail.php

index fb493907972fa0cb2067539a8bae4ea01117ce8d..0f31dd786bf10d75a45eba47b6a56ef87bfd2e9e 100644 (file)
@@ -506,13 +506,15 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
   public function statistics(&$rows) {
     $statistics = parent::statistics($rows);
 
-    $totalAmount = $average = array();
+    $totalAmount = $average = $fees = $net = array();
     $count = 0;
     $select = "
         SELECT COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as count,
                SUM( {$this->_aliases['civicrm_contribution']}.total_amount ) as amount,
                ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as avg,
-               {$this->_aliases['civicrm_contribution']}.currency as currency
+               {$this->_aliases['civicrm_contribution']}.currency as currency,
+              SUM( {$this->_aliases['civicrm_contribution']}.fee_amount ) as fees,
+               SUM( {$this->_aliases['civicrm_contribution']}.net_amount ) as net
         ";
 
     $group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency";
@@ -520,8 +522,9 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
     $dao = CRM_Core_DAO::executeQuery($sql);
 
     while ($dao->fetch()) {
-      $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency) . " (" .
-        $dao->count . ")";
+      $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency) . " (" . $dao->count . ")";
+      $fees[] = CRM_Utils_Money::format($dao->fees, $dao->currency);
+      $net[] = CRM_Utils_Money::format($dao->net, $dao->currency);
       $average[] = CRM_Utils_Money::format($dao->avg, $dao->currency);
       $count += $dao->count;
     }
@@ -534,6 +537,16 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
       'title' => ts('Total Contributions'),
       'value' => $count,
     );
+    $statistics['counts']['fees'] = array(
+      'title' => ts('Fees'),
+      'value' => implode(',  ', $fees),
+      'type' => CRM_Utils_Type::T_STRING,
+    );
+    $statistics['counts']['net'] = array(
+      'title' => ts('Net'),
+      'value' => implode(',  ', $net),
+      'type' => CRM_Utils_Type::T_STRING,
+    );
     $statistics['counts']['avg'] = array(
       'title' => ts('Average'),
       'value' => implode(',  ', $average),