From d72431cdce9020c1a310e0d0155f4a4b4118c0f5 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Thu, 26 May 2016 13:11:10 -0700 Subject: [PATCH] Include type in output; range check on one request The request date depends on the import date, not the date of the donation, so we have to range-check here to see if it's nearby the date of the last donation. --- scripts/find-already-renewed.plx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/find-already-renewed.plx b/scripts/find-already-renewed.plx index 8af39fd..6962c04 100755 --- a/scripts/find-already-renewed.plx +++ b/scripts/find-already-renewed.plx @@ -37,14 +37,21 @@ foreach my $id (@supporterIds) { my $firstGaveDate = $sp->donorFirstGave($id); if ($amount > 180.00 and $lastGaveDate ne $firstGaveDate and $firstGaveDate le $ONE_YEAR_AGO) { # Ok, so they gave more than the minimum a year later my $ledgerEntityId = $sp->getLedgerEntityId($id); - my $type = $sp->{ledgerData}{ledgerData}{__TYPE__}; + my $type = $sp->{ledgerData}{$ledgerEntityId}{__TYPE__}; my $shirt1 = $sp->getRequest({ donorId => $id, requestType => 't-shirt-1' }); my $shirt0 = $sp->getRequest({ donorId => $id, requestType => 't-shirt-0' }); + print "$type: "; if (not defined $shirt0 and not defined $shirt1) { print "NEVER WANTED SHIRT: "; } elsif (defined $shirt0 and not defined $shirt1) { if (not defined $shirt0->{fulfillDate}) { - print "NEEDS 2 SHIRTS, 2ND SHIRT REQUEST MISSING: "; + my $rangeStart = UnixDate(DateCalc(ParseDate($lastGaveDate), "- 3 months"), '%Y-%m-%d'); + my $rangeEnd = UnixDate(DateCalc(ParseDate($lastGaveDate), "+ 3 months"), '%Y-%m-%d'); + if ($shirt0->{requestDate} ge $rangeStart and $shirt0->{requestDate} le $rangeEnd) { + print "ALL OK, only 1 SHIRT EVER REQUESTED: "; + } else { + print "NEEDS 2 SHIRTS, 2ND SHIRT REQUEST MISSING: "; + } } else { print "NEEDS 1 SHIRT, 2ND SHIRT REQUEST MISSING: "; }