Skip to content

Commit

Permalink
Fix for #1573: Extra columns for Contribution Detail report.
Browse files Browse the repository at this point in the history
  • Loading branch information
twomice committed Feb 3, 2020
1 parent fd4987d commit 9e84aef
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions CRM/Report/Form/Contribute/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 9e84aef

Please sign in to comment.