-- ========================================
-- 🎯 MISE À JOUR FINALE COMPANY_INFO
-- ========================================
-- Nouvelles informations officielles GaultMillau Maroc
-- À exécuter sur : crmgaujdev ET crmgaujprod
-- ========================================

UPDATE `company_info` SET
    `company_name` = 'GAULTMILLAU',
    `company_legal_form` = 'SAS',
    `company_capital` = '90.000 Dhs',
    `company_ice` = '003770977000059',
    `company_rc` = '684903',
    `company_if` = '68298651',
    `company_address` = '81, Bd Moulay Hassan I, 6eme Etg',
    `company_city` = 'Casablanca',
    `company_country` = 'MAROC',
    `company_phone` = '06.64.08.21.88',
    `company_email` = 'contact@gaultmillau.ma',
    `company_rib` = '225780039137500651010365',
    `company_website` = 'www.gaultmillau.ma',
    `footer_text` = 'GAULTMILLAU SAS - RC : 684903 - ICE : 003770977000059 - IF : 68298651 - Patente : 35556374',
    `updated_at` = CURRENT_TIMESTAMP
WHERE `id` = 1;

-- Ajouter la colonne Patente si elle n'existe pas
SET @col_patente = (SELECT COUNT(*) FROM information_schema.COLUMNS 
    WHERE TABLE_SCHEMA = DATABASE() 
    AND TABLE_NAME = 'company_info' 
    AND COLUMN_NAME = 'company_patente');

SET @sql_patente = IF(@col_patente = 0, 
    'ALTER TABLE `company_info` ADD COLUMN `company_patente` VARCHAR(50) DEFAULT "35556374" COMMENT "Numéro de Patente"',
    'SELECT "Column company_patente already exists" AS message');
PREPARE stmt FROM @sql_patente;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- Ajouter la colonne Compte bancaire si elle n'existe pas
SET @col_compte = (SELECT COUNT(*) FROM information_schema.COLUMNS 
    WHERE TABLE_SCHEMA = DATABASE() 
    AND TABLE_NAME = 'company_info' 
    AND COLUMN_NAME = 'company_compte');

SET @sql_compte = IF(@col_compte = 0, 
    'ALTER TABLE `company_info` ADD COLUMN `company_compte` VARCHAR(50) DEFAULT "0391375006510103" COMMENT "Numéro de Compte"',
    'SELECT "Column company_compte already exists" AS message');
PREPARE stmt FROM @sql_compte;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- Mettre à jour avec les nouvelles valeurs
UPDATE `company_info` SET
    `company_patente` = '35556374',
    `company_compte` = '0391375006510103'
WHERE `id` = 1;

-- ========================================
-- ✅ VÉRIFICATION
-- ========================================
SELECT * FROM `company_info` WHERE `id` = 1;

