Class: Client

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
GuidReferenced
Defined in:
app/models/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(projects_or_tickets_or_work_units) ⇒ Object



34
35
36
# File 'app/models/client.rb', line 34

def for(projects_or_tickets_or_work_units)
  projects_or_tickets_or_work_units.collect{ |resource| resource.client }.uniq
end

.statusesObject



26
27
28
29
30
31
32
# File 'app/models/client.rb', line 26

def statuses
  {
    "10" => "Active",
    "20" => "Suspended",
    "30" => "Inactive",
  }
end

Instance Method Details

#allows_access?(user) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/client.rb', line 83

def allows_access?(user)
  projects.any? {|p| p.accepts_roles_by?(user)} || user.admin?
end

#files_and_commentsObject



87
88
89
90
91
92
# File 'app/models/client.rb', line 87

def files_and_comments
  ary = Array.new
  ary << comments
  ary << file_attachments
  ary.flatten.sort_by {|x| x.created_at}
end

#hoursObject



51
52
53
# File 'app/models/client.rb', line 51

def hours
  work_units.sum(:effective_hours)
end

#hours_this_monthObject



59
60
61
# File 'app/models/client.rb', line 59

def hours_this_month
  WorkUnit.for_client(self).scheduled_between(Time.zone.now.beginning_of_month, Time.zone.now.end_of_month).sum(:effective_hours)
end

#hours_this_weekObject



63
64
65
# File 'app/models/client.rb', line 63

def hours_this_week
  WorkUnit.for_client(self).scheduled_between(Time.zone.now.beginning_of_week, Time.zone.now.end_of_week).sum(:effective_hours)
end

#recent_usersObject



39
40
41
# File 'app/models/client.rb', line 39

def recent_users
  work_units.scheduled_between(2.weeks.ago, Time.zone.now).select("distinct user_id").includes(:user).map(&:user)
end

#statusObject



75
76
77
# File 'app/models/client.rb', line 75

def status
  Client.statuses[attributes["status"]]
end

#status=(val) ⇒ Object



79
80
81
# File 'app/models/client.rb', line 79

def status=(val)
  write_attribute(:status, Client.statuses.invert[val])
end

#ticketsObject



43
44
45
# File 'app/models/client.rb', line 43

def tickets
  Ticket.for_client(self)
end

#to_sObject



67
68
69
70
71
72
73
# File 'app/models/client.rb', line 67

def to_s
  if status == "Active"
    name
  else
    "#{name} (#{status})"
  end
end

#uninvoiced_hoursObject



55
56
57
# File 'app/models/client.rb', line 55

def uninvoiced_hours
  WorkUnit.for_client(self).not_invoiced.sum(:effective_hours)
end

#work_unitsObject



47
48
49
# File 'app/models/client.rb', line 47

def work_units
  WorkUnit.for_client(self)
end