CRM-9394
authoryashodha <yashodha.chaku@webaccess.co.in>
Mon, 18 Mar 2013 06:38:54 +0000 (12:08 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Mon, 18 Mar 2013 06:39:10 +0000 (12:09 +0530)
CRM/Report/Form/Contribute/Summary.php
CRM/Report/Form/Member/Summary.php

index 6919a382fd116fd32abcc5f3334e5ec6c84e6ade..19573520a6d82db217a37abcc03631a1c0c235a8 100644 (file)
@@ -123,6 +123,10 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
         array(
           'contribution_source' => array('title' => ts('Source'),
                  ),
+          'currency' =>
+          array('required' => TRUE,
+            'no_display' => TRUE,
+          ),
           'total_amount' =>
           array('title' => ts('Amount Statistics'),
             'default' => TRUE,
@@ -146,6 +150,12 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
             'default' => array(1),
             'type' => CRM_Utils_Type::T_INT,
           ),
+          'currency' =>
+          array('title' => 'Currency',
+            'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+            'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
+            'type' => CRM_Utils_Type::T_STRING,
+          ),
           'financial_type_id' =>
           array('title' => ts('Financial Type'), 
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
@@ -217,6 +227,8 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
       $this->_columns['civicrm_contribution']['grouping']['campaign_id'] = 'contri-fields';
       $this->_columns['civicrm_contribution']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
     }
+
+    $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
   }
 
@@ -456,28 +468,35 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
       $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
+                   ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as avg,                                                                                                                              {$this->_aliases['civicrm_contribution']}.currency as currency                
             ";
+      $group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency";
+      $sql = "{$select} {$this->_from} {$this->_where}{$group}";
 
-      $sql = "{$select} {$this->_from} {$this->_where}";
       $dao = CRM_Core_DAO::executeQuery($sql);
-
-      if ($dao->fetch()) {
-        $statistics['counts']['amount'] = array(
-          'value' => $dao->amount,
-          'title' => 'Total Amount',
-          'type' => CRM_Utils_Type::T_MONEY,
-        );
-        $statistics['counts']['count '] = array(
-          'value' => $dao->count,
-          'title' => 'Total Donations',
-        );
-        $statistics['counts']['avg   '] = array(
-          'value' => $dao->avg,
-          'title' => 'Average',
-          'type' => CRM_Utils_Type::T_MONEY,
-        );
+      $totalAmount = $average = array();
+      $count = 0;
+      while ($dao->fetch()) {
+        $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency)."(".$dao->count.")";
+        $average[] =   CRM_Utils_Money::format($dao->avg, $dao->currency);
+        $count += $dao->count;
       }
+
+      $statistics['counts']['amount'] = array(
+        'title' => ts('Total Amount'),
+        'value' => implode(',  ', $totalAmount),
+        'type' => CRM_Utils_Type::T_STRING,
+      );
+      $statistics['counts']['count'] = array(
+        'title' => ts('Total Donations'),
+        'value' => $count,
+      );
+      $statistics['counts']['avg'] = array(
+        'title' => ts('Average'),
+        'value' => implode(',  ', $average),
+        'type' => CRM_Utils_Type::T_STRING,
+      );
+
     }
     return $statistics;
   }
index 3aabc8d1f2558899351a9784431d807b4a1ed072..7259cfe3feba24f60a825a786331ac71f8759a4c 100644 (file)
@@ -131,6 +131,10 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
         'dao' => 'CRM_Contribute_DAO_Contribution',
         'fields' =>
         array(
+          'currency' =>
+          array('required' => TRUE,
+            'no_display' => TRUE,
+          ),
           'total_amount' =>
           array('title' => ts('Amount Statistics'),
             'required' => TRUE,
@@ -143,6 +147,12 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
         ),
         'filters' =>
         array(
+          'currency' =>
+          array('title' => 'Currency',
+            'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+            'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
+            'type' => CRM_Utils_Type::T_STRING,
+          ),
           'contribution_status_id' =>
           array('title' => ts('Contribution Status'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
@@ -154,6 +164,7 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
     );
     $this->_tagFilter = TRUE;
     $this->_groupFilter = TRUE;
+    $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
   }
 
@@ -385,41 +396,50 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
 
   function statistics(&$rows) {
     $statistics = parent::statistics($rows);
-
     $select = "
         SELECT COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as count,
                IFNULL(SUM({$this->_aliases['civicrm_contribution']}.total_amount ), 0) as amount,
                IFNULL(ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2),0) as avg,
-               COUNT( DISTINCT {$this->_aliases['civicrm_membership']}.id ) as memberCount
+               COUNT( DISTINCT {$this->_aliases['civicrm_membership']}.id ) as memberCount,
+               {$this->_aliases['civicrm_contribution']}.currency as currency
         ";
 
-    $sql = "{$select} {$this->_from} {$this->_where}";
-    $dao = CRM_Core_DAO::executeQuery($sql);
+    $sql = "{$select} {$this->_from} {$this->_where}
+GROUP BY    {$this->_aliases['civicrm_contribution']}.currency 
+";
 
-    if ($dao->fetch()) {
-      $statistics['counts']['amount'] = array(
-        'value' => $dao->amount,
-        'title' => 'Total Amount',
-        'type' => CRM_Utils_Type::T_MONEY,
-      );
-      $statistics['counts']['count '] = array(
-        'value' => $dao->count,
-        'title' => 'Total Donations',
-      );
-      $statistics['counts']['memberCount'] = array(
-        'value' => $dao->memberCount,
-        'title' => 'Total Members',
-      );
-      $statistics['counts']['avg   '] = array(
-        'value' => $dao->avg,
-        'title' => 'Average',
-        'type' => CRM_Utils_Type::T_MONEY,
-      );
+    $dao = CRM_Core_DAO::executeQuery($sql);
+    
+    $totalAmount = $average = array();
+    $count = $memberCount = 0;
+    while ($dao->fetch()) {
+      $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency)."(".$dao->count.")";
+      $average[] =   CRM_Utils_Money::format($dao->avg, $dao->currency);
+      $count += $dao->count;
+      $memberCount += $dao->memberCount;
+    }
+    $statistics['counts']['amount'] = array(
+      'title' => ts('Total Amount'),
+      'value' => implode(',  ', $totalAmount),
+      'type' => CRM_Utils_Type::T_STRING,
+    );
+    $statistics['counts']['count'] = array(
+      'title' => ts('Total Donations'),
+      'value' => $count,
+    );
+    $statistics['counts']['memberCount'] = array(
+      'title' => ts('Total Members'),
+      'value' => $memberCount,
+    );
+    $statistics['counts']['avg'] = array(
+      'title' => ts('Average'),
+      'value' => implode(',  ', $average),
+      'type' => CRM_Utils_Type::T_STRING,
+    );
 
-      if (!(int)$statistics['counts']['amount']['value']) {
-        //if total amount is zero then hide Chart Options
-        $this->assign('chartSupported', FALSE);
-      }
+    if (!(int)$statistics['counts']['amount']['value']) {
+      //if total amount is zero then hide Chart Options
+      $this->assign('chartSupported', FALSE);
     }
 
     return $statistics;