ash_double_entry/lib/account/calculations/balance_as_of.ex
2023-12-22 21:19:49 -05:00

20 lines
517 B
Elixir

defmodule AshDoubleEntry.Account.Calculations.BalanceAsOf do
# Calculates the balance as of a given datetime. See the getting started guide for more.
@moduledoc false
use Ash.Calculation
require Ash.Expr
def expression(opts, context) do
Ash.Expr.expr(
balance_as_of_ulid(
ulid: Ash.Expr.expr(lazy({__MODULE__, :ulid, [context.timestamp]})),
resource: opts[:resource]
)
)
end
@doc false
def ulid(timestamp) do
AshDoubleEntry.ULID.generate(timestamp)
end
end