Module: Invoicexpress::Client::Invoices
- Included in:
- Invoicexpress::Client
- Defined in:
- lib/invoicexpress/client/invoices.rb
Instance Method Summary collapse
-
#create_invoice(invoice, options = {}) ⇒ Invoicexpress::Models::Invoice
Creates a new invoice.
-
#email_invoice(invoice_id, message, options = {}) ⇒ Object
Sends the invoice by email.
-
#invoice(invoice_id, options = {}) ⇒ Invoicexpress::Models::Invoice
Returns a specific invoice.
-
#invoice_email(invoice_id, message, options = {}) ⇒ Object
deprecated.
-
#invoices(options = {}) ⇒ Array<Invoicexpress::Models::Invoice>
Returns all your invoices.
-
#update_invoice(invoice, options = {}) ⇒ Object
Updates an invoice It also allows you to create a new client and/or items in the same request.
-
#update_invoice_state(invoice_id, invoice_state, options = {}) ⇒ Invoicexpress::Models::Invoice
Changes the state of an invoice.
Instance Method Details
#create_invoice(invoice, options = {}) ⇒ Invoicexpress::Models::Invoice
Creates a new invoice. Also allows to create a new client and/or new items in the same request. If the client name does not exist a new one is created. If items do not exist with the given names, new ones will be created. If item name already exists, the item is updated with the new values. Regarding item taxes, if the tax name is not found, no tax is applyed to that item. Portuguese accounts should also send the IVA exemption reason if the invoice contains exempt items(IVA 0%)
42 43 44 45 46 47 |
# File 'lib/invoicexpress/client/invoices.rb', line 42 def create_invoice(invoice, ={}) raise(ArgumentError, "invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::Invoice) params = { :klass => Invoicexpress::Models::Invoice, :body => invoice } post("invoices.xml", params.merge()) end |
#email_invoice(invoice_id, message, options = {}) ⇒ Object
Sends the invoice by email
98 99 100 101 102 103 |
# File 'lib/invoicexpress/client/invoices.rb', line 98 def email_invoice(invoice_id, , ={}) raise(ArgumentError, "message has the wrong type") unless .is_a?(Invoicexpress::Models::Message) params = { :body => , :klass => Invoicexpress::Models::Invoice } put("invoice/#{invoice_id}/email-invoice.xml", params.merge()) end |
#invoice(invoice_id, options = {}) ⇒ Invoicexpress::Models::Invoice
Returns a specific invoice
25 26 27 28 29 |
# File 'lib/invoicexpress/client/invoices.rb', line 25 def invoice(invoice_id, ={}) params = { :klass => Invoicexpress::Models::Invoice } get("invoices/#{invoice_id}.xml", params.merge()) end |
#invoice_email(invoice_id, message, options = {}) ⇒ Object
deprecated
106 107 108 |
# File 'lib/invoicexpress/client/invoices.rb', line 106 def invoice_email(invoice_id, , ={}) email_invoice(invoice_id, , ) end |
#invoices(options = {}) ⇒ Array<Invoicexpress::Models::Invoice>
Returns all your invoices
13 14 15 16 17 |
# File 'lib/invoicexpress/client/invoices.rb', line 13 def invoices(={}) params = { :page => 1, :klass => Invoicexpress::Models::Invoices } get("invoices.xml", params.merge()) end |
#update_invoice(invoice, options = {}) ⇒ Object
Updates an invoice It also allows you to create a new client and/or items in the same request. If the client name does not exist a new client is created. Regarding item taxes, if the tax name is not found, no tax will be applied to that item. If item does not exist with the given name, a new one will be created. If item exists it will be updated with the new values Be careful when updating the document items, any missing items from the original document will be deleted.
61 62 63 64 65 66 |
# File 'lib/invoicexpress/client/invoices.rb', line 61 def update_invoice(invoice, ={}) raise(ArgumentError, "invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::Invoice) params = { :klass => Invoicexpress::Models::Invoice, :body => invoice.to_core } put("invoices/#{invoice.id}.xml", params.merge()) end |
#update_invoice_state(invoice_id, invoice_state, options = {}) ⇒ Invoicexpress::Models::Invoice
Changes the state of an invoice. Possible state transitions:
-
draft to final – finalized
-
final to second copy – second_copy
-
final or second copy to canceled – canceled
-
final or second copy to settled – settled
-
settled to final – unsettled
Any other transitions will fail. When canceling an invoice you must specify a reason.
84 85 86 87 88 89 |
# File 'lib/invoicexpress/client/invoices.rb', line 84 def update_invoice_state(invoice_id, invoice_state, ={}) raise(ArgumentError, "invoice_state has the wrong type") unless invoice_state.is_a?(Invoicexpress::Models::InvoiceState) params = { :klass => Invoicexpress::Models::Invoice, :body => invoice_state } put("invoices/#{invoice_id}/change-state.xml", params.merge()) end |