pg 8.1 fix from Chris Cappuccio
[freeside.git] / httemplate / graph / money_time.cgi
1 <%
2
3 #       #my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
4 #       my ($curmon,$curyear) = (localtime(time))[4,5];
5
6 #find first month
7 my $syear = $cgi->param('syear'); # || 1899+$curyear;
8 my $smonth = $cgi->param('smonth'); # || $curmon+1;
9
10 #find last month
11 my $eyear = $cgi->param('eyear'); # || 1900+$curyear;
12 my $emonth = $cgi->param('emonth'); # || $curmon+1;
13
14 #XXX or virtual
15 my( $agentnum, $agent ) = ('', '');
16 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
17   $agentnum = $1;
18   $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
19   die "agentnum $agentnum not found!" unless $agent;
20 }
21 my $agentname = $agent ? $agent->agent.' ' : '';
22
23 %>
24 <%= include('/elements/header.html',
25               $agentname. 'Sales, Credits and Receipts Summary'
26            )
27 %>
28
29 <IMG SRC="money_time-graph.cgi?<%= $cgi->query_string %>" WIDTH="976" HEIGHT="384">
30 <BR>
31
32 <%= table('e8e8e8') %>
33 <%
34
35 my @items = qw( invoiced netsales credits payments receipts );
36 if ( $cgi->param('12mo') == 1 ) {
37   @items = map $_.'_12mo', @items;
38 }
39
40 my %label = (
41   'invoiced' => 'Gross Sales',
42   'netsales' => 'Net Sales',
43   'credits'  => 'Credits',
44   'payments' => 'Gross Receipts',
45   'receipts' => 'Net Receipts',
46 );
47 $label{$_.'_12mo'} = $label{$_}. " (previous 12 months)"
48   foreach keys %label;
49
50 my %color = (
51   'invoiced' => '9999ff', #light blue
52   'netsales' => '0000cc', #blue
53   'credits'  => 'cc0000', #red
54   'payments' => '99cc99', #light green
55   'receipts' => '00cc00', #green
56 );
57 $color{$_.'_12mo'} = $color{$_}
58   foreach keys %color;
59
60 my %link = (
61   'invoiced' => "${p}search/cust_bill.html?agentnum=$agentnum;",
62   'credits'  => "${p}search/cust_credit.html?agentnum=$agentnum;",
63   'payments' => "${p}search/cust_pay.cgi?magic=_date;agentnum=$agentnum;",
64 );
65 # XXX link 12mo?
66
67 my $report = new FS::Report::Table::Monthly (
68   'items' => \@items,
69   'start_month' => $smonth,
70   'start_year'  => $syear,
71   'end_month'   => $emonth,
72   'end_year'    => $eyear,
73   'agentnum'    => $agentnum,
74 );
75 my $data = $report->data;
76
77 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
78
79 %>
80
81 <TR><TD></TD>
82 <% foreach my $column ( @{$data->{label}} ) {
83      #$column =~ s/^(\d+)\//$mon[$1-1]<BR>/e;
84      $column =~ s/^(\d+)\//$mon[$1-1]<BR>/;
85      %>
86      <TH><%= $column %></TH>
87 <% } %>
88   <TH>Total</TH>
89 </TR>
90
91 <% foreach my $row (@items) { %>
92   <TR><TH><FONT COLOR="#<%= $color{$row} %>"><%= $label{$row} %></FONT></TH>
93   <% my $link = exists($link{$row})
94        ? qq(<A HREF="$link{$row})
95        : '';
96      my @speriod = @{$data->{speriod}};
97      my @eperiod = @{$data->{eperiod}};
98      my $total = 0;
99   %>
100   <% foreach my $column ( @{$data->{$row}} ) { %>
101     <TD ALIGN="right" BGCOLOR="#ffffff">
102       <%= $link ? $link. 'begin='. shift(@speriod). ';end='. shift(@eperiod). '">' : '' %><FONT COLOR="#<%= $color{$row} %>">$<%= sprintf("%.2f", $column) %></FONT><%= $link ? '</A>' : '' %>
103     </TD>
104     <% $total += $column; %>
105   <% } %>
106   <TD ALIGN="right" BGCOLOR="#f5f6be">
107     <%= $link ? $link. 'begin='. @{$data->{speriod}}[0]. ';end='. @{$data->{eperiod}}[-1]. '">' : '' %><FONT COLOR="#<%= $color{$row} %>">$<%= sprintf("%.2f", $total) %></FONT><%= $link ? '</A>' : '' %>
108   </TD>
109   </TR>
110 <% } %>
111 </TABLE>
112
113 <%= include('/elements/footer.html') %>