=================================================================== RCS file: /cvs/RT/Invoicing/rt_invoices.pl,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- RT/Invoicing/rt_invoices.pl 2011/05/07 03:34:17 1.34 +++ RT/Invoicing/rt_invoices.pl 2011/05/18 20:02:36 1.35 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $AFresh1: rt_invoices.pl,v 1.33 2011/05/07 02:27:34 andrew Exp $ +# $AFresh1: rt_invoices.pl,v 1.34 2011/05/07 02:34:17 andrew Exp $ ######################################################################## # Copyright (c) 2011 Andrew Fresh # @@ -96,28 +96,31 @@ foreach my $fee ( @{ $project->{fees} } ) { my $hours = hours_for_date( $cust->{invoice}, $fee->{date} ); - my $type = exists $hours->{ $fee->{type} } - && $hours->{ $fee->{type} } > 0 ? $fee->{type} : 'default'; + my $type = 'unknown'; + while ($type && $type ne 'default' ) { + $type = exists $hours->{ $fee->{type} } + && $hours->{ $fee->{type} } > 0 ? $fee->{type} : 'default'; - next unless exists $hours->{$type} && $hours->{$type} > 0; + next unless exists $hours->{$type} && $hours->{$type} > 0; - my $discount_time = 0; - if ( $hours->{$type} > $fee->{count} ) { - $hours->{$type} -= $fee->{count}; - $discount_time = $fee->{count}; - } - else { - $discount_time = $hours->{$type}; - $hours->{$type} = 0; - } + my $discount_time = 0; + if ( $hours->{$type} > $fee->{count} ) { + $hours->{$type} -= $fee->{count}; + $discount_time = $fee->{count}; + } + else { + $discount_time = $hours->{$type}; + $hours->{$type} = 0; + } - if ($discount_time) { - $cust->{invoice}->{discount}->{amount} - += round( $discount_time * $fee->{rate} ); - $cust->{invoice}->{discount}->{hours}{$type} += $discount_time; + if ($discount_time) { + $cust->{invoice}->{discount}->{amount} + += round( $discount_time * $fee->{rate} ); + $cust->{invoice}->{discount}->{hours}{$type} += $discount_time; - $type = '' if $type eq 'default'; - $fee->{detail} = "$discount_time $type Hours Discounted"; + $type = '' if $type eq 'default'; + $fee->{detail} .= " $discount_time $type Hours Discounted"; + } } } @@ -156,7 +159,8 @@ my $c = "Included Hours\n"; if ( $invoice->{discount}{hours} ) { foreach my $t ( keys %{ $invoice->{discount}{hours} } ) { - $c .= "\n$invoice->{discount}{hours}{$t} $t hour"; + my $type = $t eq 'default' ? '' : $t; + $c .= "\n$invoice->{discount}{hours}{$t} $type hour"; $c .= 's' if $invoice->{discount}{hours}{$t} != 1; $c .= "\n"; }