From fb9c43d1191a77046946626e89301eec3258eb0f Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Fri, 2 Dec 2016 13:07:59 -0800 Subject: [PATCH] Count supporters rather than use all ids returned. We actually can't rely on a call to $sp->findDonor({}) to give us *just* Supporters, as eventually, this may be a donor database too. So, count them. Really, $sp->findDonor() should be able to take { isSupporter => 1 } instead. --- scripts/send-renewal-notices.plx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/send-renewal-notices.plx b/scripts/send-renewal-notices.plx index 84fec50..acab492 100644 --- a/scripts/send-renewal-notices.plx +++ b/scripts/send-renewal-notices.plx @@ -54,7 +54,10 @@ my(%activeCounter, %lapsedCounter); my %monthExpirations; +my $totalSupporters = 0; foreach my $supporterId (@supporterIds) { + next unless $sp->isSupporter($supporterId); + $totalSupporters++; my $expiresOn = $sp->supporterExpirationDate($supporterId); my $expiresOnMonth = UnixDate(ParseDate($expiresOn), '%Y-%m'); { no warnings 'uninitialized'; $monthExpirations{$expiresOnMonth}++; } @@ -142,13 +145,13 @@ foreach my $supporterId (@supporterIds) { } my $subject = "Supporter lapsed report for $TODAY"; -my $per = ( ($lapsedCount / scalar(@supporterIds)) * 100.00); +my $per = ( ($lapsedCount / $totalSuppporters) * 100.00); my $headerInfo = "$subject\n" . ("=" x length($subject)) . - "\n\nWe have " . scalar(@supporterIds) . " supporters and $lapsedCount are lapsed. That's " . - sprintf("%.2f", $per) . "%.\nActive supporter count: " . (scalar(@supporterIds) - $lapsedCount) . "\n" . + "\n\nWe have " . $totalSuppporters . " supporters and $lapsedCount are lapsed. That's " . + sprintf("%.2f", $per) . "%.\nActive supporter count: " . ($totalSuppporters - $lapsedCount) . "\n" . sprintf(" Of the active supporters, %.2f%% are monthly and %.2f%% are annual", - ( ($activeCounter{Monthly} / (scalar(@supporterIds) - $lapsedCount)) * 100.00), - ( ($activeCounter{Annual} / (scalar(@supporterIds) - $lapsedCount)) * 100.00)) . ".\n\n"; + ( ($activeCounter{Monthly} / ($totalSuppporters - $lapsedCount)) * 100.00), + ( ($activeCounter{Annual} / ($totalSuppporters - $lapsedCount)) * 100.00)) . ".\n\n"; foreach my $type (keys %lapsedCounter) { $headerInfo .= sprintf("%7s: Lapsed Count: %3d Active Count: %3d\n",