Support --subTotals option for each payment method.
--subTotals implies --showAmounts, and when you use it, the ticket amounts are grouped by payment type, and the subtotal for each payment type is printed. Note that I left some code duplication in the $subTotalOk / $overallTotalOk support stuff. It was just laziness. There should be a sub that tests the values for validity.
This commit is contained in:
parent
df7362f6b9
commit
b5bb608067
1 changed files with 26 additions and 6 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($VERBOSE, $INTERACTIVE, $RT_CMD, $SVN_CMD, %AMOUNTS, $SHOW_AMOUNTS, $QUERY_STRING);
|
my($VERBOSE, $INTERACTIVE, $RT_CMD, $SVN_CMD, %AMOUNTS, $SHOW_AMOUNTS, $QUERY_STRING, $SUB_TOTALS);
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
sub TicketIDsReadyForPayment () {
|
sub TicketIDsReadyForPayment () {
|
||||||
|
@ -72,7 +72,9 @@ sub FindMostRecentPaymentMethodForTicket ($) {
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
GetOptions("verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE, 'showAmounts' => \$SHOW_AMOUNTS,
|
GetOptions("verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE, 'showAmounts' => \$SHOW_AMOUNTS,
|
||||||
|
'subTotals' => \$SUB_TOTALS,
|
||||||
"rtCommand=s" => \$RT_CMD, "svnCommand=s" => \$SVN_CMD, 'queryString=s' => \$QUERY_STRING);
|
"rtCommand=s" => \$RT_CMD, "svnCommand=s" => \$SVN_CMD, 'queryString=s' => \$QUERY_STRING);
|
||||||
|
$SHOW_AMOUNTS = 1 if $SUB_TOTALS;
|
||||||
|
|
||||||
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
|
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
|
||||||
$SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD;
|
$SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD;
|
||||||
|
@ -99,21 +101,39 @@ 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);
|
||||||
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);
|
||||||
|
if ($SUB_TOTALS) {
|
||||||
|
foreach my $tix (@{$payments{$paymentMethod}}) {
|
||||||
|
$tix =~ s%^\s*ticket\s*/\s*%%;
|
||||||
|
my $val = $AMOUNTS{$tix};
|
||||||
|
print "$tix: $AMOUNTS{$tix}\n";
|
||||||
|
$val =~ s/\$//g; $val =~ s/,//g; $val =~ s/\s//g;
|
||||||
|
if ($val =~ /^[\d\.]+$/) { $subTotal += $val; } else { $subTotalOk = 0; }
|
||||||
|
|
||||||
|
}
|
||||||
|
if ($subTotalOk) {
|
||||||
|
print "SUBTOTAL for $paymentMethod: $subTotal\n";
|
||||||
|
$overallTotal += $subTotal;
|
||||||
|
} else {
|
||||||
|
$overallTotalOk = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($SHOW_AMOUNTS) {
|
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));
|
||||||
my $total = 0.00;
|
|
||||||
my $totalOk = 1;
|
|
||||||
foreach my $tix (sort { $a <=> $b} (keys %AMOUNTS)) {
|
foreach my $tix (sort { $a <=> $b} (keys %AMOUNTS)) {
|
||||||
my $val = $AMOUNTS{$tix};
|
my $val = $AMOUNTS{$tix};
|
||||||
print "$tix: $AMOUNTS{$tix}\n";
|
print "$tix: $AMOUNTS{$tix}\n";
|
||||||
$val =~ s/\$//g; $val =~ s/,//g; $val =~ s/\s//g;
|
$val =~ s/\$//g; $val =~ s/,//g; $val =~ s/\s//g;
|
||||||
if ($val =~ /^[\d\.]+$/) { $total += $val; } else { $totalOk = 0; }
|
if ($val =~ /^[\d\.]+$/) { $overallTotal += $val; } else { $overallTotalOk = 0; }
|
||||||
}
|
}
|
||||||
print "\nTOTAL AMOUNT: $total\n" if $totalOk;
|
print "\nTOTAL AMOUNT: $overallTotal\n" if $overallTotalOk;
|
||||||
|
} elsif ($SUB_TOTALS) {
|
||||||
|
print "\nTOTAL AMOUNT: $overallTotal\n" if $overallTotalOk;
|
||||||
}
|
}
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue