=================================================================== RCS file: /cvs/RT/Invoicing/rt_invoices.pl,v retrieving revision 1.29 retrieving revision 1.31 diff -u -r1.29 -r1.31 --- RT/Invoicing/rt_invoices.pl 2011/05/03 05:38:56 1.29 +++ RT/Invoicing/rt_invoices.pl 2011/05/07 02:03:55 1.31 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $AFresh1: rt_invoices.pl,v 1.28 2011/04/19 03:35:12 andrew Exp $ +# $AFresh1: rt_invoices.pl,v 1.30 2011/05/03 04:41:11 andrew Exp $ ######################################################################## # Copyright (c) 2011 Andrew Fresh # @@ -101,30 +101,28 @@ foreach my $fee ( @{ $project->{fees} } ) { my $hours = hours_for_date( $cust->{invoice}, $fee->{date} ); - my $h_type - = exists $hours->{ $fee->{type} } - ? $fee->{type} - : 'default'; + my $type = exists $hours->{ $fee->{type} } + && $hours->{ $fee->{type} } > 0 ? $type : 'default'; - next unless exists $hours->{$h_type} && $hours->{$h_type} > 0; + next unless exists $hours->{$type} && $hours->{$type} > 0; my $discount_time = 0; - if ( $hours->{$h_type} > $fee->{count} ) { - $hours->{$h_type} -= $fee->{count}; + if ( $hours->{$type} > $fee->{count} ) { + $hours->{$type} -= $fee->{count}; $discount_time = $fee->{count}; } else { - $discount_time = $hours->{$h_type}; - $hours->{$h_type} = 0; + $discount_time = $hours->{$type}; + $hours->{$type} = 0; } if ($discount_time) { $cust->{invoice}->{discount}->{amount} += round( $discount_time * $fee->{rate} ); - $cust->{invoice}->{discount}->{hours}{$h_type} += $discount_time; + $cust->{invoice}->{discount}->{hours}{$type} += $discount_time; - $h_type = '' if $h_type eq 'default'; - $fee->{detail} = "$discount_time $h_type Hours Discounted"; + $type = '' if $type eq 'default'; + $fee->{detail} = "$discount_time $type Hours Discounted"; } } @@ -341,8 +339,9 @@ } # Is the start date more than $freq $per before the end date? - my $diff = $billend - $date; - return {} if $diff->in_units($per) < 1; + return {} + if DateTime->compare( $date->clone->add( $per => $freq ), $billend ) + > 0; if ( $cust->{base_rate} ) { my ( $project, $hours ) = make_base_project(