defmodule DaProductApp.Repo.Migrations.CreateMerchantAdjustments do use Ecto.Migration @moduledoc """ Single and bulk debit/credit adjustments applied at merchant (MID) level. Applied to Settlement MIS before payout generation. Supports: - Chargeback recovery - MDR adjustments - Credit / Debit adjustments (per MPR terms) - Other fees as per MPR Can be entered via: 1. Manual single-entry form on Finance Team interface 2. Bulk CSV upload (format to be defined with Finance team) Status lifecycle: pending → applied (linked to a settlement_mis) | cancelled """ def change do create table(:merchant_adjustments) do add :merchant_mid, :string, size: 25, null: false add :merchant_name, :string, size: 200, comment: "Denormalized at creation time" add :adjustment_date, :date, null: false add :debit_credit, :string, size: 6, null: false, comment: "DEBIT | CREDIT" add :amount, :decimal, precision: 12, scale: 2, null: false add :currency, :string, size: 5, default: "AED" add :adjustment_type, :string, size: 50, null: false, comment: "chargeback_recovery | mdr_adjustment | credit_adjustment | debit_adjustment | transaction_fee | other_fee" add :description, :text, comment: "Memo / reason entered by Finance team" # Linking to MIS when applied add :settlement_mis_id, :bigint, comment: "FK settlement_mis.id — NULL until applied to a MIS" add :status, :string, size: 20, null: false, default: "pending", comment: "pending | applied | cancelled" add :applied_at, :naive_datetime add :cancelled_at, :naive_datetime add :cancel_reason, :text # Audit add :created_by, :bigint, null: false, comment: "users.id of Finance team member" add :updated_by, :bigint add :inserted_at, :naive_datetime, null: false add :updated_at, :naive_datetime, null: false end create index(:merchant_adjustments, [:merchant_mid]) create index(:merchant_adjustments, [:adjustment_date]) create index(:merchant_adjustments, [:status]) create index(:merchant_adjustments, [:settlement_mis_id]) create index(:merchant_adjustments, [:adjustment_type]) end end