CRM-16636 duplicate primary addresses causes error in report
authorWeb Access <rohan.katkar@webaccessglobal.com>
Mon, 15 Jun 2015 14:26:48 +0000 (19:56 +0530)
committerWeb Access <rohan.katkar@webaccessglobal.com>
Mon, 15 Jun 2015 14:26:48 +0000 (19:56 +0530)
CRM/Report/Form/Member/ContributionDetail.php

index c94be558449a4b6fd927c8e045865aa9be7a6ad6..965da7783c826e91c8919d2bf0ac47bd7c60ca1c 100644 (file)
@@ -610,10 +610,13 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
   public function statistics(&$rows) {
     $statistics = parent::statistics($rows);
 
-    $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                                                                                                                                       ";
+    $select = "SELECT DISTINCT {$this->_aliases['civicrm_contribution']}.id";
 
-    $group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency";
-    $sql = "{$select} {$this->_from} {$this->_where} {$group}";
+    $group = "\nGROUP BY cc.currency";
+
+    $sql = "SELECT COUNT(cc.id) as count, SUM( cc.total_amount ) as amount, ROUND(AVG(cc.total_amount), 2) as avg, cc.currency as currency
+            FROM civicrm_contribution cc
+            WHERE cc.id IN ({$select} {$this->_from} {$this->_where}) {$group}";
 
     $dao = CRM_Core_DAO::executeQuery($sql);
     $totalAmount = $average = array();