55e8982b452b085a93ea023bf17c08d880964c03
[freeside.git] / httemplate / graph / money_time-graph.cgi
1 <%
2
3 #my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
4 my ($curmon,$curyear) = (localtime(time))[4,5];
5
6 #find first month
7 my $syear = $cgi->param('syear') || 1899+$curyear;
8 my $smonth = $cgi->param('smonth') || $curmon+1;
9
10 #find last month
11 my $eyear = $cgi->param('eyear') || 1900+$curyear;
12 my $emonth = $cgi->param('emonth') || $curmon+1;
13 #if ( $emonth++>12 ) { $emonth-=12; $eyear++; }
14
15 #my @labels;
16 #my %data;
17
18 my @items = qw( invoiced netsales credits receipts );
19 my %label = (
20  'invoiced' => 'Gross Sales (invoiced)', 
21  'netsales' => 'Net Sales (invoiced - applied credits)',
22  'credits'  => 'Credits',
23  'receipts' => 'Receipts/Cashflow (payments - refunds)',
24 );
25 my %color = (
26   'invoiced' => [ 153, 153, 255 ], #light blue
27   'netsales' => [   0,   0, 204 ], #blue
28   'credits'  => [ 204,   0,   0 ], #red
29   'receipts' => [   0, 204,   0 ], #green
30 );
31
32 my $report = new FS::Report::Table::Monthly (
33   'items' => \@items,
34   'start_month' => $smonth,
35   'start_year'  => $syear,
36   'end_month'   => $emonth,
37   'end_year'    => $eyear,
38 );
39 my %data = %{$report->data};
40
41 #my $chart = Chart::LinesPoints->new(1024,480);
42 #my $chart = Chart::LinesPoints->new(768,480);
43 my $chart = Chart::LinesPoints->new(976,384);
44
45 my $d = 0;
46 $chart->set(
47   #'min_val' => 0,
48   'legend' => 'bottom',
49   'colors' => { ( map { 'dataset'.$d++ => $color{$_} } @items ),
50                 #'grey_background' => [ 211, 211, 211 ],
51                 'grey_background' => 'white',
52                 'background' => [ 0xe8, 0xe8, 0xe8 ], #grey
53               },
54   #'grey_background' => 'false',
55   'legend_labels' => [ map { $label{$_} } @items ],
56   'brush_size' => 4,
57   #'pt_size' => 12,
58 );
59
60 my @data = map { $data{$_} } ( 'label', @items );
61
62 http_header('Content-Type' => 'image/png' );
63
64 $chart->_set_colors();
65
66 %><%= $chart->scalar_png(\@data) %>