Skip to content

Instantly share code, notes, and snippets.

View noelworden's full-sized avatar

Noel Worden noelworden

View GitHub Profile
defmodule Finance.SourceFiles.Data.Screen do
import Ecto.Changeset
def validate_decimal(changeset, fields) do
%{errors: errors} = changeset
fields_not_decimal =
for field <- fields,
not_decimal?(changeset, field),
do: field
rename(
table("raw_example_product_detail"),
:first_field_2,
to: :first_field
)
rename(
table("raw_example_product_detail"),
:second_field_2,
to: :second_field
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]
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)
case Decimal.round(Decimal.sub(total_merch_rev, total_group_costs), 2) ==
Decimal.round(net_revenue_shared, 2) do
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,
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"
@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