Module: Invoicexpress::Client::SimplifiedInvoices

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

Instance Method Summary collapse

Instance Method Details

#create_simplified_invoice(simplified_invoice, options = {}) ⇒ Invoicexpress::Models::SimplifiedInvoice

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



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

def create_simplified_invoice(simplified_invoice, options={})
  raise(ArgumentError, "simplified invoice has the wrong type") unless simplified_invoice.is_a?(Invoicexpress::Models::SimplifiedInvoice)

  params = { :klass => Invoicexpress::Models::SimplifiedInvoice, :body  => simplified_invoice }
  post("simplified_invoices.xml", params.merge(options))
end

#simplified_invoice(simplified_invoice_id, options = {}) ⇒ Invoicexpress::Models::SimplifiedInvoice

Returns all the information about a simplified invoice:

  • Basic information (date, status, sequence number)

  • Client

  • Document items

  • Document timeline

Document timeline is composed by:

  • Date, time and the user who created it

  • Type of the event

The complete list of timeline events is:

  • create

  • edited

  • send_email

  • canceled

  • deleted

  • settled

  • second_copy

  • archived

  • unarchived

  • comment

Parameters:

  • simplified_invoice_id (String)

    Requested simplified invoice id

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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



45
46
47
48
49
# File 'lib/invoicexpress/client/simplified_invoices.rb', line 45

def simplified_invoice(simplified_invoice_id, options={})
  params = { :klass => Invoicexpress::Models::SimplifiedInvoice }

  get("simplified_invoices/#{simplified_invoice_id}.xml", params.merge(options))
end

#simplified_invoice_mail(simplified_invoice_id, message, options = {}) ⇒ Object

Sends the simplified invoice through email

Parameters:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

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



121
122
123
124
125
126
# File 'lib/invoicexpress/client/simplified_invoices.rb', line 121

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

  params = { :body => message, :klass => Invoicexpress::Models::SimplifiedInvoice }
  put("simplified_invoices/#{simplified_invoice_id}/email-document.xml", params.merge(options))
end

#simplified_invoices(options = {}) ⇒ Invoicexpress::Models::SimplifiedInvoices

Returns all your simplified 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 simplified invoices

Returns:

  • (Invoicexpress::Models::SimplifiedInvoices)

    A struct with results (pagination) and all the simplified invoices

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized



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

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

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

#update_simplified_invoice(simplified_invoice, options = {}) ⇒ Object

Updates a simplified 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 simplified invoice doesn’t exist



81
82
83
84
85
86
87
88
# File 'lib/invoicexpress/client/simplified_invoices.rb', line 81

def update_simplified_invoice(simplified_invoice, options={})
  raise(ArgumentError, "simplified invoice has the wrong type") unless simplified_invoice.is_a?(Invoicexpress::Models::SimplifiedInvoice)
  if !simplified_invoice.id
    raise ArgumentError, "Invoice ID is required"
  end
  params = { :klass => Invoicexpress::Models::SimplifiedInvoice, :body => simplified_invoice.to_core }
  put("simplified_invoices/#{simplified_invoice.id}.xml", params.merge(options))
end

#update_simplified_invoice_state(simplified_invoice_id, simplified_invoice_state, options = {}) ⇒ Invoicexpress::Models::SimplifiedInvoice

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

  • draft to final – 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 simplified 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 simplified invoice doesn’t exist



107
108
109
110
111
112
# File 'lib/invoicexpress/client/simplified_invoices.rb', line 107

def update_simplified_invoice_state(simplified_invoice_id, simplified_invoice_state, options={})
  raise(ArgumentError, "simplified invoice state has the wrong type") unless simplified_invoice_state.is_a?(Invoicexpress::Models::InvoiceState)

  params = { :klass => Invoicexpress::Models::SimplifiedInvoice, :body => simplified_invoice_state }
  put("simplified_invoices/#{simplified_invoice_id}/change-state.xml", params.merge(options))
end