Will things ever be the same again?
[freeside.git] / httemplate / graph / elements / monthly.html
1 %
2 %
3 %  # options example...
4 %  #
5 %  # 'title'        => 'Page title',
6 %  # 'items'        => \@items,
7 %  # 'params'       => \@params, # opt,
8 %  # 'labels'       => \@labels,       # or \%labels (keys are items)
9 %  # 'graph_labels' => \@graph_labels, # or \%graph_labels,
10 %  # 'colors'       => \@colors,       # or \%colors,
11 %  # 'links         => \@links,        # or \%link, #opt
12 %  # 'start_month'  => $smonth,
13 %  # 'start_year'   => $syear,
14 %  # 'end_month'    => $emonth,
15 %  # 'end_year'     => $eyear,
16 %  # 'agentnum'     => $agentnum, #opt
17 %  # 'nototal'      => 1, #opt,
18 %  # 'graph_type'   => 'LinesPoints', #opt
19 %  # 'remove_empty' => 1, #opt,
20 %  # 'bottom_total' => 1, #opt,
21 %
22 %  my(%opt) = @_;
23 %  my @items = @{ $opt{'items'} };
24 %
25 %  foreach my $other (qw( labels graph_labels colors links )) {
26 %  #foreach my $other (qw( labels graph_labels colors )) {
27 %    if ( ref($opt{$other}) eq 'HASH' ) {
28 %      $opt{$other} = [ map $opt{$other}{$_}, @items ];
29 %    }
30 %  }
31 %
32 %  my $report = new FS::Report::Table::Monthly (
33 %
34 %    #'items'       => $opt{'items'},
35 %    'items'        => \@items,
36 %    'params'       => $opt{'params'},
37 %    'item_labels'  => ( $cgi->param('_type') =~ /^(png)$/
38 %                          ? $opt{'graph_labels'}
39 %                          : $opt{'labels'}
40 %                      ),
41 %    'colors'       => $opt{'colors'},
42 %    'links'        => $opt{'links'},
43 %
44 %    'start_month'  => $opt{'start_month'},
45 %    'start_year'   => $opt{'start_year'},
46 %    'end_month'    => $opt{'end_month'},
47 %    'end_year'     => $opt{'end_year'},
48 %
49 %    'agentnum'     => $opt{'agentnum'},
50 %    'remove_empty' => $opt{'remove_empty'},
51 %  );
52 %  my $data = $report->data;
53 %
54 %  if ( $cgi->param('_type') =~ /^(png)$/ ) {
55 %
56 %    #my $chart = Chart::LinesPoints->new(1024,480);
57 %    #my $chart = Chart::LinesPoints->new(768,480);
58 %
59 %    my $graph_type = 'LinesPoints';
60 %    if ( $opt{'graph_type'} =~ /^(LinesPoints|Mountain)$/ ) {
61 %      $graph_type = $1;
62 %    }
63 %    my $class = "Chart::$graph_type";
64 %
65 %    my $chart = $class->new(976,384);
66 %    
67 %    my $d = 0;
68 %    $chart->set(
69 %      #'min_val' => 0,
70 %      'legend' => 'bottom',
71 %      'colors' => { ( 
72 %                      map { my $color = $_;
73 %                            'dataset'.$d++ =>
74 %                              [ map hex($_), unpack 'a2a2a2', $color ]
75 %                          }
76 %                          #@{ $opt{'colors'} }
77 %                          @{ $data->{'colors'} }
78 %                    ),
79 %                    #'grey_background' => [ 211, 211, 211 ],
80 %                    'grey_background' => 'white',
81 %                    'background' => [ 0xe8, 0xe8, 0xe8 ], #grey
82 %                  },
83 %      #'grey_background' => 'false',
84 %      'legend_labels' => $data->{'item_labels'},
85 %      'brush_size' => 4,
86 %      #'pt_size' => 12,
87 %    );
88 %
89 %    #my @data = map { $data->{$_} } ( 'label', @items );
90 %    my @data = @{ $data->{data} };
91 %    unshift @data, $data->{'label'};
92 %    
93 %    http_header('Content-Type' => 'image/png' );
94 %
95 %    $chart->_set_colors();
96 %
97 %    
98 <% $chart->scalar_png(\@data) %>
99 %
100 %
101 %  } else {
102 %
103 %    my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
104 %
105 %
106 <% include('/elements/header.html', $opt{'title'} ) %>
107 % $cgi->param('_type', 'png'); 
108
109 <IMG SRC="<% $cgi->self_url %>" WIDTH="976" HEIGHT="384">
110 <BR>
111
112 <% table('e8e8e8') %>
113
114 <TR>
115
116   <TD></TD>
117 % foreach my $column ( @{$data->{label}} ) {
118 %       #$column =~ s/^(\d+)\//$mon[$1-1]<BR>/e;
119 %       $column =~ s/^(\d+)\//$mon[$1-1]<BR>/;
120 %  
121
122     <TH><% $column %></TH>
123 % } 
124 % unless ( $opt{'nototal'} ) { 
125
126     <TH>Total</TH>
127 % } 
128
129
130 </TR>
131 % my @bottom_total = ();
132 %   foreach my $row ( @{ $data->{'items'} } ) {
133 %
134 %     #my $color = shift( @{ $opt{'colors'} } );
135 %     my $color = shift( @{ $data->{'colors'} } );
136 %     my $link = shift( @{ $data->{'links'} } );
137 %     $link = $link ? qq(<A HREF="$link) : '';
138 %
139
140
141   <TR>
142
143     <TH><FONT COLOR="#<% $color %>"><% shift( @{ $data->{'item_labels'} } ) %></FONT></TH>
144 % #my $link = exists($opt{'links'}{$row})
145 %       #  ? qq(<A HREF="$opt{'links'}{$row})
146 %       #  : '';
147 %       my @speriod = @{$data->{speriod}};
148 %       my @eperiod = @{$data->{eperiod}};
149 %       my $total = 0;
150 %    
151 % my $col = 0;
152 %       foreach my $column ( @{ shift( @{$data->{data}} ) } ) { # ( @{$data->{$row}} ) {
153 %    
154
155
156       <TD ALIGN="right" BGCOLOR="#ffffff">
157         <% $link ? $link. 'begin='. shift(@speriod). ';end='. shift(@eperiod). '">' : '' %><FONT COLOR="#<% $color %>">$<% sprintf("%.2f", $column) %></FONT><% $link ? '</A>' : '' %>
158       </TD>
159 %
160 %         $total += $column;
161 %         $bottom_total[$col++] += $column;
162 %      
163 % } 
164 % unless ( $opt{'nototal'} ) { 
165
166
167       <TD ALIGN="right" BGCOLOR="#f5f6be">
168         <% $link ? $link. 'begin='. ${$data->{speriod}}[0]. ';end='. ${$data->{eperiod}}[-1]. '">' : '' %><FONT COLOR="#<% $color %>">$<% sprintf("%.2f", $total) %></FONT><% $link ? '</A>' : '' %>
169       </TD>
170 % $bottom_total[$col++] += $total; 
171 % } 
172
173
174   </TR>
175 % } 
176 % if ( $opt{'bottom_total'} ) {
177 %     my @speriod = ( @{$data->{speriod}}, ${$data->{speriod}}[0] );
178 %     my @eperiod = ( @{$data->{eperiod}}, ${$data->{eperiod}}[-1] );
179 %
180
181
182   <TR>
183     <TH>Total</TH>
184 % foreach my $total ( @bottom_total ) { 
185
186
187       <TD ALIGN="right" BGCOLOR="#f5f6be">
188         <% $opt{'bottom_link'}
189               ? '<A HREF="'. $opt{'bottom_link'}.
190                 'begin='. shift(@speriod).
191                 ';end='. shift(@eperiod). '">'
192               : ''
193         %>$<% sprintf("%.2f", $total) %><% $opt{'bottom_link'} ? '</A>' : '' %>
194
195       </TD>
196 % } 
197
198
199   </TR>
200 % } 
201
202
203 </TABLE>
204
205 <% include('/elements/footer.html') %>
206 % } 
207