defmodule MvWeb.StatisticsLive do
@moduledoc """
LiveView for the statistics page at /statistics.
Displays aggregated member and membership fee cycle statistics.
"""
use MvWeb, :live_view
import MvWeb.LiveHelpers, only: [current_actor: 1]
alias Mv.Statistics
alias MvWeb.Helpers.MembershipFeeHelpers
@impl true
def mount(_params, _session, socket) do
socket =
socket
|> load_statistics()
|> assign(:page_title, gettext("Statistics"))
{:ok, socket}
end
@impl true
def handle_params(_params, _uri, socket) do
{:noreply, load_statistics(socket)}
end
@impl true
def render(assigns) do
~H"""
": " <> to_string(@active_count)}
>
{@active_count}
": " <> to_string(@inactive_count)}
>
{@inactive_count}
": " <> MembershipFeeHelpers.format_currency(@open_amount_total)}
>
{MembershipFeeHelpers.format_currency(@open_amount_total)}
{gettext("From %{first} to %{last} (relevant years with membership data)",
first: @years |> List.last() |> to_string(),
last: @years |> List.first() |> to_string()
)}
{gettext("Paid")}
{gettext("Unpaid")}
{gettext("Suspended")}
{gettext("Active members")}
{gettext("Inactive members")}
{gettext("Open amount")}
{gettext("Joins and exits by year")}
{gettext("Contributions by year")}
{gettext("All years combined (pie)")}
<.contributions_pie cycle_totals={@totals_over_all_years} />
| {gettext("Year")} | {gettext("Paid")} | {gettext("Unpaid")} | {gettext("Suspended")} | {gettext("Total")} |
|---|---|---|---|---|
| <%= if row.summary do %> {gettext("Total")} <% else %> {row.year} <% end %> |
|
|||
| {row.paid_formatted} | {row.unpaid_formatted} | {row.suspended_formatted} | {row.total_formatted} | |