Will things ever be the same again?
[freeside.git] / httemplate / graph / money_time.cgi
1 %
2 %
3 %#find first month
4 %my $syear = $cgi->param('start_year'); # || 1899+$curyear;
5 %my $smonth = $cgi->param('start_month'); # || $curmon+1;
6 %
7 %#find last month
8 %my $eyear = $cgi->param('end_year'); # || 1900+$curyear;
9 %my $emonth = $cgi->param('end_month'); # || $curmon+1;
10 %
11 %#XXX or virtual
12 %my( $agentnum, $agent ) = ('', '');
13 %if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
14 %  $agentnum = $1;
15 %  $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
16 %  die "agentnum $agentnum not found!" unless $agent;
17 %}
18 %my $agentname = $agent ? $agent->agent.' ' : '';
19 %
20 %my @items = qw( invoiced netsales credits payments receipts );
21 %if ( $cgi->param('12mo') == 1 ) {
22 %  @items = map $_.'_12mo', @items;
23 %}
24 %
25 %my %label = (
26 %  'invoiced' => 'Gross Sales',
27 %  'netsales' => 'Net Sales',
28 %  'credits'  => 'Credits',
29 %  'payments' => 'Gross Receipts',
30 %  'receipts' => 'Net Receipts',
31 %);
32 %
33 %my %graph_suffix = (
34 % 'invoiced' => ' (invoiced)', 
35 % 'netsales' => ' (invoiced - applied credits)',
36 % 'credits'  => '',
37 % 'payments' => ' (payments)',
38 % 'receipts' => '/Cashflow (payments - refunds)',
39 %);
40 %my %graph_label = map { $_ => $label{$_}.$graph_suffix{$_} } keys %label;
41 %
42 %$label{$_.'_12mo'} = $label{$_}. " (previous 12 months)"
43 %  foreach keys %label;
44 %
45 %$graph_label{$_.'_12mo'} = $graph_label{$_}. " (previous 12 months)"
46 %  foreach keys %graph_label;
47 %
48 %my %color = (
49 %  'invoiced' => '9999ff', #light blue
50 %  'netsales' => '0000cc', #blue
51 %  'credits'  => 'cc0000', #red
52 %  'payments' => '99cc99', #light green
53 %  'receipts' => '00cc00', #green
54 %);
55 %$color{$_.'_12mo'} = $color{$_}
56 %  foreach keys %color;
57 %
58 %my %link = (
59 %  'invoiced' => "${p}search/cust_bill.html?agentnum=$agentnum;",
60 %  'credits'  => "${p}search/cust_credit.html?agentnum=$agentnum;",
61 %  'payments' => "${p}search/cust_pay.cgi?magic=_date;agentnum=$agentnum;",
62 %);
63 %# XXX link 12mo?
64 %
65 %
66 <% include('elements/monthly.html',
67                 'title'        => $agentname.
68                                   'Sales, Credits and Receipts Summary',
69                 'items'        => \@items,
70                 'labels'       => \%label,
71                 'graph_labels' => \%graph_label,
72                 'colors'       => \%color,
73                 'links'        => \%link,
74                 'start_month'  => $smonth,
75                 'start_year'   => $syear,
76                 'end_month'    => $emonth,
77                 'end_year'     => $eyear,
78                 'agentnum'     => $agentnum,
79                 'nototal'      => scalar($cgi->param('12mo')),
80              )
81 %>