Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
peterskeide committed Nov 22, 2011
2 parents d22626e + ae59cfa commit eabdada
Show file tree
Hide file tree
Showing 41 changed files with 450 additions and 160 deletions.
4 changes: 0 additions & 4 deletions .gems

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -10,4 +10,4 @@ nbproject
*.sqlite3
*~
vendor/plugins/authlogic

.bundle
31 changes: 31 additions & 0 deletions Gemfile
@@ -0,0 +1,31 @@
source :gemcutter
source "http://gems.github.com"

gem "rake", "0.8.7"
gem "rails", "~> 2.3.8"
gem "sqlite3-ruby", "1.3.3", :require => "sqlite3"

# bundler requires these gems in all environments
# gem "nokogiri", "1.4.2"
# gem "geokit"
gem "searchlogic"
gem "authlogic", "2.1.6"

gem 'will_paginate', '2.3.16', :require => 'will_paginate'
# config.gem 'ruby-net-ldap', :require => 'net/ldap'
gem "prawn", "0.11.1"
gem 'prawn-core', "0.5.1", :require => 'prawn/core'
gem 'prawn-format', "0.2.1", :require => 'prawn/format'
gem 'prawn-layout', "0.2.1", :require => 'prawn/layout'

group :development do
# bundler requires these gems in development
# gem "rails-footnotes"
end

group :test do
# bundler requires these gems while running tests
gem 'test-unit', :require => 'test/unit'
gem 'thoughtbot-shoulda', '2.10.2', :require => 'shoulda'
gem 'mocha', :require => false
end
66 changes: 66 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,66 @@
GEM
remote: http://rubygems.org/
remote: http://gems.github.com/
specs:
Ascii85 (1.0.1)
actionmailer (2.3.14)
actionpack (= 2.3.14)
actionpack (2.3.14)
activesupport (= 2.3.14)
rack (~> 1.1.0)
activerecord (2.3.14)
activesupport (= 2.3.14)
activeresource (2.3.14)
activesupport (= 2.3.14)
activesupport (2.3.14)
authlogic (2.1.6)
activesupport
metaclass (0.0.1)
mocha (0.10.0)
metaclass (~> 0.0.1)
pdf-reader (0.10.1)
Ascii85 (~> 1.0.0)
prawn (0.11.1)
pdf-reader (>= 0.9.0)
ttfunk (~> 1.0.0)
prawn-core (0.5.1)
prawn-format (0.2.1)
prawn-core
prawn-layout (0.2.1)
rack (1.1.2)
rails (2.3.14)
actionmailer (= 2.3.14)
actionpack (= 2.3.14)
activerecord (= 2.3.14)
activeresource (= 2.3.14)
activesupport (= 2.3.14)
rake (>= 0.8.3)
rake (0.8.7)
searchlogic (2.5.8)
activerecord (~> 2.3.12)
activerecord (~> 2.3.12)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
test-unit (2.4.1)
thoughtbot-shoulda (2.10.2)
ttfunk (1.0.3)
will_paginate (2.3.16)

PLATFORMS
ruby

DEPENDENCIES
authlogic (= 2.1.6)
mocha
prawn (= 0.11.1)
prawn-core (= 0.5.1)
prawn-format (= 0.2.1)
prawn-layout (= 0.2.1)
rails (~> 2.3.8)
rake (= 0.8.7)
searchlogic
sqlite3-ruby (= 1.3.3)
test-unit
thoughtbot-shoulda (= 2.10.2)
will_paginate (= 2.3.16)
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -19,4 +19,4 @@ namespace :test do
system("#{rcov} --html test/integration/*_test.rb")
system("open coverage/index.html") if PLATFORM['darwin']
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/activities_controller.rb
Expand Up @@ -4,7 +4,7 @@ class ActivitiesController < ApplicationController
before_filter :check_admin, { :except => :show }

def index
@activities = Activity.templates.paginate :page => params[:page] || 1, :per_page => 15, :order => 'name'
@activities = Activity.templates.all.sort #.paginate :page => params[:page] || 1, :per_page => 15, :order => 'name'
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -21,7 +21,7 @@ def set_time_zone
end

