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