first pass at sales reports per agent and package class
[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,
10   # 'colors'       => \%colors,
11   # 'links         => \%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
20   my(%opt) = @_;
21   my @items = @{ $opt{'items'} };
22
23   #foreach my $other (qw( labels graph_labels colors links )) {
24   foreach my $other (qw( labels graph_labels colors )) {
25     if ( ref($opt{$other}) eq 'HASH' ) {
26       $opt{$other} = [ map $opt{$other}{$_}, @items ];
27     }
28   }
29
30   my $report = new FS::Report::Table::Monthly (
31     #'items'       => $opt{'items'},
32     'items'       => \@items,
33     'params'      => $opt{'params'},
34     'start_month' => $opt{'start_month'},
35     'start_year'  => $opt{'start_year'},
36     'end_month'   => $opt{'end_month'},
37     'end_year'    => $opt{'end_year'},
38     'agentnum'    => $opt{'agentnum'},
39   );
40   my $data = $report->data;
41
42   if ( $cgi->param('_type') =~ /^(png)$/ ) {
43
44     #my $chart = Chart::LinesPoints->new(1024,480);
45     #my $chart = Chart::LinesPoints->new(768,480);
46
47     my $graph_type = 'LinesPoints';
48     if ( $opt{'graph_type'} =~ /^(LinesPoints|Mountain)$/ ) {
49       $graph_type = $1;
50     }
51     my $class = "Chart::$graph_type";
52
53     my $chart = $class->new(976,384);
54     
55     my $d = 0;
56     $chart->set(
57       #'min_val' => 0,
58       'legend' => 'bottom',
59       'colors' => { ( 
60                       map { my $color = $_;
61                             'dataset'.$d++ =>
62                               [ map hex($_), unpack 'a2a2a2', $color ]
63                           }
64                           @{ $opt{'colors'} }
65                     ),
66                     #'grey_background' => [ 211, 211, 211 ],
67                     'grey_background' => 'white',
68                     'background' => [ 0xe8, 0xe8, 0xe8 ], #grey
69                   },
70       #'grey_background' => 'false',
71       'legend_labels' => $opt{'graph_labels'},
72       'brush_size' => 4,
73       #'pt_size' => 12,
74     );
75
76     #my @data = map { $data->{$_} } ( 'label', @items );
77     my @data = @{ $data->{data} };
78     unshift @data, $data->{'label'};
79     
80     http_header('Content-Type' => 'image/png' );
81
82     $chart->_set_colors();
83
84     %><%= $chart->scalar_png(\@data) %><%
85
86   } else {
87
88     my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
89
90 %><%= include('/elements/header.html', $opt{'title'} ) %>
91
92 <% $cgi->param('_type', 'png'); %>
93 <IMG SRC="<%= $cgi->self_url %>" WIDTH="976" HEIGHT="384">
94 <BR>
95
96 <%= table('e8e8e8') %>
97
98 <TR>
99
100   <TD></TD>
101
102   <% foreach my $column ( @{$data->{label}} ) {
103        #$column =~ s/^(\d+)\//$mon[$1-1]<BR>/e;
104        $column =~ s/^(\d+)\//$mon[$1-1]<BR>/;
105   %>
106     <TH><%= $column %></TH>
107   <% } %>
108
109   <% unless ( $opt{'nototal'} ) { %>
110     <TH>Total</TH>
111   <% } %>
112
113 </TR>
114
115 <% foreach my $row (@items) {
116
117      my $color = shift( @{ $opt{'colors'} } );
118 %>
119
120   <TR>
121
122     <TH><FONT COLOR="#<%= $color %>"><%= shift( @{ $opt{'labels'} } ) %></FONT></TH>
123
124     <% my $link = exists($opt{'links'}{$row})
125          ? qq(<A HREF="$opt{'links'}{$row})
126          : '';
127        my @speriod = @{$data->{speriod}};
128        my @eperiod = @{$data->{eperiod}};
129        my $total = 0;
130     %>
131     <% foreach my $column ( @{ shift( @{$data->{data}} ) } ) { # ( @{$data->{$row}} ) {
132     %>
133
134       <TD ALIGN="right" BGCOLOR="#ffffff">
135         <%= $link ? $link. 'begin='. shift(@speriod). ';end='. shift(@eperiod). '">' : '' %><FONT COLOR="#<%= $color %>">$<%= sprintf("%.2f", $column) %></FONT><%= $link ? '</A>' : '' %>
136       </TD>
137       <% $total += $column; %>
138
139     <% } %>
140
141     <% unless ( $opt{'nototal'} ) { %>
142
143       <TD ALIGN="right" BGCOLOR="#f5f6be">
144         <%= $link ? $link. 'begin='. @{$data->{speriod}}[0]. ';end='. @{$data->{eperiod}}[-1]. '">' : '' %><FONT COLOR="#<%= $color %>">$<%= sprintf("%.2f", $total) %></FONT><%= $link ? '</A>' : '' %>
145       </TD>
146
147     <% } %>
148
149   </TR>
150
151 <% } %>
152
153 </TABLE>
154
155 <%= include('/elements/footer.html') %>
156
157 <% } %>