Class: Ticket

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

Instance Method Summary collapse

Instance Method Details

#allows_access?(user) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/ticket.rb', line 78

def allows_access?(user)
  project.accepts_roles_by?(user) || user.admin?
end

#clientObject



36
37
38
# File 'app/models/ticket.rb', line 36

def client
  project.client
end

#files_and_commentsObject



82
83
84
# File 'app/models/ticket.rb', line 82

def files_and_comments
  [comments, file_attachments].flatten.sort_by {|x| x.created_at}
end

#hoursObject



44
45
46
# File 'app/models/ticket.rb', line 44

def hours
  work_units.sum(:effective_hours)
end

#long_nameObject



74
75
76
# File 'app/models/ticket.rb', line 74

def long_name
  "Ticket: [#{id}] - #{project.name} - #{name} ticket for #{client.name}"
end

#percentage_completeObject



56
57
58
59
60
61
62
63
64
# File 'app/models/ticket.rb', line 56

def percentage_complete
  return 100 unless self.estimated_hours
  begin
    percent = (((self.hours / self.estimated_hours)).to_f * 100.00).round(2)
    [percent, 100].min
  rescue
    0
  end
end

#remaining_hoursObject



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

def remaining_hours
  if self.estimated_hours and self.estimated_hours > self.hours
    self.estimated_hours - self.hours
  else
    0
  end
end

#to_sObject



40
41
42
# File 'app/models/ticket.rb', line 40

def to_s
  name
end

#uninvoiced_hoursObject



52
53
54
# File 'app/models/ticket.rb', line 52

def uninvoiced_hours
  work_units.not_invoiced.sum(:effective_hours)
end

#unpaid_hoursObject



48
49
50
# File 'app/models/ticket.rb', line 48

def unpaid_hours
  work_units.unpaid.sum(:effective_hours)
end