Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / Report / Table / Daily.pm
index 6087b0d..c181064 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use vars qw( @ISA );
 use FS::Report::Table;
 use FS::Conf;
-use Time::Local qw( timelocal );
+use Time::Local qw( timelocal timelocal_nocheck ); # eventually replace with DateTime
 use Date::Format qw( time2str );
 
 @ISA = qw( FS::Report::Table );
@@ -27,6 +27,7 @@ FS::Report::Table::Daily - Tables of report data, indexed daily
     'end_day'     => 27,
     #opt
     'agentnum'    => 54
+    'cust_classnum' => [ 1,2,4 ],
     'params'      => [ [ 'paramsfor', 'item_one' ], [ 'item', 'two' ] ], # ...
     'remove_empty' => 1, #collapse empty rows, default 0
     'item_labels' => [ ], #useful with remove_empty
@@ -54,6 +55,8 @@ sub data {
   my $emonth = $self->{'end_month'};
   my $eyear = $self->{'end_year'};
   my $agentnum = $self->{'agentnum'};
+  my $cust_classnum = $self->{'cust_classnum'} || [];
+  $cust_classnum = [ $cust_classnum ] if !ref($cust_classnum);
 
   my %data;
 
@@ -66,12 +69,15 @@ sub data {
   #warn "daily range $sdate $edate\n";
 
   # XXX: use date_format config for the labels since we have day in the labels now?
-  # XXX: leap seconds / DST 
   while ( $sdate < $edate ) {
     push @{$data{label}}, time2str($date_format, $sdate);
 
     my $speriod = $sdate;
-    $sdate += 86400;
+
+    #ala part_pkg->add_freq, to deal with local DST.  DateTime also a good idea
+    my ($mday,$mon,$year) = (localtime($sdate) )[3,4,5];
+    $sdate = timelocal_nocheck(0,0,0,$mday+1,$mon,$year);
+
     my $eperiod = $sdate;
 
     push @{$data{speriod}}, $speriod;
@@ -83,6 +89,7 @@ sub data {
     for ( $i = 0; $i < scalar(@items); $i++ ) {
          my $item = $items[$i];
          my @param = $self->{'params'} ? @{ $self->{'params'}[$col] }: ();
+          push @param, 'cust_classnum' => $cust_classnum if @$cust_classnum;
          my $value = $self->$item($speriod, $eperiod, $agentnum, @param);
          push @{$data{data}->[$col++]}, $value;
     }