defmodule DaProductApp.Repo.Migrations.CreatePayoutBatches do use Ecto.Migration @moduledoc """ Aggregated payout batches sent to Mercury Settlement Bank after Finance Team 2-level approval of the Settlement MIS. Each approved settlement_mis generates one payout_batch. The encrypted payout file is generated at this stage and transmitted to the bank via API or SFTP per the agreed format (see ShukriaPayout sample). Also handles re-payout batches for rejected payout_items. """ def change do create table(:payout_batches) do add :settlement_mis_id, :bigint, comment: "FK settlement_mis.id — NULL for re-payout batches" add :payout_date, :date, null: false add :batch_type, :string, size: 20, null: false, default: "regular", comment: "regular | re_payout (for rejected payment re-initiation)" add :total_merchants, :integer, default: 0 add :total_items, :integer, default: 0 add :total_amount, :decimal, precision: 14, scale: 2, default: 0 add :currency, :string, size: 5, default: "AED" # File generation add :file_path, :string, size: 500, comment: "Path to encrypted payout file" add :file_name, :string, size: 255 add :encryption_method, :string, size: 20, comment: "AES256 | PGP — per bank agreement" # Transmission add :transmission_method, :string, size: 10, comment: "API | SFTP — per bank agreement" add :status, :string, size: 20, null: false, default: "generated", comment: "generated | transmitted | confirmed | partial_reject | failed" add :transmitted_at, :naive_datetime add :transmission_reference, :string, size: 100, comment: "Reference returned by bank on submission" # Confirmation add :confirmed_at, :naive_datetime add :confirmed_item_count, :integer add :rejected_item_count, :integer add :inserted_at, :naive_datetime, null: false add :updated_at, :naive_datetime, null: false end create index(:payout_batches, [:payout_date]) create index(:payout_batches, [:status]) create index(:payout_batches, [:settlement_mis_id]) create index(:payout_batches, [:batch_type]) end end