Amount totals in Gift Aid Report are for 50 record subset, not total records in Batch
Unlike other reports, the Total amounts shown at the bottom of the Gift Aid report are just for the visible rows, not the total found. It appears the function "statistics(&$rows)" in CRM/Civigiftaid/Report/Form/Contribute/GiftAid.php is using the 50 visible rows, not the entire set, and needs to run its own query before returning the counts back in $statistics['counts']['giftaidamount'] etc.
This quick & dirty reworking of the function shows the correct amounts:
public function statistics(&$rows) {
$statistics = parent::statistics($rows);
$totals = [
'contribution' => 0,
'eligibleAmount' => 0,
'giftAidAmount' => 0,
];
$statisticsQuery = "
COUNT({$this->_aliases['civicrm_value_gift_aid_submission']}.amount) as civicrm_contribution_total_amount_count,
SUM({$this->_aliases['civicrm_value_gift_aid_submission']}.amount) as civicrm_contribution_total_amount_sum,
SUM({$this->_aliases['civicrm_value_gift_aid_submission']}.gift_aid_amount) as civicrm_contribution_gift_aid_amount_sum
{$this->_from} {$this->_where}
";
$statisticsSQL = "SELECT {$statisticsQuery} {$this->_having}";
$statisticsDAO = CRM_Core_DAO::executeQuery($statisticsSQL);
while ($statisticsDAO->fetch()) {
$totals['contribution'] = $statisticsDAO->civicrm_contribution_total_amount_sum;
$totals['giftAidAmount'] = $statisticsDAO->civicrm_contribution_gift_aid_amount_sum;
}
$statistics['counts']['amount'] = [
'value' => $totals['contribution'],
'title' => 'Total Donation Amount',
'type' => CRM_Utils_Type::T_MONEY
];
$statistics['counts']['giftaidamount'] = [
'value' => $totals['giftAidAmount'],
'title' => 'Total Gift Aid Amount',
'type' => CRM_Utils_Type::T_MONEY
];
return $statistics;
}
Edited by mattwire