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