Skip to content

Commit

Permalink
Merge pull request civicrm#4961 from pratikshad/core-bugs
Browse files Browse the repository at this point in the history
Fixed Division by zero warning in Contribution Repeat CiviReport
  • Loading branch information
monishdeb committed Jan 16, 2015
2 parents 1dc442d + 9e9b9b8 commit 3cb2529
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions CRM/Report/Form/Contribute/Repeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,11 @@ public function statistics(&$rows) {
}

$total_distinct_contacts = count($contact_sums);
$number_maintained = 0;
$number_upgraded = 0;
$number_downgraded = 0;
$number_new = 0;
$number_lapsed = 0;
$maintained = 0;
$upgraded = 0;
$downgraded = 0;
$new = 0;
$lapsed = 0;

foreach ($contact_sums as $uid => $row) {
if ($row['contribution1_total_amount_sum'] &&
Expand All @@ -634,49 +634,50 @@ public function statistics(&$rows) {
$change = ($row['contribution1_total_amount_sum'] -
$row['contribution2_total_amount_sum']);
if ($change == 0) {
$number_maintained += 1;
$maintained += 1;
}
elseif ($change > 0) {
$number_upgraded += 1;
$upgraded += 1;
}
elseif ($change < 0) {
$number_downgraded += 1;
$downgraded += 1;
}
}
elseif ($row['contribution1_total_amount_sum']) {
$number_new += 1;
$new += 1;
}
elseif ($row['contribution2_total_amount_sum']) {
$number_lapsed += 1;
$lapsed += 1;
}
}

//calculate percentages from numbers
$percent_maintained = ($number_maintained / $total_distinct_contacts) * 100;
$percent_upgraded = ($number_upgraded / $total_distinct_contacts) * 100;
$percent_downgraded = ($number_downgraded / $total_distinct_contacts) * 100;
$percent_new = ($number_new / $total_distinct_contacts) * 100;
$percent_lapsed = ($number_lapsed / $total_distinct_contacts) * 100;

if (!empty($total_distinct_contacts)) {
$maintained = ($maintained / $total_distinct_contacts) * 100;
$upgraded = ($upgraded / $total_distinct_contacts) * 100;
$downgraded = ($downgraded / $total_distinct_contacts) * 100;
$new = ($new / $total_distinct_contacts) * 100;
$lapsed = ($lapsed / $total_distinct_contacts) * 100;
}
//display percentages for new, lapsed, upgraded, downgraded, and maintained contributors
$statistics['counts']['count_new'] = array(
'value' => $percent_new,
'value' => $new,
'title' => '% New Donors',
);
$statistics['counts']['count_lapsed'] = array(
'value' => $percent_lapsed,
'value' => $lapsed,
'title' => '% Lapsed Donors',
);
$statistics['counts']['count_upgraded'] = array(
'value' => $percent_upgraded,
'value' => $upgraded,
'title' => '% Upgraded Donors',
);
$statistics['counts']['count_downgraded'] = array(
'value' => $percent_downgraded,
'value' => $downgraded,
'title' => '% Downgraded Donors',
);
$statistics['counts']['count_maintained'] = array(
'value' => $percent_maintained,
'value' => $maintained,
'title' => '% Maintained Donors',
);

Expand Down

0 comments on commit 3cb2529

Please sign in to comment.