Class: FreshBooks::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/freshbooks/extensions/invoice.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#numberObject

Returns the value of attribute number.



25
26
27
# File 'lib/freshbooks/extensions/invoice.rb', line 25

def number
  @number
end

Class Method Details

.membersObject



47
48
49
# File 'lib/freshbooks/extensions/invoice.rb', line 47

def members
  old_members + ['number']
end

.old_membersObject



46
# File 'lib/freshbooks/extensions/invoice.rb', line 46

alias_method :old_members, :members

Instance Method Details

#[](m) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/freshbooks/extensions/invoice.rb', line 28

def [](m)
  if m.to_s == 'number'
    self.number
  else
    old_brackets(m)
  end
end

#[]=(m, v) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/freshbooks/extensions/invoice.rb', line 37

def []=(m, v)
  if m.to_s == 'number'
    self.number = v 
  else
    old_brackets_equal(m, v)
  end
end

#clientObject



9
10
11
# File 'lib/freshbooks/extensions/invoice.rb', line 9

def client
  Client.get(client_id)
end

#old_bracketsObject



27
# File 'lib/freshbooks/extensions/invoice.rb', line 27

alias_method :old_brackets, :[]

#old_brackets_equalObject



36
# File 'lib/freshbooks/extensions/invoice.rb', line 36

alias_method :old_brackets_equal, :[]=

#open?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/freshbooks/extensions/invoice.rb', line 5

def open?
  !%w[draft paid].include?(status)
end

#owed_amountObject



21
22
23
# File 'lib/freshbooks/extensions/invoice.rb', line 21

def owed_amount
  amount - paid_amount
end


17
18
19
# File 'lib/freshbooks/extensions/invoice.rb', line 17

def paid_amount
  payments.inject(0) { |sum, pay|  sum + pay.amount }
end

#paymentsObject



13
14
15
# File 'lib/freshbooks/extensions/invoice.rb', line 13

def payments
  Payment.list('invoice_id' => invoice_id) || []
end