CREATE TABLE tblpayoutdetails (
id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'Unique identifier for each payout detail',
tenant_id BIGINT UNSIGNED  COMMENT 'Identifier for the tenant',
payout_id varchar(255) COMMENT 'Reference to tblpayoutrecords(source_payout_id)',
payment_id varchar(255) COMMENT 'Identifier for the payment',
type varchar(50) COMMENT 'Payout entry type',
currency VARCHAR(20) COMMENT 'Currency of the payout',
fee_amount DECIMAL(15,2) COMMENT 'Amount of fees deducted',
net_amount DECIMAL(15,2) COMMENT 'Net amount after deductions',
gross_amount DECIMAL(15,2) COMMENT 'Gross amount before deductions',
additional_data JSON DEFAULT NULL COMMENT 'Additional data in JSON format',
) COMMENT 'Table to store payout details';

ALTER TABLE tblpayoutdetails
ADD CONSTRAINT fk_payoutdetails_tenant_id
FOREIGN KEY (tenant_id)
REFERENCES tbltenants(id)
ON DELETE CASCADE
ON UPDATE CASCADE;
CREATE INDEX tenant_id ON tblpayoutdetails (tenant_id);
CREATE INDEX payout_id ON tblpayoutdetails (payout_id);
CREATE INDEX payment_id ON tblpayoutdetails (payment_id);