Project

General

Profile

Feature #14924 » percent_utilization_in_reports.diff

Patch it directly to the redmine core. No migrations necessary. - Devaroop Bhattacharya, 2013-09-16 17:43

View differences:

config/settings.yml (working copy)
default:
- '6'
- '7'
standard_man_hours_a_day:
format: int
default: 8
config/locales/en.yml (working copy)
description_date_from: Enter start date
description_date_to: Enter end date
text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'
setting_standard_man_hours_a_day: Standard man hours a day
utilization: Utilization
app/helpers/timelog_helper.rb (working copy)
end
end
def calculate_availability(columns, hours, period)
hours = hours.to_f
std_hours = Setting.standard_man_hours_a_day.to_i
business_days = case columns
when "week"
5
when "month"
period = period.split('-')
year, month = period[0].to_i, period[1].to_i
start_date = Date.new(year, month)
TimeEntry.business_days_between start_date, start_date.end_of_month
when "day"
1
when "year"
year = period.to_i
start_date = Date.new(year)
TimeEntry.business_days_between start_date, start_date.end_of_year
end
availability = hours/(std_hours * business_days)
"%.1f" % (availability * 100)
end
def report_to_csv(report)
decimal_separator = l(:general_csv_decimal_separator)
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
app/models/time_entry.rb (working copy)
def editable_by?(usr)
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
end
def self.business_days_between(date1, date2)
business_days = 0
date = date2
while date >= date1
business_days += 1 unless date.saturday? or date.sunday?
date = date - 1
end
business_days
end
end
app/controllers/timelog_controller.rb (working copy)
@report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], scope)
@show_utilization = (params[:criteria].present? and params[:criteria].include? "utilization")
respond_to do |format|
format.html { render :layout => !request.xhr? }
format.csv { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'timelog.csv') }
app/views/timelog/report.html.erb (working copy)
<% @report.criteria.each do |criterion| %>
<%= hidden_field_tag 'criteria[]', criterion, :id => nil %>
<% end %>
<%= (hidden_field_tag 'criteria[]', "utilization", :id => nil) if @show_utilization %>
<%= render :partial => 'timelog/date_range' %>
<p><label for='columns'><%= l(:label_details) %></label>: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'],
......
[l(:label_week), 'week'],
[l(:label_day_plural).titleize, 'day']], @report.columns),
:onchange => "this.form.submit();" %>
<label for='criterias'><%= l(:button_add) %></label>: <%= select_tag('criteria[]', options_for_select([[]] + (@report.available_criteria.keys - @report.criteria).collect{|k| [l_or_humanize(@report.available_criteria[k][:label]), k]}),
<% select_opts = [[]] + (@report.available_criteria.keys - @report.criteria).collect{|k| [l_or_humanize(@report.available_criteria[k][:label]), k]} %>
<% select_opts = select_opts + [[l(:utilization), "utilization"]] if (@report.criteria.count > 0 and !@show_utilization) %>
<label for='criterias'><%= l(:button_add) %></label>: <%= select_tag('criteria[]', options_for_select(select_opts),
:onchange => "this.form.submit();",
:style => 'width: 200px',
:id => nil,
......
<% total = 0 -%>
<% @report.periods.each do |period| -%>
<% sum = sum_hours(select_hours(@report.hours, @report.columns, period.to_s)); total += sum -%>
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %>
<% if @show_utilization and sum > 0 %>
<br/>
(<%= calculate_availability(@report.columns, "%.2f" % sum, period.to_s) %>%)
<% end %>
</td>
<% end -%>
<td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
</tr>
app/views/timelog/_report_criteria.html.erb (working copy)
<% total = 0 -%>
<% @report.periods.each do |period| -%>
<% sum = sum_hours(select_hours(hours_for_value, @report.columns, period.to_s)); total += sum -%>
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0; %>
<% if @show_utilization and sum > 0 %>
<br/>
(<%= calculate_availability(@report.columns, "%.2f" % sum, period.to_s) %>%)
<% end %>
</td>
<% end -%>
<td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
</tr>
app/views/settings/_general.html.erb (working copy)
<p><%= setting_text_field :repositories_encodings, :size => 60 %>
<em class="info"><%= l(:text_comma_separated) %></em></p>
<p><%= setting_text_field :standard_man_hours_a_day, :size => 6 %></p>
<%= call_hook(:view_settings_general_form) %>
</div>
(4-4/4)