From 9e84aefc0c77794cb25cc8beffdd2229a1ba9cc0 Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Mon, 3 Feb 2020 13:18:45 -0600 Subject: [PATCH] Fix for #1573: Extra columns for Contribution Detail report. --- CRM/Report/Form/Contribute/Detail.php | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 3a38e2d631ae..fc52b68299ad 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -344,6 +344,29 @@ public function __construct() { ]) + $this->addAddressFields(FALSE); // The tests test for this variation of the sort_name field. Don't argue with the tests :-). $this->_columns['civicrm_contact']['fields']['sort_name']['title'] = ts('Donor Name'); + + $this->_columns['civicrm_contact']['fields']['addressee_display'] = array('title' => ts('Addressee')); + $this->_columns['civicrm_contact']['fields']['preferred_communication_method'] = array( + 'title' => ts('Preferred Communication Method'), + ); + + $this->_columns['civicrm_contact']['fields']['employer_id'] = array( + 'no_display' => TRUE, + 'required' => TRUE, + ); + $this->_columns['civicrm_contact_employer'] = array( + 'dao' => 'CRM_Contact_DAO_Contact', + 'fields' => array( + 'employer_display_name' => array( + 'title' => ts('Current Employer'), + 'name' => 'display_name', + ), + ), + ); + $this->_columns['civicrm_address']['fields']['location_type_id'] = array( + 'title' => ts('Address Location Type'), + ); + $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; // If we have campaigns enabled, add those elements to both the fields, filters and sorting @@ -616,6 +639,8 @@ protected function storeGroupByArray() { public function alterDisplay(&$rows) { $entryFound = FALSE; $display_flag = $prev_cid = $cid = 0; + $communicationMethods = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); + $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'label'); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); @@ -675,6 +700,34 @@ public function alterDisplay(&$rows) { $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact."); } + // convert employer name to link + if ( + $employerDisplayName = CRM_Utils_Array::value('civicrm_contact_employer_employer_display_name', $row) + && $employerId = CRM_Utils_Array::value('civicrm_contact_employer_id', $row) + ) { + $url = CRM_Utils_System::url("civicrm/contact/view", + 'reset=1&cid=' . $employerId, + $this->_absoluteUrl + ); + $rows[$rowNum]['civicrm_contact_employer_employer_display_name_link'] = $url; + $rows[$rowNum]['civicrm_contact_employer_employer_display_name_hover'] = ts("View Contact Summary for Employer."); + } + + // Convert address location type id to text + if ($value = CRM_Utils_Array::value('civicrm_address_location_type_id', $row)) { + $rows[$rowNum]['civicrm_address_location_type_id'] = $locationTypes[$value]; + $entryFound = TRUE; + } + + // Convert preferred communication type value to comma-separated text + if ($value = CRM_Utils_Array::value('civicrm_contact_preferred_communication_method', $row)) { + // Explode padded values. + $values = CRM_utils_array::explodePadded($value); + // Flip values, compute intersection with $communicationMethods, and implode with commas. + $rows[$rowNum]['civicrm_contact_preferred_communication_method'] = implode(', ', array_intersect_key($communicationMethods, array_flip($values))); + $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; @@ -958,6 +1011,14 @@ public function appendAdditionalFromJoins() { ON ({$this->_aliases['civicrm_batch']}.entity_id = eft.financial_trxn_id AND {$this->_aliases['civicrm_batch']}.entity_table = 'civicrm_financial_trxn')"; } + + if ($this->isTableSelected('civicrm_contact_employer')) { + $this->_from .= " + LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact_employer']} + ON {$this->_aliases['civicrm_contact_employer']}.id = {$this->_aliases['civicrm_contact']}.employer_id + "; + } + // for credit card type $this->addFinancialTrxnFromClause(); }