=================================================================== RCS file: /cvs/RT/Invoicing/rt_invoices.pl,v retrieving revision 1.48 retrieving revision 1.51 diff -u -r1.48 -r1.51 --- RT/Invoicing/rt_invoices.pl 2012/11/28 02:23:34 1.48 +++ RT/Invoicing/rt_invoices.pl 2015/05/07 06:21:49 1.51 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $AFresh1: rt_invoices.pl,v 1.47 2012/01/31 04:36:28 andrew Exp $ +# $AFresh1: rt_invoices.pl,v 1.50 2013/06/20 04:36:06 andrew Exp $ ######################################################################## # Copyright (c) 2011 Andrew Fresh # @@ -202,6 +202,7 @@ next unless $cust; next unless $cust->{invoice}; + next unless $credits->{$custid} < 0; $cust->{invoice}->{credit} = $credits->{$custid}; @@ -421,7 +422,7 @@ while ( $date < $billend ) { my $start = $date->clone; - $date->add($freq); + $date->add_duration($freq); my $end = $date > $billend ? $billend->clone : $date->clone; $end->subtract( seconds => 1 ); @@ -537,7 +538,7 @@ # XXX Only need $ticket for the alternate subject my $work_time = sprintf "%.03f", $txn->time_taken / 60; - my $work_type = $txn->cf('WorkType'); + my $work_type = $txn->cf('WorkType') || ''; if ( $work_type =~ s/\s*Onsite//i ) { @@ -636,7 +637,9 @@ } } - return $newest_invoice->clone->subtract($max_duration) + $newest_invoice ||= DateTime->now; + + return $newest_invoice->clone->subtract_duration($max_duration) ->subtract( days => 1 ); } @@ -649,7 +652,7 @@ my $end = DateTime->now( time_zone => 'local' ) ->set( hour => 0, minute => 0, second => 0 ); - my $start = $end->clone->subtract($freq); + my $start = $end->clone->subtract_duration($freq); # XXX This is helpful, but monthly and billday > 28 == !!! $end->subtract( days => 1 ) while $day && $end->$day_method != $day; @@ -665,7 +668,7 @@ ? DateTime->now->subtract( days => $cust->{net} ) : 0; - $cust->{no_invoice} = 1 if $start->clone->add($freq) > $end; + $cust->{no_invoice} = 1 if $start->clone->add_duration($freq) > $end; $cust->{billend} = $end; $cust->{billstart} = $start; }