Helper functions for the Atrium (member self-service portal).
This module contains utility functions for:
- Transaction renewal validation
- Association data extraction (roles, user types, nodes)
- Date calculations
- URL utilities
Summary
Functions
Adds a cache-busting timestamp parameter to a URL.
Calculates the new due date after renewal based on member type.
Performs pre-checks before allowing a transaction renewal.
Formats a Decimal number as Indonesian Rupiah currency.
Extracts the node name from a user struct.
Extracts the role name from a user struct.
Extracts the user type name from a user struct.
Functions
Adds a cache-busting timestamp parameter to a URL.
This prevents browser caching of dynamic resources like user images.
Calculates the new due date after renewal based on member type.
Defaults to 21 days if member type doesn't specify max_days.
Performs pre-checks before allowing a transaction renewal.
Validates:
- Member type allows renewals
- Maximum renewals not exceeded
- Renewal window (3 days before due to 1 day before due)
Returns {:ok} if renewal is allowed, or {:error, message} otherwise.
Formats a Decimal number as Indonesian Rupiah currency.
Adds thousand separators (dots) and handles Decimal types.
Examples
iex> format_currency(Decimal.new("1000"))
"1.000"
iex> format_currency(Decimal.new("1234567"))
"1.234.567"
iex> format_currency(Decimal.new("0"))
"0"
Extracts the node name from a user struct.
Prefers loaded node struct, then node_id, or returns "-".
Extracts the role name from a user struct.
Prefers loaded roles association, then user_role_assignments,
or returns "-" if nothing is available.
Extracts the user type name from a user struct.
Prefers loaded user_type struct, then user_type_id, or returns "-".