Add command line option.
This commit is contained in:
parent
fc1c35c25c
commit
cb49fb5c3e
1 changed files with 67 additions and 2 deletions
|
@ -11,7 +11,7 @@ use Getopt::Long;
|
||||||
use File::Spec;
|
use File::Spec;
|
||||||
use Date::Manip qw(ParseDate UnixDate);
|
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(@) {
|
sub FindUniqueTicket(@) {
|
||||||
|
@ -63,14 +63,79 @@ sub LedgerTagFromTicket($$) {
|
||||||
return $tagValue;
|
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,
|
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;
|
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
|
||||||
|
|
||||||
$INTERACTIVE = 0 if not defined $INTERACTIVE;
|
$INTERACTIVE = 0 if not defined $INTERACTIVE;
|
||||||
|
|
||||||
|
unless (defined $INVOICE_LINE and $INVOICE_LINE =~ /^rt.*/) {
|
||||||
|
print STDERR "usage: $0 --invoiceLine=<RT_SPEC> option is required and must match an RT spec\n";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
unless (defined $PAYMENT_DIR and -d $PAYMENT_DIR) {
|
unless (defined $PAYMENT_DIR and -d $PAYMENT_DIR) {
|
||||||
print STDERR "usage: $0 --paymentDir=<DIRECTORY> option is required and directory must exist\n";
|
print STDERR "usage: $0 --paymentDir=<DIRECTORY> option is required and directory must exist\n";
|
||||||
exit 1;
|
exit 1;
|
||||||
|
|
Loading…
Reference in a new issue