Class: Harvest::Resources::Client

Inherits:
HarvestResource show all
Includes:
Plugins::Toggleable
Defined in:
lib/harvest/resources/client.rb

Instance Method Summary collapse

Methods included from Plugins::Toggleable

#toggle

Methods included from Plugins::ActiveResourceInheritableHeaders

included

Instance Method Details

#balanceObject



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_amountObject



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


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