3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
33 class CRM_Report_Form_Member_Detail
extends CRM_Report_Form
{
35 protected $_summary = NULL;
37 protected $_customGroupExtends = array(
46 protected $_customGroupGroupBy = FALSE;
49 * This report has not been optimised for group filtering.
51 * The functionality for group filtering has been improved but not
52 * all reports have been adjusted to take care of it. This report has not
53 * and will run an inefficient query until fixed.
59 protected $groupFilterNotOptimised = FALSE;
64 public function __construct() {
66 // Check if CiviCampaign is a) enabled and b) has active campaigns
67 $config = CRM_Core_Config
::singleton();
68 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents
);
69 if ($campaignEnabled) {
70 $getCampaigns = CRM_Campaign_BAO_Campaign
::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
71 $this->activeCampaigns
= $getCampaigns['campaigns'];
72 asort($this->activeCampaigns
);
75 $this->_columns
= array(
76 'civicrm_contact' => array(
77 'dao' => 'CRM_Contact_DAO_Contact',
78 'fields' => $this->getBasicContactFields(),
81 'title' => ts('Contact Name'),
84 'is_deleted' => array(
85 'title' => ts('Is Deleted'),
87 'type' => CRM_Utils_Type
::T_BOOLEAN
,
89 'id' => array('no_display' => TRUE),
93 'title' => ts('Last Name, First Name'),
95 'default_weight' => '0',
96 'default_order' => 'ASC',
99 'grouping' => 'contact-fields',
101 'civicrm_membership' => array(
102 'dao' => 'CRM_Member_DAO_Membership',
104 'membership_type_id' => array(
105 'title' => ts('Membership Type'),
109 'membership_start_date' => array(
110 'title' => ts('Start Date'),
113 'membership_end_date' => array(
114 'title' => ts('End Date'),
117 'join_date' => array(
118 'title' => ts('Join Date'),
121 'source' => array('title' => ts('Source')),
124 'join_date' => array('operatorType' => CRM_Report_Form
::OP_DATE
),
125 'membership_start_date' => array('operatorType' => CRM_Report_Form
::OP_DATE
),
126 'membership_end_date' => array('operatorType' => CRM_Report_Form
::OP_DATE
),
127 'owner_membership_id' => array(
128 'title' => ts('Membership Owner ID'),
129 'operatorType' => CRM_Report_Form
::OP_INT
,
132 'name' => 'membership_type_id',
133 'title' => ts('Membership Types'),
134 'type' => CRM_Utils_Type
::T_INT
,
135 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
136 'options' => CRM_Member_PseudoConstant
::membershipType(),
139 'order_bys' => array(
140 'membership_type_id' => array(
141 'title' => ts('Membership Type'),
143 'default_weight' => '1',
144 'default_order' => 'ASC',
147 'grouping' => 'member-fields',
148 'group_bys' => array(
150 'title' => ts('Membership'),
155 'civicrm_membership_status' => array(
156 'dao' => 'CRM_Member_DAO_MembershipStatus',
157 'alias' => 'mem_status',
160 'title' => ts('Status'),
167 'title' => ts('Status'),
168 'type' => CRM_Utils_Type
::T_INT
,
169 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
170 'options' => CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'label'),
173 'grouping' => 'member-fields',
175 'civicrm_email' => array(
176 'dao' => 'CRM_Core_DAO_Email',
177 'fields' => array('email' => NULL),
178 'grouping' => 'contact-fields',
180 'civicrm_phone' => array(
181 'dao' => 'CRM_Core_DAO_Phone',
182 'fields' => array('phone' => NULL),
183 'grouping' => 'contact-fields',
185 'civicrm_contribution' => array(
186 'dao' => 'CRM_Contribute_DAO_Contribution',
188 'contribution_id' => array(
190 'no_display' => TRUE,
193 'financial_type_id' => array('title' => ts('Financial Type')),
194 'contribution_status_id' => array('title' => ts('Contribution Status')),
195 'payment_instrument_id' => array('title' => ts('Payment Type')),
198 'no_display' => TRUE,
201 'receive_date' => NULL,
202 'receipt_date' => NULL,
203 'fee_amount' => NULL,
204 'net_amount' => NULL,
205 'total_amount' => array(
206 'title' => ts('Payment Amount (most recent)'),
207 'statistics' => array('sum' => ts('Amount')),
211 'receive_date' => array('operatorType' => CRM_Report_Form
::OP_DATE
),
212 'financial_type_id' => array(
213 'title' => ts('Financial Type'),
214 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
215 'options' => CRM_Contribute_PseudoConstant
::financialType(),
216 'type' => CRM_Utils_Type
::T_INT
,
218 'payment_instrument_id' => array(
219 'title' => ts('Payment Type'),
220 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
221 'options' => CRM_Contribute_PseudoConstant
::paymentInstrument(),
222 'type' => CRM_Utils_Type
::T_INT
,
225 'title' => ts('Currency'),
226 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
227 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
229 'type' => CRM_Utils_Type
::T_STRING
,
231 'contribution_status_id' => array(
232 'title' => ts('Contribution Status'),
233 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
234 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
235 'type' => CRM_Utils_Type
::T_INT
,
237 'total_amount' => array('title' => ts('Contribution Amount')),
239 'order_bys' => array(
240 'receive_date' => array(
241 'title' => ts('Date Received'),
242 'default_weight' => '2',
243 'default_order' => 'DESC',
246 'grouping' => 'contri-fields',
248 ) +
$this->getAddressColumns(array(
249 // These options are only excluded because they were not previously present.
253 $this->_groupFilter
= TRUE;
254 $this->_tagFilter
= TRUE;
256 // If we have active campaigns add those elements to both the fields and filters
257 if ($campaignEnabled && !empty($this->activeCampaigns
)) {
258 $this->_columns
['civicrm_membership']['fields']['campaign_id'] = array(
259 'title' => ts('Campaign'),
260 'default' => 'false',
262 $this->_columns
['civicrm_membership']['filters']['campaign_id'] = array(
263 'title' => ts('Campaign'),
264 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
265 'options' => $this->activeCampaigns
,
266 'type' => CRM_Utils_Type
::T_INT
,
268 $this->_columns
['civicrm_membership']['order_bys']['campaign_id'] = array('title' => ts('Campaign'));
272 $this->_currencyColumn
= 'civicrm_contribution_currency';
273 parent
::__construct();
276 public function preProcess() {
277 $this->assign('reportTitle', ts('Membership Detail Report'));
278 parent
::preProcess();
281 public function from() {
282 $this->setFromBase('civicrm_contact');
285 INNER JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
286 ON {$this->_aliases['civicrm_contact']}.id =
287 {$this->_aliases['civicrm_membership']}.contact_id AND {$this->_aliases['civicrm_membership']}.is_test = 0
288 LEFT JOIN civicrm_membership_status {$this->_aliases['civicrm_membership_status']}
289 ON {$this->_aliases['civicrm_membership_status']}.id =
290 {$this->_aliases['civicrm_membership']}.status_id ";
292 $this->joinAddressFromContact();
293 $this->joinPhoneFromContact();
294 $this->joinEmailFromContact();
296 //used when contribution field is selected.
297 if ($this->isTableSelected('civicrm_contribution')) {
299 LEFT JOIN civicrm_membership_payment cmp
300 ON {$this->_aliases['civicrm_membership']}.id = cmp.membership_id
301 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
302 ON cmp.contribution_id={$this->_aliases['civicrm_contribution']}.id\n";
307 * Alter display of rows.
309 * Iterate through the rows retrieved via SQL and make changes for display purposes,
310 * such as rendering contacts as links.
313 * Rows generated by SQL, with an array for each row.
315 public function alterDisplay(&$rows) {
317 $checkList = array();
319 $contributionTypes = CRM_Contribute_PseudoConstant
::financialType();
320 $contributionStatus = CRM_Contribute_PseudoConstant
::contributionStatus();
321 $paymentInstruments = CRM_Contribute_PseudoConstant
::paymentInstrument();
323 $repeatFound = FALSE;
324 foreach ($rows as $rowNum => $row) {
325 if ($repeatFound == FALSE ||
326 $repeatFound < $rowNum - 1
329 $checkList = array();
331 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
332 // not repeat contact display names if it matches with the one
334 foreach ($row as $colName => $colVal) {
335 if (in_array($colName, $this->_noRepeats
) &&
338 if ($rows[$rowNum][$colName] == $rows[$rowNum - 1][$colName] ||
339 (!empty($checkList[$colName]) &&
340 in_array($colVal, $checkList[$colName]))
342 $rows[$rowNum][$colName] = "";
343 // CRM-15917: Don't blank the name if it's a different contact
344 if ($colName == 'civicrm_contact_exposed_id') {
345 $rows[$rowNum]['civicrm_contact_sort_name'] = "";
347 $repeatFound = $rowNum;
350 if (in_array($colName, $this->_noRepeats
)) {
351 $checkList[$colName][] = $colVal;
356 if (array_key_exists('civicrm_membership_membership_type_id', $row)) {
357 if ($value = $row['civicrm_membership_membership_type_id']) {
358 $rows[$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant
::membershipType($value, FALSE);
363 if (array_key_exists('civicrm_address_state_province_id', $row)) {
364 if ($value = $row['civicrm_address_state_province_id']) {
365 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
370 if (array_key_exists('civicrm_address_country_id', $row)) {
371 if ($value = $row['civicrm_address_country_id']) {
372 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
377 if (array_key_exists('civicrm_contact_sort_name', $row) &&
378 $rows[$rowNum]['civicrm_contact_sort_name'] &&
379 array_key_exists('civicrm_contact_id', $row)
381 $url = CRM_Utils_System
::url("civicrm/contact/view",
382 'reset=1&cid=' . $row['civicrm_contact_id'],
385 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
386 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
390 if ($value = CRM_Utils_Array
::value('civicrm_contribution_financial_type_id', $row)) {
391 $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value];
394 if ($value = CRM_Utils_Array
::value('civicrm_contribution_contribution_status_id', $row)) {
395 $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
398 if ($value = CRM_Utils_Array
::value('civicrm_contribution_payment_instrument_id', $row)) {
399 $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value];
403 // Convert campaign_id to campaign title
404 if (array_key_exists('civicrm_membership_campaign_id', $row)) {
405 if ($value = $row['civicrm_membership_campaign_id']) {
406 $rows[$rowNum]['civicrm_membership_campaign_id'] = $this->activeCampaigns
[$value];
410 $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'member/detail', 'List all memberships(s) for this ') ?
TRUE : $entryFound;
411 $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'member/detail', 'List all memberships(s) for this ') ?
TRUE : $entryFound;