replace ammo added on with purchased on
This commit is contained in:
@ -30,6 +30,7 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
field :notes, :string
|
||||
field :price_paid, :float
|
||||
field :staged, :boolean, default: false
|
||||
field :purchased_on, :date
|
||||
|
||||
belongs_to :ammo_type, AmmoType
|
||||
belongs_to :container, Container
|
||||
@ -46,6 +47,7 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
notes: String.t() | nil,
|
||||
price_paid: float() | nil,
|
||||
staged: boolean(),
|
||||
purchased_on: Date.t(),
|
||||
ammo_type: AmmoType.t() | nil,
|
||||
ammo_type_id: AmmoType.id(),
|
||||
container: Container.t() | nil,
|
||||
@ -79,9 +81,9 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
|> change(ammo_type_id: ammo_type_id)
|
||||
|> change(user_id: user_id)
|
||||
|> change(container_id: container_id)
|
||||
|> cast(attrs, [:count, :price_paid, :notes, :staged])
|
||||
|> cast(attrs, [:count, :price_paid, :notes, :staged, :purchased_on])
|
||||
|> validate_number(:count, greater_than: 0)
|
||||
|> validate_required([:count, :staged, :ammo_type_id, :container_id, :user_id])
|
||||
|> validate_required([:count, :staged, :purchased_on, :ammo_type_id, :container_id, :user_id])
|
||||
end
|
||||
|
||||
@doc """
|
||||
@ -99,10 +101,10 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
Changeset.t(t() | new_ammo_group())
|
||||
def update_changeset(ammo_group, attrs, user) do
|
||||
ammo_group
|
||||
|> cast(attrs, [:count, :price_paid, :notes, :staged, :container_id])
|
||||
|> cast(attrs, [:count, :price_paid, :notes, :staged, :purchased_on, :container_id])
|
||||
|> validate_number(:count, greater_than_or_equal_to: 0)
|
||||
|> validate_container_id(user)
|
||||
|> validate_required([:count, :staged, :container_id])
|
||||
|> validate_required([:count, :staged, :purchased_on, :container_id])
|
||||
end
|
||||
|
||||
defp validate_container_id(changeset, user) do
|
||||
|
@ -42,7 +42,7 @@
|
||||
) %>
|
||||
<%= error_tag(f, :notes, "col-span-3") %>
|
||||
|
||||
<%= label(f, :date, gettext("Date (UTC)"), class: "title text-lg text-primary-600") %>
|
||||
<%= label(f, :date, gettext("Date"), class: "title text-lg text-primary-600") %>
|
||||
<%= date_input(f, :date,
|
||||
class: "input input-primary col-span-2",
|
||||
phx_update: "ignore",
|
||||
|
@ -54,13 +54,13 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
|
||||
<% end %>
|
||||
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Added on:") %>
|
||||
<%= @ammo_group.inserted_at |> display_datetime() %>
|
||||
<%= gettext("Purchased on:") %>
|
||||
<%= @ammo_group.purchased_on |> display_date() %>
|
||||
</span>
|
||||
|
||||
<%= if @ammo_group.count == 0 do %>
|
||||
<%= if @ammo_group |> Ammo.get_last_used_shot_group() do %>
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Used up on:") %>
|
||||
<%= gettext("Last used on:") %>
|
||||
<%= @ammo_group |> Ammo.get_last_used_shot_group() |> Map.get(:date) |> display_date() %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
@ -13,7 +13,6 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
required(:id) => UUID.t(),
|
||||
required(:current_user) => User.t(),
|
||||
required(:ammo_groups) => [AmmoGroup.t()],
|
||||
optional(:show_used) => boolean(),
|
||||
optional(:ammo_type) => Rendered.t(),
|
||||
optional(:range) => Rendered.t(),
|
||||
optional(:container) => Rendered.t(),
|
||||
@ -26,7 +25,6 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
socket =
|
||||
socket
|
||||
|> assign(assigns)
|
||||
|> assign_new(:show_used, fn -> false end)
|
||||
|> assign_new(:ammo_type, fn -> [] end)
|
||||
|> assign_new(:range, fn -> [] end)
|
||||
|> assign_new(:container, fn -> [] end)
|
||||
@ -41,7 +39,6 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
assigns: %{
|
||||
ammo_groups: ammo_groups,
|
||||
current_user: current_user,
|
||||
show_used: show_used,
|
||||
ammo_type: ammo_type,
|
||||
range: range,
|
||||
container: container,
|
||||
@ -56,14 +53,10 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
[%{label: nil, key: :actions, sortable: false}]
|
||||
end
|
||||
|
||||
columns =
|
||||
if show_used do
|
||||
[%{label: gettext("Used up on"), key: :used_up_on} | columns]
|
||||
else
|
||||
columns
|
||||
end
|
||||
|
||||
columns = [%{label: gettext("Added on"), key: :added_on} | columns]
|
||||
columns = [
|
||||
%{label: gettext("Purchased on"), key: :purchased_on},
|
||||
%{label: gettext("Last used on"), key: :used_up_on} | columns
|
||||
]
|
||||
|
||||
columns =
|
||||
if container == [] do
|
||||
@ -158,12 +151,12 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
defp get_value_for_key(:price_paid, %{price_paid: price_paid}, _additional_data),
|
||||
do: gettext("$%{amount}", amount: price_paid |> :erlang.float_to_binary(decimals: 2))
|
||||
|
||||
defp get_value_for_key(:added_on, %{inserted_at: inserted_at}, _additional_data) do
|
||||
assigns = %{inserted_at: inserted_at}
|
||||
defp get_value_for_key(:purchased_on, %{purchased_on: purchased_on}, _additional_data) do
|
||||
assigns = %{purchased_on: purchased_on}
|
||||
|
||||
{inserted_at,
|
||||
{purchased_on,
|
||||
~H"""
|
||||
<%= @inserted_at |> display_datetime() %>
|
||||
<%= @purchased_on |> display_date() %>
|
||||
"""}
|
||||
end
|
||||
|
||||
@ -178,7 +171,11 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
|
||||
{last_shot_group_date,
|
||||
~H"""
|
||||
<%= @last_shot_group_date |> display_date() %>
|
||||
<%= if @last_shot_group_date do %>
|
||||
<%= @last_shot_group_date |> display_date() %>
|
||||
<% else %>
|
||||
<%= gettext("Never used") %>
|
||||
<% end %>
|
||||
"""}
|
||||
end
|
||||
|
||||
|
@ -38,6 +38,14 @@
|
||||
) %>
|
||||
<%= error_tag(f, :price_paid, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :purchased_on, gettext("Purchased on"), class: "title text-lg text-primary-600") %>
|
||||
<%= date_input(f, :purchased_on,
|
||||
class: "input input-primary col-span-2",
|
||||
phx_update: "ignore",
|
||||
value: @changeset |> Changeset.get_field(:purchased_on) || Date.utc_today()
|
||||
) %>
|
||||
<%= error_tag(f, :purchased_on, "col-span-3 text-center") %>
|
||||
|
||||
<%= label(f, :notes, gettext("Notes"), class: "title text-lg text-primary-600") %>
|
||||
<%= textarea(f, :notes,
|
||||
class: "text-center col-span-2 input input-primary",
|
||||
|
@ -55,7 +55,6 @@
|
||||
id="ammo-group-index-table"
|
||||
ammo_groups={@ammo_groups}
|
||||
current_user={@current_user}
|
||||
show_used={@show_used}
|
||||
>
|
||||
<:ammo_type :let={%{name: ammo_type_name} = ammo_type}>
|
||||
<.link navigate={Routes.ammo_type_show_path(Endpoint, :show, ammo_type)} class="link">
|
||||
|
@ -27,8 +27,8 @@
|
||||
<% end %>
|
||||
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Added on:") %>
|
||||
<%= @ammo_group.inserted_at |> display_datetime() %>
|
||||
<%= gettext("Purchased on:") %>
|
||||
<%= @ammo_group.purchased_on |> display_date() %>
|
||||
</span>
|
||||
|
||||
<%= if @ammo_group.price_paid do %>
|
||||
|
@ -173,7 +173,6 @@
|
||||
id="ammo-type-show-table"
|
||||
ammo_groups={@ammo_groups}
|
||||
current_user={@current_user}
|
||||
show_used={@show_used}
|
||||
>
|
||||
<:container :let={%{container: %{name: container_name} = container}}>
|
||||
<.link
|
||||
|
@ -125,7 +125,6 @@
|
||||
id="ammo-type-show-table"
|
||||
ammo_groups={@ammo_groups}
|
||||
current_user={@current_user}
|
||||
show_used={@show_used}
|
||||
>
|
||||
<:ammo_type :let={%{name: ammo_type_name} = ammo_type}>
|
||||
<.link navigate={Routes.ammo_type_show_path(Endpoint, :show, ammo_type)} class="link">
|
||||
|
Reference in New Issue
Block a user