display cpr for ammo packs and add original count for ammo packs

This commit is contained in:
2022-11-12 14:33:11 -05:00
parent 3480aff61d
commit 1fed895b82
18 changed files with 349 additions and 94 deletions

View File

@ -17,6 +17,7 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
preloads = if show_container, do: [:ammo_type, :container], else: [:ammo_type]
ammo_group = ammo_group |> Repo.preload(preloads)
assigns = assigns |> assign(:ammo_group, ammo_group)
~H"""
@ -38,6 +39,13 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
<%= if @ammo_group.count == 0, do: gettext("Empty"), else: @ammo_group.count %>
</span>
<%= if @ammo_group |> Ammo.get_original_count() != @ammo_group.count do %>
<span class="rounded-lg title text-lg">
<%= gettext("Original Count:") %>
<%= @ammo_group |> Ammo.get_original_count() %>
</span>
<% end %>
<%= if @ammo_group.notes do %>
<span class="rounded-lg title text-lg">
<%= gettext("Notes:") %>
@ -64,6 +72,13 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
amount: @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2)
) %>
</span>
<span class="rounded-lg title text-lg">
<%= gettext("CPR:") %>
<%= gettext("$%{amount}",
amount: @ammo_group |> Ammo.get_cpr() |> :erlang.float_to_binary(decimals: 2)
) %>
</span>
<% end %>
<%= if @show_container and @ammo_group.container do %>

View File

@ -82,11 +82,19 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
columns = [
%{label: gettext("Count"), key: :count},
%{label: gettext("Price paid"), key: :price_paid},
%{label: gettext("CPR"), key: :cpr},
%{label: gettext("% left"), key: :remaining},
%{label: gettext("Notes"), key: :notes}
| columns
]
columns =
if show_used do
[%{label: gettext("Original Count"), key: :original_count} | columns]
else
columns
end
columns =
if ammo_type == [] do
columns
@ -215,6 +223,18 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
"""}
end
defp get_value_for_key(:original_count, ammo_group, _additional_data),
do: ammo_group |> Ammo.get_original_count()
defp get_value_for_key(:cpr, %{price_paid: nil}, _additional_data),
do: gettext("No cost information")
defp get_value_for_key(:cpr, ammo_group, _additional_data) do
gettext("$%{amount}",
amount: ammo_group |> Ammo.get_cpr() |> :erlang.float_to_binary(decimals: 2)
)
end
defp get_value_for_key(:count, %{count: count}, _additional_data),
do: if(count == 0, do: gettext("Empty"), else: count)