adding export to read mailbox status information, RT#15987
[freeside.git] / httemplate / graph / money_time_daily.cgi
1 <% include('elements/monthly.html',
2                 'title'        => $agentname.
3                                   'Daily 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                 'daily'        => 1,
12                 'start_day'    => $smday,
13                 'start_month'  => $smon+1,
14                 'start_year'   => $syear,
15                 'end_day'      => $emday,
16                 'end_month'    => $emon+1,
17                 'end_year'     => $eyear,
18              )
19 %>
20 <%init>
21
22 die "access denied"
23   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
24
25 #XXX or virtual
26 my( $agentnum, $agent ) = ('', '');
27 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
28   $agentnum = $1;
29   $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
30   die "agentnum $agentnum not found!" unless $agent;
31 }
32
33 my $agentname = $agent ? $agent->agent.' ' : '';
34
35 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
36 my ($ssec,$smin,$shour,$smday,$smon,$syear,$swday,$syday,$sisdst) 
37     = localtime($beginning);
38 my ($esec,$emin,$ehour,$emday,$emon,$eyear,$ewday,$eyday,$eisdst) 
39     = localtime($ending);
40
41 my @items = qw( invoiced netsales
42                 credits  netcredits
43                 payments receipts
44                 refunds  netrefunds
45                 cashflow netcashflow
46               );
47 if ( $cgi->param('12mo') == 1 ) {
48   @items = map $_.'_12mo', @items;
49 }
50
51 my %label = (
52   'invoiced'    => 'Gross Sales',
53   'netsales'    =>   'Net Sales',
54   'credits'     => 'Gross Credits',
55   'netcredits'  =>   'Net Credits',
56   'payments'    => 'Gross Receipts',
57   'receipts'    =>   'Net Receipts',
58   'refunds'     => 'Gross Refunds',
59   'netrefunds'  =>   'Net Refunds',
60   'cashflow'    => 'Gross Cashflow',
61   'netcashflow' =>   'Net Cashflow',
62 );
63
64 my %graph_suffix = (
65  'invoiced'    => ' (invoiced)', 
66  'netsales'    => ' (invoiced - applied credits)',
67  'credits'     => ' (credited)',
68  'netcredits'  => ' (applied credits)',
69  'payments'    => ' (payments)',
70  'receipts'    => ' (applied payments)',
71  'refunds'     => ' (refunds)',
72  'netrefunds'  => ' (applied refunds)',
73  'cashflow'    => ' (payments - refunds)',
74  'netcashflow' => ' (applied payments - applied refunds)',
75 );
76 my %graph_label = map { $_ => $label{$_}.$graph_suffix{$_} } keys %label;
77
78 $label{$_.'_12mo'} = $label{$_}. " (prev 12 months)"
79   foreach keys %label;
80
81 $graph_label{$_.'_12mo'} = $graph_label{$_}. " (prev 12 months)"
82   foreach keys %graph_label;
83
84 my %color = (
85   'invoiced'    => '9999ff', #light blue
86   'netsales'    => '0000cc', #blue
87   'credits'     => 'ff9999', #light red
88   'netcredits'  => 'cc0000', #red
89   'payments'    => '99cc99', #light green
90   'receipts'    => '00cc00', #green
91   'refunds'     => 'ffcc99', #light orange
92   'netrefunds'  => 'ff9900', #orange
93   'cashflow'    => '99cc33', #light olive
94   'netcashflow' => '339900', #olive
95 );
96 $color{$_.'_12mo'} = $color{$_}
97   foreach keys %color;
98
99 my %link = (
100   'invoiced'   => "${p}search/cust_bill.html?agentnum=$agentnum;",
101   'netsales'   => "${p}search/cust_bill.html?agentnum=$agentnum;net=1;",
102   'credits'    => "${p}search/cust_credit.html?agentnum=$agentnum;",
103   'netcredits' => "${p}search/cust_credit_bill.html?agentnum=$agentnum;",
104   'payments'   => "${p}search/cust_pay.html?magic=_date;agentnum=$agentnum;",
105   'receipts'   => "${p}search/cust_bill_pay.html?agentnum=$agentnum;",
106   'refunds'    => "${p}search/cust_refund.html?magic=_date;agentnum=$agentnum;",
107   'netrefunds' => "${p}search/cust_credit_refund.html?agentnum=$agentnum;",
108 );
109 # XXX link 12mo?
110
111 </%init>