-- Patch: Retenciones de Impuestos en Pagos a Proveedores
-- Añade withholding_amount y withholding_account_id a la tabla public.purchases_payments

ALTER TABLE public.purchases_payments 
ADD COLUMN IF NOT EXISTS withholding_amount NUMERIC(18, 4) NOT NULL DEFAULT 0.0;

ALTER TABLE public.purchases_payments 
ADD COLUMN IF NOT EXISTS withholding_account_id UUID NULL 
REFERENCES public.chart_accounts(id) ON DELETE RESTRICT;

-- Crear índice para mejorar consultas por cuenta de retención
CREATE INDEX IF NOT EXISTS idx_purchases_payments_withholding_account 
ON public.purchases_payments(withholding_account_id);
