-- Logo por empresa y sucursal con fallback en impresion

SET @logo_empresa_exists := (
    SELECT COUNT(*)
    FROM information_schema.columns
    WHERE table_schema = DATABASE()
      AND table_name = 'empresas'
      AND column_name = 'logo'
);

SET @sql_logo_empresa := IF(
    @logo_empresa_exists = 0,
    'ALTER TABLE empresas ADD COLUMN logo VARCHAR(500) NULL AFTER nombre_comercial',
    'SELECT 1'
);
PREPARE stmt_logo_empresa FROM @sql_logo_empresa;
EXECUTE stmt_logo_empresa;
DEALLOCATE PREPARE stmt_logo_empresa;

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

SET @sql_logo_sucursal := IF(
    @logo_sucursal_exists = 0,
    'ALTER TABLE empresa_sucursales ADD COLUMN logo VARCHAR(500) NULL AFTER telefono',
    'SELECT 1'
);
PREPARE stmt_logo_sucursal FROM @sql_logo_sucursal;
EXECUTE stmt_logo_sucursal;
DEALLOCATE PREPARE stmt_logo_sucursal;
