Current section
Files
Jump to
Current section
Files
lib/codat/accounting/bills.ex
defmodule Codat.Accounting.Bills do
@moduledoc """
Read and write supplier bills (accounts payable / purchase invoices).
Bills represent money owed **by** your company **to** a supplier.
## Example
# List unpaid bills
{:ok, page} = Codat.Accounting.Bills.list(client, "company-id",
query: "status=Open",
order_by: "-dueDate"
)
# Create a bill
{:ok, push_op} = Codat.Accounting.Bills.create(client, company_id, conn_id, %{
issueDate: "2024-01-01",
dueDate: "2024-01-31",
supplierRef: %{id: "supplier-id"},
lineItems: [%{description: "Office supplies", quantity: 1, unitAmount: 500}]
})
"""
use Codat.API,
base_path: "/companies/:company_id/connections/:connection_id/push/bills",
list_path: "/companies/:company_id/data/bills",
data_type: "bills",
supports: [
:list,
:get,
:create,
:update,
:delete,
:get_create_model,
:get_update_model,
:stream,
:fetch_all
]
alias Codat.Client
alias Codat.Error
import Codat.API, only: [resolve_client: 1]
@doc "Lists attachments for a bill."
@spec get_attachments(Client.t() | String.t(), String.t(), String.t() | keyword()) ::
{:ok, map()} | {:error, Error.t()}
def get_attachments(client_or_company_id, company_or_bill_id, bill_or_opts \\ [])
def get_attachments(%Client{} = client, company_id, bill_id)
when is_binary(company_id) and is_binary(bill_id) do
Codat.HTTP.Client.get(
client.config,
"/companies/#{company_id}/data/bills/#{bill_id}/attachments",
api_module: __MODULE__,
operation: :get_attachments
)
end
def get_attachments(company_id, bill_id, opts)
when is_binary(company_id) and is_binary(bill_id) do
get_attachments(resolve_client(opts), company_id, bill_id)
end
end