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