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