2016-05-26 19:34:52 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use autodie qw(open close chdir);
|
|
|
|
use DBI;
|
|
|
|
use Encode qw(encode decode);
|
|
|
|
|
|
|
|
use Supporters;
|
|
|
|
|
2016-05-26 19:53:20 +00:00
|
|
|
use Date::Manip::DM5;
|
|
|
|
|
|
|
|
my $TODAY = UnixDate(ParseDate("today"), '%Y-%m-%d');
|
|
|
|
my $ONE_YEAR_AGO = UnixDate(DateCalc(ParseDate("today"), "- 1 year"), '%Y-%m-%d');
|
|
|
|
|
2016-05-26 19:34:52 +00:00
|
|
|
my $LEDGER_CMD = "/usr/local/bin/ledger";
|
|
|
|
|
|
|
|
if (@ARGV < 5 ) {
|
|
|
|
print STDERR "usage: $0 <SUPPORTERS_SQLITE_DB_FILE> <MONTHLY_SEARCH_REGEX> <ANNUAL_SEARCH_REGEX> <VERBOSE> <LEDGER_CMD_LINE>\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my($SUPPORTERS_SQLITE_DB_FILE, $MONTHLY_SEARCH_REGEX, $ANNUAL_SEARCH_REGEX, $VERBOSE,
|
|
|
|
@LEDGER_CMD_LINE) = @ARGV;
|
|
|
|
|
|
|
|
my $dbh = DBI->connect("dbi:SQLite:dbname=$SUPPORTERS_SQLITE_DB_FILE", "", "",
|
|
|
|
{ RaiseError => 1, sqlite_unicode => 1 })
|
|
|
|
or die $DBI::errstr;
|
|
|
|
|
|
|
|
my $sp = new Supporters($dbh, \@LEDGER_CMD_LINE, { monthly => $MONTHLY_SEARCH_REGEX, annual => $ANNUAL_SEARCH_REGEX});
|
|
|
|
my(@supporterIds) = $sp->findDonor({});
|
|
|
|
|
2016-05-26 20:29:21 +00:00
|
|
|
foreach my $id (sort { $sp->donorLastGave($a) cmp $sp->donorLastGave($b) } @supporterIds) {
|
2016-05-26 19:34:52 +00:00
|
|
|
my $amount = $sp->donorTotalGaveInPeriod(donorId => $id);
|
2016-05-26 19:53:20 +00:00
|
|
|
my $lastGaveDate = $sp->donorLastGave($id);
|
|
|
|
my $firstGaveDate = $sp->donorFirstGave($id);
|
2016-05-26 20:29:00 +00:00
|
|
|
my $nineMonthsSinceFirstGave = UnixDate(DateCalc(ParseDate($firstGaveDate), "+ 9 months"), '%Y-%m-%d');
|
2016-05-26 20:18:28 +00:00
|
|
|
if ($amount > 180.00 and
|
|
|
|
$lastGaveDate ne $firstGaveDate and
|
|
|
|
$firstGaveDate le $ONE_YEAR_AGO and
|
2016-05-26 20:29:00 +00:00
|
|
|
$lastGaveDate ge $nineMonthsSinceFirstGave ) {
|
2016-05-26 19:34:52 +00:00
|
|
|
my $ledgerEntityId = $sp->getLedgerEntityId($id);
|
2016-05-26 20:11:10 +00:00
|
|
|
my $type = $sp->{ledgerData}{$ledgerEntityId}{__TYPE__};
|
2016-05-26 19:53:20 +00:00
|
|
|
my $shirt1 = $sp->getRequest({ donorId => $id, requestType => 't-shirt-1' });
|
|
|
|
my $shirt0 = $sp->getRequest({ donorId => $id, requestType => 't-shirt-0' });
|
2016-05-26 20:11:10 +00:00
|
|
|
print "$type: ";
|
2016-05-26 19:53:20 +00:00
|
|
|
if (not defined $shirt0 and not defined $shirt1) {
|
|
|
|
print "NEVER WANTED SHIRT: ";
|
|
|
|
} elsif (defined $shirt0 and not defined $shirt1) {
|
|
|
|
if (not defined $shirt0->{fulfillDate}) {
|
2016-05-26 20:11:10 +00:00
|
|
|
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: ";
|
|
|
|
}
|
2016-05-26 19:53:20 +00:00
|
|
|
} else {
|
|
|
|
print "NEEDS 1 SHIRT, 2ND SHIRT REQUEST MISSING: ";
|
|
|
|
}
|
|
|
|
} elsif (defined $shirt1 and not defined $shirt0) {
|
|
|
|
print "NEEDS WEIRDNESS ATTENTION, NO SHIRT0 REQUEST BUT THERE IS A SHIRT1 REQUEST: ";
|
|
|
|
} elsif (defined $shirt1 and defined $shirt0) {
|
|
|
|
print "ALL OK, 2 SHIRTS, WITH REQUESTS: ";
|
2016-05-26 19:34:52 +00:00
|
|
|
}
|
2016-05-26 19:53:20 +00:00
|
|
|
print " $ledgerEntityId gave total of $amount, firstGave $firstGaveDate, last Gave $lastGaveDate\n";
|
2016-05-26 19:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# compile-command: "perl -c find-already-renewed.plx"
|
|
|
|
# End:
|
|
|
|
|