add net credits to sales/credits/receipts report
[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                 'agentnum'     => $agentnum,
10                 'nototal'      => scalar($cgi->param('12mo')),
11              )
12 %>
13 <%init>
14
15 die "access denied"
16   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
17
18 #XXX or virtual
19 my( $agentnum, $agent ) = ('', '');
20 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
21   $agentnum = $1;
22   $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
23   die "agentnum $agentnum not found!" unless $agent;
24 }
25
26 my $agentname = $agent ? $agent->agent.' ' : '';
27
28 my @items = qw( invoiced netsales credits netcredits payments receipts );
29 if ( $cgi->param('12mo') == 1 ) {
30   @items = map $_.'_12mo', @items;
31 }
32
33 my %label = (
34   'invoiced'   => 'Gross Sales',
35   'netsales'   => 'Net Sales',
36   'credits'    => 'Gross Credits',
37   'netcredits' => 'Net Credits',
38   'payments'   => 'Gross Receipts',
39   'receipts'   => 'Net Receipts',
40 );
41
42 my %graph_suffix = (
43  'invoiced'   => ' (invoiced)', 
44  'netsales'   => ' (invoiced - applied credits)',
45  'credits'    => ' (credited)',
46  'netcredits' => ' (applied credits)',
47  'payments'   => ' (payments)',
48  'receipts'   => '/Cashflow (payments - refunds)',
49 );
50 my %graph_label = map { $_ => $label{$_}.$graph_suffix{$_} } keys %label;
51
52 $label{$_.'_12mo'} = $label{$_}. " (previous 12 months)"
53   foreach keys %label;
54
55 $graph_label{$_.'_12mo'} = $graph_label{$_}. " (previous 12 months)"
56   foreach keys %graph_label;
57
58 my %color = (
59   'invoiced'   => '9999ff', #light blue
60   'netsales'   => '0000cc', #blue
61   'credits'    => 'ff9999', #light red
62   'netcredits' => 'cc0000', #red
63   'payments'   => '99cc99', #light green
64   'receipts'   => '00cc00', #green
65 );
66 $color{$_.'_12mo'} = $color{$_}
67   foreach keys %color;
68
69 my %link = (
70   'invoiced'   => "${p}search/cust_bill.html?agentnum=$agentnum;",
71   'netsales'   => "${p}search/cust_bill.html?agentnum=$agentnum;net=1;",
72   'credits'    => "${p}search/cust_credit.html?agentnum=$agentnum;",
73   'netcredits' => "${p}search/cust_credit_bill.html?agentnum=$agentnum;",
74   'payments'   => "${p}search/cust_pay.cgi?magic=_date;agentnum=$agentnum;",
75 );
76 # XXX link 12mo?
77
78 </%init>