Added display of units sums for report groups. (refs #14168)

Unit sums are displayed for group_by = cost_type_id or if only time entries are displayed.

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@503 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
hjust 15 years ago
parent 19f898cb7e
commit 3015251cf6
  1. 47
      app/controllers/cost_reports_controller.rb
  2. 32
      app/views/cost_reports/_list_group_by.rhtml

@ -49,23 +49,23 @@ class CostReportsController < ApplicationController
else
render :layout => !request.xhr?
end
rescue Exception => e
logger.error "#{e.class.name}: #{e.message}" if logger
session.delete :cost_query
# Give it a name, required to be valid
@query = CostQuery.new(:name => "_")
@query.project = @project
get_entries(limit)
respond_to do |format|
format.html do
@custom_error = l(:error_generic)
render :layout => !request.xhr?
end
format.atom {render_500(l(:error_generic))}
format.csv {render_500(l(:error_generic))}
end
# rescue Exception => e
# logger.error "#{e.class.name}: #{e.message}" if logger
# session.delete :cost_query
#
# # Give it a name, required to be valid
# @query = CostQuery.new(:name => "_")
# @query.project = @project
#
# get_entries(limit)
# respond_to do |format|
# format.html do
# @custom_error = l(:error_generic)
# render :layout => !request.xhr?
# end
# format.atom {render_500(l(:error_generic))}
# format.csv {render_500(l(:error_generic))}
# end
end
def new
@ -155,6 +155,7 @@ private
0.0000
END
) AS sum,
SUM(#{table == "time_entries" ? "hours" : "units"}) as unit_sum,
COUNT(*) AS count
FROM #{from}
WHERE #{where_statement}
@ -163,15 +164,15 @@ private
end.join(" UNION ")
if scopes.length == 2
sql = "SELECT #{fields}, SUM(sum) as sum, SUM(count) AS count FROM (#{subselect}) AS entries GROUP BY #{fields}"
sql = "SELECT #{fields}, SUM(sum) as sum, SUM(unit_sum) as unit_sum, SUM(count) AS count FROM (#{subselect}) AS entries GROUP BY #{fields}"
else
sql = subselect
end
@grouped_entries = ActiveRecord::Base.connection.select_all(sql)
@entry_count, @entry_sum = @grouped_entries.inject([0, 0.0]) do |r,i|
r[0] += i["count"].to_i
r[1] += i["sum"].to_f
@entry_sum, @entry_count = @grouped_entries.inject([0, 0.0]) do |r,i|
r[0] += i["sum"].to_f
r[1] += i["count"].to_i
r
end
end
@ -250,7 +251,7 @@ private
@entry_pages = Paginator.new self, @entry_count, limit, params['page']
@entries = TimeEntry.find :all, {:order => (sort_clause if time_sort_column),
:include => [:issue, :activity, :user],
:include => [:issue, :activity, :user, :project],
:conditions => time_where,
:limit => limit,
:offset => @entry_pages.current.offset}
@ -261,7 +262,7 @@ private
@entry_pages = Paginator.new self, @entry_count, limit, params['page']
@entries = CostEntry.find :all, {:order => (sort_clause if cost_sort_column),
:include => [:issue, :cost_type, :user],
:include => [:issue, :cost_type, :user, :project],
:conditions => cost_where,
:limit => limit,
:offset => @entry_pages.current.offset}

@ -1,16 +1,20 @@
<%
def get_column
def group_by_column
CostQuery.group_by_columns[@query.group_by[:name]]
end
def display_costs
CostEntry.column_names.include?(get_column[:db_field].to_s) && @query.display_cost_entries
end
def display_time
TimeEntry.column_names.include?(get_column[:db_field].to_s) && @query.display_time_entries
end
def display_js(invert=false)
group_by_column = get_column
return "'' + Form.serialize('filter-options')" unless group_by_column[:scope] == :costs
display_costs = ((CostEntry.column_names.include? group_by_column[:db_field].to_s) && @query.display_cost_entries)
display_time = ((TimeEntry.column_names.include? group_by_column[:db_field].to_s) && @query.display_time_entries)
if invert
display_costs = !display_costs
display_time = !display_time
@ -27,8 +31,6 @@
def filter_js(filter_hash)
group_by_column = get_column
if group_by_column[:scope] == :costs && filter_hash[:values].nil?
return ""
end
@ -41,6 +43,7 @@
<thead>
<th>Group By</th>
<th class="units">Count</th>
<% if (@query.group_by["name"] == "cost_type_id") || (!display_costs && display_time) %><th><%= l(:caption_cost_unit_plural) %></th><% end %>
<th class="currency">Sum</th>
<th>Drill Down</th>
</thead>
@ -58,7 +61,7 @@
filter_js = filter_js(filter)
group_by = {:group_by=>{:name=>"", :granularity=>"year"}}
fields = entry.keys - %w[count sum]
fields = entry.keys - %w[count sum unit_sum]
if fields.include? "tmonth"
name = "#{entry[:tyear]}, #{month_name(entry["tmonth"].to_i)}"
elsif fields.include? "tweek"
@ -74,6 +77,17 @@
<%= name %>
</td>
<td class="units"><%=l :x_entries, :count => entry["count"].to_i %></td>
<% if (@query.group_by["name"] == "cost_type_id") || (!display_costs && display_time) %>
<% cost_type = CostType.find_by_id(entry["cost_type_id"]) %>
<td class="units">
<% if cost_type %>
<%= pluralize(entry["unit_sum"], cost_type.unit, cost_type.unit_plural) %>
<%- else -%>
<%= entry["unit_sum"] + "h" %>
<%- end %>
</td>
<%- end %>
<td class="currency"><%= number_to_currency(entry["sum"]) %></td>
<td>
<%= link_to_remote "Drill Down", {

Loading…
Cancel
Save