From ea9ec5790dea13ddb9eb0bc312926680e8e75ca0 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Tue, 17 Nov 2015 15:30:08 -0500 Subject: [PATCH] CRM-17586 - ensure total goal is accurate. --- CRM/Report/Form/Contribute/PCP.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/CRM/Report/Form/Contribute/PCP.php b/CRM/Report/Form/Contribute/PCP.php index 93e875e1c2..8ed35a035f 100644 --- a/CRM/Report/Form/Contribute/PCP.php +++ b/CRM/Report/Form/Contribute/PCP.php @@ -264,32 +264,48 @@ LEFT JOIN civicrm_contribution_page {$this->_aliases['civicrm_contribution_page' public function statistics(&$rows) { $statistics = parent::statistics($rows); + // Calculate totals from the civicrm_contribution_soft table. $select - = "SELECT SUM({$this->_aliases['civicrm_pcp']}.goal_amount) as goal_total, " . - "SUM({$this->_aliases['civicrm_contribution_soft']}.amount) as committed_total, " . + = "SELECT SUM({$this->_aliases['civicrm_contribution_soft']}.amount) as committed_total, " . "COUNT({$this->_aliases['civicrm_contribution_soft']}.id) as donors_total, " . "SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount)) AS received_total "; $sql = "{$select} {$this->_from} {$this->_where}"; $dao = CRM_Core_DAO::executeQuery($sql); $dao->fetch(); + $committed_total = $dao->committed_total; + $received_total = $dao->received_total; + $donors_total = $dao->donors_total; + + // Calculate goal total goal from the PCP table (we only want one result per + // PCP page - the query above produces one result per contribution made). + $sql = + "SELECT SUM(goal_amount) as goal_total FROM civicrm_pcp WHERE ". + "goal_amount IS NOT NULL AND id IN (" . + "SELECT DISTINCT {$this->_aliases['civicrm_pcp']}.id {$this->_from} ". + "{$this->_where}". + ")"; + $dao = CRM_Core_DAO::executeQuery($sql); + $dao->fetch(); + $goal_total = $dao->goal_total; + $statistics['counts']['goal_total'] = array( 'title' => ts('Goal Total'), - 'value' => $dao->goal_total, + 'value' => $goal_total, 'type' => CRM_Utils_Type::T_MONEY, ); $statistics['counts']['committed_total'] = array( 'title' => ts('Total Committed'), - 'value' => $dao->committed_total, + 'value' => $committed_total, 'type' => CRM_Utils_Type::T_MONEY, ); $statistics['counts']['received_total'] = array( 'title' => ts('Total Received'), - 'value' => $dao->received_total, + 'value' => $received_total, 'type' => CRM_Utils_Type::T_MONEY, ); $statistics['counts']['donors_total'] = array( 'title' => ts('Total Donors'), - 'value' => $dao->donors_total, + 'value' => $donors_total, 'type' => CRM_Utils_Type::T_INT, ); return $statistics; -- 2.25.1