include discounts in gross sales reports, #25943
[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 = qw( gross    netsales
45                 discounted
46                 credits  netcredits
47                 payments receipts
48                 refunds  netrefunds
49                 cashflow netcashflow
50               );
51 if ( $cgi->param('12mo') == 1 ) {
52   @items = map $_.'_12mo', @items;
53 }
54
55 my %label = (
56   'gross'       => 'Gross Sales',
57   'netsales'    =>   'Net Sales',
58   'discounted'  => 'Discounts',
59   'credits'     => 'Gross Credits',
60   'netcredits'  =>   'Net Credits',
61   'payments'    => 'Gross Receipts',
62   'receipts'    =>   'Net Receipts',
63   'refunds'     => 'Gross Refunds',
64   'netrefunds'  =>   'Net Refunds',
65   'cashflow'    => 'Gross Cashflow',
66   'netcashflow' =>   'Net Cashflow',
67 );
68
69 my %graph_suffix = (
70  'gross'       => ' (invoiced + discounts)', 
71  'netsales'    => ' (invoiced - applied credits)',
72  'discounted'  => ' (discounts)',
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   'gross'       => '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   'discounted'  => 'cc33cc', #purple-ish?
102 );
103 $color{$_.'_12mo'} = $color{$_}
104   foreach keys %color;
105
106 my $ar = "agentnum=$agentnum;refnum=$refnum";
107 $ar .= ";cust_classnum=$_" foreach @classnums;
108
109 my %link = (
110   'gross'      => "${p}search/cust_bill.html?$ar;",
111   'netsales'   => "${p}search/cust_bill.html?$ar;net=1;",
112   'credits'    => "${p}search/cust_credit.html?$ar;",
113   'netcredits' => "${p}search/cust_credit_bill.html?$ar;",
114   'payments'   => "${p}search/cust_pay.html?magic=_date;$ar;",
115   'receipts'   => "${p}search/cust_bill_pay.html?$ar;",
116   'refunds'    => "${p}search/cust_refund.html?magic=_date;$ar;",
117   'netrefunds' => "${p}search/cust_credit_refund.html?$ar;",
118   'discounted' => "${p}search/cust_bill_pkg_discount.html?$ar;",
119 );
120 # XXX link 12mo?
121
122 </%init>