2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.AuthView do
|
|
|
|
use PlausibleWeb, :view
|
2021-04-16 10:14:45 +03:00
|
|
|
alias Plausible.Billing.Plans
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2020-05-26 16:09:34 +03:00
|
|
|
def admin_email do
|
|
|
|
Application.get_env(:plausible, :admin_email)
|
|
|
|
end
|
|
|
|
|
|
|
|
def base_domain do
|
|
|
|
PlausibleWeb.Endpoint.host()
|
|
|
|
end
|
|
|
|
|
|
|
|
def plausible_url do
|
2020-10-05 15:01:54 +03:00
|
|
|
PlausibleWeb.Endpoint.url()
|
2020-05-26 16:09:34 +03:00
|
|
|
end
|
|
|
|
|
2020-08-18 14:00:02 +03:00
|
|
|
def subscription_quota(subscription) do
|
2021-05-06 11:46:22 +03:00
|
|
|
Plans.allowance(subscription) |> PlausibleWeb.StatsView.large_number_format()
|
2020-08-18 14:00:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def subscription_interval(subscription) do
|
2021-11-29 13:16:51 +03:00
|
|
|
Plans.subscription_interval(subscription)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
2021-12-09 16:49:57 +03:00
|
|
|
def format_invoices(invoice_list) do
|
|
|
|
Enum.map(invoice_list, fn invoice ->
|
|
|
|
%{
|
|
|
|
date:
|
|
|
|
invoice["payout_date"] |> Date.from_iso8601!() |> Timex.format!("{Mshort} {D}, {YYYY}"),
|
|
|
|
amount: (invoice["amount"] / 1) |> :erlang.float_to_binary(decimals: 2),
|
|
|
|
currency: invoice["currency"] |> PlausibleWeb.BillingView.present_currency(),
|
|
|
|
url: invoice["receipt_url"]
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
def delimit_integer(number) do
|
|
|
|
Integer.to_charlist(number)
|
|
|
|
|> :lists.reverse()
|
|
|
|
|> delimit_integer([])
|
|
|
|
|> String.Chars.to_string()
|
|
|
|
end
|
|
|
|
|
|
|
|
defp delimit_integer([a, b, c, d | tail], acc) do
|
|
|
|
delimit_integer([d | tail], [",", c, b, a | acc])
|
|
|
|
end
|
|
|
|
|
|
|
|
defp delimit_integer(list, acc) do
|
|
|
|
:lists.reverse(list) ++ acc
|
|
|
|
end
|
2020-07-07 16:36:06 +03:00
|
|
|
|
|
|
|
def present_subscription_status("active"), do: "Active"
|
|
|
|
def present_subscription_status("past_due"), do: "Past due"
|
|
|
|
def present_subscription_status("deleted"), do: "Cancelled"
|
|
|
|
def present_subscription_status("paused"), do: "Paused"
|
|
|
|
def present_subscription_status(status), do: status
|
|
|
|
|
|
|
|
def subscription_colors("active"), do: "bg-green-100 text-green-800"
|
|
|
|
def subscription_colors("past_due"), do: "bg-yellow-100 text-yellow-800"
|
|
|
|
def subscription_colors("paused"), do: "bg-red-100 text-red-800"
|
|
|
|
def subscription_colors("deleted"), do: "bg-red-100 text-red-800"
|
|
|
|
def subscription_colors(_), do: ""
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|