From 7f2cdba1490fc7303c5b945802453b7c771f7f55 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Wed, 20 Jul 2016 16:09:32 -0700 Subject: [PATCH] reverse sort for already lapsed; add multi-year Multiyear totals are now included in report. already lapsed list is reverse sorted by date instead. --- scripts/send-renewal-notices.plx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/send-renewal-notices.plx b/scripts/send-renewal-notices.plx index 4cbbf1e..adf91fc 100644 --- a/scripts/send-renewal-notices.plx +++ b/scripts/send-renewal-notices.plx @@ -14,6 +14,8 @@ use Supporters; my $TODAY = UnixDate(ParseDate("today"), '%Y-%m-%d'); my $ONE_WEEK = UnixDate(DateCalc(ParseDate("today"), "+ 1 week"), '%Y-%m-%d'); my $ONE_MONTH = UnixDate(DateCalc(ParseDate("today"), "+ 1 month"), '%Y-%m-%d'); +my $TWO_YEARS_AGO = UnixDate(DateCalc(ParseDate("today"), "- 2 years"), '%Y-%m-%d'); +my $THREE_YEARS_AGO = UnixDate(DateCalc(ParseDate("today"), "- 3 years"), '%Y-%m-%d'); if (@ARGV < 7 ) { print STDERR "usage: $0 \n"; @@ -120,9 +122,17 @@ foreach my $cat (sort { $a cmp $b } @lapseCategories) { $emailText .= "$heading\n"; $emailText .= "-" x length($heading); $emailText .= "\n"; - foreach my $sup (sort { $a->{expiresOn} cmp $b->{expiresOn} } @{$expireReport{$cat}{list}}) { + foreach my $sup (sort { ($cat eq '02-lapsed') ? ($b->{expiresOn} cmp $a->{expiresOn}) + : ($a->{expiresOn} cmp $b->{expiresOn}) } + @{$expireReport{$cat}{list}}) { + my $threeYearTot = $sp->donorTotalGaveInPeriod(donorId => $sup->{supporterId}, + startDate => $THREE_YEARS_AGO, endDate => $TODAY); + my $twoYearTot = $sp->donorTotalGaveInPeriod(donorId => $sup->{supporterId}, + startDate => $TWO_YEARS_AGO, endDate => $TODAY); + $emailText .= " $sup->{expiresOn}: $sup->{supporterId}, $sup->{ledgerEntityId}, $sup->{displayName}, "; - $emailText .= join(", ", @{$sup->{emails}}); + $emailText .= "2YrTot: \$" . sprintf("%.2f", $twoYearTot). ", 3YrTot: \$" . sprintf("%.2f", $threeYearTot); + $emailText .= ", Emails: " . join(", ", @{$sup->{emails}}); $emailText .= "\n"; } $emailText .= "\n";