fix XSS
[freeside.git] / httemplate / graph / money_time.cgi
1 <% include('elements/monthly.html',
2                 'title'        => $agentname. $referralname.
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                 'refnum'       => $refnum,
11                 'cust_classnum'=> \@classnums,
12                 'nototal'      => scalar($cgi->param('12mo')),
13              )
14 %>
15 <%init>
16
17 die "access denied"
18   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
19
20 #XXX or virtual
21 my( $agentnum, $agent ) = ('', '');
22 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
23   $agentnum = $1;
24   $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
25   die "agentnum $agentnum not found!" unless $agent;
26 }
27 my $agentname = $agent ? $agent->agent.' ' : '';
28
29 my @classnums;
30 if ( $cgi->param('cust_classnum') ) {
31   @classnums = grep /^\d+$/, $cgi->param('cust_classnum');
32 }
33
34 my( $refnum, $part_referral ) = ('', '');
35 if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
36   $refnum = $1;
37   $part_referral = qsearchs('part_referral', { 'refnum' => $refnum } );
38   die "refnum $refnum not found!" unless $part_referral;
39 }
40 my $referralname = $part_referral ? $part_referral->referral.' ' : '';
41
42
43 my @items = qw( invoiced netsales
44                 credits  netcredits
45                 payments receipts
46                 refunds  netrefunds
47                 cashflow netcashflow
48               );
49 if ( $cgi->param('12mo') == 1 ) {
50   @items = map $_.'_12mo', @items;
51 }
52
53 my %label = (
54   'invoiced'    => 'Gross Sales',
55   'netsales'    =>   'Net Sales',
56   'credits'     => 'Gross Credits',
57   'netcredits'  =>   'Net Credits',
58   'payments'    => 'Gross Receipts',
59   'receipts'    =>   'Net Receipts',
60   'refunds'     => 'Gross Refunds',
61   'netrefunds'  =>   'Net Refunds',
62   'cashflow'    => 'Gross Cashflow',
63   'netcashflow' =>   'Net Cashflow',
64 );
65
66 my %graph_suffix = (
67  'invoiced'    => ' (invoiced)', 
68  'netsales'    => ' (invoiced - applied credits)',
69  'credits'     => ' (credited)',
70  'netcredits'  => ' (applied credits)',
71  'payments'    => ' (payments)',
72  'receipts'    => ' (applied payments)',
73  'refunds'     => ' (refunds)',
74  'netrefunds'  => ' (applied refunds)',
75  'cashflow'    => ' (payments - refunds)',
76  'netcashflow' => ' (applied payments - applied refunds)',
77 );
78 my %graph_label = map { $_ => $label{$_}.$graph_suffix{$_} } keys %label;
79
80 $label{$_.'_12mo'} = $label{$_}. " (prev 12 months)"
81   foreach keys %label;
82
83 $graph_label{$_.'_12mo'} = $graph_label{$_}. " (prev 12 months)"
84   foreach keys %graph_label;
85
86 my %color = (
87   'invoiced'    => '9999ff', #light blue
88   'netsales'    => '0000cc', #blue
89   'credits'     => 'ff9999', #light red
90   'netcredits'  => 'cc0000', #red
91   'payments'    => '99cc99', #light green
92   'receipts'    => '00cc00', #green
93   'refunds'     => 'ffcc99', #light orange
94   'netrefunds'  => 'ff9900', #orange
95   'cashflow'    => '99cc33', #light olive
96   'netcashflow' => '339900', #olive
97 );
98 $color{$_.'_12mo'} = $color{$_}
99   foreach keys %color;
100
101 my $ar = "agentnum=$agentnum;refnum=$refnum";
102 $ar .= ";cust_classnum=$_" foreach @classnums;
103
104 my %link = (
105   'invoiced'   => "${p}search/cust_bill.html?$ar;",
106   'netsales'   => "${p}search/cust_bill.html?$ar;net=1;",
107   'credits'    => "${p}search/cust_credit.html?$ar;",
108   'netcredits' => "${p}search/cust_credit_bill.html?$ar;",
109   'payments'   => "${p}search/cust_pay.html?magic=_date;$ar;",
110   'receipts'   => "${p}search/cust_bill_pay.html?$ar;",
111   'refunds'    => "${p}search/cust_refund.html?magic=_date;$ar;",
112   'netrefunds' => "${p}search/cust_credit_refund.html?$ar;",
113 );
114 # XXX link 12mo?
115
116 </%init>