CRM-9394
authoryashodha <yashodha.chaku@webaccess.co.in>
Fri, 15 Mar 2013 10:51:39 +0000 (16:21 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Sun, 17 Mar 2013 15:57:56 +0000 (21:27 +0530)
CRM/Report/Form/Contribute/SoftCredit.php

index c3e6d4d9e8b30a7ea7e80d733dd365bc0547bfc6..9c713e32773c35cd52d4a250dc813effd1e65db0 100644 (file)
@@ -145,6 +145,10 @@ class CRM_Report_Form_Contribute_SoftCredit extends CRM_Report_Form {
         'fields' =>
         array(
           'contribution_source' => NULL,
+          'currency' => array(
+            'required' => TRUE,
+            'no_display' => TRUE,
+          ),
           'total_amount' =>
           array('title' => ts('Amount Statistics'),
             'default' => TRUE,
@@ -160,6 +164,12 @@ class CRM_Report_Form_Contribute_SoftCredit extends CRM_Report_Form {
         array(
           'receive_date' =>
           array('operatorType' => CRM_Report_Form::OP_DATE),
+          '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('Donation Status'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
@@ -208,6 +218,8 @@ class CRM_Report_Form_Contribute_SoftCredit extends CRM_Report_Form {
     );
 
     $this->_tagFilter = TRUE;
+
+    $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
   }
 
@@ -280,7 +292,7 @@ class CRM_Report_Form_Contribute_SoftCredit extends CRM_Report_Form {
       }
     }
 
-    $this->_select = "SELECT " . implode(', ', $select) . " ";
+    $this->_select = 'SELECT ' . implode(', ', $select) . ' ';
   }
 
   static function formRule($fields, $files, $self) {
@@ -349,7 +361,7 @@ class CRM_Report_Form_Contribute_SoftCredit extends CRM_Report_Form {
   }
 
   function groupBy() {
-    $this->_rollup     = "WITH ROLLUP";
+    $this->_rollup     = 'WITH ROLLUP';
     $this->_groupBy    = "
 GROUP BY {$this->_aliases['civicrm_contribution_soft']}.contact_id, constituentname.id {$this->_rollup}";
   }
@@ -365,28 +377,35 @@ GROUP BY {$this->_aliases['civicrm_contribution_soft']}.contact_id, constituentn
     $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
         ";
 
-    $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']['avg   '] = array(
-        'value' => $dao->avg,
-        'title' => 'Average',
-        'type' => CRM_Utils_Type::T_MONEY,
-      );
+    $dao = CRM_Core_DAO::executeQuery($sql);
+    $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;
   }
@@ -436,7 +455,7 @@ GROUP BY {$this->_aliases['civicrm_contribution_soft']}.contact_id, constituentn
           $this->_absoluteUrl, $this->_id, $this->_drilldownReport
         );
         $rows[$rowNum]['civicrm_contact_display_name_constituent_link'] = $url;
-        $rows[$rowNum]['civicrm_contact_display_name_constituent_hover'] = ts("List all direct contribution(s) from this contact.");
+        $rows[$rowNum]['civicrm_contact_display_name_constituent_hover'] = ts('List all direct contribution(s) from this contact.');
         $entryFound = TRUE;
       }