2023-08-06 16:27:33 +12:00
|
|
|
defmodule AshDoubleEntry.Account.Calculations.BalanceAsOf do
|
2023-09-27 02:46:07 +13:00
|
|
|
# Calculates the balance as of a given datetime. See the getting started guide for more.
|
|
|
|
@moduledoc false
|
2024-04-02 10:21:49 +13:00
|
|
|
use Ash.Resource.Calculation
|
2023-08-06 16:27:33 +12:00
|
|
|
require Ash.Expr
|
|
|
|
|
2024-04-02 10:21:49 +13:00
|
|
|
def expression(_opts, context) do
|
2023-12-23 15:19:49 +13:00
|
|
|
Ash.Expr.expr(
|
2024-04-02 10:21:49 +13:00
|
|
|
balance_as_of_ulid(ulid: lazy({__MODULE__, :ulid, [context.arguments.timestamp]}))
|
2023-12-23 15:19:49 +13:00
|
|
|
)
|
|
|
|
end
|
2023-08-06 16:27:33 +12:00
|
|
|
|
2023-12-23 15:19:49 +13:00
|
|
|
@doc false
|
|
|
|
def ulid(timestamp) do
|
|
|
|
AshDoubleEntry.ULID.generate(timestamp)
|
2023-08-06 16:27:33 +12:00
|
|
|
end
|
|
|
|
end
|