Class: Economic::CurrentInvoice
- Defined in:
- lib/economic/current_invoice.rb
Overview
CurrentInvoices are invoices that are not yet booked. They are therefore not read-only.
API documentation: www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICurrentInvoice.html
Examples
# Create invoice for debtor:
invoice = debtor.current_invoices.build
invoice.date = Time.now
invoice.due_date = Time.now + 15
invoice.exchange_rate = 100
invoice.is_vat_included = false
# Add a line to the invoice
invoice_line = invoice.lines.build
invoice_line.description = 'Line on invoice'
invoice_line.unit_handle = { :number => 1 }
invoice_line.product_handle = { :number => 101 }
invoice_line.quantity = 12
invoice_line.unit_net_price = 19.95
invoice.lines << invoice_line
invoice.save
Instance Attribute Summary
Attributes inherited from Entity
#id, #number, #partial, #persisted, #session
Instance Method Summary collapse
- #attention ⇒ Object
- #attention=(contact) ⇒ Object
- #attention_handle=(handle) ⇒ Object
-
#book ⇒ Object
Books a current invoice.
-
#book_with_number(number) ⇒ Object
Books a current invoice.
- #debtor ⇒ Object
- #debtor=(debtor) ⇒ Object
- #debtor_handle=(handle) ⇒ Object
- #handle ⇒ Object
-
#initialize(properties = {}) ⇒ CurrentInvoice
constructor
A new instance of CurrentInvoice.
- #lines ⇒ Object
- #save ⇒ Object
Methods inherited from Entity
#==, default_values, defaults, #destroy, #get, #get_data, #handle=, handle_writer, has_properties, #inspect, key, #partial?, #persisted?, properties, properties_not_triggering_full_load, property_reader, property_writer, proxy, #proxy, #update_properties
Constructor Details
#initialize(properties = {}) ⇒ CurrentInvoice
Returns a new instance of CurrentInvoice.
67 68 69 |
# File 'lib/economic/current_invoice.rb', line 67 def initialize(properties = {}) super end |
Instance Method Details
#attention ⇒ Object
71 72 73 74 |
# File 'lib/economic/current_invoice.rb', line 71 def attention return nil if attention_handle.nil? @attention ||= session.contacts.find(attention_handle) end |
#attention=(contact) ⇒ Object
76 77 78 79 |
# File 'lib/economic/current_invoice.rb', line 76 def attention=(contact) self.attention_handle = contact.handle @attention = contact end |
#attention_handle=(handle) ⇒ Object
81 82 83 84 |
# File 'lib/economic/current_invoice.rb', line 81 def attention_handle=(handle) @attention = nil unless handle == @attention_handle @attention_handle = handle end |
#book ⇒ Object
Books a current invoice. An invoice number greater than all other invoice numbers will be assigned to the resulting Economic::Invoice.
Returns the resulting Economic::Invoice object
90 91 92 93 94 95 |
# File 'lib/economic/current_invoice.rb', line 90 def book response = request(:book, "currentInvoiceHandle" => handle.to_hash) # Find the created Invoice session.invoices.find(response[:number]) end |
#book_with_number(number) ⇒ Object
Books a current invoice. The given number will be assigned to the resulting Economic::Invoice.
Returns the resulting Economic::Invoice object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/economic/current_invoice.rb', line 101 def book_with_number(number) response = request( :book_with_number, "currentInvoiceHandle" => handle.to_hash, "number" => number ) # Find the created Invoice session.invoices.find(response[:number]) end |
#debtor ⇒ Object
112 113 114 115 |
# File 'lib/economic/current_invoice.rb', line 112 def debtor return nil if debtor_handle.nil? @debtor ||= session.debtors.find(debtor_handle) end |
#debtor=(debtor) ⇒ Object
117 118 119 120 |
# File 'lib/economic/current_invoice.rb', line 117 def debtor=(debtor) self.debtor_handle = debtor.handle @debtor = debtor end |
#debtor_handle=(handle) ⇒ Object
122 123 124 125 |
# File 'lib/economic/current_invoice.rb', line 122 def debtor_handle=(handle) @debtor = nil unless handle == @debtor_handle @debtor_handle = handle end |
#handle ⇒ Object
127 128 129 |
# File 'lib/economic/current_invoice.rb', line 127 def handle @handle || Handle.new(:id => @id) end |
#lines ⇒ Object
131 132 133 |
# File 'lib/economic/current_invoice.rb', line 131 def lines @lines ||= CurrentInvoiceLineProxy.new(self) end |
#save ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/economic/current_invoice.rb', line 135 def save lines = self.lines result = super self.id = result[:id].to_i lines.each do |invoice_line| invoice_line.session = session invoice_line.invoice = self invoice_line.save end end |