From 06d4bf4d6b1214dd9770d4d1610c609efc6b21b1 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 6 Dec 2017 18:48:31 -0800 Subject: [PATCH] Revert "CRM-19060 fix Payment table join in membership Detail report to ensure latest membership payment is picked up" This reverts commit 9b213560fe662e0fc7626226ff70266779c8599a. --- CRM/Report/Form/Member/Detail.php | 47 +++---------------------------- 1 file changed, 4 insertions(+), 43 deletions(-) diff --git a/CRM/Report/Form/Member/Detail.php b/CRM/Report/Form/Member/Detail.php index 1d0d1a026b..9a145dbc7b 100644 --- a/CRM/Report/Form/Member/Detail.php +++ b/CRM/Report/Form/Member/Detail.php @@ -347,15 +347,13 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n"; } - //used when contribution field is selected. + //used when contribution field is selected if ($this->_contribField) { - $contribution_table_join = $this->contributionTableJoin(); $this->_from .= " - LEFT JOIN $contribution_table_join as max_payment - ON max_payment.entity_id = {$this->_aliases['civicrm_membership']}.id + LEFT JOIN civicrm_membership_payment cmp + ON {$this->_aliases['civicrm_membership']}.id = cmp.membership_id LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} - ON max_payment.contact_id = {$this->_aliases['civicrm_contribution']}.contact_id - AND max_payment.receive_date = {$this->_aliases['civicrm_contribution']}.receive_date\n"; + ON cmp.contribution_id={$this->_aliases['civicrm_contribution']}.id\n"; } } @@ -488,41 +486,4 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { } } - /** - * Create temporary table to get most recent - * contribution for each contact and membership type. - * - * @return string $tempTable. - */ - public function contributionTableJoin() { - static $tempTable = NULL; - if (!empty($tempTable)) { - return $tempTable; - } - $params = $this->_params; - $receive_date_relative = empty($params['receive_date_relative']) ? '' : $params['receive_date_relative']; - $receive_date_from = empty($params['receive_date_from']) ? '' : $params['receive_date_from']; - $receive_date_to = empty($params['receive_date_to']) ? '' : $params['receive_date_to']; - $dateFilter = parent::dateClause('receive_date', $receive_date_relative, - $receive_date_from, $receive_date_to); - if ($dateFilter) { - $dateWhere = 'AND ' . str_replace('receive_date', 'cc.receive_date', $dateFilter); - } - else { - $dateWhere = ''; - } - $tempTable = CRM_Core_DAO::createTempTableName('civicrm_report_memcontr', TRUE); - $sql = " - CREATE TEMPORARY TABLE $tempTable (index (contact_id, receive_date, entity_id)) - SELECT cc.contact_id, max(cc.receive_date) as receive_date, cmp.membership_id as entity_id - FROM civicrm_membership_payment cmp - INNER JOIN civicrm_contribution cc - ON cc.id = cmp.contribution_id - WHERE cc.is_test = 0 - $dateWhere - GROUP BY cc.contact_id"; - CRM_Core_DAO::executeQuery($sql); - return $tempTable; - } - } -- 2.25.1