bookyt_projects 0.18.2 → 0.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/models/activity.rb +6 -9
- data/app/models/bookyt_projects/person.rb +1 -0
- data/app/models/work_day.rb +52 -44
- data/app/views/timesheets/_show.html.haml +3 -3
- data/db/migrate/20120119102801_add_hours_due_to_activities.rb +5 -0
- data/db/migrate/20120119111230_change_materialized_columns_in_work_days.rb +8 -0
- data/lib/bookyt_projects/version.rb +1 -1
- metadata +5 -3
data/app/models/activity.rb
CHANGED
@@ -2,7 +2,6 @@ class Activity < ActiveRecord::Base
|
|
2
2
|
# Associations
|
3
3
|
belongs_to :project
|
4
4
|
belongs_to :person
|
5
|
-
belongs_to :work_day
|
6
5
|
validates :project, :presence => true, :allow_blank => false
|
7
6
|
validates :person, :presence => true, :allow_blank => false
|
8
7
|
|
@@ -14,8 +13,6 @@ class Activity < ActiveRecord::Base
|
|
14
13
|
|
15
14
|
validates_date :date, :allow_nil => false, :allow_blank => false
|
16
15
|
|
17
|
-
before_save :create_work_day
|
18
|
-
|
19
16
|
def duration=(value)
|
20
17
|
if value.match(/:/)
|
21
18
|
hours, minutes = value.split(':')
|
@@ -29,12 +26,12 @@ class Activity < ActiveRecord::Base
|
|
29
26
|
"%s: %0.2fh" % [project.name, duration]
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
work_day = WorkDay.where(:person_id => person_id, :date => date).first
|
36
|
-
work_day ||= WorkDay.create(:person_id => person_id, :date => date)
|
29
|
+
# Work day
|
30
|
+
belongs_to :work_day, :autosave => true
|
31
|
+
before_save :update_work_day
|
37
32
|
|
38
|
-
|
33
|
+
private
|
34
|
+
def update_work_day
|
35
|
+
WorkDay.create_or_update_upto(self.person, date)
|
39
36
|
end
|
40
37
|
end
|
data/app/models/work_day.rb
CHANGED
@@ -1,27 +1,42 @@
|
|
1
1
|
class WorkDay < ActiveRecord::Base
|
2
|
-
|
2
|
+
# Associations
|
3
3
|
belongs_to :person
|
4
|
+
validates :person, :presence => true
|
5
|
+
|
4
6
|
has_many :activities
|
5
7
|
|
6
|
-
|
8
|
+
# Order
|
9
|
+
default_scope order(:date)
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
# Calculations
|
12
|
+
default_scope select('work_days.*, hours_worked - hours_due AS overtime')
|
13
|
+
|
14
|
+
def self.create_or_update(person, date)
|
15
|
+
work_day = person.work_days.where(:date => date).first
|
16
|
+
work_day ||= person.work_days.build(:date => date)
|
17
|
+
|
18
|
+
work_day.update_hours
|
19
|
+
|
20
|
+
work_day.save
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_hours
|
24
|
+
self.hours_due = calculate_hours_due
|
25
|
+
self.hours_worked = calculate_hours_worked
|
14
26
|
end
|
15
27
|
|
16
|
-
def self.
|
17
|
-
|
18
|
-
|
19
|
-
start_date =
|
20
|
-
|
28
|
+
def self.create_or_update_upto(person, end_date)
|
29
|
+
# Guard
|
30
|
+
if latest_work_day = person.work_days.last
|
31
|
+
start_date = latest_work_day.date
|
32
|
+
else
|
33
|
+
start_date = end_date
|
34
|
+
end
|
21
35
|
|
22
|
-
|
23
|
-
|
24
|
-
|
36
|
+
(start_date..end_date).each do |date|
|
37
|
+
transaction do
|
38
|
+
self.create_or_update(person, date)
|
39
|
+
end
|
25
40
|
end
|
26
41
|
end
|
27
42
|
|
@@ -33,35 +48,34 @@ class WorkDay < ActiveRecord::Base
|
|
33
48
|
# params:
|
34
49
|
# :employee: Employee to build WorkDay instances for
|
35
50
|
# :range: Date range giving first and last day
|
36
|
-
def self.
|
51
|
+
def self.build_or_update(employee, date)
|
37
52
|
self.create_for_current_employment(employee)
|
38
|
-
|
39
|
-
range.inject([]) do |out, day|
|
53
|
+
range.collect do |day|
|
40
54
|
work_day = WorkDay.where(:person_id => employee.id, :date => day).first
|
41
55
|
work_day ||= WorkDay.create(:person => employee, :date => day)
|
42
|
-
out << work_day
|
43
|
-
|
44
|
-
out
|
45
56
|
end
|
46
57
|
end
|
47
58
|
|
48
|
-
# Get
|
59
|
+
# Get employment
|
49
60
|
#
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# Assume today if no date given
|
55
|
-
date_in_month ||= Date.today
|
56
|
-
|
57
|
-
start_date = date_in_month.beginning_of_month
|
58
|
-
end_date = date_in_month.end_of_month
|
61
|
+
# Lookup the employment for this day.
|
62
|
+
def employment
|
63
|
+
person.employments.current(self.date)
|
64
|
+
end
|
59
65
|
|
60
|
-
|
66
|
+
# Get daily workload
|
67
|
+
#
|
68
|
+
# Lookup daily workload for person. Returns 0.0 if no
|
69
|
+
# employment is specified.
|
70
|
+
def daily_workload
|
71
|
+
employment.try(:daily_workload) || 0.0
|
61
72
|
end
|
62
73
|
|
63
74
|
# Working hours for this day
|
64
|
-
|
75
|
+
#
|
76
|
+
# Saturday and sunday are off, uses daily workload for
|
77
|
+
# all other days.
|
78
|
+
def calculate_hours_due
|
65
79
|
case date.wday
|
66
80
|
when 6, 0
|
67
81
|
# Saturday and sunday are off
|
@@ -76,18 +90,12 @@ class WorkDay < ActiveRecord::Base
|
|
76
90
|
#
|
77
91
|
# Calculates hours worked by summing up duration of all logged
|
78
92
|
# activities.
|
79
|
-
def
|
80
|
-
activities.where(:date => date).
|
81
|
-
end
|
82
|
-
|
83
|
-
# Overtime
|
84
|
-
#
|
85
|
-
# Simply substract hours_due from hours_worked.
|
86
|
-
def overtime
|
87
|
-
hours_worked - hours_due
|
93
|
+
def calculate_hours_worked
|
94
|
+
activities.where(:date => date).sum('duration')
|
88
95
|
end
|
89
96
|
|
97
|
+
# Calculate accumulated overtime
|
90
98
|
def overall_overtime
|
91
|
-
WorkDay.where(
|
99
|
+
WorkDay.where('date <= ?', date).sum('hours_worked - hours_due')
|
92
100
|
end
|
93
101
|
end
|
@@ -5,9 +5,9 @@
|
|
5
5
|
%th.number= t_attr :overtime, Activity
|
6
6
|
%th.number= t_attr :overall_overtime, Activity
|
7
7
|
|
8
|
-
-
|
9
|
-
-
|
10
|
-
|
8
|
+
- WorkDay.create_or_update_upto(@employee, Date.today.end_of_month)
|
9
|
+
- range = Date.today.beginning_of_month..Date.today.end_of_month
|
10
|
+
- @employee.work_days.where(:date => range).each do |day|
|
11
11
|
- tr_params = {:class => work_day_classes(day)}
|
12
12
|
- tr_params.merge!(:rel => 'popover', 'data-content' => h(render 'timesheets/activities_popover', :activities => day.activities), 'data-original-title' => 'Aktivitäten', 'data-html' => 'true') unless day.activities.empty?
|
13
13
|
%tr{tr_params}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class ChangeMaterializedColumnsInWorkDays < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :work_days, :hours_due, :decimal, :precision => 10, :scale => 2
|
4
|
+
add_column :work_days, :hours_worked, :decimal, :precision => 10, :scale => 2
|
5
|
+
|
6
|
+
remove_column :work_days, :daily_workload
|
7
|
+
end
|
8
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookyt_projects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 81
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 18
|
9
|
-
-
|
10
|
-
version: 0.18.
|
9
|
+
- 3
|
10
|
+
version: 0.18.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roman Simecek (CyT)
|
@@ -145,6 +145,8 @@ files:
|
|
145
145
|
- db/migrate/20120118131814_create_work_days.rb
|
146
146
|
- db/migrate/20120118140839_add_activities_to_work_day.rb
|
147
147
|
- db/migrate/20120119081136_add_indices_to_activities.rb
|
148
|
+
- db/migrate/20120119102801_add_hours_due_to_activities.rb
|
149
|
+
- db/migrate/20120119111230_change_materialized_columns_in_work_days.rb
|
148
150
|
- lib/bookyt_projects.rb
|
149
151
|
- lib/bookyt_projects/navigation.rb
|
150
152
|
- lib/bookyt_projects/railtie.rb
|