diff --git a/CRM/Report/Form/Contribute/Repeat.php b/CRM/Report/Form/Contribute/Repeat.php index 7d0756062175..6a5782519bea 100644 --- a/CRM/Report/Form/Contribute/Repeat.php +++ b/CRM/Report/Form/Contribute/Repeat.php @@ -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'] && @@ -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', );