Final corrections to handle multiple shirt request

With this adjustments, the script seems to now handle multiple
shirt-requests properly.
This commit is contained in:
Bradley M. Kuhn 2017-01-10 11:36:50 -08:00
parent 33e2a42179
commit 22e02fb40e

View file

@ -42,14 +42,15 @@ while (my $line = <TEX_FILE>) {
close TEX_FILE; close TEX_FILE;
foreach my $id (sort keys %idsSent) { foreach my $id (sort keys %idsSent) {
my $request;
my @requestTypes = $sp->getRequestType(); my @requestTypes = $sp->getRequestType();
my $sizesSent; my $sizesSent;
my $foundRequestCount = 0;
foreach my $type (@requestTypes) { foreach my $type (@requestTypes) {
next unless ($type =~ /t-shirt/); next unless ($type =~ /shirt/);
$request = $sp->getRequest({ donorId => $id, requestType => $type, my $request = $sp->getRequest({ donorId => $id, requestType => $type,
ignoreHeldRequests => 1, ignoreFulfilledRequests => 1 }); ignoreHeldRequests => 1, ignoreFulfilledRequests => 1 });
if (defined $request and defined $request->{requestType}) { if (defined $request and defined $request->{requestId} and defined $request->{requestType}) {
$foundRequestCount++;
my $size = $request->{requestConfiguration}; my $size = $request->{requestConfiguration};
if (not defined $idsSent{$id}{$size} and $idsSent{$id}{$size}-- > 0) { if (not defined $idsSent{$id}{$size} and $idsSent{$id}{$size}-- > 0) {
my $out = "WARNING: not fufilling $id request for $request->{requstConfiguration} because we sent wrong size of $idsSent{$id}!\n"; my $out = "WARNING: not fufilling $id request for $request->{requstConfiguration} because we sent wrong size of $idsSent{$id}!\n";
@ -57,6 +58,8 @@ foreach my $id (sort keys %idsSent) {
print STDERR $out; print STDERR $out;
$request = undef; $request = undef;
} else { } else {
$sp->fulfillRequest({ donorId => $id, requestType => $request->{requestType},
who => $WHO, how => $HOW});
if (defined $sizesSent) { if (defined $sizesSent) {
$sizesSent .= ", $size"; $sizesSent .= ", $size";
} else { } else {
@ -64,18 +67,14 @@ foreach my $id (sort keys %idsSent) {
} }
} }
} }
last if defined $request;
} }
if (not defined $request) { unless ($foundRequestCount > 0) {
my $out = "WARNING: We seem to have sent $id a t-shirt that $id didn't request! Ignoring that and contuining...\n"; my $out = "WARNING: We seem to have sent $id a t-shirt that $id didn't request! Ignoring that and contuining...\n";
print $out; print $out;
print STDERR $out; print STDERR $out;
next; next;
} }
$sp->fulfillRequest({ donorId => $id, requestType => $request->{requestType}, next unless $sp->emailOk($id);
who => $WHO, how => $HOW});
next unless $sp->emailOk($donorId);
my $emailTo = $sp->getPreferredEmailAddress($id); my $emailTo = $sp->getPreferredEmailAddress($id);
if (not defined $emailTo) { if (not defined $emailTo) {
my(@addr) = $sp->getEmailAddresses($id); my(@addr) = $sp->getEmailAddresses($id);