brainfart
[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 payments receipts );
19 my %label = (
20  'invoiced' => 'Gross Sales (invoiced)', 
21  'netsales' => 'Net Sales (invoiced - applied credits)',
22  'credits'  => 'Credits',
23  'payments' => 'Gross Receipts (payments)',
24  'receipts' => 'Net Receipts/Cashflow (payments - refunds)',
25 );
26 my %color = (
27   'invoiced' => [ 153, 153, 255 ], #light blue
28   'netsales' => [   0,   0, 204 ], #blue
29   'credits'  => [ 204,   0,   0 ], #red
30   'payments' => [ 153, 204, 153 ], #light green
31   'receipts' => [   0, 204,   0 ], #green
32 );
33
34 my $report = new FS::Report::Table::Monthly (
35   'items' => \@items,
36   'start_month' => $smonth,
37   'start_year'  => $syear,
38   'end_month'   => $emonth,
39   'end_year'    => $eyear,
40 );
41 my %data = %{$report->data};
42
43 #my $chart = Chart::LinesPoints->new(1024,480);
44 #my $chart = Chart::LinesPoints->new(768,480);
45 my $chart = Chart::LinesPoints->new(976,384);
46
47 my $d = 0;
48 $chart->set(
49   #'min_val' => 0,
50   'legend' => 'bottom',
51   'colors' => { ( map { 'dataset'.$d++ => $color{$_} } @items ),
52                 #'grey_background' => [ 211, 211, 211 ],
53                 'grey_background' => 'white',
54                 'background' => [ 0xe8, 0xe8, 0xe8 ], #grey
55               },
56   #'grey_background' => 'false',
57   'legend_labels' => [ map { $label{$_} } @items ],
58   'brush_size' => 4,
59   #'pt_size' => 12,
60 );
61
62 my @data = map { $data{$_} } ( 'label', @items );
63
64 http_header('Content-Type' => 'image/png' );
65
66 $chart->_set_colors();
67
68 %><%= $chart->scalar_png(\@data) %>