From 279c3e33f9b1447ee53fb34016979692570f092f Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Mon, 7 Mar 2016 10:34:46 -0800 Subject: [PATCH] Add lapsed count to output for status report. --- scripts/send-renewal-notices.plx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/send-renewal-notices.plx b/scripts/send-renewal-notices.plx index c9f3ebc..6d64430 100644 --- a/scripts/send-renewal-notices.plx +++ b/scripts/send-renewal-notices.plx @@ -41,6 +41,7 @@ my @lapseCategories = ('00-lapsing-this-week', '01-lapsing-this-month', '02-laps foreach my $cat (@lapseCategories) { $expireReport{$cat}{list} = []; } +my $lapsedCount = 0; foreach my $supporterId (@supporterIds) { my $expiresOn = $sp->supporterExpirationDate($supporterId); @@ -48,6 +49,7 @@ foreach my $supporterId (@supporterIds) { my $lapsesInOneWeek = ( (defined $expiresOn) and $expiresOn le $ONE_WEEK); my $lapsesInOneMonth = ( (defined $expiresOn) and $expiresOn le $ONE_MONTH); $expiresOn = "NO-FULL-SIGNUP" if not defined $expiresOn; + $lapsedCount++ if $isLapsed; my %emails; my $email = $sp->getPreferredEmailAddress($supporterId); if (defined $email) { @@ -109,7 +111,12 @@ foreach my $supporterId (@supporterIds) { $sp->addRequest({donorId => $supporterId, requestType => $REQUEST_NAME}); } -my $emailText = ""; +my $subject = "Supporter lapsed report for $TODAY"; +my $per = ( ($lapsedCount / scalar(@supporterIds)) * 100.00); +my $emailText = "$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"; + foreach my $cat (sort { $a cmp $b } @lapseCategories) { my $heading = scalar(@{$expireReport{$cat}{list}}) . " " . $expireReport{$cat}{description}; $emailText .= "$heading\n"; @@ -126,7 +133,7 @@ my $email = Email::MIME->create( header_str => [ To => $FROM_ADDRESS, From => $FROM_ADDRESS, - Subject => "Supporter lapsed report for $TODAY" ], + Subject => $subject ], attributes => { content_type => 'text/plain', charset => 'utf-8',