Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary and filter by custom fields #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 54 additions & 12 deletions app/controllers/timesheet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ class TimesheetController < ApplicationController
verify :method => :delete, :only => :reset, :render => {:nothing => true, :status => :method_not_allowed }

def index
load_filters_from_session
#load_filters_from_session
unless @timesheet
@timesheet ||= Timesheet.new
end
@timesheet.allowed_projects = allowed_projects

if @timesheet.allowed_projects.empty?
render :action => 'no_projects'
return
Expand All @@ -36,7 +35,7 @@ def report
redirect_to :action => 'index'
return
end

@timesheet.allowed_projects = allowed_projects

if @timesheet.allowed_projects.empty?
Expand All @@ -51,40 +50,45 @@ def report
else
@timesheet.projects = @timesheet.allowed_projects
end

call_hook(:plugin_timesheet_controller_report_pre_fetch_time_entries, { :timesheet => @timesheet, :params => params })

save_filters_to_session(@timesheet)

@timesheet.fetch_time_entries
#save_filters_to_session(@timesheet)

@timesheet.fetch_time_entries if @timesheet.detailed == "yes"
@timesheet.fetch_time_entries_summary unless @timesheet.detailed == "yes"
# Sums
@total = { }
@total_non_billable_hours = { }
unless @timesheet.sort == :issue
@timesheet.time_entries.each do |project,logs|
@total[project] = 0
@total_non_billable_hours[project] = 0
if logs[:logs]
logs[:logs].each do |log|
@total[project] += log.hours
@total_non_billable_hours[project] += log.non_billable_hours.to_f unless log.non_billable_hours.blank?
end
end
end
else
@timesheet.time_entries.each do |project, project_data|
@total[project] = 0
@total_non_billable_hours[project] = 0
if project_data[:issues]
project_data[:issues].each do |issue, issue_data|
@total[project] += issue_data.collect(&:hours).sum
end
end
end
end

@grand_total = @total.collect{|k,v| v}.inject{|sum,n| sum + n}

@grand_total_non_billable_hours = @total_non_billable_hours.collect{|k,v| v}.inject{|sum,n| sum + n}


respond_to do |format|
format.html { render :action => 'details', :layout => false if request.xhr? }
format.csv { send_data @timesheet.to_csv, :filename => 'timesheet.csv', :type => "text/csv" }
format.csv { send_data @timesheet.to_csv, :filename => 'timesheet.csv', :type => "text/csv" }
end
end

Expand All @@ -97,6 +101,44 @@ def reset
clear_filters_from_session
redirect_to :action => 'index'
end

def getprojects
custom_field_id = CustomField.find_by_name("Project Type").id
project_type = params[:project_type]
project_status = params[:project_status]
cond = ARCondition.new
cond << ["status =?",project_status] unless project_status == "Both"
if User.current.admin?
if project_type == "Both"
projects = Project.timesheet_order_by_name.find(:all,:conditions => cond.conditions,:order => "name ASC")
else
cond << ["custom_values.custom_field_id=? && custom_values.value=?",custom_field_id,project_type]
projects = Project.timesheet_order_by_name.find(:all,:joins => :custom_values,:conditions => cond.conditions,:order => "name ASC")
end
elsif Setting.plugin_timesheet_plugin['project_status'] == 'all'
if project_type == "Both"
projects = Project.timesheet_order_by_name.timesheet_with_membership(User.current).find(:all,:conditions => cond.conditions,:order => "name ASC")
else
cond << ["custom_values.custom_field_id=? && custom_values.value=?",custom_field_id,project_type]
projects = Project.timesheet_order_by_name.timesheet_with_membership(User.current).find(:all,:joins => :custom_values,:conditions => cond.conditions,:order => "name ASC")
end
else
cond << Project.visible_condition(User.current)
if project_type == "Both"
projects = Project.timesheet_order_by_name.find(:all,:conditions => cond.conditions,:order => "name ASC")
else
cond << ["custom_values.custom_field_id=? && custom_values.value=?",custom_field_id,project_type]
projects = Project.timesheet_order_by_name.find(:all,:joins => :custom_values,:conditions => cond.conditions,:order => "name ASC")
end
end
projStr =""
projects.each do |project|
projStr << project.id.to_s() + ',' + project.name + "\n"
end
respond_to do |format|
format.text { render :text => projStr }
end
end

private
def get_list_size
Expand All @@ -115,7 +157,7 @@ def get_precision
end

def get_activities
@activities = TimeEntryActivity.all(:conditions => 'parent_id IS NULL')
@activities = TimeEntryActivity.all(:conditions => 'parent_id IS NULL',:order => "name ASC")
end

def allowed_projects
Expand All @@ -124,7 +166,7 @@ def allowed_projects
elsif Setting.plugin_timesheet_plugin['project_status'] == 'all'
Project.timesheet_order_by_name.timesheet_with_membership(User.current)
else
Project.timesheet_order_by_name.all(:conditions => Project.visible_by(User.current))
Project.timesheet_order_by_name.all(:conditions => Project.visible_condition(User.current))
end
end

Expand Down
5 changes: 3 additions & 2 deletions app/helpers/timesheet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def link_to_csv_export(timesheet)
:controller => 'timesheet',
:action => 'report',
:format => 'csv',
:timesheet => timesheet.to_param
:timesheet => timesheet.to_param,
},
:method => 'post',
:class => 'icon icon-timesheet')
Expand Down Expand Up @@ -46,7 +46,8 @@ def displayed_time_entries_for_issue(time_entries)
end

def project_options(timesheet)
available_projects = timesheet.allowed_projects
#Onload of the page the project type is billable
available_projects = timesheet.filtered_projects(timesheet.project_type.blank? ? "Billable" : timesheet.project_type,timesheet.project_status.blank? ? Project::STATUS_ACTIVE : timesheet.project_status)
selected_projects = timesheet.projects.collect(&:id)
selected_projects = available_projects.collect(&:id) if selected_projects.blank?

Expand Down
Loading