1 package FS::Report::Table::Daily;
4 use base 'FS::Report::Table';
10 FS::Report::Table::Daily - Tables of report data, indexed daily
14 use FS::Report::Table::Daily;
16 my $report = new FS::Report::Table::Daily (
17 'items' => [ 'invoiced', 'netsales', 'credits', 'receipts', ],
26 'cust_classnum' => [ 1,2,4 ],
27 'params' => [ [ 'paramsfor', 'item_one' ], [ 'item', 'two' ] ], # ...
28 'remove_empty' => 1, #collapse empty rows, default 0
29 'item_labels' => [ ], #useful with remove_empty
32 my $data = $report->data;
40 Returns a hashref of data (!! describe)
47 my $sday = $self->{'start_day'};
48 my $smonth = $self->{'start_month'};
49 my $syear = $self->{'start_year'} + 1900; # temporary kludge
50 my $eday = $self->{'end_day'};
51 my $emonth = $self->{'end_month'};
52 my $eyear = $self->{'end_year'} + 1900;
53 my $agentnum = $self->{'agentnum'};
54 my $cust_classnum = $self->{'cust_classnum'} || [];
55 $cust_classnum = [ $cust_classnum ] if !ref($cust_classnum);
57 #these need to get generalized, sheesh
59 # rows (time intervals)
60 speriod => [], # start timestamps
61 eperiod => [], # end timestamps
62 label => [], # date labels
63 data => [], # arrayrefs of column values
65 # columns (observables + query parameters)
66 items => $self->{'items'},
67 item_labels => $self->{'item_labels'} || $self->{'items'},
68 colors => $self->{'colors'}, # no default?
69 links => $self->{'links'} || [],
72 my $sdate = DateTime->new(
78 my $edate = DateTime->new(
83 )->add(days => 1); # include all of the end day
85 my $conf = FS::Conf->new;
86 my $date_format = $conf->config('date_format') || '%d/%m/%Y';
88 while ( $sdate < $edate ) {
89 push @{$data{label}}, $sdate->strftime($date_format);
91 my $speriod = $sdate->epoch;
92 $sdate->add(days => 1);
93 my $eperiod = $sdate->epoch;;
95 push @{$data{speriod}}, $speriod;
96 push @{$data{eperiod}}, $eperiod;
99 my @items = @{$self->{'items'}};
101 for ( $i = 0; $i < scalar(@items); $i++ ) {
102 my $item = $items[$i];
103 my @param = $self->{'params'} ? @{ $self->{'params'}[$col] }: ();
104 push @param, 'cust_classnum' => $cust_classnum if @$cust_classnum;
105 my $value = $self->$item($speriod, $eperiod, $agentnum, @param);
106 push @{$data{data}->[$col++]}, $value;
110 $data{'items'} = $self->{'items'};
111 $data{'item_labels'} = $self->{'item_labels'} || $self->{'items'};
112 $data{'colors'} = $self->{'colors'};
113 $data{'links'} = $self->{'links'} || [];
115 if ( $self->{'remove_empty'} ) {
118 #these need to get generalized, sheesh
125 foreach my $item ( @{$self->{'items'}} ) {
127 my $is_nonzero = scalar( grep { $_ != 0 } @{ $data{'data'}->[$col] });
128 next if ($self->{'remove_empty'} and $is_nonzero == 0);
129 # no daily reports can normalize yet
130 push @newitems, $data{'items'}->[$col];
131 push @newlabels, $data{'item_labels'}->[$col];
132 push @newdata, $data{'data'}->[$col];
133 push @newcolors, $data{'colors'}->[$col];
134 push @newlinks, $data{'links'}->[$col];
141 $data{'items'} = \@newitems;
142 $data{'item_labels'} = \@newlabels;
143 $data{'data'} = \@newdata;
144 $data{'colors'} = \@newcolors;
145 $data{'links'} = \@newlinks;
146 $data{'indices'} = \@indices;
148 } else { # not doing remove_empty; report back that all columns are included
149 $data{'indices'} = [ 0 .. scalar( @{$self->{'items'}} ) - 1 ];