Skip to content

Instantly share code, notes, and snippets.

@janxious
Forked from mileszs/report_results.html.erb
Created December 15, 2009 18:24
Show Gist options
  • Save janxious/257156 to your computer and use it in GitHub Desktop.
Save janxious/257156 to your computer and use it in GitHub Desktop.
<%# Total number of tickets for this customer by time frame -%>
<table>
<thead>
<tr>
<th>Timeframe</th>
<th>Opened</th>
<th>Closed</th>
</tr>
</thead>
<tbody>
<% Timeframe.all.map{|t| {:name => t.name,
:total => @tickets.select{|t| t.timeframe_id == timeframe.id }.size,
:closed => @tickets.select {|t| t.timeframe_id == timeframe.id }.select { |t| t.closed? }.size}}.each do |timeframe| -%>
<tr>
<td><strong><%= timeframe[:name] %><strong></td>
<td><%= timeframe[:total] %>
<td><%= timeframe[:closed] %>
</tr>
<% end -%>
<tr>
<td><strong>Totals</strong></td>
<td><%= @tickets.size %></td>
<td><%= @tickets.select(&:closed?).size %></td>
</tr>
</tbody>
</table>
<br />
<br />
<%# Total number of tickets for this customer by type -%>
<table>
<thead>
<tr>
<th>Type</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<% @ticket_type_and_tickets_size do |t| -%>
<tr>
<td><strong><%= t[:name] %></strong></td>
<td><%= t[:size] %>
</tr>
<% end -%>
</tbody>
</table>
class ReportsController < Blah
#...
def report_results
#...
@tickets = whatever
@ticket_type_and_tickets_size = TicketType.all.map{|tt| { :name => t.name, :size => @tickets.select{ |t| tt.id == t.ticket_type_id}.size } }
#...
end
#...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment