Class: Eboshi::LineItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Eboshi::LineItem
- Includes:
- Comparable
- Defined in:
- app/models/eboshi/line_item.rb
Direct Known Subclasses
Class Method Summary collapse
- .on_date(date) ⇒ Object
- .on_month(date) ⇒ Object
- .on_week(date) ⇒ Object
- .on_year(date) ⇒ Object
- .unbilled ⇒ Object
Instance Method Summary collapse
- #<=>(target) ⇒ Object
- #==(target) ⇒ Object
- #checked? ⇒ Boolean
- #hours ⇒ Object
- #invoice_total ⇒ Object
- #total ⇒ Object
- #unbilled? ⇒ Boolean
- #user_name=(name) ⇒ Object
Class Method Details
.on_date(date) ⇒ Object
35 36 37 38 39 |
# File 'app/models/eboshi/line_item.rb', line 35 def self.on_date(date) start = date.beginning_of_day finish = date.end_of_day where(start: start..finish) end |
.on_month(date) ⇒ Object
47 48 49 50 51 |
# File 'app/models/eboshi/line_item.rb', line 47 def self.on_month(date) start = date.beginning_of_month.beginning_of_day finish = date.end_of_month.end_of_day where(start: start..finish) end |
.on_week(date) ⇒ Object
41 42 43 44 45 |
# File 'app/models/eboshi/line_item.rb', line 41 def self.on_week(date) start = date.beginning_of_week(:sunday).beginning_of_day finish = date.end_of_week(:sunday).end_of_day where(start: start..finish) end |
.on_year(date) ⇒ Object
53 54 55 56 57 |
# File 'app/models/eboshi/line_item.rb', line 53 def self.on_year(date) start = date.beginning_of_year.beginning_of_day finish = date.end_of_year.end_of_day where(start: start..finish) end |
.unbilled ⇒ Object
31 32 33 |
# File 'app/models/eboshi/line_item.rb', line 31 def self.unbilled where(invoice_id: nil).order(start: :desc) end |
Instance Method Details
#<=>(target) ⇒ Object
89 90 91 |
# File 'app/models/eboshi/line_item.rb', line 89 def <=>(target) (target.start || Time.zone.parse("0000-01-01")) <=> (start || Time.zone.parse("0000-01-01")) end |
#==(target) ⇒ Object
69 70 71 |
# File 'app/models/eboshi/line_item.rb', line 69 def ==(target) target == id end |
#checked? ⇒ Boolean
77 78 79 |
# File 'app/models/eboshi/line_item.rb', line 77 def checked? unbilled? end |
#hours ⇒ Object
63 64 65 66 67 |
# File 'app/models/eboshi/line_item.rb', line 63 def hours return 0 unless finish && start seconds = BigDecimal((finish - start).to_s) seconds / 60 / 60 end |
#invoice_total ⇒ Object
85 86 87 |
# File 'app/models/eboshi/line_item.rb', line 85 def invoice_total invoice.try(:total) || client.unbilled_balance end |
#total ⇒ Object
59 60 61 |
# File 'app/models/eboshi/line_item.rb', line 59 def total 0 end |
#unbilled? ⇒ Boolean
73 74 75 |
# File 'app/models/eboshi/line_item.rb', line 73 def unbilled? invoice_id.nil? end |
#user_name=(name) ⇒ Object
81 82 83 |
# File 'app/models/eboshi/line_item.rb', line 81 def user_name=(name) self.user = User.find_by_name!(name) unless name.nil? end |