From 81afd9d0c793ed6b934e0b1671c0dca9827bc076 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 5 Dec 2011 17:58:01 +0000 Subject: [PATCH] Fixed time report broken by r8085. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8092 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/helpers/time_report.rb | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/redmine/helpers/time_report.rb b/lib/redmine/helpers/time_report.rb index 528ef02fe..e7589fffe 100644 --- a/lib/redmine/helpers/time_report.rb +++ b/lib/redmine/helpers/time_report.rb @@ -48,20 +48,23 @@ module Redmine sql_group_by = @criteria.collect{|criteria| @available_criteria[criteria][:sql]}.join(', ') sql_condition = '' - if @project.nil? - sql_condition = Project.allowed_to_condition(User.current, :view_time_entries) - elsif @issue.nil? - sql_condition = @project.project_condition(Setting.display_subprojects_issues?) - else + if @issue 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 sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours" sql << " FROM #{TimeEntry.table_name}" sql << time_report_joins - sql << " WHERE" - sql << " (%s) AND" % sql_condition - sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)] + sql << " WHERE (%s)" % sql_condition + if @from && @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" @hours = ActiveRecord::Base.connection.select_all(sql) @@ -78,7 +81,17 @@ module Redmine row['day'] = "#{row['spent_on']}" 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} @periods = []