From cebb1d813bfbe0fb9873223f4810bfd943519ed8 Mon Sep 17 00:00:00 2001
From: "Bradley M. Kuhn" <bkuhn@ebb.org>
Date: Sun, 22 Jul 2018 15:08:45 -0700
Subject: [PATCH] Move Entity lookup until after ticket is found.

---
 scripts/rt-outreachy-payment-next.plx | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/scripts/rt-outreachy-payment-next.plx b/scripts/rt-outreachy-payment-next.plx
index 81d2715..d04631a 100755
--- a/scripts/rt-outreachy-payment-next.plx
+++ b/scripts/rt-outreachy-payment-next.plx
@@ -169,12 +169,6 @@ while (my $file = readdir $dh) {
     next;
   }
 
-  # Find the ticket number for this intern.
-  my $entity = LedgerTagFromTicket($ticket, 'Entity');
-  if (not defined $entity) {
-    print STDERR "\"$file\": \"$ticket\": Skipping: cannot determine Entity from ticket." ;
-    next;
-  }
   my(@nameComponents) = split(/\s*-\s*/, $name);
   my(@searchTerms);
   foreach my $name (@nameComponents) {
@@ -196,7 +190,14 @@ while (my $file = readdir $dh) {
       die "interactive mode not yet supported";
     }
   }
-  if ($PAYMENT_NUMBER == 1) {
+  # Find the ticket number for this intern.
+  my $entity = LedgerTagFromTicket($ticket, 'Entity');
+  if (not defined $entity) {
+    print STDERR "\"$file\": \"$ticket\": Skipping: cannot determine Entity from ticket." ;
+    next;
+  }
+
+  if ($PAYMENT_NUMBER <= 1) {
     print STDERR "Sorry, script does not yet support first payment\n";
     exit 1;
   }