-- Ubigeo de sucursal para XML SUNAT

SET @ubigeo_sucursal_exists := (
    SELECT COUNT(*)
    FROM information_schema.columns
    WHERE table_schema = DATABASE()
      AND table_name = 'empresa_sucursales'
      AND column_name = 'ubigeo'
);

SET @sql_ubigeo_sucursal := IF(
    @ubigeo_sucursal_exists = 0,
    'ALTER TABLE empresa_sucursales ADD COLUMN ubigeo CHAR(6) NULL AFTER telefono',
    'SELECT 1'
);
PREPARE stmt_ubigeo_sucursal FROM @sql_ubigeo_sucursal;
EXECUTE stmt_ubigeo_sucursal;
DEALLOCATE PREPARE stmt_ubigeo_sucursal;
