Class: Harvest::Resources::Client
- Inherits:
-
HarvestResource
- Object
- ActiveResource::Base
- HarvestResource
- Harvest::Resources::Client
- Includes:
- Plugins::Toggleable
- Defined in:
- lib/harvest/resources/client.rb
Instance Method Summary collapse
- #balance ⇒ Object
- #invoiced_amount ⇒ Object
- #invoices(refresh = false) ⇒ Object
- #paid_amount ⇒ Object
Methods included from Plugins::Toggleable
Methods included from Plugins::ActiveResourceInheritableHeaders
Instance Method Details
#balance ⇒ Object
21 22 23 |
# File 'lib/harvest/resources/client.rb', line 21 def balance invoices.select {|invoice| invoice.sent? }.inject(0) {|total, invoice| total + invoice.balance} end |
#invoiced_amount ⇒ Object
25 26 27 |
# File 'lib/harvest/resources/client.rb', line 25 def invoiced_amount invoices.select {|invoice| invoice.sent? }.inject(0) {|total, invoice| total + invoice.amount} end |
#invoices(refresh = false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/harvest/resources/client.rb', line 6 def invoices(refresh = false) if not refresh and @invoices @invoices else page, @invoices = 1, [] begin set = Invoice.find(:all, :params => {:client => self.id, :page => page }) puts "Found #{set.length.to_s} invoices" if Harvest::Base.debug_level == 2 @invoices += set page +=1 end while set.length == 50 @invoices end end |
#paid_amount ⇒ Object
29 30 31 |
# File 'lib/harvest/resources/client.rb', line 29 def paid_amount invoices.select {|invoice| invoice.sent? }.inject(0) {|total, invoice| total + invoice.paid_amount} end |