VoileWeb.Frontend.Atrium.AtriumHelper (Voile v0.1.26)

Copy Markdown View Source

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

cache_bust(url)

Adds a cache-busting timestamp parameter to a URL.

This prevents browser caching of dynamic resources like user images.

calculate_new_due_date(current_due_date, member)

Calculates the new due date after renewal based on member type.

Defaults to 21 days if member type doesn't specify max_days.

can_renew_transaction_precheck(transaction_id, member, user_type)

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.

format_currency(amount)

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"

node_name(arg1)

Extracts the node name from a user struct.

Prefers loaded node struct, then node_id, or returns "-".

role_name(arg1)

Extracts the role name from a user struct.

Prefers loaded roles association, then user_role_assignments, or returns "-" if nothing is available.

user_type_name(arg1)

Extracts the user type name from a user struct.

Prefers loaded user_type struct, then user_type_id, or returns "-".