def redirect_to_ssl
redirect_to :protocol => "https://" unless (request.ssl? or local_request?)
redirect_to :protocol => "https://" unless (request.ssl? or Rails.env.development?)
end

def current_user_session
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/customers_controller.rb
Expand Up @@ -4,7 +4,7 @@ class CustomersController < ApplicationController
before_filter :check_admin

def index
@customers = Customer.paginate :page => params[:page] || 1 , :per_page => 15, :order => 'name'
@customers = Customer.all.sort #.paginate :page => params[:page] || 1 , :per_page => 15, :order => 'name'
end

def new
Expand Down
15 changes: 10 additions & 5 deletions app/controllers/reports_controller.rb
Expand Up @@ -10,7 +10,7 @@ def index

def user
setup_calender
@users = User.active.paginate :page => params[:page] || 1, :per_page => 30, :order => 'lastname'
@users = User.active.sort #.paginate :page => params[:page] || 1, :per_page => 30, :order => 'lastname'

first_day = @day.at_beginning_of_month
last_day = @day.at_end_of_month
Expand Down Expand Up @@ -40,17 +40,22 @@ def billing
params[:letter] ||= "A"

billable_customers = Customer.billable(true).to_a

@show_empty = params[:show_empty] != nil

@letters, @other = extract_customers_by_letter( billable_customers, @day )

@department_id = params[:department] && params[:department] != "" ? params[:department].to_i : nil
@department = @department_id ? Department.find(@department_id) : nil

@customers = case params[:letter]
when '*' then
Customer.billable(true).paginate :page => params[:page] || 1, :per_page => 100, :order => 'name'
Customer.billable(true).sort #.paginate :page => params[:page] || 1, :per_page => 100, :order => 'name'
when '#' then
@other.paginate :page => params[:page] || 1, :per_page => 25, :order => 'name'
@other.sort #.paginate :page => params[:page] || 1, :per_page => 25, :order => 'name'
else
Customer.billable(true).on_letter(params[:letter]).paginate :page => params[:page] || 1, :per_page => 25, :order => 'name'
Customer.billable(true).on_letter(params[:letter]).sort #.paginate :page => params[:page] || 1, :per_page => 25, :order => 'name'
end

end


Expand Down
4 changes: 2 additions & 2 deletions app/controllers/tags_controller.rb
Expand Up @@ -60,9 +60,9 @@ def update_tags

def tags_for_tag_type(tag_type_id, page=1)
if tag_type_id && tag_type_id != ""
TagType.find(tag_type_id).tags.paginate( :page => 1, :per_page => 20, :order => 'name' )
TagType.find(tag_type_id).tags #.paginate( :page => 1, :per_page => 20, :order => 'name' )
else
Tag.paginate( :page => page, :per_page => 20, :order => 'tag_type_id' )
Tag.all.sort #paginate( :page => page, :per_page => 20, :order => 'tag_type_id' )
end
end

Expand Down
17 changes: 16 additions & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -5,7 +5,7 @@ class UsersController < ApplicationController
before_filter :check_user, :only => [:show, :edit, :update]

def index
@users = User.paginate :page => params[:page] || 1, :per_page => 25, :order => 'lastname'
@users = User.all.sort #paginate :page => params[:page] || 1, :per_page => 25, :order => 'lastname'
end

def show
Expand Down Expand Up @@ -66,4 +66,19 @@ def destroy
end
redirect_to users_url
end

def unassign
@user = User.find(params[:id])
#TODO unassign from all projects

@user.projects.each do |project|
puts "Removing users from project: #{project.name}"
project.users.delete @user
end

puts '****************************User was removed from projects.'
redirect_to user_url(@user)

end

end
2 changes: 1 addition & 1 deletion app/controllers/vacations_controller.rb
Expand Up @@ -12,7 +12,7 @@ def show
def edit
@day = params[:month].blank? ? Date.today.beginning_of_month : Date.new(params[:id].to_i, params[:month].to_i, 1).at_beginning_of_month
@holidays = Holiday.holidays_between(@day, @day.end_of_month)
@others = User.all_except(@user).sort
@others = User.all_active_except(@user).sort
end

