-- Patch: Retenciones de Impuestos en Cobros de Clientes
-- Añade withholding_amount y withholding_account_id a la tabla public.payment_receives

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

ALTER TABLE public.payment_receives 
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_payment_receives_withholding_account 
ON public.payment_receives(withholding_account_id);
