X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fgraph%2Felements%2Freport.html;h=b7073db31d45a001b48a3e5ffb9c069985d837a7;hb=a72a10f754f7465121d6137bb3dcee0a21ea6443;hp=2be511aecaf1da3aa70097c46884e94e5ff1e737;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/httemplate/graph/elements/report.html b/httemplate/graph/elements/report.html index 2be511aec..b7073db31 100644 --- a/httemplate/graph/elements/report.html +++ b/httemplate/graph/elements/report.html @@ -14,6 +14,7 @@ Example: 'graph_labels' => \@graph_labels, #defaults to row_labels 'links' => \@links, #optional + 'no_graph' => \@no_graph, #optional #these run parallel to the elements of each @item 'col_labels' => \@col_labels, #required @@ -77,15 +78,16 @@ any delimiter and linked from the elements in @data. % } % % } elsif ( $cgi->param('_type') =~ /(xls)$/ ) { -% -% #http_header('Content-Type' => 'application/excel' ); #eww -% http_header('Content-Type' => 'application/vnd.ms-excel' ); -% #http_header('Content-Type' => 'application/msexcel' ); #alas -% http_header('Content-Disposition' => "attachment;filename=$filename.xls"); +% #false laziness w/ search/elements/search-xls +% my $format = $FS::CurrentUser::CurrentUser->spreadsheet_format; +% $filename .= $format->{extension}; +% +% http_header('Content-Type' => $format->{mime_type} ); +% http_header('Content-Disposition' => qq!attachment;filename="$filename"! ); % % my $output = ''; % my $XLS = new IO::Scalar \$output; -% my $workbook = Spreadsheet::WriteExcel->new($XLS) +% my $workbook = $format->{class}->new($XLS) % or die "Error opening .xls file: $!"; % % my $worksheet = $workbook->add_worksheet(substr($opt{'title'},0,31)); @@ -124,10 +126,22 @@ any delimiter and linked from the elements in @data. % $workbook->close();# or die "Error creating .xls file: $!"; % % http_header('Content-Length' => length($output) ); -% -<% $output %> -% } elsif ( $cgi->param('_type') eq 'png' ) { +% $m->print($output); % +% } elsif ( $cgi->param('_type') eq 'png' ) { +% # delete any items that shouldn't be on the graph +% if ( my $no_graph = $opt{'no_graph'} ) { +% my $i = 0; +% while (@$no_graph) { +% if ( shift @$no_graph ) { +% splice @data, $i, 1; +% splice @{$opt{'graph_labels'}}, $i, 1; +% splice @{$opt{'colors'}}, $i, 1; +% $i--; # because everything is shifted down +% } +% $i++; +% } +% } % my $graph_type = 'LinesPoints'; % if ( $opt{'graph_type'} =~ /^(LinesPoints|Mountain|Bars)$/ ) { % $graph_type = $1; @@ -135,7 +149,21 @@ any delimiter and linked from the elements in @data. % my $class = "Chart::$graph_type"; % % my $chart = $class->new(976,384); -% +% # the chart area itself is 900 pixels wide, and the date labels are ~60 each. +% # staggered, we can fit about 28 of them. +% # they're about 12 pixels high, so vertically, we can fit about 60 (allowing +% # space for them to be readable). +% # after that we have to start skipping labels. also remove the dots, since +% # they're just a blob at that point. +% my $num_labels = scalar(@{ $opt{axis_labels} }); +% my %chart_opt = %{ $opt{chart_options} || {} }; +% if ( $num_labels > 28 ) { +% $chart_opt{x_ticks} = 'vertical'; +% if ( $num_labels > 60 ) { +% $chart_opt{skip_x_ticks} = int($num_labels / 60) + 1; +% $chart_opt{pt_size} = 1; +% } +% } % my $d = 0; % $chart->set( % #'min_val' => 0, @@ -152,125 +180,157 @@ any delimiter and linked from the elements in @data. % }, % 'legend_labels' => $opt{'graph_labels'}, % 'brush_size' => 4, +% %chart_opt, % ); % % http_header('Content-Type' => 'image/png' ); +% http_header('Cache-Control' => 'no-cache' ); % % $chart->_set_colors(); % <% $chart->scalar_png([ $opt{'axis_labels'}, @data ]) %> % % } else { +% # image and download links should use the cached data +% # just directly reference this component +% my $myself = $p.'graph/elements/report.html?session='.$session; % <% include('/elements/header.html', $opt{'title'} ) %> % unless ( $opt{'graph_type'} eq 'none' ) { -% $cgi->param('_type', 'png'); - +" WIDTH="976" HEIGHT="384" + STYLE="page-break-after:always;"> % } -

