Compare commits

...

10 commits

Author SHA1 Message Date
Bradley M. Kuhn
7d24d42788 Change regex to handle currency conversation USD hint.
I found a ticket today with payment-amount set as:

   "CUR AMOUNT ($OTHER_AMOUNT)"

Since the field is free-from I figured I probably need to accept
this.
2020-09-15 11:25:08 -07:00
Bradley M. Kuhn
927bb55547 Correct copyright year; I had cut and pasted and forgot.
All this was code I just wrote a few minutes ago, so the year is
2020.
2020-07-21 13:55:29 -07:00
Bradley M. Kuhn
a85a3777b3 Rename script 2020-07-21 13:51:56 -07:00
Bradley M. Kuhn
6c2d685116 Rework to handle new format of custom fields for payment methods. 2020-07-21 13:50:43 -07:00
Bradley M. Kuhn
880da9360c Additional verbosity. 2020-07-21 13:50:27 -07:00
Bradley M. Kuhn
ca31ce7c8f Don't autodie if this has a problem. 2020-07-21 13:50:14 -07:00
Bradley M. Kuhn
877f50996f Add note. 2020-07-21 13:50:03 -07:00
Bradley M. Kuhn
5a16830b12 Cleanup key. 2020-07-21 13:49:52 -07:00
Bradley M. Kuhn
11d060a2fa rt-reassign: script to reassign tickets.
This assumes a set of ticket ids on STDIN and reassigns them if
they're open and in the queue specified on the CLI.
2020-07-21 13:48:58 -07:00
Bradley M. Kuhn
8ac2663124 Improve totals and subtotals output amounts
Various changes that I did a while ago to better support totals and
subtotals output.
2020-06-22 10:18:30 -07:00
6 changed files with 91 additions and 34 deletions

View file

