Improve totals and subtotals output amounts

Various changes that I did a while ago to better support totals and
subtotals output.
This commit is contained in:
Bradley M. Kuhn 2020-06-22 10:18:30 -07:00
parent b5bb608067
commit 8ac2663124

View file

@ -63,8 +63,11 @@ sub FindMostRecentPaymentMethodForTicket ($) {
$paymentMethod = lc($1) $paymentMethod = lc($1)
if ($showLine =~ /^\s*PAYMENT\s+METHOD\s*:\s*(.*?)\s*$/); if ($showLine =~ /^\s*PAYMENT\s+METHOD\s*:\s*(.*?)\s*$/);
# don't 'last' when found as we want the last one. # 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 ($showLine =~ /^\s*(?:TOTAL|AMOUNT)(?:\s*TO\s*PAY)?\s*:\s*(.*?)\s*$/i); $AMOUNTS{$ticketSpec} = $1;
$AMOUNTS{$ticketSpec} =~ s/\$//g; $AMOUNTS{$ticketSpec} =~ s/,//g; $AMOUNTS{$ticketSpec} =~ s/\s//g;
$AMOUNTS{$ticketSpec} =~ s/\s*U\s*sS\s*D\s*$//g;
}
} }
close $rtShowFH; close $rtShowFH;
return ($value eq 'FX Wire' or $value eq 'NO-CF-SET') ? "$value: $paymentMethod" : $value; return ($value eq 'FX Wire' or $value eq 'NO-CF-SET') ? "$value: $paymentMethod" : $value;
@ -110,13 +113,11 @@ foreach my $paymentMethod (sort { $a cmp $b } keys %payments) {
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 $val = $AMOUNTS{$tix};
print "$tix: $AMOUNTS{$tix}\n"; print sprintf(" %5d: \$%.2f\n", $tix, $AMOUNTS{$tix});
$val =~ s/\$//g; $val =~ s/,//g; $val =~ s/\s//g;
if ($val =~ /^[\d\.]+$/) { $subTotal += $val; } else { $subTotalOk = 0; } if ($val =~ /^[\d\.]+$/) { $subTotal += $val; } else { $subTotalOk = 0; }
} }
if ($subTotalOk) { if ($subTotalOk) {
print "SUBTOTAL for $paymentMethod: $subTotal\n"; print sprintf("%30s: \$%.2f\n\n", "SUBTOTAL for $paymentMethod", $subTotal);
$overallTotal += $subTotal; $overallTotal += $subTotal;
} else { } else {
$overallTotalOk = 0; $overallTotalOk = 0;
@ -127,14 +128,11 @@ 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}; my $val = $AMOUNTS{$tix};
print "$tix: $AMOUNTS{$tix}\n"; print sprintf("%5d: \$%.2f\n", $tix, $AMOUNTS{$tix});
$val =~ s/\$//g; $val =~ s/,//g; $val =~ s/\s//g;
if ($val =~ /^[\d\.]+$/) { $overallTotal += $val; } else { $overallTotalOk = 0; } if ($val =~ /^[\d\.]+$/) { $overallTotal += $val; } else { $overallTotalOk = 0; }
} }
print "\nTOTAL AMOUNT: $overallTotal\n" if $overallTotalOk;
} elsif ($SUB_TOTALS) {
print "\nTOTAL AMOUNT: $overallTotal\n" if $overallTotalOk;
} }
print sprintf("%30s: \$%.2f\n", "TOTAL AMOUNT", $overallTotal) if $overallTotalOk and $SHOW_AMOUNTS;
############################################################################### ###############################################################################
# #
# Local variables: # Local variables: