dev/core#326: Fix for fatal error in section headers.
authorAllen Shaw <allen@JoineryHQ.com>
Tue, 28 Aug 2018 13:32:05 +0000 (08:32 -0500)
committereileen <emcnaughton@wikimedia.org>
Tue, 4 Sep 2018 00:27:28 +0000 (12:27 +1200)
CRM/Report/Form/Contribute/Detail.php
tests/phpunit/api/v3/ReportTemplateTest.php

index 8b0d9d99733c8f7cfc746476058adf487cdcf0fa..2369127d1aedaa8c5b40105a5ff382ee04e573f3 100644 (file)
@@ -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;
       }
 
index 95c9e550d076ce16ce5aefd43ee7d1f9b6423599..d818c4800c1424cb8833e59efd456cfb6b78c796 100644 (file)
@@ -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')),
+    ));
+  }
+
 }