Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | class CRM_Report_Form_Member_Detail extends CRM_Report_Form { | |
34 | ||
6a488035 TO |
35 | protected $_summary = NULL; |
36 | ||
804f9330 DJ |
37 | protected $_customGroupExtends = array( |
38 | 'Membership', | |
39 | 'Contribution', | |
40 | 'Contact', | |
41 | 'Individual', | |
42 | 'Household', | |
43 | 'Organization', | |
44 | ); | |
45 | ||
f813f78e | 46 | protected $_customGroupGroupBy = FALSE; |
47 | ||
1728e9a0 | 48 | /** |
49 | * This report has not been optimised for group filtering. | |
50 | * | |
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. | |
54 | * | |
55 | * CRM-19170 | |
56 | * | |
57 | * @var bool | |
58 | */ | |
eae0f0d9 | 59 | protected $groupFilterNotOptimised = FALSE; |
1728e9a0 | 60 | |
74cf4551 | 61 | /** |
e5575773 | 62 | * Class constructor. |
74cf4551 | 63 | */ |
00be9182 | 64 | public function __construct() { |
6a488035 | 65 | $this->_columns = array( |
1e887757 EM |
66 | 'civicrm_contact' => array( |
67 | 'dao' => 'CRM_Contact_DAO_Contact', | |
e5575773 | 68 | 'fields' => $this->getBasicContactFields(), |
1e887757 EM |
69 | 'filters' => array( |
70 | 'sort_name' => array( | |
71 | 'title' => ts('Contact Name'), | |
72 | 'operator' => 'like', | |
73 | ), | |
bc390081 JP |
74 | 'is_deleted' => array( |
75 | 'title' => ts('Is Deleted'), | |
76 | 'default' => 0, | |
77 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
78 | ), | |
1e887757 EM |
79 | 'id' => array('no_display' => TRUE), |
80 | ), | |
81 | 'order_bys' => array( | |
82 | 'sort_name' => array( | |
83 | 'title' => ts('Last Name, First Name'), | |
84 | 'default' => '1', | |
85 | 'default_weight' => '0', | |
21dfd5f5 | 86 | 'default_order' => 'ASC', |
8cab7c88 | 87 | ), |
6a488035 | 88 | ), |
1e887757 EM |
89 | 'grouping' => 'contact-fields', |
90 | ), | |
8cab7c88 EM |
91 | 'civicrm_membership' => array( |
92 | 'dao' => 'CRM_Member_DAO_Membership', | |
93 | 'fields' => array( | |
94 | 'membership_type_id' => array( | |
ccc29f8e | 95 | 'title' => ts('Membership Type'), |
8cab7c88 EM |
96 | 'required' => TRUE, |
97 | 'no_repeat' => TRUE, | |
98 | ), | |
99 | 'membership_start_date' => array( | |
100 | 'title' => ts('Start Date'), | |
101 | 'default' => TRUE, | |
102 | ), | |
103 | 'membership_end_date' => array( | |
104 | 'title' => ts('End Date'), | |
105 | 'default' => TRUE, | |
106 | ), | |
950351e3 AP |
107 | 'owner_membership_id' => array( |
108 | 'title' => ts('Primary/Inherited?'), | |
109 | 'default' => TRUE, | |
110 | ), | |
8cab7c88 EM |
111 | 'join_date' => array( |
112 | 'title' => ts('Join Date'), | |
113 | 'default' => TRUE, | |
114 | ), | |
ccc29f8e | 115 | 'source' => array('title' => ts('Source')), |
244200e1 | 116 | ), |
8cab7c88 EM |
117 | 'filters' => array( |
118 | 'join_date' => array('operatorType' => CRM_Report_Form::OP_DATE), | |
119 | 'membership_start_date' => array('operatorType' => CRM_Report_Form::OP_DATE), | |
120 | 'membership_end_date' => array('operatorType' => CRM_Report_Form::OP_DATE), | |
121 | 'owner_membership_id' => array( | |
122 | 'title' => ts('Membership Owner ID'), | |
123 | 'operatorType' => CRM_Report_Form::OP_INT, | |
124 | ), | |
125 | 'tid' => array( | |
126 | 'name' => 'membership_type_id', | |
127 | 'title' => ts('Membership Types'), | |
128 | 'type' => CRM_Utils_Type::T_INT, | |
129 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
130 | 'options' => CRM_Member_PseudoConstant::membershipType(), | |
131 | ), | |
6a488035 | 132 | ), |
8d44b023 J |
133 | 'order_bys' => array( |
134 | 'membership_type_id' => array( | |
135 | 'title' => ts('Membership Type'), | |
136 | 'default' => '0', | |
137 | 'default_weight' => '1', | |
138 | 'default_order' => 'ASC', | |
139 | ), | |
140 | ), | |
8cab7c88 | 141 | 'grouping' => 'member-fields', |
490a6f02 | 142 | 'group_bys' => array( |
143 | 'id' => array( | |
144 | 'title' => ts('Membership'), | |
145 | 'default' => TRUE, | |
146 | ), | |
147 | ), | |
8cab7c88 EM |
148 | ), |
149 | 'civicrm_membership_status' => array( | |
150 | 'dao' => 'CRM_Member_DAO_MembershipStatus', | |
151 | 'alias' => 'mem_status', | |
152 | 'fields' => array( | |
153 | 'name' => array( | |
154 | 'title' => ts('Status'), | |
155 | 'default' => TRUE, | |
156 | ), | |
157 | ), | |
158 | 'filters' => array( | |
159 | 'sid' => array( | |
160 | 'name' => 'id', | |
161 | 'title' => ts('Status'), | |
162 | 'type' => CRM_Utils_Type::T_INT, | |
163 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
164 | 'options' => CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), | |
165 | ), | |
166 | ), | |
167 | 'grouping' => 'member-fields', | |
168 | ), | |
8cab7c88 EM |
169 | 'civicrm_email' => array( |
170 | 'dao' => 'CRM_Core_DAO_Email', | |
171 | 'fields' => array('email' => NULL), | |
172 | 'grouping' => 'contact-fields', | |
173 | ), | |
174 | 'civicrm_phone' => array( | |
175 | 'dao' => 'CRM_Core_DAO_Phone', | |
176 | 'fields' => array('phone' => NULL), | |
177 | 'grouping' => 'contact-fields', | |
178 | ), | |
179 | 'civicrm_contribution' => array( | |
180 | 'dao' => 'CRM_Contribute_DAO_Contribution', | |
181 | 'fields' => array( | |
182 | 'contribution_id' => array( | |
183 | 'name' => 'id', | |
184 | 'no_display' => TRUE, | |
185 | 'required' => TRUE, | |
186 | ), | |
187 | 'financial_type_id' => array('title' => ts('Financial Type')), | |
188 | 'contribution_status_id' => array('title' => ts('Contribution Status')), | |
189 | 'payment_instrument_id' => array('title' => ts('Payment Type')), | |
190 | 'currency' => array( | |
191 | 'required' => TRUE, | |
192 | 'no_display' => TRUE, | |
193 | ), | |
194 | 'trxn_id' => NULL, | |
195 | 'receive_date' => NULL, | |
196 | 'receipt_date' => NULL, | |
197 | 'fee_amount' => NULL, | |
198 | 'net_amount' => NULL, | |
199 | 'total_amount' => array( | |
200 | 'title' => ts('Payment Amount (most recent)'), | |
201 | 'statistics' => array('sum' => ts('Amount')), | |
202 | ), | |
6a488035 | 203 | ), |
8cab7c88 EM |
204 | 'filters' => array( |
205 | 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), | |
206 | 'financial_type_id' => array( | |
207 | 'title' => ts('Financial Type'), | |
208 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
209 | 'options' => CRM_Contribute_PseudoConstant::financialType(), | |
210 | 'type' => CRM_Utils_Type::T_INT, | |
211 | ), | |
212 | 'payment_instrument_id' => array( | |
213 | 'title' => ts('Payment Type'), | |
214 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
215 | 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(), | |
216 | 'type' => CRM_Utils_Type::T_INT, | |
217 | ), | |
218 | 'currency' => array( | |
ccc29f8e | 219 | 'title' => ts('Currency'), |
8cab7c88 EM |
220 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
221 | 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), | |
222 | 'default' => NULL, | |
223 | 'type' => CRM_Utils_Type::T_STRING, | |
224 | ), | |
225 | 'contribution_status_id' => array( | |
226 | 'title' => ts('Contribution Status'), | |
227 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
228 | 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), | |
229 | 'type' => CRM_Utils_Type::T_INT, | |
230 | ), | |
231 | 'total_amount' => array('title' => ts('Contribution Amount')), | |
232 | ), | |
8d44b023 J |
233 | 'order_bys' => array( |
234 | 'receive_date' => array( | |
7bc6b5bb | 235 | 'title' => ts('Date Received'), |
8d44b023 J |
236 | 'default_weight' => '2', |
237 | 'default_order' => 'DESC', | |
238 | ), | |
239 | ), | |
8cab7c88 EM |
240 | 'grouping' => 'contri-fields', |
241 | ), | |
e5575773 | 242 | ) + $this->getAddressColumns(array( |
243 | // These options are only excluded because they were not previously present. | |
244 | 'order_by' => FALSE, | |
245 | 'group_by' => FALSE, | |
246 | )); | |
6a488035 TO |
247 | $this->_groupFilter = TRUE; |
248 | $this->_tagFilter = TRUE; | |
fdb63ad1 | 249 | |
3b1c6a4f | 250 | // If we have campaigns enabled, add those elements to both the fields, filters and sorting |
251 | $this->addCampaignFields('civicrm_membership', FALSE, TRUE); | |
0211a554 | 252 | |
fdb63ad1 | 253 | $this->_currencyColumn = 'civicrm_contribution_currency'; |
6a488035 TO |
254 | parent::__construct(); |
255 | } | |
256 | ||
00be9182 | 257 | public function preProcess() { |
6a488035 TO |
258 | $this->assign('reportTitle', ts('Membership Detail Report')); |
259 | parent::preProcess(); | |
260 | } | |
261 | ||
00be9182 | 262 | public function from() { |
eae0f0d9 | 263 | $this->setFromBase('civicrm_contact'); |
264 | $this->_from .= " | |
265 | {$this->_aclFrom} | |
f813f78e | 266 | INNER JOIN civicrm_membership {$this->_aliases['civicrm_membership']} |
267 | ON {$this->_aliases['civicrm_contact']}.id = | |
6a488035 TO |
268 | {$this->_aliases['civicrm_membership']}.contact_id AND {$this->_aliases['civicrm_membership']}.is_test = 0 |
269 | LEFT JOIN civicrm_membership_status {$this->_aliases['civicrm_membership_status']} | |
f813f78e | 270 | ON {$this->_aliases['civicrm_membership_status']}.id = |
6a488035 TO |
271 | {$this->_aliases['civicrm_membership']}.status_id "; |
272 | ||
183af103 | 273 | $this->joinAddressFromContact(); |
274 | $this->joinPhoneFromContact(); | |
275 | $this->joinEmailFromContact(); | |
e5575773 | 276 | |
4b885f84 | 277 | //used when contribution field is selected. |
278 | if ($this->isTableSelected('civicrm_contribution')) { | |
6a488035 | 279 | $this->_from .= " |
06d4bf4d TO |
280 | LEFT JOIN civicrm_membership_payment cmp |
281 | ON {$this->_aliases['civicrm_membership']}.id = cmp.membership_id | |
fb7829f2 | 282 | LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} |
06d4bf4d | 283 | ON cmp.contribution_id={$this->_aliases['civicrm_contribution']}.id\n"; |
6a488035 TO |
284 | } |
285 | } | |
286 | ||
74cf4551 | 287 | /** |
ced9bfed EM |
288 | * Alter display of rows. |
289 | * | |
290 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
291 | * such as rendering contacts as links. | |
292 | * | |
293 | * @param array $rows | |
294 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 295 | */ |
00be9182 | 296 | public function alterDisplay(&$rows) { |
6a488035 TO |
297 | $entryFound = FALSE; |
298 | $checkList = array(); | |
f813f78e | 299 | |
244200e1 | 300 | $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); |
6a488035 TO |
301 | $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); |
302 | $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); | |
f813f78e | 303 | |
2ac6b1ce | 304 | $repeatFound = FALSE; |
6a488035 | 305 | foreach ($rows as $rowNum => $row) { |
2ac6b1ce J |
306 | if ($repeatFound == FALSE || |
307 | $repeatFound < $rowNum - 1 | |
308 | ) { | |
309 | unset($checkList); | |
310 | $checkList = array(); | |
311 | } | |
6a488035 TO |
312 | if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') { |
313 | // not repeat contact display names if it matches with the one | |
314 | // in previous row | |
6a488035 | 315 | foreach ($row as $colName => $colVal) { |
a5658df0 J |
316 | if (in_array($colName, $this->_noRepeats) && |
317 | $rowNum > 0 | |
6a488035 | 318 | ) { |
a5658df0 J |
319 | if ($rows[$rowNum][$colName] == $rows[$rowNum - 1][$colName] || |
320 | (!empty($checkList[$colName]) && | |
321 | in_array($colVal, $checkList[$colName])) | |
322 | ) { | |
323 | $rows[$rowNum][$colName] = ""; | |
324 | // CRM-15917: Don't blank the name if it's a different contact | |
64e8aa73 | 325 | if ($colName == 'civicrm_contact_exposed_id') { |
a5658df0 J |
326 | $rows[$rowNum]['civicrm_contact_sort_name'] = ""; |
327 | } | |
2ac6b1ce | 328 | $repeatFound = $rowNum; |
5ac295e6 | 329 | } |
6a488035 TO |
330 | } |
331 | if (in_array($colName, $this->_noRepeats)) { | |
332 | $checkList[$colName][] = $colVal; | |
333 | } | |
334 | } | |
335 | } | |
336 | ||
337 | if (array_key_exists('civicrm_membership_membership_type_id', $row)) { | |
338 | if ($value = $row['civicrm_membership_membership_type_id']) { | |
339 | $rows[$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant::membershipType($value, FALSE); | |
340 | } | |
341 | $entryFound = TRUE; | |
342 | } | |
343 | ||
6a488035 TO |
344 | if (array_key_exists('civicrm_contact_sort_name', $row) && |
345 | $rows[$rowNum]['civicrm_contact_sort_name'] && | |
346 | array_key_exists('civicrm_contact_id', $row) | |
347 | ) { | |
348 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
349 | 'reset=1&cid=' . $row['civicrm_contact_id'], | |
350 | $this->_absoluteUrl | |
351 | ); | |
352 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
353 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact."); | |
354 | $entryFound = TRUE; | |
355 | } | |
f813f78e | 356 | |
6a488035 TO |
357 | if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) { |
358 | $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value]; | |
359 | $entryFound = TRUE; | |
360 | } | |
361 | if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) { | |
362 | $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value]; | |
363 | $entryFound = TRUE; | |
364 | } | |
365 | if ($value = CRM_Utils_Array::value('civicrm_contribution_payment_instrument_id', $row)) { | |
366 | $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value]; | |
367 | $entryFound = TRUE; | |
368 | } | |
369 | ||
950351e3 AP |
370 | if (array_key_exists('civicrm_membership_owner_membership_id', $row)) { |
371 | $value = $row['civicrm_membership_owner_membership_id']; | |
372 | $rows[$rowNum]['civicrm_membership_owner_membership_id'] = ($value != '') ? 'Inherited' : 'Primary'; | |
373 | $entryFound = TRUE; | |
374 | } | |
375 | ||
0211a554 | 376 | // Convert campaign_id to campaign title |
229c2785 CD |
377 | if (array_key_exists('civicrm_membership_campaign_id', $row)) { |
378 | if ($value = $row['civicrm_membership_campaign_id']) { | |
3b1c6a4f | 379 | $rows[$rowNum]['civicrm_membership_campaign_id'] = $this->campaigns[$value]; |
0211a554 DL |
380 | $entryFound = TRUE; |
381 | } | |
382 | } | |
e5575773 | 383 | $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'member/detail', 'List all memberships(s) for this ') ? TRUE : $entryFound; |
7a4192f7 | 384 | $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'member/detail', 'List all memberships(s) for this ') ? TRUE : $entryFound; |
0211a554 | 385 | |
6a488035 TO |
386 | if (!$entryFound) { |
387 | break; | |
388 | } | |
389 | } | |
390 | } | |
96025800 | 391 | |
6a488035 | 392 | } |