@@ -16,16 +16,16 class TimeEntryReportsController < ApplicationController | |||
|
16 | 16 | @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria} |
|
17 | 17 | @criterias.uniq! |
|
18 | 18 | @criterias = @criterias[0,3] |
|
19 | ||
|
19 | ||
|
20 | 20 | @columns = (params[:columns] && %w(year month week day).include?(params[:columns])) ? params[:columns] : 'month' |
|
21 | ||
|
21 | ||
|
22 | 22 | retrieve_date_range |
|
23 | ||
|
23 | ||
|
24 | 24 | unless @criterias.empty? |
|
25 | 25 | sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ') |
|
26 | 26 | sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ') |
|
27 | 27 | sql_condition = '' |
|
28 | ||
|
28 | ||
|
29 | 29 | if @project.nil? |
|
30 | 30 | sql_condition = Project.allowed_to_condition(User.current, :view_time_entries) |
|
31 | 31 | elsif @issue.nil? |
@@ -41,9 +41,9 class TimeEntryReportsController < ApplicationController | |||
|
41 | 41 | sql << " (%s) AND" % sql_condition |
|
42 | 42 | sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)] |
|
43 | 43 | sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on" |
|
44 | ||
|
44 | ||
|
45 | 45 | @hours = ActiveRecord::Base.connection.select_all(sql) |
|
46 | ||
|
46 | ||
|
47 | 47 | @hours.each do |row| |
|
48 | 48 | case @columns |
|
49 | 49 | when 'year' |
@@ -56,9 +56,9 class TimeEntryReportsController < ApplicationController | |||
|
56 | 56 | row['day'] = "#{row['spent_on']}" |
|
57 | 57 | end |
|
58 | 58 | end |
|
59 | ||
|
59 | ||
|
60 | 60 | @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} |
|
61 | ||
|
61 | ||
|
62 | 62 | @periods = [] |
|
63 | 63 | # Date#at_beginning_of_ not supported in Rails 1.2.x |
|
64 | 64 | date_from = @from.to_time |
@@ -80,13 +80,13 class TimeEntryReportsController < ApplicationController | |||
|
80 | 80 | end |
|
81 | 81 | end |
|
82 | 82 | end |
|
83 | ||
|
83 | ||
|
84 | 84 | respond_to do |format| |
|
85 | 85 | format.html { render :layout => !request.xhr? } |
|
86 | 86 | format.csv { send_data(report_to_csv(@criterias, @periods, @hours), :type => 'text/csv; header=present', :filename => 'timelog.csv') } |
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | ||
|
89 | ||
|
90 | 90 | private |
|
91 | 91 | |
|
92 | 92 | # TODO: duplicated in TimelogController |
@@ -141,7 +141,7 class TimeEntryReportsController < ApplicationController | |||
|
141 | 141 | else |
|
142 | 142 | # default |
|
143 | 143 | end |
|
144 | ||
|
144 | ||
|
145 | 145 | @from, @to = @to, @from if @from && @to && @from > @to |
|
146 | 146 | @from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today) |
|
147 | 147 | @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today) |
@@ -170,7 +170,7 class TimeEntryReportsController < ApplicationController | |||
|
170 | 170 | :klass => Issue, |
|
171 | 171 | :label => :label_issue} |
|
172 | 172 | } |
|
173 | ||
|
173 | ||
|
174 | 174 | # Add list and boolean custom fields as available criterias |
|
175 | 175 | custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields) |
|
176 | 176 | custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf| |
@@ -178,7 +178,7 class TimeEntryReportsController < ApplicationController | |||
|
178 | 178 | :format => cf.field_format, |
|
179 | 179 | :label => cf.name} |
|
180 | 180 | end if @project |
|
181 | ||
|
181 | ||
|
182 | 182 | # Add list and boolean time entry custom fields |
|
183 | 183 | TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf| |
|
184 | 184 | @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id)", |
General Comments 0
You need to be logged in to leave comments.
Login now