Fixed time report broken by r8085.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8092 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-12-05 17:58:01 +00:00
parent 3f79a914d9
commit 81afd9d0c7
1 changed files with 21 additions and 8 deletions

View File

@ -48,20 +48,23 @@ module Redmine
sql_group_by = @criteria.collect{|criteria| @available_criteria[criteria][:sql]}.join(', ') sql_group_by = @criteria.collect{|criteria| @available_criteria[criteria][:sql]}.join(', ')
sql_condition = '' sql_condition = ''
if @project.nil? if @issue
sql_condition = Project.allowed_to_condition(User.current, :view_time_entries)
elsif @issue.nil?
sql_condition = @project.project_condition(Setting.display_subprojects_issues?)
else
sql_condition = "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}" sql_condition = "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
else
sql_condition = Project.allowed_to_condition(User.current, :view_time_entries, :project => @project, :with_subprojects => Setting.display_subprojects_issues?)
end end
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours" sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
sql << " FROM #{TimeEntry.table_name}" sql << " FROM #{TimeEntry.table_name}"
sql << time_report_joins sql << time_report_joins
sql << " WHERE" sql << " WHERE (%s)" % sql_condition
sql << " (%s) AND" % sql_condition if @from && @to
sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)] sql << " AND (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)]
elsif @from
sql << " AND (spent_on BETWEEN >= '%s')" % ActiveRecord::Base.connection.quoted_date(@from)
elsif @to
sql << " AND (spent_on BETWEEN <= '%s')" % ActiveRecord::Base.connection.quoted_date(@to)
end
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on" sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
@hours = ActiveRecord::Base.connection.select_all(sql) @hours = ActiveRecord::Base.connection.select_all(sql)
@ -79,6 +82,16 @@ module Redmine
end end
end end
if @from.nil?
min = @hours.collect {|row| row['spent_on']}.min
@from = min ? min.to_date : Date.today
end
if @to.nil?
max = @hours.collect {|row| row['spent_on']}.max
@to = max ? max.to_date : Date.today
end
@total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
@periods = [] @periods = []