Class: Eboshi::User

Inherits:
ApplicationRecord show all
Defined in:
app/models/eboshi/user.rb

Instance Method Summary collapse

Instance Method Details

#authorized?(object) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ActiveRecord::RecordNotFound)


75
76
77
78
79
80
# File 'app/models/eboshi/user.rb', line 75

def authorized?(object)
  return if object.is_a?(Client) && clients.include?(object)
  return if object.is_a?(Invoice) && clients.include?(object.client)
  return if object.is_a?(Assignment) && object.client.users.include?(self)
  raise ActiveRecord::RecordNotFound
end

#business_email_or_emailObject



91
92
93
# File 'app/models/eboshi/user.rb', line 91

def business_email_or_email
  business_email.blank? ? email : business_email
end

#business_name_or_nameObject



87
88
89
# File 'app/models/eboshi/user.rb', line 87

def business_name_or_name
  business_name.blank? ? name : business_name
end

#city_state_zipObject



82
83
84
85
# File 'app/models/eboshi/user.rb', line 82

def city_state_zip
  return nil if city.blank? || state.blank? || zip.blank?
  "#{city}, #{state}  #{zip}"
end

#default_rate_for(client) ⇒ Object



66
67
68
69
# File 'app/models/eboshi/user.rb', line 66

def default_rate_for(client)
  last_work = client.works.complete.where(user: self).order(start: :desc).first
  last_work.try(:rate) || rate
end

#hours_by_date(date) ⇒ Object



95
96
97
# File 'app/models/eboshi/user.rb', line 95

def hours_by_date(date)
  works.on_date(date).to_a.sum(&:hours)
end

#hours_by_month(date) ⇒ Object



111
112
113
# File 'app/models/eboshi/user.rb', line 111

def hours_by_month(date)
  works.on_month(date).to_a.sum(&:hours)
end

#hours_by_week(date) ⇒ Object



103
104
105
# File 'app/models/eboshi/user.rb', line 103

def hours_by_week(date)
  works.on_week(date).to_a.sum(&:hours)
end

#hours_by_year(date) ⇒ Object



119
120
121
# File 'app/models/eboshi/user.rb', line 119

def hours_by_year(date)
  works.on_year(date).to_a.sum(&:hours)
end


71
72
73
# File 'app/models/eboshi/user.rb', line 71

def related_users
  clients.collect(&:users).flatten.uniq - [self]
end

#total_by_date(date) ⇒ Object



99
100
101
# File 'app/models/eboshi/user.rb', line 99

def total_by_date(date)
  works.on_date(date).to_a.sum(&:total)
end

#total_by_month(date) ⇒ Object



115
116
117
# File 'app/models/eboshi/user.rb', line 115

def total_by_month(date)
  works.on_month(date).to_a.sum(&:total)
end

#total_by_week(date) ⇒ Object



107
108
109
# File 'app/models/eboshi/user.rb', line 107

def total_by_week(date)
  works.on_week(date).to_a.sum(&:total)
end

#total_by_year(date) ⇒ Object



123
124
125
# File 'app/models/eboshi/user.rb', line 123

def total_by_year(date)
  works.on_year(date).to_a.sum(&:total)
end