Class: Economic::Invoice

Inherits:
Entity
  • Object
show all
Defined in:
lib/economic/invoice.rb

Instance Attribute Summary

Attributes inherited from Entity

#id, #number, #partial, #persisted, #session

Instance Method Summary collapse

Methods inherited from Entity

#==, default_values, defaults, #destroy, #get, #get_data, #handle, #handle=, handle_writer, has_properties, #initialize, #inspect, key, #partial?, #persisted?, properties, properties_not_triggering_full_load, property_reader, property_writer, proxy, #proxy, #save, #update_properties

Constructor Details

This class inherits a constructor from Economic::Entity

Instance Method Details

#attentionObject



21
22
23
24
# File 'lib/economic/invoice.rb', line 21

def attention
  return nil if attention_handle.nil?
  @attention ||= session.contacts.find(attention_handle)
end

#attention=(contact) ⇒ Object



26
27
28
29
# File 'lib/economic/invoice.rb', line 26

def attention=(contact)
  self.attention_handle = contact.handle
  @attention = contact
end

#attention_handle=(handle) ⇒ Object



31
32
33
34
# File 'lib/economic/invoice.rb', line 31

def attention_handle=(handle)
  @attention = nil unless handle == @attention_handle
  @attention_handle = handle
end

#days_past_dueObject



55
56
57
58
# File 'lib/economic/invoice.rb', line 55

def days_past_due
  days = Date.today - due_date.to_date
  days > 0 ? days : 0
end

#debtorObject



36
37
38
39
# File 'lib/economic/invoice.rb', line 36

def debtor
  return nil if debtor_handle.nil?
  @debtor ||= session.debtors.find(debtor_handle)
end

#debtor=(debtor) ⇒ Object



41
42
43
44
# File 'lib/economic/invoice.rb', line 41

def debtor=(debtor)
  self.debtor_handle = debtor.handle
  @debtor = debtor
end

#debtor_handle=(handle) ⇒ Object



46
47
48
49
# File 'lib/economic/invoice.rb', line 46

def debtor_handle=(handle)
  @debtor = nil unless handle == @debtor_handle
  @debtor_handle = handle
end

#past_due?Boolean

Returns true if the due date has expired, and there is a remainder left on the invoice

Returns:

  • (Boolean)


62
63
64
# File 'lib/economic/invoice.rb', line 62

def past_due?
  days_past_due > 0 && remainder > 0
end

#pdfObject

Returns the PDF version of Invoice as a String.

To get it as a file you can do:

File.open("invoice.pdf", 'wb') do |file|
  file << invoice.pdf
end


73
74
75
76
77
# File 'lib/economic/invoice.rb', line 73

def pdf
  response = request(:get_pdf, "invoiceHandle" => handle.to_hash)

  Base64.decode64(response)
end

#remainderObject



51
52
53
# File 'lib/economic/invoice.rb', line 51

def remainder
  @remainder ||= request(:get_remainder, "invoiceHandle" => handle.to_hash).to_f
end