def update
Expand Down
59 changes: 49 additions & 10 deletions app/models/billing.rb
@@ -1,21 +1,49 @@
class Billing

def initialize(customers, date)
def initialize(customers, date, show_empty, department)
@customers = customers
@from = date.at_beginning_of_month
@to = date.at_end_of_month
@show_empty = show_empty
@department = department
end


def billing_report_data

data = []
customer_total=0

@customers.each do |customer|
# TODO use one query to improve efficiency
# projects = Project.for_customer(@customers)
# time_entries = TimeEntry.between(@from,@to).for_projects(projects)

if @department
add_report_data_for_projects(data, @department.projects, @department.name)
else
add_report_data_for_projects(data, Project.find(:all, :conditions => "department_id IS NULL"), "No department")

Department.all.each do |department|
add_report_data_for_projects(data, department.projects, department.name)
end
end

return data
end

private

def add_report_data_for_projects(data, project_list, group_name)
projects = project_list.select { |project| @customers.include?(project.customer) }

projects.group_by(&:customer).each do |customer,grouped_projects|

customer_total=0
projects_data = []
customer.projects.sort.each do |project|
time_entries = TimeEntry.billed(false).between(@from,@to).for_project(project).include_users.include_hour_types.all


grouped_projects.each do |project|

time_entries = TimeEntry.between(@from,@to).for_project(project).include_users.include_hour_types.all

unless time_entries.empty?
project_total = 0
entries = []
Expand All @@ -25,7 +53,16 @@ def billing_report_data

sum = 0
group2.each{|e| sum += e.hours}
entries << [user,"#{type.name}",sum]

status_string = {}
group2.group_by(&:status).each do |status,group3|
if group3.size > 0
status_string.merge!({status => group3.size})
end
end
billed = status_string

entries << [user,"#{type.name}",sum, billed]
project_total += sum
end
end
Expand All @@ -34,8 +71,10 @@ def billing_report_data
customer_total += project_total
end
end
data << [customer.name, customer_total, projects_data]
unless customer_total == 0 && ! @show_empty
data << [group_name, customer.name, customer_total, projects_data]
end
end
data
end

end
9 changes: 9 additions & 0 deletions app/models/department.rb
@@ -1,8 +1,17 @@
class Department < ActiveRecord::Base

has_many :users
has_many :projects

validates_presence_of :internal_id, :name
validates_uniqueness_of :internal_id, :name

def <=>(other)
name <=> other.name
end

def to_s
name
end

end
3 changes: 2 additions & 1 deletion app/models/period.rb
Expand Up @@ -65,7 +65,8 @@ def find_billing_degree(from=@start, to=@end)
end

if sum_billable > 0 then
sum_billable / find_expected_hours(from, to)
billing_degree = sum_billable / find_expected_hours(from, to)
billing_degree.infinite? ? 1 : billing_degree
else
0
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/project.rb
Expand Up @@ -2,12 +2,18 @@ class Project < ActiveRecord::Base

has_many :activities
belongs_to :customer
belongs_to :department
has_and_belongs_to_many :users

validates_uniqueness_of :name, :scope => :customer_id
validates_length_of :comment, :maximum => 1024, :allow_nil => true


before_destroy :validate_has_no_activities

named_scope :for_customer, lambda { |customers|
customers ? { :conditions => { :customer_id => customers } } : {}
}

def <=>(other)
[customer.name,name] <=> [other.customer.name,other.name]
Expand Down
4 changes: 4 additions & 0 deletions app/models/time_entry.rb
Expand Up @@ -79,6 +79,10 @@ def before_destroy
project_id ? { :joins => :activity, :conditions => ["activities.project_id = ?", project_id] } : {}
}

named_scope :for_projects, lambda { |projects|
{ :joins => :activity, :conditions => ["activities.project_id IN (#{projects.collect{|p| p.id}.join(',')})"] }
}

named_scope :include_users, { :include => :user }

named_scope :include_hour_types, { :include => :hour_type }
Expand Down

0 comments on commit eabdada

Please sign in to comment.