SELECT COUNT( conts.total_amount ) as total_count,
SUM( conts.total_amount ) as total_amount,
AVG( conts.total_amount ) as total_avg,
+ conts.total_amount as amount,
conts.currency as currency";
if ($this->_permissionWhereClause) {
$where .= " AND " . $this->_permissionWhereClause;
$summary = array();
$summary['total'] = array();
$summary['total']['count'] = $summary['total']['amount'] = $summary['total']['avg'] = "n/a";
+ $innerQuery = "SELECT civicrm_contribution.total_amount, COUNT(civicrm_contribution.total_amount) as civicrm_contribution_total_amount_count,
+ civicrm_contribution.currency $from $completedWhere";
$query = "$select FROM (
- SELECT civicrm_contribution.total_amount, civicrm_contribution.currency $from $completedWhere
- GROUP BY civicrm_contribution.id
+ $innerQuery GROUP BY civicrm_contribution.id
) as conts
GROUP BY currency";
$summary['total']['amount'][] = CRM_Utils_Money::format($dao->total_amount, $dao->currency);
$summary['total']['avg'][] = CRM_Utils_Money::format($dao->total_avg, $dao->currency);
}
+
+ $orderBy = 'ORDER BY civicrm_contribution_total_amount_count DESC';
+ $groupBy = 'GROUP BY civicrm_contribution.total_amount';
+ $modeSQL = "$select, conts.civicrm_contribution_total_amount_count as civicrm_contribution_total_amount_count FROM ($innerQuery
+ $groupBy $orderBy) as conts
+ GROUP BY currency";
+
+ $summary['total']['mode'] = CRM_Contribute_BAO_Contribution::computeStats('mode', $modeSQL);
+
+ $medianSQL = "{$from} {$completedWhere}";
+ $summary['total']['median'] = CRM_Contribute_BAO_Contribution::computeStats('median', $medianSQL, 'civicrm_contribution');
+ $summary['total']['currencyCount'] = count($summary['total']['median']);
+
if (!empty($summary['total']['amount'])) {
$summary['total']['amount'] = implode(', ', $summary['total']['amount']);
$summary['total']['avg'] = implode(', ', $summary['total']['avg']);
+ $summary['total']['mode'] = implode(', ', $summary['total']['mode']);
+ $summary['total']['median'] = implode(', ', $summary['total']['median']);
}
else {
- $summary['total']['amount'] = $summary['total']['avg'] = 0;
+ $summary['total']['amount'] = $summary['total']['avg'] = $summary['total']['median'] = 0;
}
// soft credit summary
{if $contributionSummary }
<tr>
{if $contributionSummary.total.amount}
- <th class="contriTotalLeft right">{ts}Total Amount{/ts} - {$contributionSummary.total.amount}</th>
- <th class="right"> {ts}# Completed Contributions{/ts} - {$contributionSummary.total.count}</th>
- <th class="right contriTotalRight"> {ts}Avg Amount{/ts} - {$contributionSummary.total.avg}</th>
+ {if $contributionSummary.total.currencyCount gt 1}
+ <th class="contriTotalLeft right">{ts}Total{/ts} - {$contributionSummary.total.amount}</th>
+ <th class="left contriTotalRight"> {ts}# Completed{/ts} - {$contributionSummary.total.count}</th>
+ </tr><tr>
+ <th class="contriTotalLeft">{ts}Avg{/ts} - {$contributionSummary.total.avg}</th>
+ <th class="right"> {ts}Median{/ts} - {$contributionSummary.total.median}</th>
+ <th class="right contriTotalRight"> {ts}Mode{/ts} - {$contributionSummary.total.mode}</th>
+ {else}
+ <th class="contriTotalLeft right">{ts}Total{/ts} - {$contributionSummary.total.amount}</th>
+ <th class="right"> {ts}# Completed{/ts} - {$contributionSummary.total.count}</th>
+ <th class="right"> {ts}Avg{/ts} - {$contributionSummary.total.avg}</th>
+ <th class="right"> {ts}Median{/ts} - {$contributionSummary.total.median}</th>
+ <th class="right contriTotalRight"> {ts}Mode{/ts} - {$contributionSummary.total.mode}</th>
+ {/if}
{/if}
{if $contributionSummary.cancel.amount}
<th class="disabled right contriTotalRight"> {ts}Total Cancelled Amount{/ts} - {$contributionSummary.cancel.amount}</th>