+

% unless ( $opt{'disable_download'} ) { -% $cgi->param('_type', "xls" ); Download full results
- as Excel spreadsheet
-% $cgi->param('_type', 'csv'); - as CSV file

-% $cgi->param('_type', "html" ); + as ">Excel spreadsheet
+ as ">CSV file

% } %

-<% include('/elements/table.html', 'f8f8f8') %> - - - - - +%# indexed by item, then by entry (the element indices of @{$data[$i]}). +% my @cell = (); +% my @styles; +% my $num_entries = scalar(@col_labels); +% my $num_items = scalar(@items); +% $cell[0] = ['']; #top left corner % foreach my $column ( @col_labels ) { -% $column =~ s/ /\/; # working on a smarter way to do this - <% $column %> -% } - -% unless ( $opt{'nototal'} ) { - Total -% } - - +% $column =~ s/ /\/; +% push @{$cell[0]}, $column; +% } +% if ( ! $opt{'nototal'} ) { +% $num_entries++; +% push @{$cell[0]}, emt('Total'); +% } -% my @bottom_total = (); +% # i for item, e for entry +% my $i = 1; % foreach my $row ( @items ) { +% #make a style +% my $color = shift @{ $opt{'colors'} }; +% push @styles, ".i$i { text-align: right; color: #$color; }"; +% #create the data row +% my $links = shift @{$opt{'links'}} || ['']; +% my $link_prefix = shift @$links; +% $link_prefix = ' - - - <% $label %> - +% my $data_row = $data[$i-1]; +%# my $data_row = shift @data; +% if ( ! $opt{'nototal'} ) { +% push @$data_row, sum(@$data_row); +% } +% foreach ( @$data_row ) { +% my $entry = $_; +% $entry = $money_char . sprintf($sprintf, $entry); +% $entry = $link_prefix . shift(@$links) . "\">$entry" if $link_prefix; +% push @{$cell[$i]}, $entry; +% } +% $i++; +% } +% if ( $opt{'bottom_total'} ) { +% # it's an extra item +% $num_items++; +% push @styles, ".i$i { text-align: right; background-color: #f5f6be; }"; +% my $links = $opt{'bottom_link'} || []; +% my $link_prefix = shift @$links; +% $link_prefix = '$entry" if $link_prefix; +% push @{$cell[$i]}, $entry; +% } +% } -% my $total = 0; -% my $col = 0; -% foreach my $column ( @{ shift( @data ) } ) { + - - <% $link_prefix ? $link_prefix . shift(@links) . '">' : '' %><% $money_char %><% sprintf($sprintf,, $column) %><% $link_prefix ? '' : '' %> - +<% include('/elements/table.html', 'f8f8f8') %> +% if ( $opt{'transpose'} ) { +% for ( my $e = 0; $e < $num_entries + 1; $e++ ) { + +% for ( my $i = 0; $i < $num_items + 1; $i++ ) { + "><% $cell[$i][$e] %> +% } + +% } % -% $total += $column; -% $bottom_total[$col++] += $column; -% -% } - -% unless ( $opt{'nototal'} ) { - - <% $link_prefix ? $link_prefix. shift(@links) . '">' : '' %><% $money_char %><% sprintf($sprintf, $total) %><% $link_prefix ? '' : '' %> - -% $bottom_total[$col++] += $total; -% } - - - -% } - -% if ( $opt{'bottom_total'} ) { +% } else { #!transpose +% +% for (my $i = 0; $i < $num_items + 1; $i++) { - Total -% my @bottom_links = $opt{'bottom_link'} ? @{ $opt{'bottom_link'} } : (); -% my $prefix = shift(@bottom_links); -% pop @bottom_links if $opt{'nototal'}; -% foreach my $total ( @bottom_total ) { - - - <% $prefix - ? '' - : '' - %><% $money_char %><% sprintf($sprintf, $total) %><% $prefix ? '' : '' %> - - - -% } - +% for (my $e = 0; $e < $num_entries + 1; $e++) { + "><% $cell[$i][$e] %> +% } - -% } - +% } +% } <% include('/elements/footer.html') %> % } -<%once> - - <%init> my(%opt) = @_; +my $session; +# load from cache if possible, to avoid recalculating +if ( $cgi->param('session') =~ /^(\d+)$/ ) { + $session = $1; + %opt = %{ $m->cache->get($session) }; +} +else { + $session = sprintf("%010d%06d", time, int(rand(1000000))); + $m->cache->set($session, \%opt, '1h'); +} my $sprintf = $opt{'sprintf'} || '%.2f';