5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Member_Detail
extends CRM_Report_Form
{
39 protected $_addressField = FALSE;
41 protected $_emailField = FALSE;
43 protected $_phoneField = FALSE;
45 protected $_contribField = FALSE;
47 protected $_summary = NULL;
49 protected $_customGroupExtends = array('Membership', 'Contribution');
50 protected $_customGroupGroupBy = FALSE;
52 function __construct() {
53 $this->_columns
= array(
56 'dao' => 'CRM_Contact_DAO_Contact',
60 array('title' => ts('Contact Name'),
71 array('title' => ts('First Name'),
80 array('title' => ts('Last Name'),
92 array('title' => ts('Contact Name'),
96 array('no_display' => TRUE),
98 'grouping' => 'contact-fields',
100 'civicrm_membership' =>
102 'dao' => 'CRM_Member_DAO_Membership',
105 'membership_type_id' => array(
106 'title' => 'Membership Type',
110 'membership_start_date' => array('title' => ts('Start Date'),
113 'membership_end_date' => array('title' => ts('End Date'),
116 'join_date' => array('title' => ts('Join Date'),
119 'source' => array('title' => 'Source'),
123 array('operatorType' => CRM_Report_Form
::OP_DATE
),
124 'membership_start_date' =>
125 array('operatorType' => CRM_Report_Form
::OP_DATE
),
126 'membership_end_date' =>
127 array('operatorType' => CRM_Report_Form
::OP_DATE
),
128 'owner_membership_id' =>
129 array('title' => ts('Membership Owner ID'),
130 'operatorType' => CRM_Report_Form
::OP_INT
,
134 'name' => 'membership_type_id',
135 'title' => ts('Membership Types'),
136 'type' => CRM_Utils_Type
::T_INT
,
137 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
138 'options' => CRM_Member_PseudoConstant
::membershipType(),
141 'grouping' => 'member-fields',
143 'civicrm_membership_status' =>
145 'dao' => 'CRM_Member_DAO_MembershipStatus',
146 'alias' => 'mem_status',
148 array('name' => array('title' => ts('Status'),
156 'title' => ts('Status'),
157 'type' => CRM_Utils_Type
::T_INT
,
158 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
159 'options' => CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'label'),
162 'grouping' => 'member-fields',
166 'dao' => 'CRM_Core_DAO_Address',
169 'street_address' => NULL,
171 'postal_code' => NULL,
172 'state_province_id' =>
173 array('title' => ts('State/Province'),
176 array('title' => ts('Country'),
179 'grouping' => 'contact-fields',
183 'dao' => 'CRM_Core_DAO_Email',
185 array('email' => NULL),
186 'grouping' => 'contact-fields',
190 'dao' => 'CRM_Core_DAO_Phone',
192 array('phone' => NULL),
193 'grouping' => 'contact-fields',
195 'civicrm_contribution' =>
197 'dao' => 'CRM_Contribute_DAO_Contribution',
200 'contribution_id' => array(
202 'no_display' => TRUE,
205 'financial_type_id' => array('title' => ts('Financial Type')),
206 'contribution_status_id' => array('title' => ts('Contribution Status')),
207 'payment_instrument_id' => array('title' => ts('Payment Type')),
210 'no_display' => TRUE,
213 'receive_date' => NULL,
214 'receipt_date' => NULL,
215 'fee_amount' => NULL,
216 'net_amount' => NULL,
217 'total_amount' => array('title' => ts('Payment Amount (most recent)'),
219 array('sum' => ts('Amount')),
225 array('operatorType' => CRM_Report_Form
::OP_DATE
),
226 'financial_type_id' =>
227 array('title' => ts('Financial Type'),
228 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
229 'options' => CRM_Contribute_PseudoConstant
::financialType(),
230 'type' => CRM_Utils_Type
::T_INT
,
232 'payment_instrument_id' =>
233 array('title' => ts('Payment Type'),
234 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
235 'options' => CRM_Contribute_PseudoConstant
::paymentInstrument(),
236 'type' => CRM_Utils_Type
::T_INT
,
239 array('title' => 'Currency',
240 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
241 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
242 'type' => CRM_Utils_Type
::T_STRING
,
244 'contribution_status_id' =>
245 array('title' => ts('Contribution Status'),
246 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
247 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
248 'type' => CRM_Utils_Type
::T_INT
,
251 array('title' => ts('Contribution Amount')),
253 'grouping' => 'contri-fields',
256 $this->_groupFilter
= TRUE;
257 $this->_tagFilter
= TRUE;
259 $this->_currencyColumn
= 'civicrm_contribution_currency';
260 parent
::__construct();
263 function preProcess() {
264 $this->assign('reportTitle', ts('Membership Detail Report'));
265 parent
::preProcess();
269 $select = $this->_columnHeaders
= array();
271 foreach ($this->_columns
as $tableName => $table) {
272 if (array_key_exists('fields', $table)) {
273 foreach ($table['fields'] as $fieldName => $field) {
274 if (CRM_Utils_Array
::value('required', $field) ||
275 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
277 if ($tableName == 'civicrm_address') {
278 $this->_addressField
= TRUE;
280 elseif ($tableName == 'civicrm_email') {
281 $this->_emailField
= TRUE;
283 elseif ($tableName == 'civicrm_phone') {
284 $this->_phoneField
= TRUE;
286 elseif ($tableName == 'civicrm_contribution') {
287 $this->_contribField
= TRUE;
289 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
290 if (array_key_exists('title', $field)) {
291 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
293 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
299 $this->_select
= "SELECT " . implode(', ', $select) . " ";
306 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
307 INNER JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
308 ON {$this->_aliases['civicrm_contact']}.id =
309 {$this->_aliases['civicrm_membership']}.contact_id AND {$this->_aliases['civicrm_membership']}.is_test = 0
310 LEFT JOIN civicrm_membership_status {$this->_aliases['civicrm_membership_status']}
311 ON {$this->_aliases['civicrm_membership_status']}.id =
312 {$this->_aliases['civicrm_membership']}.status_id ";
315 //used when address field is selected
316 if ($this->_addressField
) {
318 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
319 ON {$this->_aliases['civicrm_contact']}.id =
320 {$this->_aliases['civicrm_address']}.contact_id AND
321 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
323 //used when email field is selected
324 if ($this->_emailField
) {
326 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
327 ON {$this->_aliases['civicrm_contact']}.id =
328 {$this->_aliases['civicrm_email']}.contact_id AND
329 {$this->_aliases['civicrm_email']}.is_primary = 1\n";
331 //used when phone field is selected
332 if ($this->_phoneField
) {
334 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
335 ON {$this->_aliases['civicrm_contact']}.id =
336 {$this->_aliases['civicrm_phone']}.contact_id AND
337 {$this->_aliases['civicrm_phone']}.is_primary = 1\n";
339 //used when contribution field is selected
340 if ($this->_contribField
) {
343 SELECT cc.*, cmp.membership_id as membership_id
344 FROM civicrm_membership_payment cmp
345 JOIN civicrm_contribution cc
346 ON cc.id = cmp.contribution_id
347 ORDER BY cc.receive_date DESC
348 ) {$this->_aliases['civicrm_contribution']}
349 ON {$this->_aliases['civicrm_membership']}.id =
350 {$this->_aliases['civicrm_contribution']}.membership_id\n";
356 foreach ($this->_columns
as $tableName => $table) {
357 if (array_key_exists('filters', $table)) {
358 foreach ($table['filters'] as $fieldName => $field) {
360 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Utils_Type
::T_DATE
) {
361 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
362 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
363 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
365 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
368 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
370 $clause = $this->whereClause($field,
372 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
373 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
374 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
379 if (!empty($clause)) {
380 $clauses[] = $clause;
386 if (empty($clauses)) {
387 $this->_where
= "WHERE ( 1 ) ";
390 $this->_where
= "WHERE " . implode(' AND ', $clauses);
393 if ($this->_aclWhere
) {
394 $this->_where
.= " AND {$this->_aclWhere} ";
399 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_membership']}.membership_type_id";
403 $this->_orderBy
= " ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_membership']}.membership_type_id";
406 function postProcess() {
408 $this->beginPostProcess();
410 // get the acl clauses built before we assemble the query
411 $this->buildACLClause($this->_aliases
['civicrm_contact']);
412 $sql = $this->buildQuery(TRUE);
415 $this->buildRows($sql, $rows);
417 $this->formatDisplay($rows);
418 $this->doTemplateAssignment($rows);
419 $this->endPostProcess($rows);
422 function alterDisplay(&$rows) {
423 // custom code to alter rows
425 $checkList = array();
427 $contributionTypes = CRM_Contribute_PseudoConstant
::financialType();
428 $contributionStatus = CRM_Contribute_PseudoConstant
::contributionStatus();
429 $paymentInstruments = CRM_Contribute_PseudoConstant
::paymentInstrument();
431 foreach ($rows as $rowNum => $row) {
433 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
434 // not repeat contact display names if it matches with the one
436 $repeatFound = FALSE;
437 foreach ($row as $colName => $colVal) {
438 if (CRM_Utils_Array
::value($colName, $checkList) &&
439 is_array($checkList[$colName]) &&
440 in_array($colVal, $checkList[$colName])
442 $rows[$rowNum][$colName] = "";
445 if (in_array($colName, $this->_noRepeats
)) {
446 $checkList[$colName][] = $colVal;
451 if (array_key_exists('civicrm_membership_membership_type_id', $row)) {
452 if ($value = $row['civicrm_membership_membership_type_id']) {
453 $rows[$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant
::membershipType($value, FALSE);
458 if (array_key_exists('civicrm_address_state_province_id', $row)) {
459 if ($value = $row['civicrm_address_state_province_id']) {
460 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
465 if (array_key_exists('civicrm_address_country_id', $row)) {
466 if ($value = $row['civicrm_address_country_id']) {
467 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
472 if (array_key_exists('civicrm_contact_sort_name', $row) &&
473 $rows[$rowNum]['civicrm_contact_sort_name'] &&
474 array_key_exists('civicrm_contact_id', $row)
476 $url = CRM_Utils_System
::url("civicrm/contact/view",
477 'reset=1&cid=' . $row['civicrm_contact_id'],
480 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
481 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
485 if ($value = CRM_Utils_Array
::value('civicrm_contribution_financial_type_id', $row)) {
486 $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value];
489 if ($value = CRM_Utils_Array
::value('civicrm_contribution_contribution_status_id', $row)) {
490 $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
493 if ($value = CRM_Utils_Array
::value('civicrm_contribution_payment_instrument_id', $row)) {
494 $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value];