Class: Eboshi::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Eboshi::User
- Defined in:
- app/models/eboshi/user.rb
Instance Method Summary collapse
- #authorized?(object) ⇒ Boolean
- #business_email_or_email ⇒ Object
- #business_name_or_name ⇒ Object
- #city_state_zip ⇒ Object
- #default_rate_for(client) ⇒ Object
- #hours_by_date(date) ⇒ Object
- #hours_by_month(date) ⇒ Object
- #hours_by_week(date) ⇒ Object
- #hours_by_year(date) ⇒ Object
- #related_users ⇒ Object
- #total_by_date(date) ⇒ Object
- #total_by_month(date) ⇒ Object
- #total_by_week(date) ⇒ Object
- #total_by_year(date) ⇒ Object
Instance Method Details
#authorized?(object) ⇒ Boolean
75 76 77 78 79 80 |
# File 'app/models/eboshi/user.rb', line 75 def (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_email ⇒ Object
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_name ⇒ Object
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_zip ⇒ Object
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 |
#related_users ⇒ Object
71 72 73 |
# File 'app/models/eboshi/user.rb', line 71 def 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 |