Skip to content

Commit

Permalink
Readability cleanup on EventIncome report to bring it under testing
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Apr 5, 2019
1 parent e4d61a8 commit 14ddb0f
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions CRM/Report/Form/Event/Income.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public function buildEventReport($eventIDs) {

$eventID = implode(',', $eventIDs);

$participantStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "is_counted = 1", "label");
$participantRole = CRM_Event_PseudoConstant::participantRole();
$paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();

Expand All @@ -90,15 +89,8 @@ public function buildEventReport($eventIDs) {
if ($optionGroupDAO->find(TRUE)) {
$optionGroupId = $optionGroupDAO->id;
}
//show the income of active participant status (Counted = filter = 1)
$activeParticipantStatusIDArray = $activeParticipantStatusLabelArray = array();
foreach ($participantStatus as $id => $label) {
$activeParticipantStatusIDArray[] = $id;
$activeParticipantStatusLabelArray[] = $label;
}
$activeParticipantStatus = implode(',', $activeParticipantStatusIDArray);
$activeparticipnatStutusLabel = implode(', ', $activeParticipantStatusLabelArray);
$activeParticipantClause = " AND civicrm_participant.status_id IN ( $activeParticipantStatus ) ";

$activeParticipantClause = " AND civicrm_participant.status_id IN ( " . implode(',', array_keys($this->getActiveParticipantStatuses())) . " ) ";
$select = array(
"civicrm_event.id as event_id",
"civicrm_event.title as event_title",
Expand Down Expand Up @@ -133,7 +125,7 @@ public function buildEventReport($eventIDs) {
$eventSummary[$eventDAO->event_id][ts('End Date')] = CRM_Utils_Date::customFormat($eventDAO->end_date);
$eventSummary[$eventDAO->event_id][ts('Event Type')] = $eventDAO->event_type;
$eventSummary[$eventDAO->event_id][ts('Event Income')] = CRM_Utils_Money::format($eventDAO->total, $eventDAO->currency);
$eventSummary[$eventDAO->event_id][ts('Registered Participant')] = "{$eventDAO->participant} ({$activeparticipnatStutusLabel})";
$eventSummary[$eventDAO->event_id][ts('Registered Participant')] = "{$eventDAO->participant} ({" . implode(', ', $this->getActiveParticipantStatuses()) .")";
$currency[$eventDAO->event_id] = $eventDAO->currency;
}
$this->assign_by_ref('summary', $eventSummary);
Expand Down Expand Up @@ -216,6 +208,7 @@ public function buildEventReport($eventIDs) {

$statusDAO = $this->executeReportQuery($status);

$participantStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "is_counted = 1", "label");
while ($statusDAO->fetch()) {
$statusRows[$statusDAO->event_id][$participantStatus[$statusDAO->STATUSID]]['total'] = $statusDAO->participant;
$statusRows[$statusDAO->event_id][$participantStatus[$statusDAO->STATUSID]]['round'] = round(($statusDAO->participant / $count[$statusDAO->event_id]) * 100, 2);
Expand Down Expand Up @@ -382,4 +375,17 @@ public function postProcess() {
parent::endPostProcess();
}

/**
* Get statuses with the counted filter set to TRUE.
*
* @return array
*/
protected function getActiveParticipantStatuses() {
$activeParticipantStatuses = [];
foreach (CRM_Event_PseudoConstant::participantStatus(NULL, "is_counted = 1", "label") as $id => $label) {
$activeParticipantStatuses[$id] = $label;
}
return $activeParticipantStatuses;
}

}

0 comments on commit 14ddb0f

Please sign in to comment.