Class: Economic::Invoice
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
Instance Method Details
#attention ⇒ Object
23
24
25
26
|
# File 'lib/economic/invoice.rb', line 23
def attention
return nil if attention_handle.nil?
@attention ||= session.contacts.find(attention_handle)
end
|
#attention=(contact) ⇒ Object
28
29
30
31
|
# File 'lib/economic/invoice.rb', line 28
def attention=(contact)
self.attention_handle = contact.handle
@attention = contact
end
|
#attention_handle=(handle) ⇒ Object
33
34
35
36
|
# File 'lib/economic/invoice.rb', line 33
def attention_handle=(handle)
@attention = nil unless handle == @attention_handle
@attention_handle = handle
end
|
#days_past_due ⇒ Object
57
58
59
60
|
# File 'lib/economic/invoice.rb', line 57
def days_past_due
days = Date.today - due_date.to_date
days > 0 ? days : 0
end
|
#debtor ⇒ Object
38
39
40
41
|
# File 'lib/economic/invoice.rb', line 38
def debtor
return nil if debtor_handle.nil?
@debtor ||= session.debtors.find(debtor_handle)
end
|
#debtor=(debtor) ⇒ Object
43
44
45
46
|
# File 'lib/economic/invoice.rb', line 43
def debtor=(debtor)
self.debtor_handle = debtor.handle
@debtor = debtor
end
|
#debtor_handle=(handle) ⇒ Object
48
49
50
51
|
# File 'lib/economic/invoice.rb', line 48
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
64
65
66
|
# File 'lib/economic/invoice.rb', line 64
def past_due?
days_past_due > 0 && remainder > 0
end
|
#pdf ⇒ Object
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
75
76
77
78
79
|
# File 'lib/economic/invoice.rb', line 75
def pdf
response = request(:get_pdf, "invoiceHandle" => handle.to_hash)
Base64.decode64(response)
end
|
#remainder ⇒ Object
53
54
55
|
# File 'lib/economic/invoice.rb', line 53
def remainder
@remainder ||= request(:get_remainder, "invoiceHandle" => handle.to_hash).to_f
end
|