adding export to read mailbox status information, RT#15987
[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
29                 credits  netcredits
30                 payments receipts
31                 refunds  netrefunds
32                 cashflow netcashflow
33               );
34 if ( $cgi->param('12mo') == 1 ) {
35   @items = map $_.'_12mo', @items;
36 }
37
38 my %label = (
39   'invoiced'    => 'Gross Sales',
40   'netsales'    =>   'Net Sales',
41   'credits'     => 'Gross Credits',
42   'netcredits'  =>   'Net Credits',
43   'payments'    => 'Gross Receipts',
44   'receipts'    =>   'Net Receipts',
45   'refunds'     => 'Gross Refunds',
46   'netrefunds'  =>   'Net Refunds',
47   'cashflow'    => 'Gross Cashflow',
48   'netcashflow' =>   'Net Cashflow',
49 );
50
51 my %graph_suffix = (
52  'invoiced'    => ' (invoiced)', 
53  'netsales'    => ' (invoiced - applied credits)',
54  'credits'     => ' (credited)',
55  'netcredits'  => ' (applied credits)',
56  'payments'    => ' (payments)',
57  'receipts'    => ' (applied payments)',
58  'refunds'     => ' (refunds)',
59  'netrefunds'  => ' (applied refunds)',
60  'cashflow'    => ' (payments - refunds)',
61  'netcashflow' => ' (applied payments - applied refunds)',
62 );
63 my %graph_label = map { $_ => $label{$_}.$graph_suffix{$_} } keys %label;
64
65 $label{$_.'_12mo'} = $label{$_}. " (prev 12 months)"
66   foreach keys %label;
67
68 $graph_label{$_.'_12mo'} = $graph_label{$_}. " (prev 12 months)"
69   foreach keys %graph_label;
70
71 my %color = (
72   'invoiced'    => '9999ff', #light blue
73   'netsales'    => '0000cc', #blue
74   'credits'     => 'ff9999', #light red
75   'netcredits'  => 'cc0000', #red
76   'payments'    => '99cc99', #light green
77   'receipts'    => '00cc00', #green
78   'refunds'     => 'ffcc99', #light orange
79   'netrefunds'  => 'ff9900', #orange
80   'cashflow'    => '99cc33', #light olive
81   'netcashflow' => '339900', #olive
82 );
83 $color{$_.'_12mo'} = $color{$_}
84   foreach keys %color;
85
86 my %link = (
87   'invoiced'   => "${p}search/cust_bill.html?agentnum=$agentnum;",
88   'netsales'   => "${p}search/cust_bill.html?agentnum=$agentnum;net=1;",
89   'credits'    => "${p}search/cust_credit.html?agentnum=$agentnum;",
90   'netcredits' => "${p}search/cust_credit_bill.html?agentnum=$agentnum;",
91   'payments'   => "${p}search/cust_pay.html?magic=_date;agentnum=$agentnum;",
92   'receipts'   => "${p}search/cust_bill_pay.html?agentnum=$agentnum;",
93   'refunds'    => "${p}search/cust_refund.html?magic=_date;agentnum=$agentnum;",
94   'netrefunds' => "${p}search/cust_credit_refund.html?agentnum=$agentnum;",
95 );
96 # XXX link 12mo?
97
98 </%init>