Module: Invoicexpress::Client::CashInvoices

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

Instance Method Summary collapse

Instance Method Details

#cash_invoice(invoice_id, options = {}) ⇒ Invoicexpress::Models::CashInvoice

Returns a specific cash 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



24
25
26
27
28
# File 'lib/invoicexpress/client/cash_invoices.rb', line 24

def cash_invoice(invoice_id, options={})
  params = { :klass => Invoicexpress::Models::CashInvoice }

  get("cash_invoices/#{invoice_id}.xml", params.merge(options))
end

#cash_invoices(options = {}) ⇒ Invoicexpress::Models::CashInvoices

Returns all your cash 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



12
13
14
15
16
# File 'lib/invoicexpress/client/cash_invoices.rb', line 12

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

  get("cash_invoices.xml", params.merge(options))
end

#create_cash_invoice(invoice, options = {}) ⇒ Invoicexpress::Models::CashInvoice

Creates a new cash 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



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

def create_cash_invoice(invoice, options={})
  raise(ArgumentError, "cash invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::CashInvoice)

  params = { :klass => Invoicexpress::Models::CashInvoice, :body  => invoice }
  post("cash_invoices.xml", params.merge(options))
end

#update_cash_invoice(invoice, options = {}) ⇒ Object

Updates a cash 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



60
61
62
63
64
65
66
67
68
# File 'lib/invoicexpress/client/cash_invoices.rb', line 60

def update_cash_invoice(invoice, options={})
  raise(ArgumentError, "cash invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::CashInvoice)

  if !invoice.id
    raise ArgumentError, "Sequence ID is required"
  end
  params = { :klass => Invoicexpress::Models::CashInvoice, :body  => invoice.to_core }
  put("cash_invoices/#{invoice.id}.xml", params.merge(options))
end

#update_cash_invoice_state(invoice_id, invoice_state, options = {}) ⇒ Invoicexpress::Models::CashInvoice

Changes the state of a cash invoice. Possible state transitions:

  • draft to settle – finalized

  • draft to deleted – deleted

  • settled to final – unsettled

  • final to second copy – second_copy

  • final or second copy to canceled – canceled

  • final or second copy to settled – settled

Any other transitions will fail. When canceling a cash 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



87
88
89
90
91
92
# File 'lib/invoicexpress/client/cash_invoices.rb', line 87

def update_cash_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::CashInvoice, :body => invoice_state }
  put("cash_invoices/#{invoice_id}/change-state.xml", params.merge(options))
end