Module: SageOne::Client::SalesInvoices

Included in:
SageOne::Client
Defined in:
lib/sage_one/client/sales_invoices.rb

Instance Method Summary collapse

Instance Method Details

#create_sales_invoice(options) ⇒ Invoice

Create a sales invoice

Examples:

Create a sales invoice:

SageOne.create_sales_invoice({
  date: Time.now
  contact_id: 654
  contact_name: "Dave Regis"
  main_address: "Regis Enterprises, PO Box 123"
  carriage_tax_code_id: 5
  line_items_attributes: { unit_price: 12.34, quantity: 1.0, description: "Salmon steak", tax_code_id: 1, ledger_account_id: 987 }
})

Parameters:

  • options (Hash)

    A customizable set of options. Note that you don’t have to wrap these, i.e. { sales_invoice: options }, just pass in the options hash

Options Hash (options):

  • :date (String, #strftime)

    The invoice date either as a dd/mm/yyyy-formatted string or any object that responds to strftime

  • :contact_id (Integer)

    The ID of the contact associated with the sales invoice. This must be a customer (contact_type 1).

  • :contact_name (String)

    The name of the contact associated with the invoice. This should be the contact from the ID of the specified contact.

  • :main_address (String)

    The address where the invoice is to be sent.

  • :carriage_tax_code_id (Integer)

    The ID of the tax_rate if sales_invoice is supplied.

  • :line_items_attributes (Array<Hash>)

    An array of line items. Each Hash requires:

    • :unit_price (Float) The unit cost of the line item.

    • :quantity (Float) The number of units on the specified line item.

    • :description (String) The description of the specified line item, maximum 60 characters.

    • :tax_code_id (Integer) The ID of the tax_rate for the item line.

    • :ledger_account_id (Integer) The ID of the income_type.

Returns:

  • (Invoice)

    A Hashie of the created invoice



44
45
46
# File 'lib/sage_one/client/sales_invoices.rb', line 44

def create_sales_invoice(options)
  post('sales_invoices', sales_invoice: options)
end

#delete_sales_invoice!(id) ⇒ Invoice

Delete a sales invoice

Examples:

Delete an invoice

invoice = SageOne.delete_sales_invoice!(12)

Parameters:

  • id (Integer)

    The id of the invoice you want to delete.

Returns:

  • (Invoice)

    A Hashie of the deleted invoice



71
72
73
# File 'lib/sage_one/client/sales_invoices.rb', line 71

def delete_sales_invoice!(id)
  delete("sales_invoices/#{id}")
end

#sales_invoice(id) ⇒ Invoice

Retrieve a sales invoice

Examples:

Load an invoice

invoice = SageOne.sales_invoice(8754)

Parameters:

  • id (Integer)

    The id of the invoice you want to retrieve.

Returns:

  • (Invoice)

    A Hashie of the requested invoice



53
54
55
# File 'lib/sage_one/client/sales_invoices.rb', line 53

def sales_invoice(id)
  get "sales_invoices/#{id}"
end

#sales_invoices(options = {}) ⇒ Array<Invoice>

List sales invoices

Examples:

Get all sales invoices

SageOne.sales_invoices

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :contact (Integer)

    Use this to filter by contact id

  • :status (Integer)

    Invoice payment status.

  • :search (String)

    Filter by contact_name or reference (not case sensitive)

  • :from_date (String, #strftime)

    Either a string formatted as ‘dd/mm/yyyy’ or an object which responds to strftime

  • :to_date (String, #strftime)

    Either a string formatted as ‘dd/mm/yyyy’ or an object which responds to strftime

  • :start_index (Integer)

    The start index in pagination to begin from.

Returns:

  • (Array<Invoice>)

    A list of all sales_invoices. Each invoice is a Hashie.



16
17
18
# File 'lib/sage_one/client/sales_invoices.rb', line 16

def sales_invoices(options={})
  get("sales_invoices", options)
end

#update_sales_invoice(id, options) ⇒ Invoice

Update a sales invoice

Parameters:

  • id (Integer)

    The id of the invoice you want to update.

  • options (Hash)

    A customizable set of options. Note that you don’t have to wrap these, i.e. { sales_invoice: options }, just pass in the options hash

Options Hash (options):

  • :date (String, #strftime)

    The invoice date either as a dd/mm/yyyy-formatted string or any object that responds to strftime

  • :contact_id (Integer)

    The ID of the contact associated with the sales invoice. This must be a customer (contact_type 1).

  • :contact_name (String)

    The name of the contact associated with the invoice. This should be the contact from the ID of the specified contact.

  • :main_address (String)

    The address where the invoice is to be sent.

  • :carriage_tax_code_id (Integer)

    The ID of the tax_rate if sales_invoice is supplied.

  • :line_items_attributes (Array<Hash>)

    An array of line items. Each Hash requires:

    • :unit_price (Float) The unit cost of the line item.

    • :quantity (Float) The number of units on the specified line item.

    • :description (String) The description of the specified line item, maximum 60 characters.

    • :tax_code_id (Integer) The ID of the tax_rate for the item line.

    • :ledger_account_id (Integer) The ID of the income_type.

Returns:

  • (Invoice)

    A Hashie of the updated invoice



62
63
64
# File 'lib/sage_one/client/sales_invoices.rb', line 62

def update_sales_invoice(id, options)
  put("sales_invoices/#{id}", sales_invoice: options)
end