@ -46,28 +46,27 @@ sub FindMostRecentPaymentMethodForTicket ($) {
$ticketSpec =~ s%^\s*ticket\s*/\s*%%; $ticketSpec =~ s%^\s*ticket\s*/\s*%%;
open(my $rtShowFH, "-|", "$RT_CMD", "show", '-t', 'ticket', '-f', 'CF.{payment-method}', $ticketSpec); open(my $rtShowFH, "-|", "$RT_CMD", "show", '-t', 'ticket', '-f', 'CF.{payment-method}', $ticketSpec);
my($ticketDataAgain, $value) = <$rtShowFH>; my($ticketDataAgain, $value) = <$rtShowFH>;
close $rtShowFH; close $rtShowFH;
chomp $value; $value =~ s/^\s*cf.\{payment-method\}\s*:\s+(.*)$/$1/i
chomp $value; $value =~ s/^\s*cf.{payment-method}\s*:\s+(.*)$/$1/i
or warn "$ticketSpec: Unknown value for payment-method of \"$value\""; or warn "$ticketSpec: Unknown value for payment-method of \"$value\"";
if (not defined $value or $value =~ /^\s*$/) { if (not defined $value or $value =~ /^\s*$/) {
$value = "NO-CF-SET"; $value = "NO-CF-SET";
} elsif ($value ne 'FX Wire') {
return $value unless $SHOW_AMOUNTS;
}
$ticketSpec =~ s%^\s*ticket\s*/\s*%%;
open($rtShowFH, "-|", "$RT_CMD", "show", $ticketSpec);
while (my $showLine = <$rtShowFH>) {
print STDERR "rt show line for $ticketSpec: $showLine" if ($VERBOSE >= 10);
$paymentMethod = lc($1)
if ($showLine =~ /^\s*PAYMENT\s+METHOD\s*:\s*(.*?)\s*$/);
# don't 'last' when found as we want the last one.
$AMOUNTS{$ticketSpec} = $1
if ($showLine =~ /^\s*(?:TOTAL|AMOUNT)(?:\s*TO\s*PAY)?\s*:\s*(.*?)\s*$/i);
} }
if ($SHOW_AMOUNTS) {
open(my $rtShowFH, "-|", "$RT_CMD", "show", '-t', 'ticket', '-f', 'CF.{payment-amount}', $ticketSpec);
my($ticketDataYetAgain, $curAndAmount) = <$rtShowFH>;
close $rtShowFH; close $rtShowFH;
return ($value eq 'FX Wire' or $value eq 'NO-CF-SET') ? "$value: $paymentMethod" : $value; chomp $curAndAmount; $curAndAmount =~ s/^\s*cf.\{payment-amount\}\s*:\s+(.*)$/$1/i;
$ticketSpec =~ s%^\s*ticket\s*/\s*%%;
$curAndAmount = "USD -32767.69" if not defined $curAndAmount;
$curAndAmount =~ /^\s*([A-Z]{3,3})\s+([\-\d\,\.]+)(\s+\(\s*\$\s*[\-\d\,\.]+\s*\))?\s*$/
or die "Ticket, $ticketSpec, has amount of $curAndAmount";
($AMOUNTS{$ticketSpec}{currency}, $AMOUNTS{$ticketSpec}{amount}) = ($1, $2);
$AMOUNTS{$ticketSpec}{amount} =~ s/\$//g; $AMOUNTS{$ticketSpec}{amount} =~ s/,//g;
$AMOUNTS{$ticketSpec}{currency} =~ s/\s//g;
}
return $value;
} }
############################################################################### ###############################################################################
@ -101,23 +100,28 @@ foreach my $ticketSpec (@ticketSpecs) {
push(@{$payments{$paymentMethod}}, $ticketSpec); push(@{$payments{$paymentMethod}}, $ticketSpec);
} }
print "#" x 70, "\n"; print "#" x 70, "\n";
my ($overallTotal, $overallTotalOk) = (0.00, 1); my $overallTotalOk = 1;
my %overallTotals;
foreach my $paymentMethod (sort { $a cmp $b } keys %payments) { foreach my $paymentMethod (sort { $a cmp $b } keys %payments) {
print "$paymentMethod: Count: ", scalar(@{$payments{$paymentMethod}}), "\n"; print "$paymentMethod: Count: ", scalar(@{$payments{$paymentMethod}}), "\n";
print " Tickets: ", join(" ", map { s%^\s*ticket\s*/\s*%%; $_; } @{$payments{$paymentMethod}}), "\n"; print " Tickets: ", join(" ", map { s%^\s*ticket\s*/\s*%%; $_; } @{$payments{$paymentMethod}}), "\n";
my($subTotal, $subTotalOk) = (0.00, 1); my $subTotalOk = 1;
my %subTotals;
if ($SUB_TOTALS) { if ($SUB_TOTALS) {
foreach my $tix (@{$payments{$paymentMethod}}) { foreach my $tix (@{$payments{$paymentMethod}}) {
$tix =~ s%^\s*ticket\s*/\s*%%; $tix =~ s%^\s*ticket\s*/\s*%%;
my $val = $AMOUNTS{$tix}; my($currency, $val) = ($AMOUNTS{$tix}{currency}, $AMOUNTS{$tix}{amount});
print "$tix: $AMOUNTS{$tix}\n"; $subTotals{$currency} = 0.00 unless defined $subTotals{$currency};
$val =~ s/\$//g; $val =~ s/,//g; $val =~ s/\s//g; print sprintf(" %5d: %.2f %3.3s\n", $tix, $val, $currency);
if ($val =~ /^[\d\.]+$/) { $subTotal += $val; } else { $subTotalOk = 0; } if (defined $val and $val =~ /^[\d\.]+$/) { $subTotals{$currency} += $val; } else { $subTotalOk = 0; }
} }
if ($subTotalOk) { if ($subTotalOk) {
print "SUBTOTAL for $paymentMethod: $subTotal\n"; print sprintf("%30s", "SUBTOTAL for $paymentMethod\n");
$overallTotal += $subTotal; foreach my $currency (keys %subTotals) {
print sprintf("%30s %.2f %3.3s\n\n", " ", $subTotals{$currency}, $currency);
$overallTotals{$currency} = 0.00 unless defined $overallTotals{$currency};
$overallTotals{$currency} += $subTotals{$currency};
}
} else { } else {
$overallTotalOk = 0; $overallTotalOk = 0;
} }
@ -126,14 +130,19 @@ foreach my $paymentMethod (sort { $a cmp $b } keys %payments) {
if ($SHOW_AMOUNTS and not $SUB_TOTALS) { if ($SHOW_AMOUNTS and not $SUB_TOTALS) {
print "Unable to find amounts for all tickets\n" if (scalar(@ticketSpecs) != scalar(keys %AMOUNTS)); print "Unable to find amounts for all tickets\n" if (scalar(@ticketSpecs) != scalar(keys %AMOUNTS));
foreach my $tix (sort { $a <=> $b} (keys %AMOUNTS)) { foreach my $tix (sort { $a <=> $b} (keys %AMOUNTS)) {
my $val = $AMOUNTS{$tix}; foreach my $currency (keys %overallTotals) {
print "$tix: $AMOUNTS{$tix}\n"; my $val = $AMOUNTS{$tix}{$currency};
$val =~ s/\$//g; $val =~ s/,//g; $val =~ s/\s//g; print sprintf("%5d: %.2f %3.3d\n", $tix, $val, $currency);
if ($val =~ /^[\d\.]+$/) { $overallTotal += $val; } else { $overallTotalOk = 0; } $overallTotals{$currency} = 0.00 unless defined $overallTotals{$currency};
if ($val =~ /^[\d\.]+$/) { $overallTotals{$currency} += $val; } else { $overallTotalOk = 0; }
}
}
}
if ($overallTotalOk and $SHOW_AMOUNTS) {
print sprintf("%30s:\n", "TOTAL AMOUNT");
foreach my $currency (keys %overallTotals) {
print sprintf("%30s %.2f %3.3s\n\n", " ", $overallTotals{$currency}, $currency);
} }
print "\nTOTAL AMOUNT: $overallTotal\n" if $overallTotalOk;
} elsif ($SUB_TOTALS) {
print "\nTOTAL AMOUNT: $overallTotal\n" if $overallTotalOk;
} }
############################################################################### ###############################################################################
# #

View file

@ -50,6 +50,7 @@ sub GetLinksForTicket($) {
my %linked; my %linked;
open(my $rtLinksFH, "-|", "$RT_CMD", "show", $ticketSpec . '/links'); open(my $rtLinksFH, "-|", "$RT_CMD", "show", $ticketSpec . '/links');
my $type = 'NONE'; my $type = 'NONE';
print STDERR "rt-helper: GetLinksForTicket: starting\n" if ($VERBOSE > 9);
while (my $linksLine = <$rtLinksFH>) { while (my $linksLine = <$rtLinksFH>) {
print STDERR "rt-helper: GetLinksForTicket: processing line: $linksLine\n" if ($VERBOSE > 9); print STDERR "rt-helper: GetLinksForTicket: processing line: $linksLine\n" if ($VERBOSE > 9);
if ($linksLine =~ m%^([^:\s]+)\s*:%) { if ($linksLine =~ m%^([^:\s]+)\s*:%) {
@ -127,7 +128,9 @@ sub FindReimbursementTicketFromList($@) {
} }
} }
} }
{ no autodie qw(:all);
close $rtReimburseFH; close $rtReimburseFH;
}
last if defined $reimbursementTicket; last if defined $reimbursementTicket;
} }
return $reimbursementTicket; return $reimbursementTicket;

View file

@ -265,7 +265,8 @@ foreach my $ticket (@processList) {
} elsif ($line =~ /^\s*([^:]+)\s*:\s*(.+)$/) { } elsif ($line =~ /^\s*([^:]+)\s*:\s*(.+)$/) {
my($key, $val) = ($1, $2); my($key, $val) = ($1, $2);
# Note that this will take the last one used, since rt log gives ticket traffic IN ORDER. # Note that this will take the last one used, since rt log gives ticket traffic IN ORDER.
if ($key =~ /(CONTRACTED NAME|PAYMENT NAME|PAYMENT METHOD)/i) { $key =~ s/^\s*//; $key =~ s/\s*$//;
if ($key =~ /^(CONTRACTED NAME|PAYMENT NAME|PAYMENT METHOD)$/i) {
$paymentVals{$key} = $val; $paymentVals{$key} = $val;
print STDERR "\"$ticket\": rt show $ticketNum line match: $key $val for $line\n" if ($VERBOSE > 7); print STDERR "\"$ticket\": rt show $ticketNum line match: $key $val for $line\n" if ($VERBOSE > 7);
} }

43
scripts/rt-reassign.plx Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/perl
# Copyright © 2020, Bradley M. Kuhn
# License: AGPL-3.0-or-later
# probably want to pipe in: rt ls -i "Status = 'needs-release-approval'" | xargs -I_ rt show -f DependsOn _/links | grep -Eo '[0-9]+,?' | sed -e 's/,$//'
use strict;
use warnings;
use autodie qw(:all);
my $RT_CMD = '/usr/bin/rt';
my($queue, $oldUser, $newUser) = @ARGV;
my $count = 0;
foreach my $id (<STDIN>) {
chomp $id;
my $line;
open(my $rtShowFH, "-|", "$RT_CMD", "show", '-t', 'ticket', '-f', 'Queue,id,status,owner', $id);
my %tixData;
while (my $line = <$rtShowFH>) {
die "$id: invalid line: $line" unless $line =~ /^(\S+)\s*:\s+(\S+)\s*$/;
$tixData{$1} = $2;
}
close $rtShowFH;
die "$tixData{id} is not $id" unless $tixData{id} =~ /$id/;
die "$id: missing status or Owner" unless defined $tixData{Status} and defined $tixData{Owner};
my $skip = 0;
if ($tixData{Queue} ne $queue) {
$skip++; print STDERR "$id: skipping since status $tixData{Queue}\n";
} elsif ($tixData{Status} ne 'open') {
$skip++; print STDERR "$id: skipping since status $tixData{Status} is not open\n"
} elsif ($tixData{Owner} ne $oldUser) {
$skip++; print STDERR "$id: skipping since status $tixData{Owner} is not $oldUser\n" unless $tixData{Owner} eq $oldUser;
}
next if $skip > 0;
print STDERR "$id: reassigning to $newUser\n";
system($RT_CMD, 'edit', $id, 'set', "Owner=$newUser");
$count++;
}
print "Reassigned $count tickets to $newUser from $oldUser\n";

1
scripts/rt-set-deadline-from-last-correspondence.plx Normal file → Executable file
View file

@ -5,6 +5,7 @@
# This script finds the most recent correspondence from the requestor, and # This script finds the most recent correspondence from the requestor, and
# sets the Due date out from that, based on the CLI input using Date::Manip # sets the Due date out from that, based on the CLI input using Date::Manip
# should also add correspondence to note it wsa received. Easiest way to send template?
use strict; use strict;
use warnings; use warnings;