2009-01-13 19:01:56 +01:00
|
|
|
class Workgroup < Group
|
|
|
|
|
|
|
|
has_many :tasks
|
|
|
|
# returns all non-finished tasks
|
|
|
|
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
|
|
|
|
|
2012-06-24 11:01:16 +02:00
|
|
|
validates_presence_of :task_name, :weekday, :task_required_users, :next_weekly_tasks_number,
|
|
|
|
:if => :weekly_task
|
|
|
|
validates_numericality_of :next_weekly_tasks_number, :greater_than => 0, :less_than => 21, :only_integer => true,
|
|
|
|
:if => :weekly_task
|
2009-08-02 18:42:52 +02:00
|
|
|
|
2009-01-13 19:01:56 +01:00
|
|
|
def self.weekdays
|
|
|
|
[["Montag", "1"], ["Dienstag", "2"], ["Mittwoch","3"],["Donnerstag","4"],["Freitag","5"],["Samstag","6"],["Sonntag","0"]]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns an Array with date-objects to represent the next weekly-tasks
|
2012-06-24 11:01:16 +02:00
|
|
|
def next_weekly_tasks
|
2009-01-13 19:01:56 +01:00
|
|
|
# our system starts from 0 (sunday) to 6 (saturday)
|
|
|
|
# get difference between groups weekday and now
|
|
|
|
diff = self.weekday - Time.now.wday
|
|
|
|
if diff >= 0
|
|
|
|
# weektask is in current week
|
|
|
|
nextTask = diff.day.from_now
|
|
|
|
else
|
|
|
|
# weektask is in the next week
|
|
|
|
nextTask = (diff + 7).day.from_now
|
|
|
|
end
|
|
|
|
# now generate the Array
|
|
|
|
nextTasks = Array.new
|
2012-06-24 11:01:16 +02:00
|
|
|
next_weekly_tasks_number.times do
|
2009-08-11 18:10:14 +02:00
|
|
|
nextTasks << nextTask.to_date
|
|
|
|
nextTask = 1.week.from_now(nextTask)
|
2009-01-13 19:01:56 +01:00
|
|
|
end
|
|
|
|
return nextTasks
|
|
|
|
end
|
|
|
|
|
2009-08-11 17:17:18 +02:00
|
|
|
def task_attributes(date)
|
|
|
|
{
|
2011-05-07 21:54:00 +02:00
|
|
|
:name => task_name,
|
|
|
|
:description => task_description,
|
|
|
|
:due_date => date,
|
|
|
|
:required_users => task_required_users,
|
|
|
|
:duration => task_duration,
|
|
|
|
:weekly => true
|
2009-08-11 17:17:18 +02:00
|
|
|
}
|
|
|
|
end
|
2009-08-11 18:10:14 +02:00
|
|
|
|
2009-01-13 19:01:56 +01:00
|
|
|
end
|
2011-05-07 20:50:39 +02:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: groups
|
|
|
|
#
|
2011-05-07 21:55:24 +02:00
|
|
|
# id :integer(4) not null, primary key
|
2011-05-07 20:50:39 +02:00
|
|
|
# type :string(255) default(""), not null
|
|
|
|
# name :string(255) default(""), not null
|
|
|
|
# description :string(255)
|
2011-05-07 21:55:24 +02:00
|
|
|
# account_balance :decimal(8, 2) default(0.0), not null
|
2011-05-07 20:50:39 +02:00
|
|
|
# account_updated :datetime
|
|
|
|
# created_on :datetime not null
|
2011-05-07 21:55:24 +02:00
|
|
|
# role_admin :boolean(1) default(FALSE), not null
|
|
|
|
# role_suppliers :boolean(1) default(FALSE), not null
|
|
|
|
# role_article_meta :boolean(1) default(FALSE), not null
|
|
|
|
# role_finance :boolean(1) default(FALSE), not null
|
|
|
|
# role_orders :boolean(1) default(FALSE), not null
|
|
|
|
# weekly_task :boolean(1) default(FALSE)
|
|
|
|
# weekday :integer(4)
|
2011-05-07 20:50:39 +02:00
|
|
|
# task_name :string(255)
|
|
|
|
# task_description :string(255)
|
2011-05-07 21:55:24 +02:00
|
|
|
# task_required_users :integer(4) default(1)
|
2011-05-07 20:50:39 +02:00
|
|
|
# deleted_at :datetime
|
|
|
|
# contact_person :string(255)
|
|
|
|
# contact_phone :string(255)
|
|
|
|
# contact_address :string(255)
|
|
|
|
# stats :text
|
2011-05-07 21:55:24 +02:00
|
|
|
# task_duration :integer(4) default(1)
|
2011-05-07 20:50:39 +02:00
|
|
|
#
|
|
|
|
|