Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
34cd78e1 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
34cd78e1 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
34cd78e1 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | require_once 'CRM/Report/Form.php'; | |
37 | require_once 'CRM/Contribute/PseudoConstant.php'; | |
38 | require_once 'CRM/Core/OptionGroup.php'; | |
39 | require_once 'CRM/Event/BAO/Participant.php'; | |
40 | require_once 'CRM/Contact/BAO/Contact.php'; | |
41 | class CRM_Report_Form_Contribute_Baykeeper extends CRM_Report_Form { | |
42 | protected $_addressField = FALSE; | |
43 | ||
44 | protected $_emailField = FALSE; | |
45 | ||
46 | protected $_summary = NULL; | |
47 | ||
430ae6dd TO |
48 | protected $_customGroupExtends = array('Contact', 'Contribution'); |
49 | ||
50 | function __construct() { | |
6a488035 TO |
51 | $this->_columns = array('civicrm_contact' => |
52 | array('dao' => 'CRM_Contact_DAO_Contact', | |
53 | 'fields' => | |
54 | array('display_name' => | |
55 | array('title' => ts('Contact Name'), | |
56 | 'required' => TRUE, | |
57 | 'no_repeat' => TRUE, | |
58 | ), | |
59 | 'id' => | |
60 | array('no_display' => FALSE, | |
61 | 'title' => ts('Contact ID'), | |
62 | 'required' => TRUE, | |
63 | ), | |
64 | 'contact_id' => | |
65 | array('title' => ts('Contact ID'), | |
66 | 'name' => 'id', | |
67 | 'default' => FALSE, | |
68 | 'no_repeat' => TRUE, | |
69 | 'required' => TRUE, | |
70 | ), | |
71 | 'addressee_display' => array('title' => ts('Addressee Name')), | |
72 | 'postal_greeting_display' => array('title' => ts('Greeting')), | |
73 | 'display_name_creditor' => | |
74 | array('title' => ts('Soft Credit Name'), | |
75 | 'name' => 'display_name', | |
76 | 'alias' => 'soft_credit', | |
77 | 'no_repeat' => TRUE, | |
78 | ), | |
79 | 'id_creditor' => | |
80 | array('title' => ts('Soft Credit Id'), | |
81 | 'name' => 'id', | |
82 | 'alias' => 'soft_credit', | |
83 | ), | |
84 | 'employer_name' => | |
85 | array('title' => ts('Employer Name'), | |
86 | 'name' => 'display_name', | |
87 | 'alias' => 'employer_company', | |
88 | ), | |
89 | 'employer_id' => | |
90 | array('title' => ts('Employer Id'), | |
91 | 'name' => 'employer_id', | |
92 | ), | |
93 | 'do_not_mail' => array('title' => ts('Do Not Mail')), | |
94 | ), | |
95 | 'filters' => | |
96 | array('sort_name' => | |
97 | array('title' => ts('Contact Name'), | |
98 | 'operator' => 'like', | |
99 | ), | |
100 | 'id' => | |
101 | array('title' => ts('Contact ID'), | |
102 | 'no_display' => TRUE, | |
103 | ), | |
104 | ), | |
105 | 'grouping' => 'contact-fields', | |
106 | ), | |
107 | 'civicrm_email' => | |
108 | array('dao' => 'CRM_Core_DAO_Email', | |
109 | 'fields' => | |
110 | array('email' => | |
111 | array('title' => ts('Email'), | |
112 | 'default' => TRUE, | |
113 | 'no_repeat' => TRUE, | |
114 | ), | |
115 | ), | |
116 | 'grouping' => 'contact-fields', | |
117 | ), | |
118 | 'civicrm_phone' => | |
119 | array('dao' => 'CRM_Core_DAO_Phone', | |
120 | 'fields' => | |
121 | array('phone' => | |
122 | array('title' => ts('Phone'), | |
123 | 'default' => TRUE, | |
124 | 'no_repeat' => TRUE, | |
125 | ), | |
126 | ), | |
127 | 'grouping' => 'contact-fields', | |
128 | ), | |
129 | 'civicrm_address' => | |
130 | array('dao' => 'CRM_Core_DAO_Address', | |
131 | 'fields' => | |
132 | array('street_address' => NULL, | |
133 | 'supplemental_address_1' => array('title' => ts('Sup Address 1'), | |
134 | ), | |
135 | 'supplemental_address_2' => array('title' => ts('Sup Address 2'), | |
136 | ), | |
137 | 'city' => NULL, | |
138 | 'postal_code' => NULL, | |
139 | 'location_type_id' => array('title' => ts('Location Type ID'), | |
140 | ), | |
141 | 'state_province_id' => | |
142 | array('title' => ts('State/Province'), | |
143 | ), | |
144 | 'country_id' => | |
145 | array('title' => ts('Country'), | |
146 | 'default' => TRUE, | |
147 | ), | |
148 | ), | |
149 | 'grouping' => 'contact-fields', | |
150 | 'filters' => | |
151 | array('country_id' => | |
152 | array('title' => ts('Country'), | |
153 | 'type' => CRM_Utils_Type::T_INT, | |
154 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
155 | 'options' => CRM_Core_PseudoConstant::country(), | |
156 | ), | |
157 | 'state_province_id' => | |
158 | array('title' => ts('State/Province'), | |
159 | 'type' => CRM_Utils_Type::T_INT, | |
160 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
161 | 'options' => CRM_Core_PseudoConstant::stateProvince(), | |
162 | ), | |
163 | ), | |
164 | ), | |
165 | 'civicrm_contribution' => | |
166 | array('dao' => 'CRM_Contribute_DAO_Contribution', | |
167 | 'fields' => | |
168 | array( | |
169 | 'contribution_id' => array( | |
170 | 'name' => 'id', | |
171 | 'no_display' => TRUE, | |
172 | 'required' => TRUE, | |
173 | ), | |
174 | 'contribution_type_id' => array('title' => ts('Contribution Type'), | |
175 | 'default' => TRUE, | |
176 | ), | |
177 | 'trxn_id' => NULL, | |
178 | 'receive_date' => array('default' => TRUE), | |
179 | 'receipt_date' => NULL, | |
180 | 'source' => array('title' => ts('Source')), | |
181 | 'fee_amount' => NULL, | |
182 | 'net_amount' => NULL, | |
183 | 'non_deductible_amount' => array('title' => ts('Non Deductible Amount')), | |
184 | 'total_amount' => array('title' => ts('Total Amount'), | |
185 | 'required' => TRUE, | |
186 | ), | |
187 | 'honor_contact_id' => array('title' => ts('Honor Contact ID'), | |
188 | ), | |
189 | 'honor_type_id' => array('title' => ts('Hon/Mem Type')), | |
190 | ), | |
191 | 'filters' => | |
192 | array('receive_date' => | |
193 | array('operatorType' => CRM_Report_Form::OP_DATE), | |
194 | 'contribution_type_id' => | |
195 | array('title' => ts('Contribution Type'), | |
196 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
197 | 'options' => CRM_Contribute_PseudoConstant::contributionType(), | |
198 | ), | |
199 | 'contribution_status_id' => | |
200 | array('title' => ts('Contribution Status'), | |
201 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
202 | 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), | |
203 | ), | |
204 | 'total_amount' => | |
205 | array('title' => ts('Contribution Amount')), | |
206 | ), | |
207 | 'grouping' => 'contri-fields', | |
208 | ), | |
209 | 'civicrm_contact_hon_mem' => | |
210 | array('dao' => 'CRM_Contact_DAO_Contact', | |
211 | 'alias' => 'hon_mem', | |
212 | 'fields' => | |
213 | array('id' => array('title' => ts('Hon/Mem Contact ID'), | |
214 | 'required' => TRUE, | |
215 | 'no_display' => TRUE, | |
216 | ), | |
217 | 'display_name' => array('title' => ts('In Honor Of'), | |
218 | 'required' => FALSE, | |
219 | ), | |
220 | ), | |
221 | 'grouping' => 'contri-fields', | |
222 | ), | |
223 | 'civicrm_note' => | |
224 | array('dao' => 'CRM_Core_DAO_Note', | |
225 | 'fields' => | |
226 | array( | |
227 | 'note' => | |
228 | array('title' => ts('Note'), | |
229 | 'default' => TRUE, | |
230 | 'no_repeat' => FALSE, | |
231 | ), | |
232 | ), | |
233 | 'grouping' => 'contri-fields', | |
234 | ), | |
235 | 'civicrm_contribution_soft' => | |
236 | array('dao' => 'CRM_Contribute_DAO_ContributionSoft', | |
237 | 'fields' => | |
238 | array('contribution_id' => | |
239 | array('title' => ts('Contribution ID'), | |
240 | 'no_display' => TRUE, | |
241 | 'default' => TRUE, | |
242 | ), | |
243 | 'contact_id' => | |
244 | array('title' => ts('Contact ID'), | |
245 | 'no_display' => TRUE, | |
246 | 'default' => TRUE, | |
247 | ), | |
248 | 'id' => | |
249 | array('default' => TRUE, | |
250 | 'no_display' => TRUE, | |
251 | ), | |
252 | ), | |
253 | 'grouping' => 'softcredit-fields', | |
254 | ), | |
255 | 'civicrm_group_field' => | |
256 | array('dao' => 'CRM_Contact_DAO_Group', | |
257 | 'fields' => | |
258 | array('title' => | |
259 | array('title' => ts('Groups')), | |
260 | ), | |
261 | ), | |
262 | 'civicrm_group' => | |
263 | array('dao' => 'CRM_Contact_DAO_GroupContact', | |
264 | 'alias' => 'cgroup', | |
265 | 'fields' => | |
430ae6dd | 266 | array( |
6a488035 TO |
267 | ), |
268 | 'filters' => | |
269 | array('gid' => | |
270 | array('name' => 'group_id', | |
271 | 'title' => ts('Group'), | |
272 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
273 | 'group' => TRUE, | |
274 | 'options' => CRM_Core_PseudoConstant::group(), | |
275 | ), | |
276 | ), | |
277 | ), | |
278 | 'civicrm_contribution_ordinality' => | |
279 | array('dao' => 'CRM_Contribute_DAO_Contribution', | |
280 | 'alias' => 'cordinality', | |
281 | 'filters' => | |
282 | array('ordinality' => | |
283 | array('title' => ts('Contribution Ordinality'), | |
284 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
285 | 'options' => array(0 => 'First by Contributor', | |
286 | 1 => 'Second or Later by Contributor', | |
287 | ), | |
288 | ), | |
289 | ), | |
290 | ), | |
291 | ); | |
292 | ||
293 | $this->_options = array('first_contribution' => array('title' => ts('First Contribution'), | |
294 | 'type' => 'checkbox', | |
295 | ), | |
296 | 'last_contribution' => array('title' => ts('Last Contribution'), | |
297 | 'type' => 'checkbox', | |
298 | ), | |
299 | 'include_nondonors' => array('title' => ts('Include non-donors?'), | |
300 | 'type' => 'checkbox', | |
301 | ), | |
302 | ); | |
303 | ||
304 | $this->_tagFilter = TRUE; | |
305 | parent::__construct(); | |
306 | } | |
307 | ||
308 | function preProcess() { | |
309 | parent::preProcess(); | |
310 | } | |
311 | ||
312 | function select() { | |
313 | $select = array(); | |
314 | ||
315 | $this->_columnHeaders = array(); | |
316 | foreach ($this->_columns as $tableName => $table) { | |
317 | if (array_key_exists('fields', $table)) { | |
318 | foreach ($table['fields'] as $fieldName => $field) { | |
8cc574cf | 319 | if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) { |
6a488035 TO |
320 | if ($tableName == 'civicrm_address') { |
321 | $this->_addressField = TRUE; | |
322 | } | |
323 | elseif ($tableName == 'civicrm_email') { | |
324 | $this->_emailField = TRUE; | |
325 | } | |
326 | /* | |
327 | if ( $tableName == 'civicrm_group_field' && $fieldName == 'title' ) { | |
328 | $select[] = "GROUP_CONCAT(DISTINCT {$field['dbAlias']} ORDER BY {$field['dbAlias']} ) as {$tableName}_{$fieldName}"; | |
329 | } else { | |
330 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
331 | } | |
332 | */ | |
333 | ||
334 | ||
335 | // only include statistics columns if set | |
a7488080 | 336 | if (!empty($field['statistics'])) { |
6a488035 TO |
337 | foreach ($field['statistics'] as $stat => $label) { |
338 | switch (strtolower($stat)) { | |
339 | case 'sum': | |
340 | $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}"; | |
341 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label; | |
342 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type']; | |
343 | $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}"; | |
344 | break; | |
345 | ||
346 | case 'count': | |
347 | $select[] = "COUNT({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}"; | |
348 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label; | |
349 | $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}"; | |
350 | break; | |
351 | ||
352 | case 'avg': | |
353 | $select[] = "ROUND(AVG({$field['dbAlias']}),2) as {$tableName}_{$fieldName}_{$stat}"; | |
354 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type']; | |
355 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label; | |
356 | $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}"; | |
357 | break; | |
358 | } | |
359 | } | |
360 | } | |
361 | elseif ($tableName == 'civicrm_group_field' && $fieldName == 'title') { | |
362 | $select[] = " GROUP_CONCAT(DISTINCT {$field['dbAlias']} ORDER BY {$field['dbAlias']} SEPARATOR ' | <br>') as {$tableName}_{$fieldName} "; | |
363 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
364 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
365 | } | |
366 | else { | |
367 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
368 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
369 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
370 | } | |
371 | } | |
372 | } | |
373 | } | |
374 | } | |
375 | ||
376 | // insert first and last contribution at end | |
a7488080 | 377 | if (!empty($this->_params['options']['first_contribution'])) { |
6a488035 TO |
378 | $select[] = " '' as first_contribution"; |
379 | $this->_columnHeaders['first_contribution']['title'] = ts('First Contribution'); | |
380 | } | |
381 | ||
a7488080 | 382 | if (!empty($this->_params['options']['last_contribution'])) { |
6a488035 TO |
383 | $select[] = " '' as last_contribution"; |
384 | $this->_columnHeaders['last_contribution']['title'] = ts('Last Contribution'); | |
385 | } | |
386 | ||
387 | ||
388 | $this->_select = "SELECT " . implode(', ', $select) . " "; | |
389 | } | |
390 | ||
391 | function from() { | |
392 | $alias_constituent = 'constituentname'; | |
393 | $alias_creditor = 'soft_credit'; | |
394 | $alias_employer = "employer_company"; | |
395 | ||
396 | $this->_from = NULL; | |
397 | ||
398 | $hackValue = CRM_Utils_Array::value('include_nondonors', $this->_params['options'], 0); | |
399 | $contribJoin = $hackValue ? "LEFT" : "INNER"; | |
400 | ||
401 | $this->_from = " | |
402 | FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom} | |
403 | $contribJoin JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} | |
404 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id AND {$this->_aliases['civicrm_contribution']}.is_test = 0 | |
405 | $contribJoin JOIN (SELECT c.id, IF(COUNT(oc.id) = 0, 0, 1) AS ordinality FROM civicrm_contribution c LEFT JOIN civicrm_contribution oc ON c.contact_id = oc.contact_id AND oc.receive_date < c.receive_date GROUP BY c.id) {$this->_aliases['civicrm_contribution_ordinality']} | |
406 | ON {$this->_aliases['civicrm_contribution_ordinality']}.id = {$this->_aliases['civicrm_contribution']}.id | |
407 | LEFT JOIN civicrm_note {$this->_aliases['civicrm_note']} | |
408 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_note']}.contact_id AND | |
409 | {$this->_aliases['civicrm_contribution']}.id = {$this->_aliases['civicrm_note']}.entity_id ) | |
410 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} | |
411 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND | |
412 | {$this->_aliases['civicrm_phone']}.is_primary = 1) | |
413 | LEFT JOIN civicrm_contact {$alias_employer} | |
414 | ON {$this->_aliases['civicrm_contact']}.employer_id = | |
415 | {$alias_employer}.id | |
416 | LEFT JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']} | |
417 | ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id = | |
418 | {$this->_aliases['civicrm_contribution']}.id | |
419 | LEFT JOIN civicrm_contact {$alias_creditor} | |
420 | ON {$this->_aliases['civicrm_contribution_soft']}.contact_id = | |
421 | {$alias_creditor}.id | |
422 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact_hon_mem']} | |
423 | ON {$this->_aliases['civicrm_contribution']}.honor_contact_id = {$this->_aliases['civicrm_contact_hon_mem']}.id | |
424 | "; | |
425 | // add group - concatenated | |
426 | $this->_from .= " LEFT JOIN civicrm_group_contact gc ON {$this->_aliases['civicrm_contact']}.id = gc.contact_id AND gc.status = 'Added' | |
427 | LEFT JOIN civicrm_group {$this->_aliases['civicrm_group_field']} ON {$this->_aliases['civicrm_group_field']}.id = gc.group_id "; | |
428 | ||
429 | if ($this->_addressField OR (!empty($this->_params['state_province_id_value']) OR !empty($this->_params['country_id_value']))) { | |
430 | $this->_from .= " | |
431 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} | |
432 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND | |
433 | {$this->_aliases['civicrm_address']}.is_primary = 1\n"; | |
434 | } | |
435 | ||
436 | if ($this->_emailField) { | |
437 | $this->_from .= " | |
438 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} | |
439 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND | |
440 | {$this->_aliases['civicrm_email']}.is_primary = 1\n"; | |
441 | } | |
442 | } | |
443 | ||
444 | function groupBy() { | |
445 | $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_contribution']}.id "; | |
446 | } | |
447 | ||
448 | function orderBy() { | |
449 | $this->_orderBy = " ORDER BY {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_contribution']}.receive_date "; | |
450 | } | |
451 | ||
452 | function statistics(&$rows) { | |
453 | $statistics = parent::statistics($rows); | |
454 | // because the query returns groups, the amount is multiplied by the number of groups a contact is in | |
455 | // that's why this is disabled | |
456 | /* SUM( {$this->_aliases['civicrm_contribution']}.total_amount ) as amount, */ | |
457 | ||
458 | ||
459 | $select = " | |
460 | SELECT COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as count, | |
461 | ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as avg | |
462 | "; | |
463 | $sql = "{$select} {$this->_from} {$this->_where}"; | |
464 | $dao = CRM_Core_DAO::executeQuery($sql); | |
465 | ||
466 | if ($dao->fetch()) { | |
467 | // because the query returns groups, the amount is multiplied by the number of groups a contact is in | |
468 | // that's why this is disabled | |
469 | /* SUM( {$this->_aliases['civicrm_contribution']}.total_amount ) as amount, */ | |
470 | ||
471 | ||
472 | /* | |
473 | $statistics['counts']['amount'] = array( 'value' => $dao->amount, | |
474 | 'title' => 'Total Amount', | |
475 | 'type' => CRM_Utils_Type::T_MONEY ); | |
476 | $statistics['counts']['avg'] = array( 'value' => $dao->avg, | |
477 | 'title' => 'Average', | |
478 | 'type' => CRM_Utils_Type::T_MONEY ); | |
479 | */ | |
480 | } | |
481 | ||
482 | return $statistics; | |
483 | } | |
484 | ||
485 | function postProcess() { | |
486 | // get the acl clauses built before we assemble the query | |
487 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
488 | parent::postProcess(); | |
489 | } | |
490 | ||
491 | function alterDisplay(&$rows) { | |
492 | ||
493 | require_once 'CRM/Contribute/BAO/Contribution/Utils.php'; | |
494 | require_once 'CRM/Utils/Money.php'; | |
495 | require_once 'CRM/Utils/Date.php'; | |
496 | ||
497 | $config = &CRM_Core_Config::singleton(); | |
498 | ||
499 | // custom code to alter rows | |
500 | $checkList = array(); | |
501 | $entryFound = FALSE; | |
502 | $display_flag = $prev_cid = $cid = 0; | |
503 | $contributionTypes = CRM_Contribute_PseudoConstant::contributionType(); | |
504 | ||
505 | foreach ($rows as $rowNum => $row) { | |
506 | if (!empty($this->_noRepeats) && | |
507 | $this->_outputMode != 'csv' | |
508 | ) { | |
509 | // don't repeat contact details if its same as the previous row | |
510 | if (array_key_exists('civicrm_contact_id', $row)) { | |
511 | if ($cid = $row['civicrm_contact_id']) { | |
512 | if ($rowNum == 0) { | |
513 | $prev_cid = $cid; | |
514 | } | |
515 | else { | |
516 | if ($prev_cid == $cid) { | |
517 | $display_flag = 1; | |
518 | $prev_cid = $cid; | |
519 | } | |
520 | else { | |
521 | $display_flag = 0; | |
522 | $prev_cid = $cid; | |
523 | } | |
524 | } | |
525 | ||
526 | if ($display_flag) { | |
527 | foreach ($row as $colName => $colVal) { | |
528 | if (in_array($colName, $this->_noRepeats)) { | |
529 | unset($rows[$rowNum][$colName]); | |
530 | } | |
531 | } | |
532 | } | |
533 | $entryFound = TRUE; | |
534 | } | |
535 | } | |
536 | } | |
537 | ||
538 | if (array_key_exists('first_contribution', $row) || | |
539 | array_key_exists('last_contribution', $row) | |
540 | ) { | |
541 | $details = CRM_Contribute_BAO_Contribution_Utils::getFirstLastDetails($row['civicrm_contact_id']); | |
542 | if ($details['first']) { | |
543 | $rows[$rowNum]['first_contribution'] = CRM_Utils_Money::format($details['first']['total_amount']) . ' - ' . CRM_Utils_Date::customFormat($details['first']['receive_date'], $config->dateformatFull); | |
544 | } | |
545 | if ($details['last']) { | |
546 | $rows[$rowNum]['last_contribution'] = CRM_Utils_Money::format($details['last']['total_amount']) . ' - ' . CRM_Utils_Date::customFormat($details['last']['receive_date'], $config->dateformatFull); | |
547 | } | |
548 | } | |
549 | ||
550 | // handle state province | |
551 | if (array_key_exists('civicrm_address_state_province_id', $row)) { | |
552 | if ($value = $row['civicrm_address_state_province_id']) { | |
553 | $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); | |
554 | ||
555 | $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', | |
556 | "reset=1&force=1&" . | |
557 | "state_province_id_op=in&state_province_id_value={$value}", | |
558 | $this->_absoluteUrl, $this->_id | |
559 | ); | |
560 | $rows[$rowNum]['civicrm_address_state_province_id_link'] = $url; | |
561 | $rows[$rowNum]['civicrm_address_state_province_id_hover'] = ts("List all contribution(s) for this State."); | |
562 | } | |
563 | $entryFound = TRUE; | |
564 | } | |
565 | ||
566 | // handle country | |
567 | if (array_key_exists('civicrm_address_country_id', $row)) { | |
568 | if ($value = $row['civicrm_address_country_id']) { | |
569 | $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); | |
570 | ||
571 | $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', | |
572 | "reset=1&force=1&" . | |
573 | "country_id_op=in&country_id_value={$value}", | |
574 | $this->_absoluteUrl, $this->_id | |
575 | ); | |
576 | $rows[$rowNum]['civicrm_address_country_id_link'] = $url; | |
577 | $rows[$rowNum]['civicrm_address_country_id_hover'] = ts("List all contribution(s) for this Country."); | |
578 | } | |
579 | ||
580 | $entryFound = TRUE; | |
581 | } | |
582 | ||
583 | // convert display name to links | |
8cc574cf | 584 | if (array_key_exists('civicrm_contact_display_name', $row) && !empty($rows[$rowNum]['civicrm_contact_display_name']) && |
6a488035 TO |
585 | array_key_exists('civicrm_contact_id', $row) |
586 | ) { | |
587 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
588 | 'reset=1&cid=' . $row['civicrm_contact_id'], | |
589 | $this->_absoluteUrl | |
590 | ); | |
591 | $rows[$rowNum]['civicrm_contact_display_name_link'] = $url; | |
592 | $rows[$rowNum]['civicrm_contact_display_name_hover'] = ts("View Contact Summary for this Contact."); | |
593 | } | |
594 | ||
595 | // convert soft credit id to link | |
8cc574cf | 596 | if (array_key_exists('soft_credit_display_name', $row) && !empty($rows[$rowNum]['soft_credit_display_name']) && |
6a488035 TO |
597 | array_key_exists('id', $row) |
598 | ) { | |
599 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
600 | 'reset=1&cid=' . $row['id'], | |
601 | $this->_absoluteUrl | |
602 | ); | |
603 | $rows[$rowNum]['soft_credit_display_name_creditor_link'] = $url; | |
604 | $rows[$rowNum]['soft_credit_display_name_creditor_hover'] = ts("View Contact Summary for this Soft Credit."); | |
605 | } | |
606 | ||
607 | // convert hon/mem contact to link | |
8cc574cf | 608 | if (array_key_exists('civicrm_contact_hon_mem_display_name', $row) && !empty($rows[$rowNum]['civicrm_contribution_honor_contact_id']) && |
6a488035 TO |
609 | array_key_exists('civicrm_contribution_honor_contact_id', $row) |
610 | ) { | |
611 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
612 | 'reset=1&cid=' . $row['civicrm_contribution_honor_contact_id'], | |
613 | $this->_absoluteUrl | |
614 | ); | |
615 | $rows[$rowNum]['civicrm_contact_hon_mem_display_name_link'] = $url; | |
616 | $rows[$rowNum]['civicrm_contact_hon_mem_display_name_hover'] = ts("View Contact Summary for this Honor/Memory Contribution."); | |
617 | } | |
618 | ||
619 | // honor of/memory of type | |
8cc574cf | 620 | if ($value = CRM_Utils_Array::value('civicrm_contribution_honor_type_id', $row) && !empty($rows[$rowNum]['civicrm_contribution_honor_type_id'])) { |
6a488035 TO |
621 | // rather than do a join, just change the output here, since there these values are pretty static |
622 | ||
623 | ||
624 | if ($rows[$rowNum]['civicrm_contribution_honor_type_id'] == 1) { | |
625 | $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "In Honor Of"; | |
626 | } | |
627 | elseif ($rows[$rowNum]['civicrm_contribution_honor_type_id'] == 2) { | |
628 | $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "In Memory Of"; | |
629 | } | |
630 | else { | |
631 | $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "n/a"; | |
632 | } | |
633 | } | |
634 | ||
635 | if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_type_id', $row)) { | |
636 | $rows[$rowNum]['civicrm_contribution_contribution_type_id'] = $contributionTypes[$value]; | |
637 | $entryFound = TRUE; | |
638 | } | |
639 | ||
640 | if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount', $row)) && | |
641 | CRM_Core_Permission::check('access CiviContribute') | |
642 | ) { | |
643 | $url = CRM_Utils_System::url("civicrm/contact/view/contribution", | |
644 | "reset=1&id=" . | |
645 | $row['civicrm_contribution_contribution_id'] . | |
646 | "&cid=" . | |
647 | $row['civicrm_contact_id'] . | |
648 | "&action=view&context=contribution&selectedChild=contribute", | |
649 | $this->_absoluteUrl | |
650 | ); | |
651 | $rows[$rowNum]['civicrm_contribution_total_amount_link'] = $url; | |
652 | $rows[$rowNum]['civicrm_contribution_total_amount_hover'] = ts("View Details of this Contribution."); | |
653 | $entryFound = TRUE; | |
654 | } | |
655 | ||
656 | // skip looking further in rows, if first row itself doesn't | |
657 | // have the column we need | |
658 | if (!$entryFound) { | |
659 | break; | |
660 | } | |
661 | $lastKey = $rowNum; | |
662 | } | |
663 | } | |
664 | } | |
665 |