From ff94a23fe2e8160671e0a17622b94f9eebae53b9 Mon Sep 17 00:00:00 2001 From: Edsel Date: Fri, 22 May 2015 17:13:42 +0530 Subject: [PATCH] ICM-14 Fixed stats on contribution tab --- CRM/Contact/BAO/Query.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 47a9892457..4f39cdc132 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4747,6 +4747,13 @@ SELECT COUNT( conts.total_amount ) as total_count, if ($context == 'search') { $where .= " AND contact_a.is_deleted = 0 "; } + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes); + if (!empty($financialTypes)) { + $where .= " AND civicrm_contribution.financial_type_id IN (" . implode(',' , array_keys($financialTypes)) . ") AND li.id IS NULL"; + } + else { + $where .= " AND civicrm_contribution.financial_type_id IN (0) AND li.financial_type_id IN (0)"; + } // make sure contribution is completed - CRM-4989 $completedWhere = $where . " AND civicrm_contribution.contribution_status_id = 1 "; @@ -4756,7 +4763,9 @@ SELECT COUNT( conts.total_amount ) as total_count, $summary['total']['count'] = $summary['total']['amount'] = $summary['total']['avg'] = "n/a"; $innerQuery = "SELECT civicrm_contribution.total_amount, COUNT(civicrm_contribution.total_amount) as civicrm_contribution_total_amount_count, civicrm_contribution.currency $from $completedWhere"; - + $from .= " LEFT JOIN civicrm_line_item li + ON civicrm_contribution.id = li.contribution_id AND + li.entity_table = 'civicrm_contribution' AND li.financial_type_id NOT IN (" . implode(',' , array_keys($financialTypes)) . ") "; $query = "$select FROM ( $innerQuery GROUP BY civicrm_contribution.id ) as conts -- 2.25.1