Codat.Accounting.Invoices (codat v1.0.0)

Copy Markdown View Source

Read and write accounting invoices (sales invoices / accounts receivable).

Supported Operations

OperationDescription
list/2,3Paginated list of invoices
get/3,4Single invoice by ID
create/4,5Create a new invoice (async)
update/5,6Update an existing invoice (async)
delete/3,4Delete an invoice (async, not all integrations)
get_create_modelGet required fields for create
get_update_modelGet required fields for update
stream/2,3Lazy stream of all invoices
fetch_all/2,3All invoices as a list (concurrent paging)
get_attachmentsList attachments for an invoice
upload_attachmentUpload a PDF/image attachment

Example

# List open invoices
{:ok, page} = Codat.Accounting.Invoices.list(client, "company-id",
  query: "status=Open",
  order_by: "-issueDate"
)

# Stream all invoices without loading all into memory
Codat.Accounting.Invoices.stream(client, "company-id")
|> Stream.filter(&(&1["amountDue"] > 0))
|> Enum.take(10)

# Create an invoice (async)
{:ok, push_op} = Codat.Accounting.Invoices.create(
  client, "company-id", "connection-id",
  %{
    issueDate: "2024-01-15",
    dueDate: "2024-02-15",
    customerRef: %{id: "customer-id"},
    lineItems: [%{description: "Consulting", quantity: 1, unitAmount: 1000}]
  }
)
# Poll or await webhook for completion
{:ok, done} = Codat.Platform.PushOperations.poll_until_done(
  client, "company-id", push_op["pushOperationKey"]
)

Summary

Functions

create(client_or_company_id, company_or_conn_id, conn_or_body, body_or_opts \\ %{})

@spec create(
  Codat.Client.t() | String.t(),
  String.t(),
  String.t() | map(),
  map() | keyword()
) ::
  {:ok, map()} | {:error, Codat.Error.t()}

Creates a new invoices (async). Returns a push operation.

delete(client_or_company_id, company_or_resource_id, resource_id_or_opts \\ [])

@spec delete(Codat.Client.t() | String.t(), String.t(), String.t() | keyword()) ::
  {:ok, nil} | {:error, Codat.Error.t()}

Deletes a invoices by ID (async).

download_attachment(client_or_company_id, company_or_invoice_id, invoice_or_attachment_id, attachment_or_opts \\ [])

@spec download_attachment(
  Codat.Client.t() | String.t(),
  String.t(),
  String.t(),
  String.t() | keyword()
) :: {:ok, binary() | map() | list() | nil} | {:error, Codat.Error.t()}

Downloads a specific attachment for an invoice.

fetch_all(client_or_company_id, company_id_or_opts \\ [], opts \\ [])

@spec fetch_all(Codat.Client.t() | String.t(), String.t() | keyword(), keyword()) ::
  {:ok, [map()]} | {:error, Codat.Error.t()}

Fetches all invoices across all pages concurrently.

get(client_or_company_id, company_or_resource_id, resource_id_or_opts \\ [])

@spec get(Codat.Client.t() | String.t(), String.t(), String.t() | keyword()) ::
  {:ok, map()} | {:error, Codat.Error.t()}

Fetches a single invoices by ID.

get_attachments(client_or_company_id, company_or_invoice_id, invoice_or_opts \\ [])

@spec get_attachments(
  Codat.Client.t() | String.t(),
  String.t(),
  String.t() | keyword()
) ::
  {:ok, map()} | {:error, Codat.Error.t()}

Lists attachments for an invoice.

Example

{:ok, attachments} = Codat.Accounting.Invoices.get_attachments(
  client, "company-id", "invoice-id"
)

get_create_model(client_or_company_id, company_or_conn_id, opts \\ [])

@spec get_create_model(Codat.Client.t() | String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, Codat.Error.t()}

Returns the push model for creating invoices.

get_update_model(client_or_company_id, company_or_conn_id, conn_or_resource_id, resource_id_or_opts \\ [])

@spec get_update_model(
  Codat.Client.t() | String.t(),
  String.t(),
  String.t() | keyword(),
  keyword()
) ::
  {:ok, map()} | {:error, Codat.Error.t()}

Returns the push model for updating a invoices record.

list(client_or_company_id, company_id_or_opts \\ [], opts \\ [])

@spec list(Codat.Client.t() | String.t(), String.t() | keyword(), keyword()) ::
  {:ok, Codat.Pagination.t()} | {:error, Codat.Error.t()}

Returns a paginated list of invoices.

stream(client_or_company_id, company_id_or_opts \\ [], opts \\ [])

@spec stream(Codat.Client.t() | String.t(), String.t() | keyword(), keyword()) ::
  Enumerable.t()

Returns a lazy Stream of all results.

update(client_or_company_id, company_or_conn_id, conn_or_resource_id, resource_or_body, body_or_opts \\ %{})

@spec update(
  Codat.Client.t() | String.t(),
  String.t(),
  String.t(),
  String.t() | map(),
  map() | keyword()
) :: {:ok, map()} | {:error, Codat.Error.t()}

Updates an existing invoices (async).