Module: Invoicexpress::Client::Invoices

Included in:
Invoicexpress::Client
Defined in:
lib/invoicexpress/client/invoices.rb

Instance Method Summary collapse

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%)

Parameters:

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission



42
43
44
45
46
47
# File 'lib/invoicexpress/client/invoices.rb', line 42

def create_invoice(invoice, options={})
  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(options))
end

#email_invoice(invoice_id, message, options = {}) ⇒ Object

Sends the invoice by email

Parameters:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the invoice doesn’t exist



98
99
100
101
102
103
# File 'lib/invoicexpress/client/invoices.rb', line 98

def email_invoice(invoice_id, message, options={})
  raise(ArgumentError, "message has the wrong type") unless message.is_a?(Invoicexpress::Models::Message)

  params = { :body => message, :klass => Invoicexpress::Models::Invoice }
  put("invoice/#{invoice_id}/email-invoice.xml", params.merge(options))
end

#invoice(invoice_id, options = {}) ⇒ Invoicexpress::Models::Invoice

Returns a specific invoice

Parameters:

  • invoice_id (String)

    Requested invoice id

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::NotFound When the invoice doesn’t exist



25
26
27
28
29
# File 'lib/invoicexpress/client/invoices.rb', line 25

def invoice(invoice_id, options={})
  params = { :klass => Invoicexpress::Models::Invoice }

  get("invoices/#{invoice_id}.xml", params.merge(options))
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, message, options={})
  email_invoice(invoice_id, message, options)
end

#invoices(options = {}) ⇒ Array<Invoicexpress::Models::Invoice>

Returns all your invoices

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • page (Integer) — default: 1

    You can ask a specific page of invoices

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized



13
14
15
16
17
# File 'lib/invoicexpress/client/invoices.rb', line 13

def invoices(options={})
  params = { :page => 1, :klass => Invoicexpress::Models::Invoices }

  get("invoices.xml", params.merge(options))
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.

Parameters:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the invoice doesn’t exist



61
62
63
64
65
66
# File 'lib/invoicexpress/client/invoices.rb', line 61

def update_invoice(invoice, options={})
  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(options))
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.

Parameters:

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the invoice doesn’t exist



84
85
86
87
88
89
# File 'lib/invoicexpress/client/invoices.rb', line 84

def update_invoice_state(invoice_id, invoice_state, options={})
  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(options))
end