default to a session cookie instead of setting an explicit timeout, weird timezone...
[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 # need to clean this up. the false symmetry of "gross" and "net" everything
43 # makes it aesthetically hard to make this report more useful.
44 my @items = ($cgi->param('exclude_discount') ? 'invoiced' : 'gross');
45 push @items,
46             qw( discounted   netsales
47                 credits  netcredits
48                 payments receipts
49                 refunds  netrefunds
50                 cashflow netcashflow
51             );
52
53 my %label = (
54   'gross'       => 'Gross Sales',
55   'invoiced'    => 'Invoiced Sales',
56   'netsales'    => 'Net Sales',
57   'discounted'  => 'Discounts',
58   'credits'     => 'Gross Credits',
59   'netcredits'  => 'Net Credits',
60   'payments'    => 'Gross Receipts',
61   'receipts'    => 'Net Receipts',
62   'refunds'     => 'Gross Refunds',
63   'netrefunds'  => 'Net Refunds',
64   'cashflow'    => 'Gross Cashflow',
65   'netcashflow' => 'Net Cashflow',
66 );
67
68 my %graph_suffix = (
69  'gross'       => ' (invoiced + discounts)', 
70  'invoiced'    => '',
71  'netsales'    => ' (invoiced - applied credits)',
72  'discounted'  => '',
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 my %color = (
85   'gross'       => '9999ff', #light blue
86   'invoiced'    => '9999ff', #light blue
87   'netsales'    => '0000cc', #blue
88   'credits'     => 'ff9999', #light red
89   'netcredits'  => 'cc0000', #red
90   'payments'    => '99cc99', #light green
91   'receipts'    => '00cc00', #green
92   'refunds'     => 'ffcc99', #light orange
93   'netrefunds'  => 'ff9900', #orange
94   'cashflow'    => '99cc33', #light olive
95   'netcashflow' => '339900', #olive
96   'discounted'  => 'cc33cc', #purple-ish?
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   'gross'      => "${p}search/cust_bill.html?$ar;",
106   'invoiced'   => "${p}search/cust_bill.html?$ar;invoiced=1;",
107   'netsales'   => "${p}search/cust_bill.html?$ar;net=1;",
108   'credits'    => "${p}search/cust_credit.html?$ar;",
109   'netcredits' => "${p}search/cust_credit_bill.html?$ar;",
110   'payments'   => "${p}search/cust_pay.html?magic=_date;$ar;",
111   'receipts'   => "${p}search/cust_bill_pay.html?$ar;",
112   'refunds'    => "${p}search/cust_refund.html?magic=_date;$ar;",
113   'netrefunds' => "${p}search/cust_credit_refund.html?$ar;",
114   'discounted' => "${p}search/cust_bill_pkg_discount.html?$ar;",
115 );
116 # XXX link 12mo?
117
118 if ( $cgi->param('12mo') ) {
119   $label{$_} .= " (prev 12 months)"
120     foreach keys %label;
121
122   $graph_label{$_} .= " (prev 12 months)"
123     foreach keys %graph_label;
124 }
125
126 </%init>