Module: Invoicexpress::Client::Clients

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

Instance Method Summary collapse

Instance Method Details

#client(client_id, options = {}) ⇒ Invoicexpress::Models::Client

Returns a specific client

Parameters:

  • client_id (String)

    The client’s ID

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

  • Invoicexpress::NotFound When the client ID is not found



66
67
68
69
70
# File 'lib/invoicexpress/client/clients.rb', line 66

def client(client_id, options={})
  params = { :klass => Invoicexpress::Models::Client }

  get("clients/#{client_id.to_s}.xml", params.merge(options))
end

#client_by_code(client_code, options = {}) ⇒ Invoicexpress::Models::Client

Use this method to obtain a client by your code. Partial searches are not supported

Parameters:

  • client_code (String)

    The client’s code (your code)

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::NotFound When there are no clients with that name



116
117
118
119
120
121
122
123
# File 'lib/invoicexpress/client/clients.rb', line 116

def client_by_code(client_code, options={})
  params = {
    :klass       => Invoicexpress::Models::Client,
    :client_code => client_code
  }

  get("clients/find-by-code.xml", params.merge(options))
end

#client_by_name(client_name, options = {}) ⇒ Invoicexpress::Models::Client

Use this method to obtain a client by name. Partial searches are not supported

Parameters:

  • client_name (String)

    The client’s name

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::NotFound When there are no clients with that name



101
102
103
104
105
106
107
108
# File 'lib/invoicexpress/client/clients.rb', line 101

def client_by_name(client_name, options={})
  params = {
    :klass       => Invoicexpress::Models::Client,
    :client_name => client_name
  }

  get("clients/find-by-name.xml", params.merge(options))
end

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

This method allows you to create a new cash invoice for a specific client. When creating the invoice:

  • 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 applied to that item.

Parameters:

  • client_id (String)

    The ID of the client

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

  • Invoicexpress::NotFound When there are no clients with that name



158
159
160
161
162
163
164
165
166
167
# File 'lib/invoicexpress/client/clients.rb', line 158

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

  params = {
    :klass => Invoicexpress::Models::CashInvoice,
    :body  => invoice
  }

  post("clients/#{client_id}/create/cash-invoice.xml", params.merge(options))
end

#client_create_credit_note(client_id, invoice, options = {}) ⇒ Invoicexpress::Models::CreditNote

This method allows you to create a new Credit Note for a specific client. When creating the invoice:

  • 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 applied to that item.

Parameters:

  • client_id (String)

    The ID of the client

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

  • Invoicexpress::NotFound When there are no clients with that name



180
181
182
183
184
185
186
187
188
189
# File 'lib/invoicexpress/client/clients.rb', line 180

def client_create_credit_note(client_id, invoice, options={})
  raise(ArgumentError, "credit note has the wrong type") unless invoice.is_a?(Invoicexpress::Models::CreditNote)

  params = {
    :klass => Invoicexpress::Models::CreditNote,
    :body  => invoice
  }

  post("clients/#{client_id}/create/credit-note.xml", params.merge(options))
end

#client_create_debit_note(client_id, invoice, options = {}) ⇒ Invoicexpress::Models::DebitNote

This method allows you to create a new Debit Note for a specific client. When creating the invoice:

  • 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 applied to that item.

Parameters:

  • client_id (String)

    The ID of the client

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

  • Invoicexpress::NotFound When there are no clients with that name



202
203
204
205
206
207
208
209
210
211
# File 'lib/invoicexpress/client/clients.rb', line 202

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

  params = {
    :klass => Invoicexpress::Models::DebitNote,
    :body  => invoice
  }

  post("clients/#{client_id}/create/debit-note.xml", params.merge(options))
end

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

This method allows you to create a new invoice for a specific client. When creating the invoice:

  • 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 applied to that item.

Parameters:

  • client_id (String)

    The ID of the client

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

  • Invoicexpress::NotFound When there are no clients with that name



136
137
138
139
140
141
142
143
144
145
# File 'lib/invoicexpress/client/clients.rb', line 136

def client_create_invoice(client_id, invoice, options={})
  raise(ArgumentError, "invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::Invoice)

  params = {
    :klass => Invoicexpress::Models::Invoice,
    :body  => invoice
  }

  post("clients/#{client_id}/create/invoice.xml", params.merge(options))
end

#client_invoices(client_id, filter = Invoicexpress::Models::Filter.new, options = {}) ⇒ Invoicexpress::Models::ClientInvoices

This method allows you to obtain the invoices for a specific client. Allowing filtering aswell.

Parameters:

  • client_id (String)

    The client’s ID

  • filter (Invoicexpress::Models::Filter) (defaults to: Invoicexpress::Models::Filter.new)

    An optional filter

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

    a customizable set of options

Options Hash (options):

  • per_page (Integer) — default: 10

    You can specify how many results you want to fetch

  • page (Integer) — default: 1

    You can ask a specific page of clients

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::NotFound When the client ID is not found



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/invoicexpress/client/clients.rb', line 82

def client_invoices(client_id, filter=Invoicexpress::Models::Filter.new, options={})
  raise(ArgumentError, "filter has the wrong type") unless filter.is_a?(Invoicexpress::Models::Filter)

  params = {
    :klass    => Invoicexpress::Models::ClientInvoices,
    :per_page => 10,
    :page     => 1,
    :body     => filter
  }

  post("clients/#{client_id.to_s}/invoices.xml", params.merge(options))
end

#clients(options = {}) ⇒ Array<Invoicexpress::Models::Client>

Returns all your clients

Parameters:

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

    a customizable set of options

Options Hash (options):

  • per_page (Integer) — default: 30

    You can specify how many results you want to fetch

  • page (Integer) — default: 1

    You can ask a specific page of clients

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized



14
15
16
17
18
# File 'lib/invoicexpress/client/clients.rb', line 14

def clients(options={})
  params = { :per_page => 30, :page => 1, :klass => Invoicexpress::Models::Client }

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

#create_client(client, options = {}) ⇒ Invoicexpress::Models::Client

Creates a new client.

Parameters:

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/invoicexpress/client/clients.rb', line 26

def create_client(client, options={})
  if !client || !client.is_a?(Invoicexpress::Models::Client)
    raise ArgumentError, "Need a Invoicexpress::Models::Client instance"
  end

  if !client.name
    raise ArgumentError, "Client's name is required"
  end

  params = { :body => client, :klass => Invoicexpress::Models::Client }
  post("clients.xml", params.merge(options))
end

#update_client(client, options = {}) ⇒ Invoicexpress::Models::Client

Updates a client.

Parameters:

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

  • Invoicexpress::NotFound When the Client’s ID is not found



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/invoicexpress/client/clients.rb', line 46

def update_client(client, options={})
  if !client || !client.is_a?(Invoicexpress::Models::Client)
    raise ArgumentError, "Need a Invoicexpress::Models::Client instance"
  end

  if !client.id
    raise ArgumentError, "Client's ID is required"
  end

  params = { :body => client, :klass => Invoicexpress::Models::Client }
  put("clients/#{client.id.to_s}.xml", params.merge(options))
end