Remove summary row from charts, when rollup used
authorAndrew West <awest@humanism.org.uk>
Wed, 27 May 2020 15:07:06 +0000 (16:07 +0100)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 29 Jun 2020 00:44:32 +0000 (10:44 +1000)
Issue: https://lab.civicrm.org/dev/report/-/issues/40

CRM/Report/Form/Contribute/Summary.php

index 79465208aa377dbb3649c3cb229696c1954cbe71..29dd59842e0bfe5f141831a2636ca192bb1596e8 100644 (file)
@@ -764,9 +764,9 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
   /**
    * Build chart.
    *
-   * @param array $rows
+   * @param array $original_rows
    */
-  public function buildChart(&$rows) {
+  public function buildChart(&$original_rows) {
     $graphRows = [];
 
     if (!empty($this->_params['charts'])) {
@@ -775,6 +775,14 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
         $contrib = !empty($this->_params['fields']['total_amount']);
         $softContrib = !empty($this->_params['fields']['soft_amount']);
 
+        // Make a copy so that we don't affect what gets passed later to hooks etc.
+        $rows = $original_rows;
+        if ($this->_rollup) {
+          // Remove the total row otherwise it overwrites the real last month's data since it has the
+          // same date.
+          array_pop($rows);
+        }
+
         foreach ($rows as $key => $row) {
           if ($row['civicrm_contribution_receive_date_subtotal']) {
             $graphRows['receive_date'][] = $row['civicrm_contribution_receive_date_start'];