# Module de Gestion des Clients ## 📋 Vue d'ensemble Le module de gestion des clients permet de centraliser toutes les informations relatives aux clients de NOVALINK. Il offre une interface complĂšte pour crĂ©er, modifier, consulter et supprimer des clients. ## 🎯 FonctionnalitĂ©s ### 1. Liste des Clients (`/clients`) - **Affichage** : Tableau avec colonnes : Client, Contact, Localisation, Sites, Incidents, Statut - **Recherche** : Par nom, email ou tĂ©lĂ©phone - **Filtres** : Actifs / Inactifs / Tous - **Actions** : Voir, Modifier, Supprimer (admin uniquement) - **Design** : Avatar circulaire avec initiale, badges pour compteurs ### 2. CrĂ©ation de Client (`/clients/create`) - **Champs obligatoires** : - Nom du client - **Champs optionnels** : - Email - TĂ©lĂ©phone - Adresse complĂšte - Ville - Pays (CĂŽte d'Ivoire par dĂ©faut) - Personne de contact - TĂ©lĂ©phone de contact - Notes internes - Statut (Actif par dĂ©faut) - **Validation** : HTML5 + Bootstrap validation - **Layout** : 2 colonnes (8+4) avec carte d'aide ### 3. DĂ©tail Client (`/clients/show?id=X`) - **Hero Section** : Nom, statut, avatar avec dĂ©gradĂ© violet - **KPI Cards** : 4 cartes (Incidents Total, Ouverts, RĂ©solus, Sites) - **Informations** : Email, tĂ©lĂ©phone, adresse, contact - **Sites** : Liste des locations avec compteur incidents - **Incidents rĂ©cents** : 10 derniers incidents avec lien vers dĂ©tail - **Actions rapides** : DĂ©clarer incident, Ajouter site, Modifier, Activer/DĂ©sactiver, Supprimer ### 4. Modification Client (`/clients/edit?id=X`) - **Formulaire** : Identique Ă  crĂ©ation avec valeurs prĂ©-remplies - **MĂ©tadonnĂ©es** : Date crĂ©ation, derniĂšre modification - **Validation** : Identique Ă  crĂ©ation ### 5. Suppression Client (`/clients/delete`) - **Protection** : Impossible si incidents associĂ©s - **Cascade** : Supprime les locations du client - **Modal** : Confirmation avec nom du client - **Restriction** : Admin uniquement ### 6. Activation/DĂ©sactivation (`/clients/toggle`) - **Fonction** : Bascule le statut actif/inactif - **Impact** : Clients inactifs n'apparaissent pas dans les sĂ©lections - **RĂŽles** : Admin et Agent ## đŸ—„ïž Structure de la Base de DonnĂ©es ### Table `clients` ```sql CREATE TABLE `clients` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `email` VARCHAR(255) DEFAULT NULL, `phone` VARCHAR(50) DEFAULT NULL, `address` TEXT DEFAULT NULL, `city` VARCHAR(100) DEFAULT NULL, `country` VARCHAR(100) DEFAULT 'CĂŽte d''Ivoire', `contact_person` VARCHAR(255) DEFAULT NULL, `contact_phone` VARCHAR(50) DEFAULT NULL, `notes` TEXT DEFAULT NULL, `active` TINYINT(1) NOT NULL DEFAULT 1, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_name` (`name`), KEY `idx_active` (`active`), KEY `idx_email` (`email`), KEY `idx_city` (`city`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ``` ### Relations - **locations** : `locations.client_id` → `clients.id` (ON DELETE RESTRICT) - **incidents** : `incidents.client_id` → `clients.id` (ON DELETE RESTRICT) ## 🔐 Permissions | Action | Admin | Manager | Superviseur | Agent | Technicien | |--------|-------|---------|-------------|-------|------------| | Voir liste | ✅ | ✅ | ✅ | ✅ | ✅ | | Voir dĂ©tail | ✅ | ✅ | ✅ | ✅ | ✅ | | CrĂ©er | ✅ | ❌ | ❌ | ✅ | ❌ | | Modifier | ✅ | ❌ | ❌ | ✅ | ❌ | | Activer/DĂ©sactiver | ✅ | ❌ | ❌ | ✅ | ❌ | | Supprimer | ✅ | ❌ | ❌ | ❌ | ❌ | ## 🎹 Design ### Palette de Couleurs - **Hero** : DĂ©gradĂ© violet (#667eea → #764ba2) - **Avatar** : Cercle bleu primaire avec initiale blanche - **Badges** : - Actif : `bg-success` (vert) - Inactif : `bg-secondary` (gris) - Incidents : `bg-warning` (orange) si > 0, sinon `bg-secondary` - Sites : `bg-info` (bleu) ### IcĂŽnes (Font Awesome 6.5.2) - Client : `fa-building` - Email : `fa-envelope` - TĂ©lĂ©phone : `fa-phone` - Mobile : `fa-mobile` - Adresse : `fa-map-marker-alt` - Contact : `fa-user-tie` - Notes : `fa-sticky-note` ## 📁 Architecture des Fichiers ``` app/ ├── Controllers/ │ └── ClientsController.php # ContrĂŽleur principal (CRUD + toggle) └── Views/ └── clients/ ├── index.php # Liste des clients ├── create.php # Formulaire crĂ©ation ├── edit.php # Formulaire modification └── show.php # DĂ©tail client database/ └── create_clients_table.sql # Script crĂ©ation table + demo data public/ └── index.php # Routes (lignes 103-110) ``` ## đŸ›Łïž Routes ```php // Module Clients $router->get('/clients', [ClientsController::class, 'index']); $router->get('/clients/create', [ClientsController::class, 'create']); $router->post('/clients/create', [ClientsController::class, 'store']); $router->get('/clients/show', [ClientsController::class, 'show']); $router->get('/clients/edit', [ClientsController::class, 'edit']); $router->post('/clients/edit', [ClientsController::class, 'update']); $router->post('/clients/delete', [ClientsController::class, 'delete']); $router->post('/clients/toggle', [ClientsController::class, 'toggle']); ``` ## 🚀 Installation ### 1. ExĂ©cuter le Script SQL ```bash # Via MySQL CLI mysql -u root -p bd_insuite_backbone < database/create_clients_table.sql # Ou via phpMyAdmin : importer le fichier ``` ### 2. VĂ©rifier les Routes Les routes sont dĂ©jĂ  configurĂ©es dans `public/index.php` (lignes 103-110) ### 3. VĂ©rifier le Menu Le menu "Clients" est dĂ©jĂ  ajoutĂ© dans `app/Views/layouts/main.php` (aprĂšs Incidents) ### 4. Tester l'AccĂšs ``` http://localhost/Insuite_backbones/public/clients ``` ## đŸ§Ș Tests ### ScĂ©narios de Test 1. **CrĂ©ation basique** - Remplir uniquement le nom - VĂ©rifier crĂ©ation rĂ©ussie - VĂ©rifier redirection vers liste avec message succĂšs 2. **CrĂ©ation complĂšte** - Remplir tous les champs - VĂ©rifier sauvegarde correcte - VĂ©rifier affichage dans dĂ©tail 3. **Recherche** - Rechercher par nom partiel - Rechercher par email - Rechercher par tĂ©lĂ©phone - VĂ©rifier rĂ©sultats filtrĂ©s 4. **Filtres** - Filtrer clients actifs - Filtrer clients inactifs - VĂ©rifier compteur 5. **Modification** - Modifier nom - Modifier statut - VĂ©rifier mise Ă  jour `updated_at` 6. **Suppression** - Tenter supprimer client avec incidents → Erreur - Supprimer client sans incidents → SuccĂšs - VĂ©rifier cascade sur locations 7. **IntĂ©gration Incidents** - CrĂ©er incident pour client - VĂ©rifier compteur dans liste - VĂ©rifier affichage dans dĂ©tail client 8. **Permissions** - Tester accĂšs admin → OK - Tester accĂšs agent → OK (crĂ©ation/modif) - Tester accĂšs technicien → Liste/DĂ©tail OK, crĂ©ation KO ## 📊 Statistiques Disponibles Dans la page dĂ©tail client : - **Total incidents** : Nombre total d'incidents du client - **Incidents ouverts** : Status IN ('open', 'ouvert', 'nouveau') - **Incidents rĂ©solus** : Status IN ('closed', 'clos', 'cloture') - **Sites gĂ©rĂ©s** : Nombre de locations ## 🔄 IntĂ©grations ### Avec Module Incidents - Lien "DĂ©clarer incident" prĂ©-remplit `client_id` - Liste incidents filtrĂ©e par client - Compteur incidents dans liste/dĂ©tail ### Avec Module Locations - Lien "Ajouter site" prĂ©-remplit `client_id` - Liste sites avec compteur incidents - Foreign key cascade ## 📝 Messages d'Erreur | Code | Message | Cause | |------|---------|-------| | `name_required` | Le nom du client est obligatoire | Nom vide | | `database` | Une erreur est survenue | Erreur SQL | | `has_incidents` | Impossible de supprimer : X incident(s) associĂ©(s) | Tentative suppression avec incidents | ## 📝 Messages de SuccĂšs | Code | Message | |------|---------| | `created` | Client créé avec succĂšs ! | | `updated` | Client mis Ă  jour avec succĂšs ! | | `deleted` | Client supprimĂ© avec succĂšs ! | | `toggled` | Statut du client modifiĂ© avec succĂšs ! | ## 🎯 Bonnes Pratiques 1. **Validation** - Toujours valider le nom (obligatoire) - Valider format email si fourni - Sanitizer les entrĂ©es utilisateur 2. **SĂ©curitĂ©** - VĂ©rifier permissions avant actions sensibles - Protection CSRF implicite (session) - Échappement HTML dans vues 3. **UX** - Messages de feedback clairs - Redirections logiques aprĂšs actions - Confirmation avant suppression 4. **Performance** - Indexes sur `name`, `email`, `city`, `active` - RequĂȘtes avec LEFT JOIN pour stats - Pagination si > 100 clients (Ă  implĂ©menter si nĂ©cessaire) ## 🐛 DĂ©pannage ### Erreur "Table 'clients' doesn't exist" → ExĂ©cuter `database/create_clients_table.sql` ### Erreur "Foreign key constraint fails" → VĂ©rifier que tables `locations` et `incidents` existent ### Menu "Clients" n'apparaĂźt pas → Vider cache navigateur, vĂ©rifier fichier `layouts/main.php` ### Page blanche sur `/clients` → VĂ©rifier logs Apache/PHP, vĂ©rifier namespace `ClientsController` ## 🔼 Évolutions Futures - [ ] Export CSV/Excel de la liste clients - [ ] Import en masse via CSV - [ ] Historique des modifications - [ ] Documents attachĂ©s (contrats, devis) - [ ] Gestion multi-contacts - [ ] Facturation intĂ©grĂ©e - [ ] Pagination de la liste (si > 100) - [ ] Tri personnalisable des colonnes - [ ] Dashboard client (mĂ©triques SLA, satisfaction) ## 📞 Support Pour toute question sur le module clients : 1. Consulter cette documentation 2. VĂ©rifier les logs : `storage/logs/` 3. Contacter l'Ă©quipe de dĂ©veloppement --- **Date de crĂ©ation** : 15 dĂ©cembre 2025 **Version** : 1.0.0 **Auteur** : GitHub Copilot **Projet** : NOVALINK - Insuite Backbones