Class: Client
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Client
- Includes:
- GuidReferenced
- Defined in:
- app/models/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #allows_access?(user) ⇒ Boolean
- #files_and_comments ⇒ Object
- #hours ⇒ Object
- #hours_this_month ⇒ Object
- #hours_this_week ⇒ Object
- #recent_users ⇒ Object
- #status ⇒ Object
- #status=(val) ⇒ Object
- #tickets ⇒ Object
- #to_s ⇒ Object
- #uninvoiced_hours ⇒ Object
- #work_units ⇒ Object
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 |
.statuses ⇒ Object
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
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_comments ⇒ Object
87 88 89 90 91 92 |
# File 'app/models/client.rb', line 87 def files_and_comments ary = Array.new ary << comments ary << ary.flatten.sort_by {|x| x.created_at} end |
#hours ⇒ Object
51 52 53 |
# File 'app/models/client.rb', line 51 def hours work_units.sum(:effective_hours) end |
#hours_this_month ⇒ Object
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_week ⇒ Object
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_users ⇒ Object
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 |
#status ⇒ Object
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 |
#tickets ⇒ Object
43 44 45 |
# File 'app/models/client.rb', line 43 def tickets Ticket.for_client(self) end |
#to_s ⇒ Object
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_hours ⇒ Object
55 56 57 |
# File 'app/models/client.rb', line 55 def uninvoiced_hours WorkUnit.for_client(self).not_invoiced.sum(:effective_hours) end |
#work_units ⇒ Object
47 48 49 |
# File 'app/models/client.rb', line 47 def work_units WorkUnit.for_client(self) end |