defmodule PlatformCore.Repo.Migrations.AddMarginContributionSettlementMisItems do use Ecto.Migration @moduledoc """ Phase 1.5: Add margin_contribution to settlement_mis_items. margin_contribution = total_mdr_amount - total_interchange_fee This is Mercury's gross margin on a per-group basis: - total_mdr_amount: what Mercury charged the merchant - total_interchange_fee: what Mercury paid to the card scheme - margin_contribution: Mercury's gross margin (difference) Interchange does NOT reduce merchant payout — it is Mercury's internal cost. The margin column is purely for Finance team reporting and profitability analysis. """ def change do alter table(:settlement_mis_items) do add :margin_contribution, :decimal, precision: 18, scale: 4, null: true, comment: "Mercury gross margin = total_mdr_amount - total_interchange_fee" end end end