agent-specific sales/credit/receipts summary
[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 </TR>
81
82 <% foreach my $row (@items) { %>
83   <TR><TH><FONT COLOR="#<%= $color{$row} %>"><%= $label{$row} %></FONT></TH>
84   <% my $link = exists($link{$row})
85        ? qq(<A HREF="$link{$row})
86        : '';
87      my @speriod = @{$data->{speriod}};
88      my @eperiod = @{$data->{eperiod}};
89   %>
90   <% foreach my $column ( @{$data->{$row}} ) { %>
91     <TD ALIGN="right" BGCOLOR="#ffffff">
92       <%= $link ? $link. 'begin='. shift(@speriod). ';end='. shift(@eperiod). '">' : '' %><FONT COLOR="#<%= $color{$row} %>">$<%= sprintf("%.2f", $column) %></FONT><%= $link ? '</A>' : '' %>
93     </TD>
94   <% } %>
95   </TR>
96 <% } %>
97 </TABLE>
98
99 <BR>
100 <FORM METHOD="POST">
101 <!--
102 <INPUT TYPE="checkbox" NAME="ar">
103   Accounts receivable (invoices - applied credits)<BR>
104 <INPUT TYPE="checkbox" NAME="charged">
105   Just Invoices<BR>
106 <INPUT TYPE="checkbox" NAME="defer">
107   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>
108 <INPUT TYPE="checkbox" NAME="cash">
109   Cashflow (payments - refunds)<BR>
110 <BR>
111 -->
112 From <SELECT NAME="smonth">
113 <% foreach my $mon ( 1..12 ) { %>
114 <OPTION VALUE="<%= $mon %>"<%= $mon == $smonth ? ' SELECTED' : '' %>><%= $mon[$mon-1] %>
115 <% } %>
116 </SELECT>
117 <SELECT NAME="syear">
118 <% foreach my $y ( 1999 .. 2010 ) { %>
119 <OPTION VALUE="<%= $y %>"<%= $y == $syear ? ' SELECTED' : '' %>><%= $y %>
120 <% } %>
121 </SELECT>
122  to <SELECT NAME="emonth">
123 <% foreach my $mon ( 1..12 ) { %>
124 <OPTION VALUE="<%= $mon %>"<%= $mon == $emonth ? ' SELECTED' : '' %>><%= $mon[$mon-1] %>
125 <% } %>
126 </SELECT>
127 <SELECT NAME="eyear">
128 <% foreach my $y ( 1999 .. 2010 ) { %>
129 <OPTION VALUE="<%= $y %>"<%= $y == $eyear ? ' SELECTED' : '' %>><%= $y %>
130 <% } %>
131 </SELECT>
132
133 for agent: <%= include('/elements/select-agent.html', $agentnum) %>
134
135 <INPUT TYPE="submit" VALUE="Redisplay">
136 </FORM>
137 </BODY>
138 </HTML>