Added time report.
Report can be generated by member/activity/tracker/version and year/month/week for the selected period. git-svn-id: http://redmine.rubyforge.org/svn/trunk@572 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -1,13 +1,106 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class TimelogController < ApplicationController
|
||||
layout 'base'
|
||||
|
||||
before_filter :find_project
|
||||
before_filter :authorize, :only => :edit
|
||||
before_filter :check_project_privacy, :only => :details
|
||||
before_filter :check_project_privacy, :except => :edit
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def report
|
||||
@available_criterias = { 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
|
||||
:values => @project.versions,
|
||||
:label => :label_version},
|
||||
'category' => {:sql => "#{Issue.table_name}.category_id",
|
||||
:values => @project.issue_categories,
|
||||
:label => :field_category},
|
||||
'member' => {:sql => "#{TimeEntry.table_name}.user_id",
|
||||
:values => @project.users,
|
||||
:label => :label_member},
|
||||
'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
|
||||
:values => Tracker.find(:all),
|
||||
:label => :label_tracker},
|
||||
'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
|
||||
:values => Enumeration::get_values('ACTI'),
|
||||
:label => :label_activity}
|
||||
}
|
||||
|
||||
@criterias = params[:criterias] || []
|
||||
@criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
|
||||
@criterias.uniq!
|
||||
|
||||
@columns = (params[:period] && %w(year month week).include?(params[:period])) ? params[:period] : 'month'
|
||||
|
||||
if params[:date_from]
|
||||
begin; @date_from = params[:date_from].to_date; rescue; end
|
||||
end
|
||||
if params[:date_to]
|
||||
begin; @date_to = params[:date_to].to_date; rescue; end
|
||||
end
|
||||
@date_from ||= Date.civil(Date.today.year, 1, 1)
|
||||
@date_to ||= Date.civil(Date.today.year, Date.today.month+1, 1) - 1
|
||||
|
||||
unless @criterias.empty?
|
||||
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
|
||||
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
|
||||
|
||||
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, SUM(hours) AS hours"
|
||||
sql << " FROM #{TimeEntry.table_name} LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
|
||||
sql << " WHERE spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@date_from.to_time), ActiveRecord::Base.connection.quoted_date(@date_to.to_time)]
|
||||
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek"
|
||||
|
||||
@hours = ActiveRecord::Base.connection.select_all(sql)
|
||||
|
||||
@hours.each do |row|
|
||||
case @columns
|
||||
when 'year'
|
||||
row['year'] = row['tyear']
|
||||
when 'month'
|
||||
row['month'] = "#{row['tyear']}-#{row['tmonth']}"
|
||||
when 'week'
|
||||
row['week'] = "#{row['tyear']}-#{row['tweek']}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@periods = []
|
||||
date_from = @date_from
|
||||
# 100 columns max
|
||||
while date_from < @date_to && @periods.length < 100
|
||||
case @columns
|
||||
when 'year'
|
||||
@periods << "#{date_from.year}"
|
||||
date_from = date_from >> 12
|
||||
when 'month'
|
||||
@periods << "#{date_from.year}-#{date_from.month}"
|
||||
date_from = date_from >> 1
|
||||
when 'week'
|
||||
@periods << "#{date_from.year}-#{date_from.cweek}"
|
||||
date_from = date_from + 7
|
||||
end
|
||||
end
|
||||
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def details
|
||||
sort_init 'spent_on', 'desc'
|
||||
sort_update
|
||||
|
||||
@@ -1,2 +1,30 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module TimelogHelper
|
||||
def select_hours(data, criteria, value)
|
||||
data.select {|row| row[criteria] == value.to_s}
|
||||
end
|
||||
|
||||
def sum_hours(data)
|
||||
sum = 0
|
||||
data.each do |row|
|
||||
sum += row['hours'].to_f
|
||||
end
|
||||
sum
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class TimeEntry < ActiveRecord::Base
|
||||
# could have used polymorphic association
|
||||
# project association here allows easy loading of time entries at project level with one database trip
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<h2><%=l(:label_report_plural)%></h2>
|
||||
|
||||
<% if @total_hours %>
|
||||
<h3 class="textright"><%= l(:label_spent_time) %>:
|
||||
<%= link_to(lwr(:label_f_hour, @total_hours), {:controller => 'timelog', :action => 'details', :project_id => @project}, :class => 'icon icon-time') %>
|
||||
</h3>
|
||||
<div style="float:right;text-align:right;">
|
||||
<strong><%= l(:label_spent_time) %></strong>: <span class="icon icon-time"><%= lwr(:label_f_hour, @total_hours) %></span><br />
|
||||
<%= link_to(l(:label_details), {:controller => 'timelog', :action => 'details', :project_id => @project}) %> |
|
||||
<%= link_to(l(:label_report), {:controller => 'timelog', :action => 'report', :project_id => @project}) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<h2><%=l(:label_report_plural)%></h2>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<h3><%=l(:field_tracker)%> <%= link_to image_tag('zoom_in.png'), :detail => 'tracker' %></h3>
|
||||
<%= render :partial => 'simple', :locals => { :data => @issues_by_tracker, :field_name => "tracker_id", :rows => @trackers } %>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<% @available_criterias[criterias[level]][:values].each do |value| %>
|
||||
<tr class="<%= cycle('odd', 'even') if criterias.length < level + 2 %>">
|
||||
<%= '<td></td>' * level %>
|
||||
<td><%= value.name %></td>
|
||||
<%= '<td></td>' * (criterias.length - level - 1) %>
|
||||
<% hours_for_value = select_hours(hours, criterias[level], value.id) %>
|
||||
<% @periods.each do |period| %>
|
||||
<% sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)) %>
|
||||
<td align="center"><%= sum > 0 ? sum : "-" %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% if criterias.length > level+1 %>
|
||||
<%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
<% reset_cycle %>
|
||||
@@ -0,0 +1,52 @@
|
||||
<h2><%= l(:label_spent_time) %></h2>
|
||||
|
||||
<% form_remote_tag(:url => {:project_id => @project}, :update => 'content') do %>
|
||||
<% @criterias.each do |criteria| %>
|
||||
<%= hidden_field_tag 'criterias[]', criteria %>
|
||||
<% end %>
|
||||
<p>
|
||||
<%= l(:label_date_from) %>: <%= text_field_tag 'date_from', @date_from, :size => 10 %><%= calendar_for('date_from') %>
|
||||
|
||||
<%= l(:label_date_to) %>: <%= text_field_tag 'date_to', @date_to, :size => 10 %><%= calendar_for('date_to') %>
|
||||
|
||||
<%= l(:label_details) %>:
|
||||
<%= select_tag 'period', options_for_select([[l(:label_year), 'year'],
|
||||
[l(:label_month), 'month'],
|
||||
[l(:label_week), 'week']], @columns) %>
|
||||
|
||||
<%= submit_tag l(:button_apply) %>
|
||||
<%= link_to_remote l(:button_clear), {:url => {:project_id => @project}, :update => 'content'}, :class => 'icon icon-reload' %>
|
||||
</p>
|
||||
|
||||
<% if @criterias.length < 3 %>
|
||||
<p><%= l(:button_add) %>: <%= select_tag('criterias[]', options_for_select([[]] + (@available_criterias.keys - @criterias).collect{|k| [l(@available_criterias[k][:label]), k]}), :onchange => "this.form.onsubmit();") %></p>
|
||||
<% end %>
|
||||
|
||||
<br />
|
||||
|
||||
<% unless @criterias.empty? %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<% @criterias.each do |criteria| %>
|
||||
<th width="15%"><%= l(@available_criterias[criteria][:label]) %></th>
|
||||
<% end %>
|
||||
<% @periods.each do |period| %>
|
||||
<th width="<%= ((100 - @criterias.length * 15 - 15 ) / @periods.length).to_i %>%"><%= period %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<%= render :partial => 'report_criteria', :locals => {:criterias => @criterias, :hours => @hours, :level => 0} %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% content_for :header_tags do %>
|
||||
<%= javascript_include_tag 'calendar/calendar' %>
|
||||
<%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
|
||||
<%= javascript_include_tag 'calendar/calendar-setup' %>
|
||||
<%= stylesheet_link_tag 'calendar' %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user