Skip to content

Commit

Permalink
Merge pull request #15435 from MegaphoneJon/reporting-21
Browse files Browse the repository at this point in the history
reporting#21 - don't multiple contribution details when a 1-to-many r…
  • Loading branch information
eileenmcnaughton authored Jul 13, 2020
2 parents 755efeb + 22da2be commit 64aa560
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions CRM/Report/Form/Contribute/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,17 +418,21 @@ public function statistics(&$rows) {
$totalAmount = $average = $fees = $net = [];
$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,
SUM( {$this->_aliases['civicrm_contribution']}.fee_amount ) as fees,
SUM( {$this->_aliases['civicrm_contribution']}.net_amount ) as net
SELECT COUNT(civicrm_contribution_total_amount ) as count,
SUM( civicrm_contribution_total_amount ) as amount,
ROUND(AVG(civicrm_contribution_total_amount), 2) as avg,
stats.currency as currency,
SUM( stats.fee_amount ) as fees,
SUM( stats.net_amount ) as net
";

$group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency";
$sql = "{$select} {$this->_from} {$this->_where} {$group}";
$group = "\nGROUP BY civicrm_contribution_currency";
$from = " FROM {$this->temporaryTables['civireport_contribution_detail_temp3']['name']} "
. "JOIN civicrm_contribution stats ON {$this->temporaryTables['civireport_contribution_detail_temp3']['name']}.civicrm_contribution_contribution_id = stats.id ";
$sql = "{$select} {$from} {$group} ";
CRM_Core_DAO::disableFullGroupByMode();
$dao = CRM_Core_DAO::executeQuery($sql);
CRM_Core_DAO::reenableFullGroupByMode();
$this->addToDeveloperTab($sql);

while ($dao->fetch()) {
Expand Down

0 comments on commit 64aa560

Please sign in to comment.