From c93f6d836db246bfe3aea047f57d0368a5b4d439 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Wed, 6 Nov 2013 13:23:37 -0800 Subject: [PATCH] CRM-13715 - Add custom field column to Contribution Details report crashes http://issues.civicrm.org/jira/browse/CRM-13715 --- CRM/Report/Form.php | 10 +++++----- CRM/Report/Form/Contribute/Detail.php | 8 +++++--- CRM/Report/Form/Contribute/Summary.php | 14 +++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 6b353d5cdb..e48b71ffba 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -514,7 +514,7 @@ class CRM_Report_Form extends CRM_Core_Form { } // a few auto fills for filters - if ($fieldGrp == 'filters') { + if ($fieldGrp == 'filters') { // fill operator types if (!array_key_exists('operatorType', $this->_columns[$tableName][$fieldGrp][$fieldName])) { switch (CRM_Utils_Array::value('type', $this->_columns[$tableName][$fieldGrp][$fieldName])) { @@ -526,18 +526,18 @@ class CRM_Report_Form extends CRM_Core_Form { $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_INT; break; case CRM_Utils_Type::T_DATE: - $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_DATE; + $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_DATE; break; case CRM_Utils_Type::T_BOOLEAN: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_SELECT; if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) { - $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] = + $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] = array('' => ts('Any'), '0' => ts('No'), '1' => ts('Yes')); } break; default: - if ($daoOrBaoName && - (array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName]) + if ($daoOrBaoName && + (array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName]) || array_key_exists('enumValues', $this->_columns[$tableName][$fieldGrp][$fieldName])) ) { // with multiple options operator-type is generally multi-select diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index b3c68d9e00..9afbc1db00 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -43,8 +43,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { protected $_summary = NULL; protected $_allBatches = NULL; - protected $_customGroupExtends = array( - 'Contribution'); + protected $_customGroupExtends = array( 'Contribution'); function __construct() { @@ -604,7 +603,10 @@ GROUP BY {$this->_aliases['civicrm_contribution']}.currency"; // copy _from for later use of stats calculation for soft credits, and reset $this->_from to main query $this->_softFrom = $this->_from; - $this->from(); // simple reset of ->_from + + // simple reset of ->_from + $this->from(); + $this->customDataFrom(); // 3. Decide where to populate temp3 table from if (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) == 'contributions_only') { diff --git a/CRM/Report/Form/Contribute/Summary.php b/CRM/Report/Form/Contribute/Summary.php index a968fcbb3a..7d01d875d9 100644 --- a/CRM/Report/Form/Contribute/Summary.php +++ b/CRM/Report/Form/Contribute/Summary.php @@ -175,7 +175,7 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form { 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionPage(), 'type' => CRM_Utils_Type::T_INT, - ), + ), 'total_amount' => array('title' => ts('Contribution Amount'), ), @@ -429,7 +429,7 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form { function from() { $softCreditJoin = "LEFT"; - if (CRM_Utils_Array::value('soft_amount', $this->_params['fields']) && + if (CRM_Utils_Array::value('soft_amount', $this->_params['fields']) && !CRM_Utils_Array::value('total_amount', $this->_params['fields'])) { // if its only soft credit stats, use inner join $softCreditJoin = "INNER"; @@ -514,21 +514,21 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form { $softCredit = CRM_Utils_Array::value('soft_amount', $this->_params['fields']); $onlySoftCredit = $softCredit && !CRM_Utils_Array::value('total_amount', $this->_params['fields']); - $select = "SELECT + $select = "SELECT COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as civicrm_contribution_total_amount_count, SUM({$this->_aliases['civicrm_contribution']}.total_amount ) as civicrm_contribution_total_amount_sum, ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as civicrm_contribution_total_amount_avg, {$this->_aliases['civicrm_contribution']}.currency as currency"; if ($softCredit) { - $select .= ", + $select .= ", COUNT({$this->_aliases['civicrm_contribution_soft']}.amount ) as civicrm_contribution_soft_soft_amount_count, SUM({$this->_aliases['civicrm_contribution_soft']}.amount ) as civicrm_contribution_soft_soft_amount_sum, ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_contribution_soft_soft_amount_avg"; } $group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency"; $sql = "{$select} {$this->_from} {$this->_where} {$group} {$this->_having}"; - + $dao = CRM_Core_DAO::executeQuery($sql); $totalAmount = $average = $softTotalAmount = $softAverage = array(); $count = $softCount = 0; @@ -536,14 +536,14 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_ $totalAmount[] = CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->currency)." (".$dao->civicrm_contribution_total_amount_count.")"; $average[] = CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_avg, $dao->currency); $count += $dao->civicrm_contribution_total_amount_count; - + if ($softCredit) { $softTotalAmount[] = CRM_Utils_Money::format($dao->civicrm_contribution_soft_soft_amount_sum, $dao->currency)." (".$dao->civicrm_contribution_soft_soft_amount_count.")"; $softAverage[] = CRM_Utils_Money::format($dao->civicrm_contribution_soft_soft_amount_avg, $dao->currency); $softCount += $dao->civicrm_contribution_soft_soft_amount_count; } } - + if (!$onlySoftCredit) { $statistics['counts']['amount'] = array( 'title' => ts('Total Amount'), -- 2.25.1