=================================================================== RCS file: /cvs/RT/Invoicing/rt_invoices.pl,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- RT/Invoicing/rt_invoices.pl 2011/04/19 04:21:06 1.27 +++ RT/Invoicing/rt_invoices.pl 2011/04/19 04:35:12 1.28 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $AFresh1: rt_invoices.pl,v 1.25 2011/04/19 03:18:13 andrew Exp $ +# $AFresh1: rt_invoices.pl,v 1.27 2011/04/19 03:21:06 andrew Exp $ ######################################################################## # Copyright (c) 2011 Andrew Fresh # @@ -135,7 +135,8 @@ my $invoice = $cust->{invoice}; next unless $invoice && $invoice->{projects} && @{ $invoice->{projects} }; - my %li = ( custid => $cust->{id}, invdate => DateTime->now->ymd, ); + my %li = ( custid => $cust->{id}, invdate => + DateTime->now( time_zone => 'local' )->ymd, ); foreach my $project ( @{ $invoice->{projects} } ) { if ( $project->{transactions} ) { @@ -313,19 +314,16 @@ default { die "Unknown per [$per]\n" } } - my $billends = DateTime->now - ->subtract( days => 1 ) - ->set( hour => 23, minute => 59, second => 59 ); + my $billend = DateTime->now( time_zone => 'local' ) + ->set( hour => 0, minute => 0, second => 0 ); # XXX This is helpful, but monthly and billday > 28 == !!! - $billends->subtract( days => 1 ) - while $day && $billends->$day_method != $day; + $billend->subtract( days => 1 ) + while $day && $billend->$day_method != $day; - my $date = $billends->clone->subtract( $per => $freq ) - ->set( hour => 0, minute => 0, second => 0 ); + my $date = $billend->clone->subtract( $per => $freq ); + my %invoice = ( end => $billend->clone->subtract( seconds => 1 ) ); - my %invoice = ( end => $billends->clone->subtract( seconds => 1 ) ); - my $lastinvoice = $state->last_invoice( $cust->{id} ); if ( $lastinvoice->{date} ) { my $last_invoice_date = ymd_to_DateTime( $lastinvoice->{date} ); @@ -338,18 +336,16 @@ } # Is the start date more than $freq $per before the end date? - my $diff = $billends - $date; + my $diff = $billend - $date; return {} if $diff->in_units($per) < 1; if ( $cust->{base_rate} ) { my ( $project, $hours ) = make_base_project( $cust, - { startdate => $date, - enddate => $billends, + { date => $date, + billend => $billend, per => $per, freq => $freq, - day => $day, - day_method => $day_method, } ); @@ -375,12 +371,10 @@ sub make_base_project { my ( $cust, $args ) = @_; - my $date = $args->{startdate}; - my $enddate = $args->{enddate}; - my $per = $args->{per}; - my $freq = $args->{freq}; - my $day = $args->{day}; - my $day_method = $args->{day_method}; + my $date = $args->{date}; + my $billend = $args->{billend}; + my $per = $args->{per}; + my $freq = $args->{freq}; my $title = $freq == 1 @@ -391,19 +385,14 @@ my %project = ( title => $title, start => $date->clone, fees => [], ); my @hours; - while ( $date < $enddate ) { + while ( $date < $billend ) { my $start = $date->clone; $date->add( $per => $freq ); - $date = $enddate->clone if $date > $enddate; - # XXX This is helpful, but monthly and billday > 28 == !!! - $date->subtract( days => 1 ) while $day && $date->$day_method != $day; - my $end = $date->clone->subtract( seconds => 1 ); + $end = $billend->clone->subtract( seconds => 1 ) if $date > $billend; - last if $end < $start; - $project{end} = $end->clone; push @{ $project{fees} }, @@ -550,12 +539,13 @@ my ( $hour, $minute, $second ) = split ':', $time if $time; return DateTime->new( - year => $year, - month => $month, - day => $day, - hour => $hour || 0, - minute => $minute || 0, - second => $second || 0, + year => $year, + month => $month, + day => $day, + hour => $hour || 0, + minute => $minute || 0, + second => $second || 0, + time_zone => 'local', ); }