ALTER TABLE finance_accounts_receivable
    ADD COLUMN counterparty_id INT UNSIGNED NULL AFTER lead_id,
    ADD CONSTRAINT fk_finance_ar_counterparty FOREIGN KEY (counterparty_id) REFERENCES finance_counterparties (id) ON DELETE SET NULL,
    ADD INDEX idx_finance_ar_counterparty (counterparty_id);

ALTER TABLE finance_accounts_payable
    ADD COLUMN counterparty_id INT UNSIGNED NULL AFTER loan_proposal_id,
    ADD CONSTRAINT fk_finance_ap_counterparty FOREIGN KEY (counterparty_id) REFERENCES finance_counterparties (id) ON DELETE SET NULL,
    ADD INDEX idx_finance_ap_counterparty (counterparty_id);
