From 6a6ec1fca24bac85a1ef947f5e59b39eb059c36a Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Thu, 26 May 2016 20:38:48 -0700 Subject: [PATCH] Properly sort so most in need get shirts first. The idea behind this sort is to give monthlies top priority based on their id number (i.e., when they hit $60, just get that shirt out to them), and for annuals, make sure we prioritize based on how long it has been since their last donation. --- scripts/t-shirt-label-print.plx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/t-shirt-label-print.plx b/scripts/t-shirt-label-print.plx index f549950..6435e28 100644 --- a/scripts/t-shirt-label-print.plx +++ b/scripts/t-shirt-label-print.plx @@ -63,7 +63,20 @@ my(@supporterIds) = $sp->findDonor({}); my $overallCount = 0; my %lines; -foreach my $id (@supporterIds) { +sub sortFunction($$) { + my $lastGaveDate0 = $sp->donorLastGave($_[0]); + my $lastGaveDate1 = $sp->donorLastGave($_[1]); + my $ledgerEntityId0 = $sp->getLedgerEntityId($_[0]); + my $ledgerEntityId1 = $sp->getLedgerEntityId($_[1]); + my $type0 = $sp->{ledgerData}{$ledgerEntityId0}{__TYPE__}; + my $type1 = $sp->{ledgerData}{$ledgerEntityId1}{__TYPE__}; + if ( (defined $type0 and $type =~ /month/i) or (defined $type1 and $type =~ /month/i)) { + return ($_[0] <=> $_[1]); + } else { + return ($lastGaveDate0 cmp $lastGaveDate1); + } +} +foreach my $id (sort { sortFunction($a, $b); } @supporterIds) { my $sizeNeeded; foreach my $type (qw/t-shirt-0 t-shirt-1/) { my $request = $sp->getRequest({ donorId => $id, requestType => 't-shirt-0', ignoreFulfilledRequests => 1 });