correct period & use a yellow color for the total column
[freeside.git] / httemplate / graph / money_time.cgi
1 <!-- mason kludge -->
2 <%
3
4 #my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
5 my ($curmon,$curyear) = (localtime(time))[4,5];
6
7 #find first month
8 my $syear = $cgi->param('syear') || 1899+$curyear;
9 my $smonth = $cgi->param('smonth') || $curmon+1;
10
11 #find last month
12 my $eyear = $cgi->param('eyear') || 1900+$curyear;
13 my $emonth = $cgi->param('emonth') || $curmon+1;
14
15 #XXX or virtual
16 my( $agentnum, $agent ) = ('', '');
17 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
18   $agentnum = $1;
19   $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
20   die "agentnum $agentnum not found!" unless $agent;
21 }
22 my $agentname = $agent ? $agent->agent.' ' : '';
23 warn $agentname;
24
25 %>
26
27 <%= include('/elements/header.html',
28               $agentname. 'Sales, Credits and Receipts Summary'
29            )
30 %>
31
32 <IMG SRC="money_time-graph.cgi?<%= $cgi->query_string %>" WIDTH="976" HEIGHT="384">
33 <BR>
34
35 <%= table('e8e8e8') %>
36 <%
37
38 my @items = qw( invoiced netsales credits payments receipts );
39 my %label = (
40   'invoiced' => 'Gross Sales',
41   'netsales' => 'Net Sales',
42   'credits'  => 'Credits',
43   'payments' => 'Gross Receipts',
44   'receipts' => 'Net Receipts',
45 );
46 my %color = (
47   'invoiced' => '9999ff', #light blue
48   'netsales' => '0000cc', #blue
49   'credits'  => 'cc0000', #red
50   'payments' => '99cc99', #light green
51   'receipts' => '00cc00', #green
52 );
53 my %link = (
54   'invoiced' => "${p}search/cust_bill.html?agentnum=$agentnum;",
55   'credits'  => "${p}search/cust_credit.html?agentnum=$agentnum;",
56   'payments' => "${p}search/cust_pay.cgi?magic=_date;agentnum=$agentnum;",
57 );
58
59 my $report = new FS::Report::Table::Monthly (
60   'items' => \@items,
61   'start_month' => $smonth,
62   'start_year'  => $syear,
63   'end_month'   => $emonth,
64   'end_year'    => $eyear,
65   'agentnum'    => $agentnum,
66 );
67 my $data = $report->data;
68
69 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
70
71 %>
72
73 <TR><TD></TD>
74 <% foreach my $column ( @{$data->{label}} ) {
75      #$column =~ s/^(\d+)\//$mon[$1-1]<BR>/e;
76      $column =~ s/^(\d+)\//$mon[$1-1]<BR>/;
77      %>
78      <TH><%= $column %></TH>
79 <% } %>
80   <TH>Total</TH>
81 </TR>
82
83 <% foreach my $row (@items) { %>
84   <TR><TH><FONT COLOR="#<%= $color{$row} %>"><%= $label{$row} %></FONT></TH>
85   <% my $link = exists($link{$row})
86        ? qq(<A HREF="$link{$row})
87        : '';
88      my @speriod = @{$data->{speriod}};
89      my @eperiod = @{$data->{eperiod}};
90      my $total = 0;
91   %>
92   <% foreach my $column ( @{$data->{$row}} ) { %>
93     <TD ALIGN="right" BGCOLOR="#ffffff">
94       <%= $link ? $link. 'begin='. shift(@speriod). ';end='. shift(@eperiod). '">' : '' %><FONT COLOR="#<%= $color{$row} %>">$<%= sprintf("%.2f", $column) %></FONT><%= $link ? '</A>' : '' %>
95     </TD>
96     <% $total += $column; %>
97   <% } %>
98   <TD ALIGN="right" BGCOLOR="#f5f6be">
99     <%= $link ? $link. 'begin='. @{$data->{speriod}}[0]. ';end='. @{$data->{eperiod}}[0]. '">' : '' %><FONT COLOR="#<%= $color{$row} %>">$<%= sprintf("%.2f", $total) %></FONT><%= $link ? '</A>' : '' %>
100   </TD>
101   </TR>
102 <% } %>
103 </TABLE>
104
105 <BR>
106 <FORM METHOD="POST">
107 <!--
108 <INPUT TYPE="checkbox" NAME="ar">
109   Accounts receivable (invoices - applied credits)<BR>
110 <INPUT TYPE="checkbox" NAME="charged">
111   Just Invoices<BR>
112 <INPUT TYPE="checkbox" NAME="defer">
113   Accounts receivable, with deferred revenue (invoices - applied credits, with charges for annual/semi-annual/quarterly/etc. services deferred over applicable time period) (there has got to be a shorter description for this)<BR>
114 <INPUT TYPE="checkbox" NAME="cash">
115   Cashflow (payments - refunds)<BR>
116 <BR>
117 -->
118 From <SELECT NAME="smonth">
119 <% foreach my $mon ( 1..12 ) { %>
120 <OPTION VALUE="<%= $mon %>"<%= $mon == $smonth ? ' SELECTED' : '' %>><%= $mon[$mon-1] %>
121 <% } %>
122 </SELECT>
123 <SELECT NAME="syear">
124 <% foreach my $y ( 1999 .. 2010 ) { %>
125 <OPTION VALUE="<%= $y %>"<%= $y == $syear ? ' SELECTED' : '' %>><%= $y %>
126 <% } %>
127 </SELECT>
128  to <SELECT NAME="emonth">
129 <% foreach my $mon ( 1..12 ) { %>
130 <OPTION VALUE="<%= $mon %>"<%= $mon == $emonth ? ' SELECTED' : '' %>><%= $mon[$mon-1] %>
131 <% } %>
132 </SELECT>
133 <SELECT NAME="eyear">
134 <% foreach my $y ( 1999 .. 2010 ) { %>
135 <OPTION VALUE="<%= $y %>"<%= $y == $eyear ? ' SELECTED' : '' %>><%= $y %>
136 <% } %>
137 </SELECT>
138
139 for agent: <%= include('/elements/select-agent.html', $agentnum) %>
140
141 <INPUT TYPE="submit" VALUE="Redisplay">
142 </FORM>
143 </BODY>
144 </HTML>