diff --git a/scripts/rt-outreachy-payment-next.plx b/scripts/rt-outreachy-payment-next.plx index 926b7d6..81d2715 100755 --- a/scripts/rt-outreachy-payment-next.plx +++ b/scripts/rt-outreachy-payment-next.plx @@ -11,7 +11,7 @@ use Getopt::Long; use File::Spec; use Date::Manip qw(ParseDate UnixDate); -my($PAYMENT_DIR, $VERBOSE, $INTERACTIVE, $PAYMENT_NUMBER, $RT_CMD); +my($PAYMENT_DIR, $VERBOSE, $INTERACTIVE, $PAYMENT_NUMBER, $RT_CMD, $INVOICE_LINE); ############################################################################### sub FindUniqueTicket(@) { @@ -63,14 +63,79 @@ sub LedgerTagFromTicket($$) { return $tagValue; } ############################################################################### +sub GetLinksForTicket($) { + my($ticketSpec) = @_; + my @linked; + open(my $rtLinksFH, "-|", "$RT_CMD", "show", $ticketSpec . '/links'); + while (my $linksLine = <$rtLinksFH>) { + if ($linksLine =~ m%rt.*ticket/(\d+)\s*$%) { + push(@linked, $1); + } + } + close $rtLinksFH; + return @linked; +} +############################################################################### +sub FindTaxTicketFromList(@) { + my $taxTicket; + foreach my $ticket (@_) { + open(my $rtQueueFH, "-|", "$RT_CMD", "show", "-f", 'Queue', $ticket); + while (my $queueLine = <$rtQueueFH>) { + if ($queueLine =~ /\s*Queue\s*:\s*(\S+)\s*$/) { + my $queue = $1; + $taxTicket = $ticket if $queue =~ /accounts-taxinfo/; + last; + } + } + close $rtQueueFH; + last if defined $taxTicket; + } + $taxTicket = "ticket/$taxTicket" if defined $taxTicket; + return $taxTicket; +} +############################################################################### +sub GetStatusFromTicket($) { + my($ticketSpec) = @_; + my $status; + open(my $statusFH, "-|", "$RT_CMD", "show", "-f", 'Status', $ticketSpec); + while (my $statusLine = <$statusFH>) { + if ($statusLine =~ /\s*Status\s*:\s*(\S+)\s*$/) { + $status = $1; + last; + } + } + close $statusFH; + return $status; +} +############################################################################### +sub GetCustomFieldForTicket($$) { + my($ticketSpec, $customField) = @_; + open(my $rtPayFH, "-|", "$RT_CMD", "show", "-f", 'CF.{' . $customField .'}', $ticketSpec); + my $val; + while (my $customFieldLine = <$rtPayFH>) { + chomp $customFieldLine; + if ($customFieldLine =~ /^\s*(\S+)\s*$/) { + $val = $customFieldLine; + last; + } + } + close $rtPayFH; + return $val; +} +############################################################################### GetOptions("paymentDir=s" => \$PAYMENT_DIR, "verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE, - "paymentNumber=i" => \$PAYMENT_NUMBER, "rtCommand=s" => $RT_CMD); + "paymentNumber=i" => \$PAYMENT_NUMBER, "rtCommand=s" => \$RT_CMD, + "invoiceLine=s" => \$INVOICE_LINE); $RT_CMD = '/usr/bin/rt' unless defined $RT_CMD; $INTERACTIVE = 0 if not defined $INTERACTIVE; +unless (defined $INVOICE_LINE and $INVOICE_LINE =~ /^rt.*/) { + print STDERR "usage: $0 --invoiceLine= option is required and must match an RT spec\n"; + exit 1; +} unless (defined $PAYMENT_DIR and -d $PAYMENT_DIR) { print STDERR "usage: $0 --paymentDir= option is required and directory must exist\n"; exit 1;