add customer status column to customer & most other reports. also put the C in ACL...
[freeside.git] / httemplate / graph / money_time.cgi
1 <% include('elements/monthly.html',
2                 'title'        => $agentname.
3                                   'Sales, Credits and Receipts Summary',
4                 'items'        => \@items,
5                 'labels'       => \%label,
6                 'graph_labels' => \%graph_label,
7                 'colors'       => \%color,
8                 'links'        => \%link,
9                 'start_month'  => $smonth,
10                 'start_year'   => $syear,
11                 'end_month'    => $emonth,
12                 'end_year'     => $eyear,
13                 'agentnum'     => $agentnum,
14                 'nototal'      => scalar($cgi->param('12mo')),
15              )
16 %>
17 <%init>
18
19 die "access denied"
20   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
21
22 #find first month
23 my $syear = $cgi->param('start_year'); # || 1899+$curyear;
24 my $smonth = $cgi->param('start_month'); # || $curmon+1;
25
26 #find last month
27 my $eyear = $cgi->param('end_year'); # || 1900+$curyear;
28 my $emonth = $cgi->param('end_month'); # || $curmon+1;
29
30 #XXX or virtual
31 my( $agentnum, $agent ) = ('', '');
32 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
33   $agentnum = $1;
34   $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
35   die "agentnum $agentnum not found!" unless $agent;
36 }
37
38 my $agentname = $agent ? $agent->agent.' ' : '';
39
40 my @items = qw( invoiced netsales credits payments receipts );
41 if ( $cgi->param('12mo') == 1 ) {
42   @items = map $_.'_12mo', @items;
43 }
44
45 my %label = (
46   'invoiced' => 'Gross Sales',
47   'netsales' => 'Net Sales',
48   'credits'  => 'Credits',
49   'payments' => 'Gross Receipts',
50   'receipts' => 'Net Receipts',
51 );
52
53 my %graph_suffix = (
54  'invoiced' => ' (invoiced)', 
55  'netsales' => ' (invoiced - applied credits)',
56  'credits'  => '',
57  'payments' => ' (payments)',
58  'receipts' => '/Cashflow (payments - refunds)',
59 );
60 my %graph_label = map { $_ => $label{$_}.$graph_suffix{$_} } keys %label;
61
62 $label{$_.'_12mo'} = $label{$_}. " (previous 12 months)"
63   foreach keys %label;
64
65 $graph_label{$_.'_12mo'} = $graph_label{$_}. " (previous 12 months)"
66   foreach keys %graph_label;
67
68 my %color = (
69   'invoiced' => '9999ff', #light blue
70   'netsales' => '0000cc', #blue
71   'credits'  => 'cc0000', #red
72   'payments' => '99cc99', #light green
73   'receipts' => '00cc00', #green
74 );
75 $color{$_.'_12mo'} = $color{$_}
76   foreach keys %color;
77
78 my %link = (
79   'invoiced' => "${p}search/cust_bill.html?agentnum=$agentnum;",
80   'credits'  => "${p}search/cust_credit.html?agentnum=$agentnum;",
81   'payments' => "${p}search/cust_pay.cgi?magic=_date;agentnum=$agentnum;",
82 );
83 # XXX link 12mo?
84
85 </%init>