From 17c0ca6f0c8f3c9330010dfa997938d664914e14 Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Tue, 28 Aug 2018 08:32:05 -0500 Subject: [PATCH] dev/core#326: Fix for fatal error in section headers. --- CRM/Report/Form/Contribute/Detail.php | 10 +++++++-- tests/phpunit/api/v3/ReportTemplateTest.php | 25 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 8b0d9d9973..2369127d1a 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -823,6 +823,12 @@ WHERE civicrm_contribution_contribution_id={$row['civicrm_contribution_contribu // pull section aliases out of $this->_sections $sectionAliases = array_keys($this->_sections); + // hack alert - but it's tested so go forth & make pretty, or whack the new mole that popped up with gay abandon. + if (in_array('civicrm_contribution_total_amount', $this->_selectAliases)) { + $keyToHack = array_search('civicrm_contribution_total_amount', $this->_selectAliases); + $this->_selectAliases[$keyToHack] = 'civicrm_contribution_total_amount_sum'; + } + $ifnulls = array(); foreach (array_merge($sectionAliases, $this->_selectAliases) as $alias) { $ifnulls[] = "ifnull($alias, '') as $alias"; @@ -837,10 +843,10 @@ WHERE civicrm_contribution_contribution_id={$row['civicrm_contribution_contribu $addtotals = ''; - if (array_search("civicrm_contribution_total_amount", $this->_selectAliases) !== + if (array_search("civicrm_contribution_total_amount_sum", $this->_selectAliases) !== FALSE ) { - $addtotals = ", sum(civicrm_contribution_total_amount) as sumcontribs"; + $addtotals = ", sum(civicrm_contribution_total_amount_sum) as sumcontribs"; $showsumcontribs = TRUE; } diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 95c9e550d0..d818c4800c 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -906,4 +906,29 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { ]); } + /** + * Test the group filter works on the contribution summary. + */ + public function testContributionDetailTotalHeader() { + $contactID = $this->individualCreate(); + $contactID2 = $this->individualCreate(); + $this->contributionCreate(['contact_id' => $contactID, 'api.ContributionSoft.create' => ['amount' => 5, 'contact_id' => $contactID2]]); + $template = 'contribute/detail'; + $rows = $this->callAPISuccess('report_template', 'getrows', array( + 'report_id' => $template, + 'contribution_or_soft_value' => 'contributions_only', + 'fields' => [ + 'sort_name' => '1', + 'age' => '1', + 'email' => '1', + 'phone' => '1', + 'financial_type_id' => '1', + 'receive_date' => '1', + 'total_amount' => '1', + ], + 'order_bys' => [['column' => 'sort_name', 'order' => 'ASC', 'section' => '1']], + 'options' => array('metadata' => array('sql')), + )); + } + } -- 2.25.1