Module: Invoicexpress::Client::DebitNotes

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

Instance Method Summary collapse

Instance Method Details

#create_debit_note(debit_note, options = {}) ⇒ Invoicexpress::Models::DebitNote

Creates a new debit note. 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



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

def create_debit_note(debit_note, options={})
  raise(ArgumentError, "debit note has the wrong type") unless debit_note.is_a?(Invoicexpress::Models::DebitNote)

  params = { :klass => Invoicexpress::Models::DebitNote, :body  => debit_note }
  post("debit_notes.xml", params.merge(options))
end

#debit_note(debit_note_id, options = {}) ⇒ Invoicexpress::Models::DebitNote

Returns all the information about a debit note:

  • 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:

  • debit_note_id (String)

    Requested debit note id

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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



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

def debit_note(debit_note_id, options={})
  params = { :klass => Invoicexpress::Models::DebitNote }

  get("debit_notes/#{debit_note_id}.xml", params.merge(options))
end

#debit_note_mail(debit_note_id, message, options = {}) ⇒ Object

Sends the debit note through email

Parameters:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

  • Invoicexpress::NotFound When the debit note doesn’t exist



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

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

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

#debit_notes(options = {}) ⇒ Invoicexpress::Models::DebitNotes

Returns all your debit notes

Parameters:

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

    a customizable set of options

Options Hash (options):

  • page (Integer) — default: 1

    You can ask a specific page of debit notes

Returns:

  • (Invoicexpress::Models::DebitNotes)

    A struct with results (pagination) and all the debit notes

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized



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

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

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

#update_debit_note(debit_note, options = {}) ⇒ Object

Updates a debit note 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 debit note doesn’t exist



79
80
81
82
83
84
85
86
87
# File 'lib/invoicexpress/client/debit_notes.rb', line 79

def update_debit_note(debit_note, options={})
  raise(ArgumentError, "debit note has the wrong type") unless debit_note.is_a?(Invoicexpress::Models::DebitNote)

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

#update_debit_note_state(debit_note_id, debit_note_state, options = {}) ⇒ Invoicexpress::Models::DebitNote

Changes the state of a debit note. 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 debit note 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 debit note doesn’t exist



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

def update_debit_note_state(debit_note_id, debit_note_state, options={})
  raise(ArgumentError, "debit note state has the wrong type") unless debit_note_state.is_a?(Invoicexpress::Models::InvoiceState)

  params = { :klass => Invoicexpress::Models::DebitNote, :body => debit_note_state }
  put("debit_notes/#{debit_note_id}/change-state.xml", params.merge(options))
end