add a total column
[freeside.git] / httemplate / graph / money_time.cgi
index 14af0f2..9c0a94f 100644 (file)
@@ -12,32 +12,49 @@ my $smonth = $cgi->param('smonth') || $curmon+1;
 my $eyear = $cgi->param('eyear') || 1900+$curyear;
 my $emonth = $cgi->param('emonth') || $curmon+1;
 
+#XXX or virtual
+my( $agentnum, $agent ) = ('', '');
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+  $agentnum = $1;
+  $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
+  die "agentnum $agentnum not found!" unless $agent;
+}
+my $agentname = $agent ? $agent->agent.' ' : '';
+warn $agentname;
+
+%>
+
+<%= include('/elements/header.html',
+              $agentname. 'Sales, Credits and Receipts Summary'
+           )
 %>
 
-<HTML>
-  <HEAD>
-    <TITLE>Graphing monetary values over time</TITLE>
-  </HEAD>
-<BODY BGCOLOR="#e8e8e8">
 <IMG SRC="money_time-graph.cgi?<%= $cgi->query_string %>" WIDTH="976" HEIGHT="384">
 <BR>
 
 <%= table('e8e8e8') %>
 <%
 
-my @items = qw( invoiced netsales credits receipts );
+my @items = qw( invoiced netsales credits payments receipts );
 my %label = (
   'invoiced' => 'Gross Sales',
   'netsales' => 'Net Sales',
   'credits'  => 'Credits',
-  'receipts' => 'Receipts',
+  'payments' => 'Gross Receipts',
+  'receipts' => 'Net Receipts',
 );
 my %color = (
   'invoiced' => '9999ff', #light blue
   'netsales' => '0000cc', #blue
   'credits'  => 'cc0000', #red
+  'payments' => '99cc99', #light green
   'receipts' => '00cc00', #green
 );
+my %link = (
+  'invoiced' => "${p}search/cust_bill.html?agentnum=$agentnum;",
+  'credits'  => "${p}search/cust_credit.html?agentnum=$agentnum;",
+  'payments' => "${p}search/cust_pay.cgi?magic=_date;agentnum=$agentnum;",
+);
 
 my $report = new FS::Report::Table::Monthly (
   'items' => \@items,
@@ -45,10 +62,10 @@ my $report = new FS::Report::Table::Monthly (
   'start_year'  => $syear,
   'end_month'   => $emonth,
   'end_year'    => $eyear,
+  'agentnum'    => $agentnum,
 );
 my $data = $report->data;
 
-
 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
 
 %>
@@ -60,15 +77,25 @@ my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
      %>
      <TH><%= $column %></TH>
 <% } %>
+  <TH>Total</TH>
 </TR>
 
 <% foreach my $row (@items) { %>
   <TR><TH><FONT COLOR="#<%= $color{$row} %>"><%= $label{$row} %></FONT></TH>
+  <% my $link = exists($link{$row})
+       ? qq(<A HREF="$link{$row})
+       : '';
+     my @speriod = @{$data->{speriod}};
+     my @eperiod = @{$data->{eperiod}};
+     my $total = 0;
+  %>
   <% foreach my $column ( @{$data->{$row}} ) { %>
     <TD ALIGN="right" BGCOLOR="#ffffff">
-      <FONT COLOR="#<%= $color{$row} %>">$<%= sprintf("%.2f", $column) %></FONT>
+      <%= $link ? $link. 'begin='. shift(@speriod). ';end='. shift(@eperiod). '">' : '' %><FONT COLOR="#<%= $color{$row} %>">$<%= sprintf("%.2f", $column) %></FONT><%= $link ? '</A>' : '' %>
     </TD>
+    <% $total += $column; %>
   <% } %>
+  <TD><%= sprintf("%.2f", $total) %>
   </TR>
 <% } %>
 </TABLE>
@@ -107,6 +134,8 @@ From <SELECT NAME="smonth">
 <% } %>
 </SELECT>
 
+for agent: <%= include('/elements/select-agent.html', $agentnum) %>
+
 <INPUT TYPE="submit" VALUE="Redisplay">
 </FORM>
 </BODY>