Class: Eboshi::Client
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Eboshi::Client
- Defined in:
- app/models/eboshi/client.rb
Instance Method Summary collapse
- #balance ⇒ Object
- #build_invoice_from_unbilled(line_items_ids = nil) ⇒ Object
- #clock_in(user) ⇒ Object
- #credits ⇒ Object
- #debits ⇒ Object
- #default_project_name ⇒ Object
- #invoices_with_unbilled ⇒ Object
- #overdue_balance ⇒ Object
- #unbilled_balance ⇒ Object
Instance Method Details
#balance ⇒ Object
51 52 53 |
# File 'app/models/eboshi/client.rb', line 51 def balance credits - debits end |
#build_invoice_from_unbilled(line_items_ids = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/models/eboshi/client.rb', line 37 def build_invoice_from_unbilled(line_items_ids = nil) lis = line_items_ids ? LineItem.find(line_items_ids) : line_items.unbilled budget = budgets.order(:created_at).last invoice = invoices.build line_items: lis, budget: budget budget.unbilled_invoice = invoice if budget invoice end |
#clock_in(user) ⇒ Object
72 73 74 75 76 77 78 |
# File 'app/models/eboshi/client.rb', line 72 def clock_in(user) Work.new.tap do |line_item| now = Time.now line_item.attributes = { start: now, finish: now, user: user, rate: user.default_rate_for(self) } line_items << line_item end end |
#credits ⇒ Object
64 65 66 |
# File 'app/models/eboshi/client.rb', line 64 def credits line_items.to_a.sum(&:total) end |
#debits ⇒ Object
68 69 70 |
# File 'app/models/eboshi/client.rb', line 68 def debits payments.to_a.sum(&:total) end |
#default_project_name ⇒ Object
80 81 82 |
# File 'app/models/eboshi/client.rb', line 80 def default_project_name invoices.last.try(:project_name) end |
#invoices_with_unbilled ⇒ Object
45 46 47 48 49 |
# File 'app/models/eboshi/client.rb', line 45 def invoices_with_unbilled new_invoices = invoices.to_a new_invoices.unshift build_invoice_from_unbilled new_invoices end |
#overdue_balance ⇒ Object
60 61 62 |
# File 'app/models/eboshi/client.rb', line 60 def overdue_balance balance - unbilled_balance end |
#unbilled_balance ⇒ Object
55 56 57 58 |
# File 'app/models/eboshi/client.rb', line 55 def unbilled_balance return 0.0 if line_items.empty? line_items.to_a.select(&:unbilled?).sum(&:total) end |