@@ -44,31 +44,22 module Redmine | |||||
44 |
|
44 | |||
45 | def run |
|
45 | def run | |
46 | unless @criteria.empty? |
|
46 | unless @criteria.empty? | |
47 | sql_select = @criteria.collect{|criteria| @available_criteria[criteria][:sql] + " AS " + criteria}.join(', ') |
|
47 | scope = TimeEntry.visible.spent_between(@from, @to) | |
48 | sql_group_by = @criteria.collect{|criteria| @available_criteria[criteria][:sql]}.join(', ') |
|
|||
49 | sql_condition = '' |
|
|||
50 |
|
||||
51 | if @issue |
|
48 | if @issue | |
52 | sql_condition = "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}" |
|
49 | scope = scope.on_issue(@issue) | |
53 | else |
|
50 | elsif @project | |
54 |
s |
|
51 | scope = scope.on_project(@project, Setting.display_subprojects_issues?) | |
55 | end |
|
52 | end | |
56 |
|
53 | time_columns = %w(tyear tmonth tweek spent_on) | ||
57 | sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours" |
|
54 | @hours = [] | |
58 | sql << " FROM #{TimeEntry.table_name}" |
|
55 | scope.sum(:hours, :include => :issue, :group => @criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns).each do |hash, hours| | |
59 | sql << time_report_joins |
|
56 | h = {'hours' => hours} | |
60 | sql << " WHERE (%s)" % sql_condition |
|
57 | (@criteria + time_columns).each_with_index do |name, i| | |
61 | if @from && @to |
|
58 | h[name] = hash[i] | |
62 | sql << " AND (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)] |
|
59 | end | |
63 | elsif @from |
|
60 | @hours << h | |
64 | sql << " AND (spent_on BETWEEN >= '%s')" % ActiveRecord::Base.connection.quoted_date(@from) |
|
|||
65 | elsif @to |
|
|||
66 | sql << " AND (spent_on BETWEEN <= '%s')" % ActiveRecord::Base.connection.quoted_date(@to) |
|
|||
67 | end |
|
61 | end | |
68 | sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on" |
|
62 | ||
69 |
|
||||
70 | @hours = ActiveRecord::Base.connection.select_all(sql) |
|
|||
71 |
|
||||
72 | @hours.each do |row| |
|
63 | @hours.each do |row| | |
73 | case @columns |
|
64 | case @columns | |
74 | when 'year' |
|
65 | when 'year' | |
@@ -165,13 +156,6 module Redmine | |||||
165 |
|
156 | |||
166 | @available_criteria |
|
157 | @available_criteria | |
167 | end |
|
158 | end | |
168 |
|
||||
169 | def time_report_joins |
|
|||
170 | sql = '' |
|
|||
171 | sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id" |
|
|||
172 | sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id" |
|
|||
173 | sql |
|
|||
174 | end |
|
|||
175 | end |
|
159 | end | |
176 | end |
|
160 | end | |
177 | end |
|
161 | end |
General Comments 0
You need to be logged in to leave comments.
Login now