_columns = array( 'civicrm_contact' => array( 'dao' => 'CRM_Contact_DAO_Contact', 'fields' => $this->getBasicContactFields(), 'filters' => array( 'sort_name' => array( 'title' => ts('Contact Name'), 'operator' => 'like', ), 'is_deleted' => array( 'title' => ts('Is Deleted'), 'default' => 0, 'type' => CRM_Utils_Type::T_BOOLEAN, ), 'id' => array('no_display' => TRUE), ), 'order_bys' => array( 'sort_name' => array( 'title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC', ), ), 'grouping' => 'contact-fields', ), 'civicrm_membership' => array( 'dao' => 'CRM_Member_DAO_Membership', 'fields' => array( 'membership_type_id' => array( 'title' => ts('Membership Type'), 'required' => TRUE, 'no_repeat' => TRUE, ), 'membership_start_date' => array( 'title' => ts('Start Date'), 'default' => TRUE, ), 'membership_end_date' => array( 'title' => ts('End Date'), 'default' => TRUE, ), 'join_date' => array( 'title' => ts('Join Date'), 'default' => TRUE, ), 'source' => array('title' => ts('Source')), ), 'filters' => array( 'join_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'membership_start_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'membership_end_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'owner_membership_id' => array( 'title' => ts('Membership Owner ID'), 'operatorType' => CRM_Report_Form::OP_INT, ), 'tid' => array( 'name' => 'membership_type_id', 'title' => ts('Membership Types'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Member_PseudoConstant::membershipType(), ), ), 'order_bys' => array( 'membership_type_id' => array( 'title' => ts('Membership Type'), 'default' => '0', 'default_weight' => '1', 'default_order' => 'ASC', ), ), 'grouping' => 'member-fields', 'group_bys' => array( 'id' => array( 'title' => ts('Membership'), 'default' => TRUE, ), ), ), 'civicrm_membership_status' => array( 'dao' => 'CRM_Member_DAO_MembershipStatus', 'alias' => 'mem_status', 'fields' => array( 'name' => array( 'title' => ts('Status'), 'default' => TRUE, ), ), 'filters' => array( 'sid' => array( 'name' => 'id', 'title' => ts('Status'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), ), ), 'grouping' => 'member-fields', ), 'civicrm_email' => array( 'dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => NULL), 'grouping' => 'contact-fields', ), 'civicrm_phone' => array( 'dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => NULL), 'grouping' => 'contact-fields', ), 'civicrm_contribution' => array( 'dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array( 'contribution_id' => array( 'name' => 'id', 'no_display' => TRUE, 'required' => TRUE, ), 'financial_type_id' => array('title' => ts('Financial Type')), 'contribution_status_id' => array('title' => ts('Contribution Status')), 'payment_instrument_id' => array('title' => ts('Payment Type')), 'currency' => array( 'required' => TRUE, 'no_display' => TRUE, ), 'trxn_id' => NULL, 'receive_date' => NULL, 'receipt_date' => NULL, 'fee_amount' => NULL, 'net_amount' => NULL, 'total_amount' => array( 'title' => ts('Payment Amount (most recent)'), 'statistics' => array('sum' => ts('Amount')), ), ), 'filters' => array( 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'financial_type_id' => array( 'title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialType(), 'type' => CRM_Utils_Type::T_INT, ), 'payment_instrument_id' => array( 'title' => ts('Payment Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(), 'type' => CRM_Utils_Type::T_INT, ), 'currency' => array( 'title' => ts('Currency'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING, ), 'contribution_status_id' => array( 'title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'type' => CRM_Utils_Type::T_INT, ), 'total_amount' => array('title' => ts('Contribution Amount')), ), 'order_bys' => array( 'receive_date' => array( 'title' => ts('Date Received'), 'default_weight' => '2', 'default_order' => 'DESC', ), ), 'grouping' => 'contri-fields', ), ) + $this->getAddressColumns(array( // These options are only excluded because they were not previously present. 'order_by' => FALSE, 'group_by' => FALSE, )); $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; // If we have campaigns enabled, add those elements to both the fields, filters and sorting $this->addCampaignFields('civicrm_membership', FALSE, TRUE); $this->_currencyColumn = 'civicrm_contribution_currency'; parent::__construct(); } public function preProcess() { $this->assign('reportTitle', ts('Membership Detail Report')); parent::preProcess(); } public function from() { $this->setFromBase('civicrm_contact'); $this->_from .= " {$this->_aclFrom} INNER JOIN civicrm_membership {$this->_aliases['civicrm_membership']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_membership']}.contact_id AND {$this->_aliases['civicrm_membership']}.is_test = 0 LEFT JOIN civicrm_membership_status {$this->_aliases['civicrm_membership_status']} ON {$this->_aliases['civicrm_membership_status']}.id = {$this->_aliases['civicrm_membership']}.status_id "; $this->joinAddressFromContact(); $this->joinPhoneFromContact(); $this->joinEmailFromContact(); //used when contribution field is selected. if ($this->isTableSelected('civicrm_contribution')) { $this->_from .= " LEFT JOIN civicrm_membership_payment cmp ON {$this->_aliases['civicrm_membership']}.id = cmp.membership_id LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} ON cmp.contribution_id={$this->_aliases['civicrm_contribution']}.id\n"; } } /** * Alter display of rows. * * Iterate through the rows retrieved via SQL and make changes for display purposes, * such as rendering contacts as links. * * @param array $rows * Rows generated by SQL, with an array for each row. */ public function alterDisplay(&$rows) { $entryFound = FALSE; $checkList = array(); $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); $repeatFound = FALSE; foreach ($rows as $rowNum => $row) { if ($repeatFound == FALSE || $repeatFound < $rowNum - 1 ) { unset($checkList); $checkList = array(); } if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') { // not repeat contact display names if it matches with the one // in previous row foreach ($row as $colName => $colVal) { if (in_array($colName, $this->_noRepeats) && $rowNum > 0 ) { if ($rows[$rowNum][$colName] == $rows[$rowNum - 1][$colName] || (!empty($checkList[$colName]) && in_array($colVal, $checkList[$colName])) ) { $rows[$rowNum][$colName] = ""; // CRM-15917: Don't blank the name if it's a different contact if ($colName == 'civicrm_contact_exposed_id') { $rows[$rowNum]['civicrm_contact_sort_name'] = ""; } $repeatFound = $rowNum; } } if (in_array($colName, $this->_noRepeats)) { $checkList[$colName][] = $colVal; } } } if (array_key_exists('civicrm_membership_membership_type_id', $row)) { if ($value = $row['civicrm_membership_membership_type_id']) { $rows[$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant::membershipType($value, FALSE); } $entryFound = TRUE; } if (array_key_exists('civicrm_contact_sort_name', $row) && $rows[$rowNum]['civicrm_contact_sort_name'] && array_key_exists('civicrm_contact_id', $row) ) { $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl ); $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact."); $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) { $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value]; $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) { $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value]; $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_payment_instrument_id', $row)) { $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value]; $entryFound = TRUE; } // Convert campaign_id to campaign title if (array_key_exists('civicrm_membership_campaign_id', $row)) { if ($value = $row['civicrm_membership_campaign_id']) { $rows[$rowNum]['civicrm_membership_campaign_id'] = $this->campaigns[$value]; $entryFound = TRUE; } } $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'member/detail', 'List all memberships(s) for this ') ? TRUE : $entryFound; $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'member/detail', 'List all memberships(s) for this ') ? TRUE : $entryFound; if (!$entryFound) { break; } } } }