show average cost per round for ammo types
This commit is contained in:
		| @@ -14,11 +14,14 @@ defmodule CanneryWeb.AmmoTypeLive.Show do | ||||
|  | ||||
|   @impl true | ||||
|   def handle_params(%{"id" => id}, _, socket) do | ||||
|     ammo_type = Ammo.get_ammo_type!(id) |> Repo.preload(:ammo_groups) | ||||
|  | ||||
|     socket = | ||||
|       socket | ||||
|       |> assign( | ||||
|         page_title: page_title(socket.assigns.live_action), | ||||
|         ammo_type: Ammo.get_ammo_type!(id) |> Repo.preload(:ammo_groups) | ||||
|         ammo_type: ammo_type, | ||||
|         avg_cost_per_round: ammo_type |> Ammo.get_average_cost_for_ammo_type!() | ||||
|       ) | ||||
|  | ||||
|     {:noreply, socket} | ||||
|   | ||||
| @@ -40,7 +40,7 @@ | ||||
|         ] do %> | ||||
|       <%= if @ammo_type |> Map.get(field) do %> | ||||
|         <h3 class="mb-2 sm:mr-4 title text-lg"> | ||||
|           <%= field |> humanize() %> : | ||||
|           <%= field |> humanize() %>: | ||||
|         </h3> | ||||
|  | ||||
|         <span class="mb-4 sm:mb-2 text-primary-600"> | ||||
| @@ -57,7 +57,7 @@ | ||||
|           :corrosive | ||||
|         ] do %> | ||||
|       <h3 class="mb-2 sm:mr-4 title text-lg"> | ||||
|         <%= field |> humanize() %> : | ||||
|         <%= field |> humanize() %>: | ||||
|       </h3> | ||||
|  | ||||
|       <span class="mb-4 sm:mb-2 text-primary-600"> | ||||
| @@ -68,7 +68,7 @@ | ||||
|     <%= for field <- [:manufacturer, :sku] do %> | ||||
|       <%= if @ammo_type |> Map.get(field) do %> | ||||
|         <h3 class="mb-2 sm:mr-4 title text-lg"> | ||||
|           <%= field |> humanize() %> : | ||||
|           <%= field |> humanize() %>: | ||||
|         </h3> | ||||
|  | ||||
|         <span class="mb-4 sm:mb-2 text-primary-600"> | ||||
| @@ -76,6 +76,16 @@ | ||||
|         </span> | ||||
|       <% end %> | ||||
|     <% end %> | ||||
|  | ||||
|     <%= if @avg_cost_per_round do %> | ||||
|       <h3 class="mb-2 sm:mr-4 title text-lg"> | ||||
|         Average Price paid: | ||||
|       </h3> | ||||
|  | ||||
|       <span class="mb-4 sm:mb-2 text-primary-600"> | ||||
|         <%= @avg_cost_per_round |> :erlang.float_to_binary(decimals: 2) %> | ||||
|       </span> | ||||
|     <% end %> | ||||
|   </div> | ||||
|  | ||||
|   <hr class="hr"> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user