Skip to content

Instantly share code, notes, and snippets.

View noelworden's full-sized avatar

Noel Worden noelworden

View GitHub Profile
Enum.zip(
[:first_field_2, :second_field_2, :third_field_2],
[:first_field, :second_field, :third_field]
)
|> Enum.each(fn {key, value} -> rename(table("raw_nmi_product_detail"), key, to: value) end)
[first_field_2: :first_field, second_field_2: :second_field, third_field_2: :third_field]
case Decimal.round(Decimal.sub(total_merch_rev, total_group_costs), 2) ==
Decimal.round(Decimal.cast(0), 2) do
true ->
case net_revenue_shared == Decimal.cast(0) do
true ->
changeset
false ->
add_error(
changeset,
round(sub(total_merch_rev, total_group_costs), 2) == 0.00 && net_revenue_shared == 0 ||
round(sub(total_merch_rev, total_group_costs), 2) == round(net_revenue_shared, 2)
@zero_with_decimal round(cast(0), 2)
rev_minus_cost = round(sub(total_merch_rev, total_group_costs), 2)
net_rev = round(net_revenue_shared, 2)
net_rev_valid =
Enum.any?([
rev_minus_cost == @zero_with_decimal && net_rev == @zero_with_decimal,
rev_minus_cost == net_rev
])
case Decimal.round(Decimal.sub(total_merch_rev, total_group_costs), 2) ==
Decimal.round(Decimal.cast(0), 2) do
true ->
case net_revenue_shared == Decimal.cast(0) do
case Decimal.round(Decimal.sub(total_merch_rev, total_group_costs), 2) ==
Decimal.round(net_revenue_shared, 2) do
rev_minus_cost = round(sub(total_merch_rev, total_group_costs), 2)
net_rev = round(net_revenue_shared, 2)
if rev_minus_cost == net_rev do
changeset
else
add_error(
changeset,
:net_revenue_shared,
"must be total_merch_rev minus total_group costs"
defmodule FinanceWeb.ErrorHelpers do
@moduledoc """
Conveniences for translating and building error messages.
"""
use Phoenix.HTML
@doc """
Generates tag for inlined form input errors.
"""
Enum.map(error.opts, fn {key, value} ->
{String.to_existing_atom(key), value}
end)