@@ -80,14 +80,22 class TimelogController < ApplicationController | |||
|
80 | 80 | unless @criterias.empty? |
|
81 | 81 | sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ') |
|
82 | 82 | sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ') |
|
83 | sql_condition = '' | |
|
83 | 84 | |
|
85 | if @project.nil? | |
|
86 | sql_condition = Project.allowed_to_condition(User.current, :view_time_entries) | |
|
87 | elsif @issue.nil? | |
|
88 | sql_condition = @project.project_condition(Setting.display_subprojects_issues?) | |
|
89 | else | |
|
90 | sql_condition = "#{TimeEntry.table_name}.issue_id = #{@issue.id}" | |
|
91 | end | |
|
92 | ||
|
84 | 93 | sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours" |
|
85 | 94 | sql << " FROM #{TimeEntry.table_name}" |
|
86 | 95 | sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id" |
|
87 | 96 | sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id" |
|
88 | 97 | sql << " WHERE" |
|
89 | sql << " (%s) AND" % @project.project_condition(Setting.display_subprojects_issues?) if @project | |
|
90 | sql << " (%s) AND" % Project.allowed_to_condition(User.current, :view_time_entries) | |
|
98 | sql << " (%s) AND" % sql_condition | |
|
91 | 99 | sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)] |
|
92 | 100 | sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on" |
|
93 | 101 |
@@ -27,9 +27,9 | |||
|
27 | 27 | <div class="tabs"> |
|
28 | 28 | <% url_params = @free_period ? { :from => @from, :to => @to } : { :period => params[:period] } %> |
|
29 | 29 | <ul> |
|
30 | <li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'details', :project_id => @project }), | |
|
30 | <li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'details', :project_id => @project, :issue_id => @issue }), | |
|
31 | 31 | :class => (@controller.action_name == 'details' ? 'selected' : nil)) %></li> |
|
32 | <li><%= link_to(l(:label_report), url_params.merge({:controller => 'timelog', :action => 'report', :project_id => @project}), | |
|
32 | <li><%= link_to(l(:label_report), url_params.merge({:controller => 'timelog', :action => 'report', :project_id => @project, :issue_id => @issue}), | |
|
33 | 33 | :class => (@controller.action_name == 'report' ? 'selected' : nil)) %></li> |
|
34 | 34 | </ul> |
|
35 | 35 | </div> |
@@ -12,6 +12,7 | |||
|
12 | 12 | <% end %> |
|
13 | 13 | <%# TODO: get rid of the project_id field, that should already be in the URL %> |
|
14 | 14 | <%= hidden_field_tag('project_id', params[:project_id]) if @project %> |
|
15 | <%= hidden_field_tag('issue_id', params[:issue_id]) if @issue %> | |
|
15 | 16 | <%= render :partial => 'date_range' %> |
|
16 | 17 | |
|
17 | 18 | <p><%= l(:label_details) %>: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'], |
@@ -206,6 +206,14 class TimelogControllerTest < ActionController::TestCase | |||
|
206 | 206 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
207 | 207 | end |
|
208 | 208 | |
|
209 | def test_report_at_issue_level | |
|
210 | get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
|
211 | assert_response :success | |
|
212 | assert_template 'report' | |
|
213 | assert_not_nil assigns(:total_hours) | |
|
214 | assert_equal "154.25", "%.2f" % assigns(:total_hours) | |
|
215 | end | |
|
216 | ||
|
209 | 217 | def test_report_custom_field_criteria |
|
210 | 218 | get :report, :project_id => 1, :criterias => ['project', 'cf_1'] |
|
211 | 219 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now