feat: Version 3.5.2 - Configuration Stripe et gestion des immeubles
- Configuration complète Stripe pour les 3 environnements (DEV/REC/PROD) * DEV: Clés TEST Pierre (mode test) * REC: Clés TEST Client (mode test) * PROD: Clés LIVE Client (mode live) - Ajout de la gestion des bases de données immeubles/bâtiments * Configuration buildings_database pour DEV/REC/PROD * Service BuildingService pour enrichissement des adresses - Optimisations pages et améliorations ergonomie - Mises à jour des dépendances Composer - Nettoyage des fichiers obsolètes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
495
api/docs/EVENTS-LOG.md
Normal file
495
api/docs/EVENTS-LOG.md
Normal file
@@ -0,0 +1,495 @@
|
||||
# Système de logs d'événements JSONL
|
||||
|
||||
## 📋 Vue d'ensemble
|
||||
|
||||
Système de traçabilité des événements métier pour statistiques et audit, stocké en fichiers JSONL (JSON Lines) sans impact sur la base de données principale.
|
||||
|
||||
**Créé le :** 26 Octobre 2025
|
||||
**Rétention :** 15 mois
|
||||
**Format :** JSONL (une ligne = un événement JSON)
|
||||
|
||||
## 🎯 Objectifs
|
||||
|
||||
### Événements tracés
|
||||
|
||||
**Authentification**
|
||||
- Connexions réussies (user_id, entity_id, plateforme, IP)
|
||||
- Tentatives échouées (username, raison, IP, nb tentatives)
|
||||
|
||||
**CRUD métier**
|
||||
- **Passages** : création, modification, suppression
|
||||
- **Secteurs** : création, modification, suppression
|
||||
- **Membres** : création, modification, suppression
|
||||
- **Entités** : création, modification, suppression
|
||||
|
||||
### Cas d'usage
|
||||
|
||||
**1. Admin entité**
|
||||
- Stats de son entité : connexions, passages, secteurs sur 1 jour/semaine/mois
|
||||
- Activité des membres de l'entité
|
||||
|
||||
**2. Super-admin**
|
||||
- Stats globales : tous les passages modifiés sur 2 semaines
|
||||
- Événements toutes entités sur période donnée
|
||||
- Détection d'anomalies
|
||||
|
||||
## 📁 Architecture de stockage
|
||||
|
||||
### Structure des répertoires
|
||||
|
||||
```
|
||||
/logs/events/
|
||||
├── 2025-10-26.jsonl # Fichier du jour (écriture append)
|
||||
├── 2025-10-25.jsonl
|
||||
├── 2025-10-24.jsonl
|
||||
├── 2025-09-30.jsonl
|
||||
├── 2025-09-29.jsonl.gz # Compression auto après 30 jours
|
||||
└── archive/
|
||||
├── 2025-09.jsonl.gz # Archive mensuelle
|
||||
├── 2025-08.jsonl.gz
|
||||
└── 2024-07.jsonl.gz # Supprimé auto après 15 mois
|
||||
```
|
||||
|
||||
### Cycle de vie des fichiers
|
||||
|
||||
| Âge | État | Taille estimée | Accès |
|
||||
|-----|------|----------------|-------|
|
||||
| 0-30 jours | `.jsonl` non compressé | 1-10 MB/jour | Lecture directe rapide |
|
||||
| 30 jours-15 mois | `.jsonl.gz` compressé | ~100 KB/jour | Décompression à la volée |
|
||||
| > 15 mois | Supprimé automatiquement | - | - |
|
||||
|
||||
### Rotation et rétention
|
||||
|
||||
**CRON mensuel** : `scripts/cron/rotate_event_logs.php`
|
||||
- **Fréquence** : 1er du mois à 3h00
|
||||
- **Actions** :
|
||||
1. Compresser les fichiers `.jsonl` de plus de 30 jours en `.jsonl.gz`
|
||||
2. Supprimer les fichiers `.jsonl.gz` de plus de 15 mois
|
||||
3. Logger le résumé de rotation
|
||||
|
||||
**Commande manuelle** :
|
||||
```bash
|
||||
php scripts/cron/rotate_event_logs.php
|
||||
```
|
||||
|
||||
## 📊 Format des événements
|
||||
|
||||
### Structure commune
|
||||
|
||||
Tous les événements partagent ces champs :
|
||||
|
||||
```json
|
||||
{
|
||||
"timestamp": "2025-10-26T14:32:15Z", // ISO 8601 UTC
|
||||
"event": "nom_evenement", // Type d'événement
|
||||
"user_id": 123, // ID utilisateur (si authentifié)
|
||||
"entity_id": 5, // ID entité (si applicable)
|
||||
"ip": "192.168.1.100", // IP client
|
||||
"platform": "ios|android|web", // Plateforme
|
||||
"app_version": "3.3.6" // Version app (mobile uniquement)
|
||||
}
|
||||
```
|
||||
|
||||
### Événements d'authentification
|
||||
|
||||
#### Login réussi
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T14:32:15Z","event":"login_success","user_id":123,"entity_id":5,"platform":"ios","app_version":"3.3.6","ip":"192.168.1.100","username":"user123"}
|
||||
```
|
||||
|
||||
#### Login échoué
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T14:35:22Z","event":"login_failed","username":"test","reason":"invalid_password","ip":"192.168.1.101","attempt":3,"platform":"web"}
|
||||
```
|
||||
|
||||
**Raisons possibles** : `invalid_password`, `user_not_found`, `account_inactive`, `blocked_ip`
|
||||
|
||||
#### Logout
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T16:45:00Z","event":"logout","user_id":123,"entity_id":5,"platform":"android","session_duration":7800}
|
||||
```
|
||||
|
||||
### Événements Passages
|
||||
|
||||
#### Création
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T14:40:10Z","event":"passage_created","passage_id":45678,"user_id":123,"entity_id":5,"operation_id":789,"sector_id":12,"amount":50.00,"payment_type":"cash","platform":"android"}
|
||||
```
|
||||
|
||||
#### Modification
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T14:42:05Z","event":"passage_updated","passage_id":45678,"user_id":123,"entity_id":5,"changes":{"amount":{"old":50.00,"new":75.00},"payment_type":{"old":"cash","new":"stripe"}},"platform":"ios"}
|
||||
```
|
||||
|
||||
#### Suppression
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T14:45:30Z","event":"passage_deleted","passage_id":45678,"user_id":123,"entity_id":5,"operation_id":789,"deleted_by":123,"soft_delete":true,"platform":"web"}
|
||||
```
|
||||
|
||||
### Événements Secteurs
|
||||
|
||||
#### Création
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:10:00Z","event":"sector_created","sector_id":456,"operation_id":789,"entity_id":5,"user_id":123,"sector_name":"Secteur A","platform":"web"}
|
||||
```
|
||||
|
||||
#### Modification
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:12:00Z","event":"sector_updated","sector_id":456,"operation_id":789,"entity_id":5,"user_id":123,"changes":{"sector_name":{"old":"Secteur A","new":"Secteur Alpha"}},"platform":"web"}
|
||||
```
|
||||
|
||||
#### Suppression
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:15:00Z","event":"sector_deleted","sector_id":456,"operation_id":789,"entity_id":5,"user_id":123,"deleted_by":123,"soft_delete":true,"platform":"web"}
|
||||
```
|
||||
|
||||
### Événements Membres (Users)
|
||||
|
||||
#### Création
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:20:00Z","event":"user_created","new_user_id":789,"entity_id":5,"created_by":123,"role_id":1,"username":"newuser","platform":"web"}
|
||||
```
|
||||
|
||||
#### Modification
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:25:00Z","event":"user_updated","user_id":789,"entity_id":5,"updated_by":123,"changes":{"role_id":{"old":1,"new":2},"encrypted_phone":true},"platform":"web"}
|
||||
```
|
||||
|
||||
**Note** : Les champs chiffrés sont indiqués par un booléen `true` sans exposer les valeurs
|
||||
|
||||
#### Suppression
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:30:00Z","event":"user_deleted","user_id":789,"entity_id":5,"deleted_by":123,"soft_delete":true,"platform":"web"}
|
||||
```
|
||||
|
||||
### Événements Entités
|
||||
|
||||
#### Création
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:35:00Z","event":"entity_created","entity_id":25,"created_by":1,"entity_type_id":1,"postal_code":"75001","platform":"web"}
|
||||
```
|
||||
|
||||
#### Modification
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:40:00Z","event":"entity_updated","entity_id":25,"user_id":123,"updated_by":123,"changes":{"encrypted_name":true,"encrypted_email":true,"chk_stripe":{"old":0,"new":1}},"platform":"web"}
|
||||
```
|
||||
|
||||
#### Suppression (rare)
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T15:45:00Z","event":"entity_deleted","entity_id":25,"deleted_by":1,"soft_delete":true,"reason":"duplicate","platform":"web"}
|
||||
```
|
||||
|
||||
### Événements Opérations
|
||||
|
||||
#### Création
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T16:00:00Z","event":"operation_created","operation_id":999,"entity_id":5,"created_by":123,"date_start":"2025-11-01","date_end":"2025-11-30","platform":"web"}
|
||||
```
|
||||
|
||||
#### Modification
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T16:05:00Z","event":"operation_updated","operation_id":999,"entity_id":5,"updated_by":123,"changes":{"date_end":{"old":"2025-11-30","new":"2025-12-15"},"chk_active":{"old":0,"new":1}},"platform":"web"}
|
||||
```
|
||||
|
||||
#### Suppression
|
||||
```jsonl
|
||||
{"timestamp":"2025-10-26T16:10:00Z","event":"operation_deleted","operation_id":999,"entity_id":5,"deleted_by":123,"soft_delete":true,"platform":"web"}
|
||||
```
|
||||
|
||||
## 🛠️ Implémentation
|
||||
|
||||
### Service EventLogService.php
|
||||
|
||||
**Emplacement** : `src/Services/EventLogService.php`
|
||||
|
||||
**Méthodes publiques** :
|
||||
```php
|
||||
EventLogService::logLoginSuccess($userId, $entityId, $username)
|
||||
EventLogService::logLoginFailed($username, $reason, $attempt)
|
||||
EventLogService::logLogout($userId, $entityId, $sessionDuration)
|
||||
|
||||
EventLogService::logPassageCreated($passageId, $operationId, $sectorId, $amount, $paymentType)
|
||||
EventLogService::logPassageUpdated($passageId, $changes)
|
||||
EventLogService::logPassageDeleted($passageId, $operationId, $softDelete)
|
||||
|
||||
EventLogService::logSectorCreated($sectorId, $operationId, $sectorName)
|
||||
EventLogService::logSectorUpdated($sectorId, $operationId, $changes)
|
||||
EventLogService::logSectorDeleted($sectorId, $operationId, $softDelete)
|
||||
|
||||
EventLogService::logUserCreated($newUserId, $entityId, $roleId, $username)
|
||||
EventLogService::logUserUpdated($userId, $changes)
|
||||
EventLogService::logUserDeleted($userId, $softDelete)
|
||||
|
||||
EventLogService::logEntityCreated($entityId, $entityTypeId, $postalCode)
|
||||
EventLogService::logEntityUpdated($entityId, $changes)
|
||||
EventLogService::logEntityDeleted($entityId, $reason)
|
||||
|
||||
EventLogService::logOperationCreated($operationId, $dateStart, $dateEnd)
|
||||
EventLogService::logOperationUpdated($operationId, $changes)
|
||||
EventLogService::logOperationDeleted($operationId, $softDelete)
|
||||
```
|
||||
|
||||
**Enrichissement automatique** :
|
||||
- `timestamp` : Généré automatiquement (UTC)
|
||||
- `user_id`, `entity_id` : Récupérés depuis `Session`
|
||||
- `ip` : Récupérée via `ClientDetector`
|
||||
- `platform` : Détecté via `ClientDetector` (ios/android/web)
|
||||
- `app_version` : Extrait du User-Agent pour mobile
|
||||
|
||||
### Intégration dans les Controllers
|
||||
|
||||
**Exemple dans PassageController** :
|
||||
```php
|
||||
public function createPassage(Request $request, Response $response): void {
|
||||
// ... validation et création ...
|
||||
|
||||
$passageId = $db->lastInsertId();
|
||||
|
||||
// Log de l'événement
|
||||
EventLogService::logPassageCreated(
|
||||
$passageId,
|
||||
$data['fk_operation'],
|
||||
$data['fk_sector'],
|
||||
$data['montant'],
|
||||
$data['fk_type_reglement']
|
||||
);
|
||||
|
||||
// ... suite du code ...
|
||||
}
|
||||
```
|
||||
|
||||
### Scripts d'analyse
|
||||
|
||||
#### 1. Stats entité
|
||||
|
||||
**Fichier** : `scripts/stats/entity_stats.php`
|
||||
|
||||
**Usage** :
|
||||
```bash
|
||||
# Stats entité 5 sur 7 derniers jours
|
||||
php scripts/stats/entity_stats.php --entity-id=5 --days=7
|
||||
|
||||
# Stats entité 5 entre deux dates
|
||||
php scripts/stats/entity_stats.php --entity-id=5 --from=2025-10-01 --to=2025-10-26
|
||||
|
||||
# Résultat JSON
|
||||
{
|
||||
"entity_id": 5,
|
||||
"period": {"from": "2025-10-20", "to": "2025-10-26"},
|
||||
"stats": {
|
||||
"logins": {"success": 45, "failed": 2},
|
||||
"passages": {"created": 120, "updated": 15, "deleted": 3},
|
||||
"sectors": {"created": 2, "updated": 8, "deleted": 0},
|
||||
"users": {"created": 1, "updated": 5, "deleted": 0}
|
||||
},
|
||||
"top_users": [
|
||||
{"user_id": 123, "actions": 85},
|
||||
{"user_id": 456, "actions": 42}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### 2. Stats globales super-admin
|
||||
|
||||
**Fichier** : `scripts/stats/global_stats.php`
|
||||
|
||||
**Usage** :
|
||||
```bash
|
||||
# Tous les passages modifiés sur 2 semaines
|
||||
php scripts/stats/global_stats.php --event=passage_updated --days=14
|
||||
|
||||
# Toutes les connexions échouées du mois
|
||||
php scripts/stats/global_stats.php --event=login_failed --month=2025-10
|
||||
|
||||
# Résultat JSON
|
||||
{
|
||||
"event": "passage_updated",
|
||||
"period": {"from": "2025-10-13", "to": "2025-10-26"},
|
||||
"total_events": 342,
|
||||
"by_entity": [
|
||||
{"entity_id": 5, "count": 120},
|
||||
{"entity_id": 12, "count": 85},
|
||||
{"entity_id": 18, "count": 67}
|
||||
],
|
||||
"by_day": {
|
||||
"2025-10-26": 45,
|
||||
"2025-10-25": 38,
|
||||
"2025-10-24": 52
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 3. Export CSV pour analyse externe
|
||||
|
||||
**Fichier** : `scripts/stats/export_events_csv.php`
|
||||
|
||||
**Usage** :
|
||||
```bash
|
||||
# Exporter toutes les connexions du mois en CSV
|
||||
php scripts/stats/export_events_csv.php \
|
||||
--event=login_success \
|
||||
--month=2025-10 \
|
||||
--output=/tmp/logins_october.csv
|
||||
```
|
||||
|
||||
### CRON de rotation
|
||||
|
||||
**Fichier** : `scripts/cron/rotate_event_logs.php`
|
||||
|
||||
**Configuration crontab** :
|
||||
```cron
|
||||
# Rotation des logs d'événements - 1er du mois à 3h
|
||||
0 3 1 * * cd /var/www/geosector/api && php scripts/cron/rotate_event_logs.php
|
||||
```
|
||||
|
||||
**Actions** :
|
||||
1. Compresser fichiers > 30 jours : `gzip logs/events/2025-09-*.jsonl`
|
||||
2. Supprimer archives > 15 mois : `rm logs/events/*-2024-06-*.jsonl.gz`
|
||||
3. Logger résumé dans `logs/rotation.log`
|
||||
|
||||
## 📈 Performances et volumétrie
|
||||
|
||||
### Estimations
|
||||
|
||||
**Volume quotidien moyen** (pour 50 entités actives) :
|
||||
- 500 connexions/jour = 500 lignes
|
||||
- 2000 passages créés/modifiés = 2000 lignes
|
||||
- 100 autres événements = 100 lignes
|
||||
- **Total : ~2600 événements/jour**
|
||||
|
||||
**Taille fichier** :
|
||||
- 1 événement ≈ 200-400 bytes JSON
|
||||
- 2600 événements ≈ 0.8-1 MB/jour non compressé
|
||||
- Compression gzip : ratio ~10:1 → **~100 KB/jour compressé**
|
||||
|
||||
**Rétention 15 mois** :
|
||||
- Non compressé (30 jours) : 30 MB
|
||||
- Compressé (14.5 mois) : 45 MB
|
||||
- **Total stockage : ~75 MB** pour 15 mois
|
||||
|
||||
### Optimisation lecture
|
||||
|
||||
**Lecture mono-fichier** : < 50ms pour analyser 1 jour (2600 événements)
|
||||
|
||||
**Lecture période 7 jours** :
|
||||
- 7 fichiers × 1 MB = 7 MB à lire
|
||||
- Filtrage `jq` ou PHP : ~200-300ms
|
||||
|
||||
**Lecture période 2 semaines (super-admin)** :
|
||||
- 14 fichiers × 1 MB = 14 MB à lire
|
||||
- Filtrage sur type événement : ~500ms
|
||||
|
||||
**Lecture archive compressée** :
|
||||
- Décompression à la volée : +100-200ms
|
||||
- Total : ~700-800ms pour 1 mois compressé
|
||||
|
||||
## 🔒 Sécurité et confidentialité
|
||||
|
||||
### Données sensibles
|
||||
|
||||
**❌ Jamais loggé en clair** :
|
||||
- Mots de passe
|
||||
- Contenu chiffré (noms, emails, téléphones, IBAN)
|
||||
- Tokens d'authentification
|
||||
|
||||
**✅ Loggé** :
|
||||
- IDs (user_id, entity_id, passage_id, etc.)
|
||||
- Montants financiers
|
||||
- Dates et timestamps
|
||||
- Types de modifications (indicateur booléen pour champs chiffrés)
|
||||
|
||||
### Exemple champ chiffré
|
||||
```json
|
||||
{
|
||||
"event": "user_updated",
|
||||
"changes": {
|
||||
"encrypted_name": true, // Indique modification sans valeur
|
||||
"encrypted_email": true,
|
||||
"role_id": {"old": 1, "new": 2} // Champ non sensible = valeurs OK
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Permissions d'accès
|
||||
|
||||
**Fichiers logs** :
|
||||
- Propriétaire : `nginx:nginx`
|
||||
- Permissions : `0640` (lecture nginx, écriture nginx, aucun autre)
|
||||
- Dossier `/logs/events/` : `0750`
|
||||
|
||||
**Scripts d'analyse** :
|
||||
- Exécution : root ou nginx uniquement
|
||||
- Pas d'accès direct via endpoints API (pour l'instant)
|
||||
|
||||
## 🚀 Roadmap et évolutions futures
|
||||
|
||||
### Phase 1 - MVP (actuel) ✅
|
||||
- [x] Architecture JSONL quotidienne
|
||||
- [x] Service EventLogService.php
|
||||
- [x] Intégration dans controllers (LoginController, PassageController, UserController, SectorController, OperationController, EntiteController)
|
||||
- [ ] CRON de rotation 15 mois
|
||||
- [ ] Scripts d'analyse de base
|
||||
|
||||
### Phase 2 - Dashboards (Q1 2026)
|
||||
- [ ] Endpoints API : `GET /api/stats/entity/{id}`, `GET /api/stats/global`
|
||||
- [ ] Interface web admin : graphiques connexions, passages
|
||||
- [ ] Filtres avancés (période, plateforme, utilisateur)
|
||||
|
||||
### Phase 3 - Alertes (Q2 2026)
|
||||
- [ ] Détection anomalies (pics de connexions échouées)
|
||||
- [ ] Alertes email super-admins
|
||||
- [ ] Seuils configurables par entité
|
||||
|
||||
### Phase 4 - Migration TimescaleDB (si besoin)
|
||||
- [ ] Évaluation volume : si > 50k événements/jour
|
||||
- [ ] Import JSONL → TimescaleDB
|
||||
- [ ] Rétention hybride : 90j TimescaleDB, archives JSONL
|
||||
|
||||
## 📝 Statut implémentation
|
||||
|
||||
**Date : 28 Octobre 2025**
|
||||
|
||||
### ✅ Terminé
|
||||
- Service `EventLogService.php` créé avec toutes les méthodes de logging
|
||||
- Intégration complète dans les 6 controllers principaux :
|
||||
- **LoginController** : login réussi/échoué, logout
|
||||
- **PassageController** : création, modification, suppression passages
|
||||
- **UserController** : création, modification, suppression utilisateurs
|
||||
- **SectorController** : création, modification, suppression secteurs
|
||||
- **OperationController** : création, modification, suppression opérations
|
||||
- **EntiteController** : création, modification entités
|
||||
- Enrichissement automatique : timestamp UTC, user_id, entity_id, IP, platform, app_version
|
||||
- Sécurité : champs sensibles loggés en booléen uniquement (pas de valeurs chiffrées)
|
||||
- Script de déploiement `deploy-api.sh` crée automatiquement `/logs/events/` avec permissions 0750
|
||||
|
||||
### 🔄 En attente
|
||||
- Scripts d'analyse (`entity_stats.php`, `global_stats.php`, `export_events_csv.php`)
|
||||
- CRON de rotation 15 mois (`rotate_event_logs.php`)
|
||||
- Tests en environnement DEV
|
||||
|
||||
## 📝 Checklist déploiement
|
||||
|
||||
### Environnement DEV (dva-geo)
|
||||
- [x] Créer dossier `/logs/events/` (permissions 0750) - Intégré dans deploy-api.sh
|
||||
- [x] Déployer `EventLogService.php`
|
||||
- [ ] Déployer scripts stats et rotation
|
||||
- [ ] Configurer CRON rotation
|
||||
- [ ] Tests : générer événements manuellement
|
||||
- [ ] Valider format JSONL et rotation
|
||||
|
||||
### Environnement RECETTE (rca-geo)
|
||||
- [ ] Déployer depuis DEV validé
|
||||
- [ ] Tests de charge : 10k événements/jour
|
||||
- [ ] Valider performances scripts d'analyse
|
||||
- [ ] Valider compression et suppression auto
|
||||
|
||||
### Environnement PRODUCTION (pra-geo)
|
||||
- [ ] Déployer depuis RECETTE validée
|
||||
- [ ] Monitoring volumétrie
|
||||
- [ ] Backups quotidiens `/logs/events/` (via CRON général)
|
||||
|
||||
---
|
||||
|
||||
**Dernière mise à jour :** 28 Octobre 2025
|
||||
**Version :** 1.1
|
||||
**Statut :** ✅ Service implémenté et intégré - Scripts d'analyse à développer
|
||||
@@ -24,24 +24,78 @@ Ce document décrit le système de gestion des secteurs dans l'API Geosector, in
|
||||
- Contient toutes les tables de l'application
|
||||
- Tables concernées : `ope_sectors`, `sectors_adresses`, `ope_pass`, `ope_users_sectors`, `x_departements_contours`
|
||||
|
||||
2. **Base adresses** (dans conteneurs Incus séparés)
|
||||
- DVA : `dva-maria` (13.23.33.46) - base `adresses`
|
||||
- RCA : `rca-maria` (13.23.33.36) - base `adresses`
|
||||
- PRA : `pra-maria` (13.23.33.26) - base `adresses`
|
||||
- Credentials : `adr_geo_user` / `d66,AdrGeoDev.User`
|
||||
2. **Base adresses** (dans conteneurs maria3/maria4)
|
||||
- **DVA** : maria3 (13.23.33.4) - base `adresses`
|
||||
- User : `adr_geo_user` / `d66,AdrGeoDev.User`
|
||||
- **RCA** : maria3 (13.23.33.4) - base `adresses`
|
||||
- User : `adr_geo_user` / `d66,AdrGeoRec.User`
|
||||
- **PROD** : maria4 (13.23.33.4) - base `adresses`
|
||||
- User : `adr_geo_user` / `d66,AdrGeoPrd.User`
|
||||
- Tables par département : `cp22`, `cp23`, etc.
|
||||
|
||||
3. **Base bâtiments** (dans conteneurs maria3/maria4)
|
||||
- **DVA** : maria3 (13.23.33.4) - base `batiments`
|
||||
- User : `adr_geo_user` / `d66,AdrGeoDev.User`
|
||||
- **RCA** : maria3 (13.23.33.4) - base `batiments`
|
||||
- User : `adr_geo_user` / `d66,AdrGeoRec.User`
|
||||
- **PROD** : maria4 (13.23.33.4) - base `batiments`
|
||||
- User : `adr_geo_user` / `d66,AdrGeoPrd.User`
|
||||
- Tables par département : `bat22`, `bat23`, etc.
|
||||
- Colonnes principales : `batiment_groupe_id`, `cle_interop_adr`, `nb_log`, `nb_niveau`, `residence`, `altitude_sol_mean`
|
||||
- Lien avec adresses : `bat{dept}.cle_interop_adr = cp{dept}.id`
|
||||
|
||||
### Configuration
|
||||
|
||||
Dans `src/Config/AppConfig.php` :
|
||||
|
||||
```php
|
||||
// DÉVELOPPEMENT
|
||||
'addresses_database' => [
|
||||
'host' => '13.23.33.46', // Varie selon l'environnement
|
||||
'host' => '13.23.33.4', // Container maria3 sur IN3
|
||||
'name' => 'adresses',
|
||||
'username' => 'adr_geo_user',
|
||||
'password' => 'd66,AdrGeoDev.User',
|
||||
],
|
||||
|
||||
// RECETTE
|
||||
'addresses_database' => [
|
||||
'host' => '13.23.33.4', // Container maria3 sur IN3
|
||||
'name' => 'adresses',
|
||||
'username' => 'adr_geo_user',
|
||||
'password' => 'd66,AdrGeoRec.User',
|
||||
],
|
||||
|
||||
// PRODUCTION
|
||||
'addresses_database' => [
|
||||
'host' => '13.23.33.4', // Container maria4 sur IN4
|
||||
'name' => 'adresses',
|
||||
'username' => 'adr_geo_user',
|
||||
'password' => 'd66,AdrGeoPrd.User',
|
||||
],
|
||||
|
||||
// DÉVELOPPEMENT - Bâtiments
|
||||
'buildings_database' => [
|
||||
'host' => '13.23.33.4', // Container maria3 sur IN3
|
||||
'name' => 'batiments',
|
||||
'username' => 'adr_geo_user',
|
||||
'password' => 'd66,AdrGeoDev.User',
|
||||
],
|
||||
|
||||
// RECETTE - Bâtiments
|
||||
'buildings_database' => [
|
||||
'host' => '13.23.33.4', // Container maria3 sur IN3
|
||||
'name' => 'batiments',
|
||||
'username' => 'adr_geo_user',
|
||||
'password' => 'd66,AdrGeoRec.User',
|
||||
],
|
||||
|
||||
// PRODUCTION - Bâtiments
|
||||
'buildings_database' => [
|
||||
'host' => '13.23.33.4', // Container maria4 sur IN4
|
||||
'name' => 'batiments',
|
||||
'username' => 'adr_geo_user',
|
||||
'password' => 'd66,AdrGeoPrd.User',
|
||||
],
|
||||
```
|
||||
|
||||
## Gestion des contours départementaux
|
||||
@@ -100,7 +154,7 @@ Vérifie les limites départementales des secteurs :
|
||||
class DepartmentBoundaryService {
|
||||
// Vérifie si un secteur est contenu dans un département
|
||||
public function checkSectorInDepartment(array $sectorCoordinates, string $departmentCode): array
|
||||
|
||||
|
||||
// Liste tous les départements touchés par un secteur
|
||||
public function getDepartmentsForSector(array $sectorCoordinates): array
|
||||
}
|
||||
@@ -118,6 +172,46 @@ class DepartmentBoundaryService {
|
||||
]
|
||||
```
|
||||
|
||||
### BuildingService
|
||||
|
||||
Enrichit les adresses avec les données bâtiments :
|
||||
|
||||
```php
|
||||
namespace App\Services;
|
||||
|
||||
class BuildingService {
|
||||
// Enrichit une liste d'adresses avec les métadonnées des bâtiments
|
||||
public function enrichAddresses(array $addresses): array
|
||||
}
|
||||
```
|
||||
|
||||
**Fonctionnement** :
|
||||
- Connexion à la base `batiments` externe
|
||||
- Interrogation des tables `bat{dept}` par département
|
||||
- JOIN sur `bat{dept}.cle_interop_adr = cp{dept}.id`
|
||||
- Ajout des métadonnées : `fk_batiment`, `fk_habitat`, `nb_niveau`, `nb_log`, `residence`, `alt_sol`
|
||||
- Fallback : `fk_habitat=1` (maison individuelle) si pas de bâtiment trouvé
|
||||
|
||||
**Données retournées** :
|
||||
```php
|
||||
[
|
||||
'id' => 'cp22.123456',
|
||||
'numero' => '10',
|
||||
'voie' => 'Rue Victor Hugo',
|
||||
'code_postal' => '22000',
|
||||
'commune' => 'Saint-Brieuc',
|
||||
'latitude' => 48.5149,
|
||||
'longitude' => -2.7658,
|
||||
// Données bâtiment enrichies :
|
||||
'fk_batiment' => 'BAT_123456', // null si maison
|
||||
'fk_habitat' => 2, // 1=individuel, 2=collectif
|
||||
'nb_niveau' => 4, // null si maison
|
||||
'nb_log' => 12, // null si maison
|
||||
'residence' => 'Résidence Les Pins', // '' si maison
|
||||
'alt_sol' => 25.5 // null si maison
|
||||
]
|
||||
```
|
||||
|
||||
## Processus de création de secteur
|
||||
|
||||
### 1. Structure du payload
|
||||
@@ -150,13 +244,77 @@ class DepartmentBoundaryService {
|
||||
- Recherche des passages avec `fk_sector = 0` dans le polygone
|
||||
- Mise à jour de leur `fk_sector` vers le nouveau secteur
|
||||
- Exclusion des passages ayant déjà une `fk_adresse`
|
||||
7. **Récupération** des adresses via `AddressService`
|
||||
8. **Stockage** des adresses dans `sectors_adresses`
|
||||
9. **Création** des passages dans `ope_pass` pour chaque adresse :
|
||||
7. **Récupération** des adresses via `AddressService::getAddressesInPolygon()`
|
||||
8. **Enrichissement** avec données bâtiments via `AddressService::enrichAddressesWithBuildings()`
|
||||
9. **Stockage** des adresses dans `sectors_adresses` avec colonnes bâtiment :
|
||||
- `fk_batiment`, `fk_habitat`, `nb_niveau`, `nb_log`, `residence`, `alt_sol`
|
||||
10. **Création** des passages dans `ope_pass` :
|
||||
- **Maisons individuelles** (fk_habitat=1) : 1 passage par adresse
|
||||
- **Immeubles** (fk_habitat=2) : nb_log passages par adresse (1 par appartement)
|
||||
- Champs ajoutés : `residence`, `appt` (numéro 1 à nb_log), `fk_habitat`
|
||||
- Affectés au premier utilisateur de la liste
|
||||
- Avec toutes les FK nécessaires (entité, opération, secteur, user)
|
||||
- Données d'adresse complètes
|
||||
10. **Commit** de la transaction ou **rollback** en cas d'erreur
|
||||
11. **Commit** de la transaction ou **rollback** en cas d'erreur
|
||||
|
||||
## Processus de modification de secteur
|
||||
|
||||
### 1. Structure du payload UPDATE
|
||||
|
||||
```json
|
||||
{
|
||||
"libelle": "Secteur Centre-Ville Modifié",
|
||||
"color": "#00FF00",
|
||||
"sector": "48.117266/-1.6777926#48.118500/-1.6750000#...",
|
||||
"users": [12, 34],
|
||||
"chk_adresses_change": 1
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Paramètre chk_adresses_change
|
||||
|
||||
**Valeurs** :
|
||||
- `0` : Ne pas recalculer les adresses et passages (modification simple)
|
||||
- `1` : Recalculer les adresses et passages (défaut)
|
||||
|
||||
**Cas d'usage** :
|
||||
|
||||
#### chk_adresses_change = 0
|
||||
Modification rapide sans toucher aux adresses/passages :
|
||||
- ✅ Modification du libellé
|
||||
- ✅ Modification de la couleur
|
||||
- ✅ Modification des coordonnées du polygone (visuel uniquement)
|
||||
- ✅ Modification des membres affectés
|
||||
- ❌ Pas de recalcul des adresses dans sectors_adresses
|
||||
- ❌ Pas de mise à jour des passages (orphelins, créés, supprimés)
|
||||
- ❌ **Réponse sans passages_sector** (tableau vide)
|
||||
|
||||
**Utilité** : Permet aux admins de corriger rapidement un libellé, une couleur, ou d'ajuster légèrement le périmètre visuel sans déclencher un recalcul complet qui pourrait prendre plusieurs secondes.
|
||||
|
||||
**Réponse API** :
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"message": "Secteur modifié avec succès",
|
||||
"sector": { "id": 123, "libelle": "...", "color": "...", "sector": "..." },
|
||||
"passages_sector": [], // Vide car chk_adresses_change = 0
|
||||
"passages_orphaned": 0,
|
||||
"passages_deleted": 0,
|
||||
"passages_updated": 0,
|
||||
"passages_created": 0,
|
||||
"passages_total": 0,
|
||||
"users_sectors": [...]
|
||||
}
|
||||
```
|
||||
|
||||
#### chk_adresses_change = 1 (défaut)
|
||||
Modification complète avec recalcul :
|
||||
- ✅ Modification du libellé/couleur/polygone
|
||||
- ✅ Modification des membres
|
||||
- ✅ Suppression et recréation de sectors_adresses
|
||||
- ✅ Application des règles de gestion des bâtiments
|
||||
- ✅ Mise en orphelin des passages hors périmètre
|
||||
- ✅ Création de nouveaux passages pour nouvelles adresses
|
||||
|
||||
### 3. Réponse API pour CREATE
|
||||
|
||||
@@ -287,14 +445,28 @@ $coordinates = [
|
||||
|
||||
### sectors_adresses
|
||||
- `fk_sector` : Lien vers le secteur
|
||||
- `fk_address` : ID de l'adresse dans la base externe
|
||||
- `numero`, `voie`, `code_postal`, `commune`
|
||||
- `latitude`, `longitude`
|
||||
- `fk_adresse` : ID de l'adresse dans la base externe
|
||||
- `numero`, `rue`, `rue_bis`, `cp`, `ville`
|
||||
- `gps_lat`, `gps_lng`
|
||||
- **Colonnes bâtiment** :
|
||||
- `fk_batiment` : ID bâtiment (VARCHAR 50, null si maison)
|
||||
- `fk_habitat` : 1=individuel, 2=collectif (TINYINT UNSIGNED)
|
||||
- `nb_niveau` : Nombre d'étages (INT, null)
|
||||
- `nb_log` : Nombre de logements (INT, null)
|
||||
- `residence` : Nom résidence/copropriété (VARCHAR 75)
|
||||
- `alt_sol` : Altitude sol en mètres (DECIMAL 10,2, null)
|
||||
|
||||
### ope_pass (passages)
|
||||
- `fk_entite`, `fk_operation`, `fk_sector`, `fk_user`
|
||||
- `numero`, `voie`, `code_postal`, `commune`
|
||||
- `latitude`, `longitude`
|
||||
- `fk_operation`, `fk_sector`, `fk_user`, `fk_adresse`
|
||||
- `numero`, `rue`, `rue_bis`, `ville`
|
||||
- `gps_lat`, `gps_lng`
|
||||
- **Colonnes bâtiment** :
|
||||
- `residence` : Nom résidence (VARCHAR 75)
|
||||
- `appt` : Numéro appartement (VARCHAR 10, saisie libre)
|
||||
- `niveau` : Étage (VARCHAR 10, saisie libre)
|
||||
- `fk_habitat` : 1=individuel, 2=collectif (TINYINT UNSIGNED)
|
||||
- `fk_type` : Type passage (2=à faire, autres valeurs pour fait/refus)
|
||||
- `encrypted_name`, `encrypted_email`, `encrypted_phone` : Données cryptées
|
||||
- `created_at`, `fk_user_creat`, `chk_active`
|
||||
|
||||
### ope_users_sectors
|
||||
@@ -303,6 +475,103 @@ $coordinates = [
|
||||
- `fk_sector` : Lien vers le secteur
|
||||
- `created_at`, `fk_user_creat`, `chk_active`
|
||||
|
||||
## Règles de gestion des bâtiments lors de l'UPDATE
|
||||
|
||||
### Principe général
|
||||
|
||||
Lors de la mise à jour d'un secteur, le système applique une logique intelligente pour gérer les passages en fonction du type d'habitat (maison/immeuble) et du nombre de logements.
|
||||
|
||||
### Clé d'identification unique
|
||||
|
||||
**Tous les passages** sont identifiés par la clé : `numero|rue|rue_bis|ville`
|
||||
|
||||
Cette clé ne contient **pas** `residence` ni `appt` car ces champs sont en **saisie libre** par l'utilisateur.
|
||||
|
||||
### Cas 1 : Maison individuelle (fk_habitat=1)
|
||||
|
||||
#### Si 0 passage existant :
|
||||
```
|
||||
→ INSERT 1 nouveau passage
|
||||
- fk_habitat = 1
|
||||
- residence = ''
|
||||
- appt = ''
|
||||
```
|
||||
|
||||
#### Si 1+ passages existants :
|
||||
```
|
||||
→ UPDATE le premier passage
|
||||
- fk_habitat = 1
|
||||
- residence = ''
|
||||
→ Les autres passages restent INTACTS
|
||||
(peuvent correspondre à plusieurs habitants saisis manuellement)
|
||||
```
|
||||
|
||||
### Cas 2 : Immeuble (fk_habitat=2)
|
||||
|
||||
#### Étape 1 : UPDATE systématique
|
||||
```
|
||||
→ UPDATE TOUS les passages existants à cette adresse
|
||||
- fk_habitat = 2
|
||||
- residence = sectors_adresses.residence (si non vide)
|
||||
```
|
||||
|
||||
#### Étape 2a : Si nb_existants < nb_log (ex: 3 passages, nb_log=6)
|
||||
```
|
||||
→ INSERT (nb_log - nb_existants) nouveaux passages
|
||||
- fk_habitat = 2
|
||||
- residence = sectors_adresses.residence
|
||||
- appt = '' (pas de numéro prédéfini)
|
||||
- fk_type = 2 (à faire)
|
||||
|
||||
Résultat : 6 passages total (3 conservés + 3 créés)
|
||||
```
|
||||
|
||||
#### Étape 2b : Si nb_existants > nb_log (ex: 10 passages, nb_log=6)
|
||||
```
|
||||
→ DELETE max (nb_existants - nb_log) passages
|
||||
Conditions de suppression :
|
||||
- fk_type = 2 (à faire)
|
||||
- ET encrypted_name vide (non visité)
|
||||
- Tri par created_at ASC (les plus anciens d'abord)
|
||||
|
||||
Résultat : Entre 6 et 10 passages (selon combien sont visités)
|
||||
```
|
||||
|
||||
### Points importants
|
||||
|
||||
✅ **Préservation des données utilisateur** :
|
||||
- `appt` et `niveau` ne sont **JAMAIS modifiés** (saisie libre conservée)
|
||||
- Les passages visités (encrypted_name rempli) ne sont **JAMAIS supprimés**
|
||||
|
||||
✅ **Mise à jour conditionnelle** :
|
||||
- `residence` est mis à jour **uniquement si non vide** dans sectors_adresses
|
||||
- Permet de conserver une saisie manuelle si la base bâtiments n'a pas l'info
|
||||
|
||||
✅ **Gestion des transitions** :
|
||||
- Une adresse peut passer de maison (fk_habitat=1) à immeuble (fk_habitat=2) ou inversement
|
||||
- La logique s'adapte automatiquement au nouveau type d'habitat
|
||||
|
||||
✅ **Uniformisation GPS** :
|
||||
- **Tous les passages d'une même adresse partagent les mêmes coordonnées GPS** (gps_lat, gps_lng)
|
||||
- Ces coordonnées proviennent de `sectors_adresses` (enrichies depuis la base externe `adresses`)
|
||||
- Cette règle s'applique lors de la **création** et de la **mise à jour** avec `chk_adresses_change=1`
|
||||
- Garantit la cohérence géographique pour tous les passages d'un même immeuble
|
||||
|
||||
### Exemple concret
|
||||
|
||||
**Situation initiale** :
|
||||
- Adresse : "10 rue Victor Hugo, 22000 Saint-Brieuc"
|
||||
- 8 passages existants (dont 3 visités)
|
||||
- nb_log passe de 8 à 5
|
||||
|
||||
**Actions** :
|
||||
1. UPDATE les 8 passages → fk_habitat=2, residence="Les Chênes"
|
||||
2. Tentative suppression de (8-5) = 3 passages
|
||||
3. Recherche des passages avec fk_type=2 ET encrypted_name vide
|
||||
4. Suppose 5 passages non visités trouvés
|
||||
5. Suppression des 3 plus anciens non visités
|
||||
6. **Résultat** : 5 passages restants (3 visités + 2 non visités)
|
||||
|
||||
## Logs et monitoring
|
||||
|
||||
Le système génère des logs détaillés pour :
|
||||
|
||||
464
api/docs/STRIPE-BACKEND-MIGRATION.md
Normal file
464
api/docs/STRIPE-BACKEND-MIGRATION.md
Normal file
@@ -0,0 +1,464 @@
|
||||
# 🔧 Migration Backend Stripe - Option A (Tout en 1)
|
||||
|
||||
## 📋 Objectif
|
||||
|
||||
Optimiser la création de compte Stripe Connect en **1 seule requête** côté Flutter qui crée :
|
||||
1. Le compte Stripe Connect
|
||||
2. La Location Terminal
|
||||
3. Le lien d'onboarding
|
||||
|
||||
---
|
||||
|
||||
## 🗄️ 1. Modification de la base de données
|
||||
|
||||
### **Ajouter la colonne `stripe_location_id`**
|
||||
|
||||
```sql
|
||||
ALTER TABLE amicales
|
||||
ADD COLUMN stripe_location_id VARCHAR(255) NULL
|
||||
AFTER stripe_id;
|
||||
```
|
||||
|
||||
**Vérification** :
|
||||
```sql
|
||||
DESCRIBE amicales;
|
||||
```
|
||||
|
||||
Doit afficher :
|
||||
```
|
||||
+-------------------+--------------+------+-----+---------+-------+
|
||||
| Field | Type | Null | Key | Default | Extra |
|
||||
+-------------------+--------------+------+-----+---------+-------+
|
||||
| stripe_id | varchar(255) | YES | | NULL | |
|
||||
| stripe_location_id| varchar(255) | YES | | NULL | |
|
||||
+-------------------+--------------+------+-----+---------+-------+
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔧 2. Modification de l'endpoint `POST /stripe/accounts`
|
||||
|
||||
### **Fichier** : `app/Http/Controllers/StripeController.php` (ou similaire)
|
||||
|
||||
### **Méthode** : `createAccount()` ou `store()`
|
||||
|
||||
### **Code proposé** :
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Amicale;
|
||||
|
||||
/**
|
||||
* Créer un compte Stripe Connect avec Location Terminal et lien d'onboarding
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function createStripeAccount(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'fk_entite' => 'required|integer|exists:amicales,id',
|
||||
'return_url' => 'required|string|url',
|
||||
'refresh_url' => 'required|string|url',
|
||||
]);
|
||||
|
||||
$fkEntite = $request->fk_entite;
|
||||
$amicale = Amicale::findOrFail($fkEntite);
|
||||
|
||||
// Vérifier si un compte existe déjà
|
||||
if (!empty($amicale->stripe_id)) {
|
||||
return $this->handleExistingAccount($amicale, $request);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
// Configurer la clé Stripe (selon environnement)
|
||||
\Stripe\Stripe::setApiKey(config('services.stripe.secret'));
|
||||
|
||||
// 1️⃣ Créer le compte Stripe Connect Express
|
||||
$account = \Stripe\Account::create([
|
||||
'type' => 'express',
|
||||
'country' => 'FR',
|
||||
'email' => $amicale->email,
|
||||
'business_type' => 'non_profit', // ou 'company' selon le cas
|
||||
'business_profile' => [
|
||||
'name' => $amicale->name,
|
||||
'url' => config('app.url'),
|
||||
],
|
||||
'capabilities' => [
|
||||
'card_payments' => ['requested' => true],
|
||||
'transfers' => ['requested' => true],
|
||||
],
|
||||
]);
|
||||
|
||||
\Log::info('Stripe account created', [
|
||||
'amicale_id' => $amicale->id,
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
// 2️⃣ Créer la Location Terminal pour Tap to Pay
|
||||
$location = \Stripe\Terminal\Location::create([
|
||||
'display_name' => $amicale->name,
|
||||
'address' => [
|
||||
'line1' => $amicale->adresse1 ?: 'Non renseigné',
|
||||
'line2' => $amicale->adresse2,
|
||||
'city' => $amicale->ville ?: 'Non renseigné',
|
||||
'postal_code' => $amicale->code_postal ?: '00000',
|
||||
'country' => 'FR',
|
||||
],
|
||||
], [
|
||||
'stripe_account' => $account->id, // ← Important : Connect account
|
||||
]);
|
||||
|
||||
\Log::info('Stripe Terminal Location created', [
|
||||
'amicale_id' => $amicale->id,
|
||||
'location_id' => $location->id,
|
||||
]);
|
||||
|
||||
// 3️⃣ Créer le lien d'onboarding
|
||||
$accountLink = \Stripe\AccountLink::create([
|
||||
'account' => $account->id,
|
||||
'refresh_url' => $request->refresh_url,
|
||||
'return_url' => $request->return_url,
|
||||
'type' => 'account_onboarding',
|
||||
]);
|
||||
|
||||
\Log::info('Stripe onboarding link created', [
|
||||
'amicale_id' => $amicale->id,
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
// 4️⃣ Sauvegarder TOUT en base de données
|
||||
$amicale->stripe_id = $account->id;
|
||||
$amicale->stripe_location_id = $location->id;
|
||||
$amicale->chk_stripe = true;
|
||||
$amicale->save();
|
||||
|
||||
DB::commit();
|
||||
|
||||
// 5️⃣ Retourner TOUTES les informations
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'account_id' => $account->id,
|
||||
'location_id' => $location->id,
|
||||
'onboarding_url' => $accountLink->url,
|
||||
'charges_enabled' => $account->charges_enabled,
|
||||
'payouts_enabled' => $account->payouts_enabled,
|
||||
'existing' => false,
|
||||
'message' => 'Compte Stripe Connect créé avec succès',
|
||||
], 201);
|
||||
|
||||
} catch (\Stripe\Exception\ApiErrorException $e) {
|
||||
DB::rollBack();
|
||||
|
||||
\Log::error('Stripe API error', [
|
||||
'amicale_id' => $amicale->id,
|
||||
'error' => $e->getMessage(),
|
||||
'type' => get_class($e),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Erreur Stripe : ' . $e->getMessage(),
|
||||
], 500);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
||||
\Log::error('Stripe account creation failed', [
|
||||
'amicale_id' => $amicale->id,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Erreur lors de la création du compte Stripe',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gérer le cas d'un compte Stripe existant
|
||||
*/
|
||||
private function handleExistingAccount(Amicale $amicale, Request $request)
|
||||
{
|
||||
try {
|
||||
\Stripe\Stripe::setApiKey(config('services.stripe.secret'));
|
||||
|
||||
// Récupérer les infos du compte existant
|
||||
$account = \Stripe\Account::retrieve($amicale->stripe_id);
|
||||
|
||||
// Si pas de location_id, la créer maintenant
|
||||
if (empty($amicale->stripe_location_id)) {
|
||||
$location = \Stripe\Terminal\Location::create([
|
||||
'display_name' => $amicale->name,
|
||||
'address' => [
|
||||
'line1' => $amicale->adresse1 ?: 'Non renseigné',
|
||||
'city' => $amicale->ville ?: 'Non renseigné',
|
||||
'postal_code' => $amicale->code_postal ?: '00000',
|
||||
'country' => 'FR',
|
||||
],
|
||||
], [
|
||||
'stripe_account' => $amicale->stripe_id,
|
||||
]);
|
||||
|
||||
$amicale->stripe_location_id = $location->id;
|
||||
$amicale->save();
|
||||
|
||||
\Log::info('Location created for existing account', [
|
||||
'amicale_id' => $amicale->id,
|
||||
'location_id' => $location->id,
|
||||
]);
|
||||
}
|
||||
|
||||
// Si le compte est déjà complètement configuré
|
||||
if ($account->charges_enabled && $account->payouts_enabled) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'account_id' => $amicale->stripe_id,
|
||||
'location_id' => $amicale->stripe_location_id,
|
||||
'onboarding_url' => null,
|
||||
'charges_enabled' => true,
|
||||
'payouts_enabled' => true,
|
||||
'existing' => true,
|
||||
'message' => 'Compte Stripe déjà configuré et actif',
|
||||
]);
|
||||
}
|
||||
|
||||
// Compte existant mais configuration incomplète : générer un nouveau lien
|
||||
$accountLink = \Stripe\AccountLink::create([
|
||||
'account' => $amicale->stripe_id,
|
||||
'refresh_url' => $request->refresh_url,
|
||||
'return_url' => $request->return_url,
|
||||
'type' => 'account_onboarding',
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'account_id' => $amicale->stripe_id,
|
||||
'location_id' => $amicale->stripe_location_id,
|
||||
'onboarding_url' => $accountLink->url,
|
||||
'charges_enabled' => $account->charges_enabled,
|
||||
'payouts_enabled' => $account->payouts_enabled,
|
||||
'existing' => true,
|
||||
'message' => 'Compte existant, configuration à finaliser',
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Error handling existing account', [
|
||||
'amicale_id' => $amicale->id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Erreur lors de la vérification du compte existant',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📡 3. Modification de l'endpoint `GET /stripe/accounts/{id}/status`
|
||||
|
||||
Ajouter `location_id` dans la réponse :
|
||||
|
||||
```php
|
||||
public function checkAccountStatus($amicaleId)
|
||||
{
|
||||
$amicale = Amicale::findOrFail($amicaleId);
|
||||
|
||||
if (empty($amicale->stripe_id)) {
|
||||
return response()->json([
|
||||
'has_account' => false,
|
||||
'account_id' => null,
|
||||
'location_id' => null,
|
||||
'charges_enabled' => false,
|
||||
'payouts_enabled' => false,
|
||||
'onboarding_completed' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
\Stripe\Stripe::setApiKey(config('services.stripe.secret'));
|
||||
$account = \Stripe\Account::retrieve($amicale->stripe_id);
|
||||
|
||||
return response()->json([
|
||||
'has_account' => true,
|
||||
'account_id' => $amicale->stripe_id,
|
||||
'location_id' => $amicale->stripe_location_id, // ← Ajouté
|
||||
'charges_enabled' => $account->charges_enabled,
|
||||
'payouts_enabled' => $account->payouts_enabled,
|
||||
'onboarding_completed' => $account->details_submitted,
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'has_account' => false,
|
||||
'error' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🗑️ 4. Endpoint à SUPPRIMER (devenu inutile)
|
||||
|
||||
### **❌ `POST /stripe/locations`**
|
||||
|
||||
Cet endpoint n'est plus nécessaire car la Location est créée automatiquement dans `POST /stripe/accounts`.
|
||||
|
||||
**Option 1** : Supprimer complètement
|
||||
**Option 2** : Le garder pour compatibilité temporaire (si utilisé ailleurs)
|
||||
|
||||
---
|
||||
|
||||
## 📝 5. Modification du modèle Eloquent
|
||||
|
||||
### **Fichier** : `app/Models/Amicale.php`
|
||||
|
||||
Ajouter le champ `stripe_location_id` :
|
||||
|
||||
```php
|
||||
protected $fillable = [
|
||||
// ... autres champs
|
||||
'stripe_id',
|
||||
'stripe_location_id', // ← Ajouté
|
||||
'chk_stripe',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'chk_stripe' => 'boolean',
|
||||
];
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ 6. Tests à effectuer
|
||||
|
||||
### **Test 1 : Nouvelle amicale**
|
||||
```bash
|
||||
curl -X POST http://localhost/api/stripe/accounts \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer {token}" \
|
||||
-d '{
|
||||
"fk_entite": 123,
|
||||
"return_url": "https://app.geosector.fr/stripe/success",
|
||||
"refresh_url": "https://app.geosector.fr/stripe/refresh"
|
||||
}'
|
||||
```
|
||||
|
||||
**Réponse attendue** :
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"account_id": "acct_xxxxxxxxxxxxx",
|
||||
"location_id": "tml_xxxxxxxxxxxxx",
|
||||
"onboarding_url": "https://connect.stripe.com/setup/...",
|
||||
"charges_enabled": false,
|
||||
"payouts_enabled": false,
|
||||
"existing": false,
|
||||
"message": "Compte Stripe Connect créé avec succès"
|
||||
}
|
||||
```
|
||||
|
||||
### **Test 2 : Amicale avec compte existant**
|
||||
```bash
|
||||
curl -X POST http://localhost/api/stripe/accounts \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer {token}" \
|
||||
-d '{
|
||||
"fk_entite": 456,
|
||||
"return_url": "https://app.geosector.fr/stripe/success",
|
||||
"refresh_url": "https://app.geosector.fr/stripe/refresh"
|
||||
}'
|
||||
```
|
||||
|
||||
**Réponse attendue** :
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"account_id": "acct_xxxxxxxxxxxxx",
|
||||
"location_id": "tml_xxxxxxxxxxxxx",
|
||||
"onboarding_url": null,
|
||||
"charges_enabled": true,
|
||||
"payouts_enabled": true,
|
||||
"existing": true,
|
||||
"message": "Compte Stripe déjà configuré et actif"
|
||||
}
|
||||
```
|
||||
|
||||
### **Test 3 : Vérifier la BDD**
|
||||
```sql
|
||||
SELECT id, name, stripe_id, stripe_location_id, chk_stripe
|
||||
FROM amicales
|
||||
WHERE id = 123;
|
||||
```
|
||||
|
||||
**Résultat attendu** :
|
||||
```
|
||||
+-----+------------------+-------------------+-------------------+------------+
|
||||
| id | name | stripe_id | stripe_location_id| chk_stripe |
|
||||
+-----+------------------+-------------------+-------------------+------------+
|
||||
| 123 | Pompiers Paris15 | acct_xxxxxxxxxxxxx| tml_xxxxxxxxxxxxx | 1 |
|
||||
+-----+------------------+-------------------+-------------------+------------+
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 7. Déploiement
|
||||
|
||||
### **Étapes** :
|
||||
1. ✅ Appliquer la migration SQL
|
||||
2. ✅ Déployer le code Backend modifié
|
||||
3. ✅ Tester avec Postman/curl
|
||||
4. ✅ Déployer le code Flutter modifié
|
||||
5. ✅ Tester le flow complet depuis l'app
|
||||
|
||||
---
|
||||
|
||||
## 📊 Comparaison Avant/Après
|
||||
|
||||
| Aspect | Avant | Après |
|
||||
|--------|-------|-------|
|
||||
| **Appels API Flutter → Backend** | 3 | 1 |
|
||||
| **Appels Backend → Stripe** | 3 | 3 (mais atomiques) |
|
||||
| **Latence totale** | ~3-5s | ~1-2s |
|
||||
| **Gestion erreurs** | Complexe | Simplifié avec transaction |
|
||||
| **Atomicité** | ❌ Non | ✅ Oui (DB transaction) |
|
||||
| **Location ID sauvegardé** | ❌ Non | ✅ Oui |
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Bénéfices
|
||||
|
||||
1. ✅ **Performance** : Latence divisée par 2-3
|
||||
2. ✅ **Fiabilité** : Transaction BDD garantit la cohérence
|
||||
3. ✅ **Simplicité** : Code Flutter plus simple
|
||||
4. ✅ **Maintenance** : Moins de code à maintenir
|
||||
5. ✅ **Traçabilité** : Logs centralisés côté Backend
|
||||
6. ✅ **Tap to Pay prêt** : `location_id` disponible immédiatement
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ Points d'attention
|
||||
|
||||
1. **Rollback** : Si la transaction échoue, rien n'est sauvegardé (bon comportement)
|
||||
2. **Logs** : Bien logger chaque étape pour le debug
|
||||
3. **Stripe Connect limitations** : Respecter les rate limits Stripe
|
||||
4. **Tests** : Tester avec des comptes Stripe de test d'abord
|
||||
|
||||
---
|
||||
|
||||
## 📚 Ressources
|
||||
|
||||
- [Stripe Connect Express Accounts](https://stripe.com/docs/connect/express-accounts)
|
||||
- [Stripe Terminal Locations](https://stripe.com/docs/terminal/fleet/locations)
|
||||
- [Stripe Account Links](https://stripe.com/docs/connect/account-links)
|
||||
1482
api/docs/TECHBOOK.md
1482
api/docs/TECHBOOK.md
File diff suppressed because it is too large
Load Diff
@@ -1,476 +0,0 @@
|
||||
-- -------------------------------------------------------------
|
||||
-- TablePlus 6.4.8(608)
|
||||
--
|
||||
-- https://tableplus.com/
|
||||
--
|
||||
-- Database: geo_app
|
||||
-- Generation Time: 2025-06-09 18:03:43.5140
|
||||
-- -------------------------------------------------------------
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
|
||||
-- Tables préfixées "chat_"
|
||||
CREATE TABLE chat_rooms (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
title VARCHAR(255),
|
||||
type ENUM('private', 'group', 'broadcast'),
|
||||
created_at TIMESTAMP,
|
||||
created_by INT
|
||||
);
|
||||
|
||||
CREATE TABLE chat_messages (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
room_id VARCHAR(36),
|
||||
content TEXT,
|
||||
sender_id INT,
|
||||
sent_at TIMESTAMP,
|
||||
FOREIGN KEY (room_id) REFERENCES chat_rooms(id)
|
||||
);
|
||||
|
||||
CREATE TABLE chat_participants (
|
||||
room_id VARCHAR(36),
|
||||
user_id INT,
|
||||
role INT,
|
||||
entite_id INT,
|
||||
joined_at TIMESTAMP,
|
||||
PRIMARY KEY (room_id, user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE chat_read_receipts (
|
||||
message_id VARCHAR(36),
|
||||
user_id INT,
|
||||
read_at TIMESTAMP,
|
||||
PRIMARY KEY (message_id, user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE `email_counter` (
|
||||
`id` int(10) unsigned NOT NULL DEFAULT 1,
|
||||
`hour_start` timestamp NULL DEFAULT NULL,
|
||||
`count` int(10) unsigned DEFAULT 0,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `email_queue` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_pass` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`to_email` varchar(255) DEFAULT NULL,
|
||||
`subject` varchar(255) DEFAULT NULL,
|
||||
`body` text DEFAULT NULL,
|
||||
`headers` text DEFAULT NULL,
|
||||
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||
`status` enum('pending','sent','failed') DEFAULT 'pending',
|
||||
`sent_at` timestamp NULL DEFAULT NULL,
|
||||
`attempts` int(10) unsigned DEFAULT 0,
|
||||
`error_message` text DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `entites` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`encrypted_name` varchar(255) DEFAULT NULL,
|
||||
`adresse1` varchar(45) DEFAULT '',
|
||||
`adresse2` varchar(45) DEFAULT '',
|
||||
`code_postal` varchar(5) DEFAULT '',
|
||||
`ville` varchar(45) DEFAULT '',
|
||||
`fk_region` int(10) unsigned DEFAULT NULL,
|
||||
`fk_type` int(10) unsigned DEFAULT 1,
|
||||
`encrypted_phone` varchar(128) DEFAULT '',
|
||||
`encrypted_mobile` varchar(128) DEFAULT '',
|
||||
`encrypted_email` varchar(255) DEFAULT '',
|
||||
`gps_lat` varchar(20) NOT NULL DEFAULT '',
|
||||
`gps_lng` varchar(20) NOT NULL DEFAULT '',
|
||||
`chk_stripe` tinyint(1) unsigned DEFAULT 0,
|
||||
`encrypted_stripe_id` varchar(255) DEFAULT '',
|
||||
`encrypted_iban` varchar(255) DEFAULT '',
|
||||
`encrypted_bic` varchar(128) DEFAULT '',
|
||||
`chk_demo` tinyint(1) unsigned DEFAULT 1,
|
||||
`chk_mdp_manuel` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Gestion des mots de passe manuelle (1) ou automatique (0)',
|
||||
`chk_username_manuel` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Gestion des usernames manuelle (1) ou automatique (0)',
|
||||
`chk_copie_mail_recu` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`chk_accept_sms` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
|
||||
`fk_user_creat` int(10) unsigned DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
|
||||
`fk_user_modif` int(10) unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `entites_ibfk_1` (`fk_region`),
|
||||
KEY `entites_ibfk_2` (`fk_type`),
|
||||
CONSTRAINT `entites_ibfk_1` FOREIGN KEY (`fk_region`) REFERENCES `x_regions` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `entites_ibfk_2` FOREIGN KEY (`fk_type`) REFERENCES `x_entites_types` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1230 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `medias` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`support` varchar(45) NOT NULL DEFAULT '' COMMENT 'Type de support (entite, user, operation, passage)',
|
||||
`support_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'ID de élément associé',
|
||||
`fichier` varchar(250) NOT NULL DEFAULT '' COMMENT 'Nom du fichier stocké',
|
||||
`file_type` varchar(50) DEFAULT NULL COMMENT 'Extension du fichier (pdf, jpg, xlsx, etc.)',
|
||||
`file_category` varchar(50) DEFAULT NULL COMMENT 'export, logo, carte, etc.',
|
||||
`file_size` int(10) unsigned DEFAULT NULL COMMENT 'Taille du fichier en octets',
|
||||
`mime_type` varchar(100) DEFAULT NULL COMMENT 'Type MIME du fichier',
|
||||
`original_name` varchar(255) DEFAULT NULL COMMENT 'Nom original du fichier uploadé',
|
||||
`fk_entite` int(10) unsigned DEFAULT NULL COMMENT 'ID de entité propriétaire',
|
||||
`fk_operation` int(10) unsigned DEFAULT NULL COMMENT 'ID de opération (pour passages)',
|
||||
`file_path` varchar(500) DEFAULT NULL COMMENT 'Chemin complet du fichier',
|
||||
`original_width` int(10) unsigned DEFAULT NULL COMMENT 'Largeur originale de image',
|
||||
`original_height` int(10) unsigned DEFAULT NULL COMMENT 'Hauteur originale de image',
|
||||
`processed_width` int(10) unsigned DEFAULT NULL COMMENT 'Largeur après traitement',
|
||||
`processed_height` int(10) unsigned DEFAULT NULL COMMENT 'Hauteur après traitement',
|
||||
`is_processed` tinyint(1) unsigned DEFAULT 0 COMMENT 'Image redimensionnée (1) ou originale (0)',
|
||||
`description` varchar(100) NOT NULL DEFAULT '' COMMENT 'Description du fichier',
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`fk_user_creat` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
|
||||
`fk_user_modif` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
KEY `idx_entite` (`fk_entite`),
|
||||
KEY `idx_operation` (`fk_operation`),
|
||||
KEY `idx_support_type` (`support`, `support_id`),
|
||||
KEY `idx_file_type` (`file_type`),
|
||||
KEY `idx_file_category` (`file_category`),
|
||||
CONSTRAINT `fk_medias_entite` FOREIGN KEY (`fk_entite`) REFERENCES `entites` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
CONSTRAINT `fk_medias_operation` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `ope_pass` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`fk_sector` int(10) unsigned DEFAULT 0,
|
||||
`fk_user` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`fk_adresse` varchar(25) DEFAULT '' COMMENT 'adresses.cp??.id',
|
||||
`passed_at` timestamp NULL DEFAULT NULL COMMENT 'Date du passage',
|
||||
`fk_type` int(10) unsigned DEFAULT 0,
|
||||
`numero` varchar(10) NOT NULL DEFAULT '',
|
||||
`rue` varchar(75) NOT NULL DEFAULT '',
|
||||
`rue_bis` varchar(1) NOT NULL DEFAULT '',
|
||||
`ville` varchar(75) NOT NULL DEFAULT '',
|
||||
`fk_habitat` int(10) unsigned DEFAULT 1,
|
||||
`appt` varchar(5) DEFAULT '',
|
||||
`niveau` varchar(5) DEFAULT '',
|
||||
`residence` varchar(75) DEFAULT '',
|
||||
`gps_lat` varchar(20) NOT NULL DEFAULT '',
|
||||
`gps_lng` varchar(20) NOT NULL DEFAULT '',
|
||||
`encrypted_name` varchar(255) NOT NULL DEFAULT '',
|
||||
`montant` decimal(7,2) NOT NULL DEFAULT 0.00,
|
||||
`fk_type_reglement` int(10) unsigned DEFAULT 1,
|
||||
`remarque` text DEFAULT '',
|
||||
`encrypted_email` varchar(255) DEFAULT '',
|
||||
`nom_recu` varchar(50) DEFAULT NULL,
|
||||
`date_recu` timestamp NULL DEFAULT NULL COMMENT 'Date de réception',
|
||||
`date_creat_recu` timestamp NULL DEFAULT NULL COMMENT 'Date de création du reçu',
|
||||
`date_sent_recu` timestamp NULL DEFAULT NULL COMMENT 'Date envoi du reçu',
|
||||
`email_erreur` varchar(30) DEFAULT '',
|
||||
`chk_email_sent` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`encrypted_phone` varchar(128) NOT NULL DEFAULT '',
|
||||
`is_striped` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`docremis` tinyint(1) unsigned DEFAULT 0,
|
||||
`date_repasser` timestamp NULL DEFAULT NULL COMMENT 'Date prévue pour repasser',
|
||||
`nb_passages` int(11) DEFAULT 1 COMMENT 'Nb passages pour les a repasser',
|
||||
`chk_gps_maj` tinyint(1) unsigned DEFAULT 0,
|
||||
`chk_map_create` tinyint(1) unsigned DEFAULT 0,
|
||||
`chk_mobile` tinyint(1) unsigned DEFAULT 0,
|
||||
`chk_synchro` tinyint(1) unsigned DEFAULT 1 COMMENT 'chk synchro entre web et appli',
|
||||
`chk_api_adresse` tinyint(1) unsigned DEFAULT 0,
|
||||
`chk_maj_adresse` tinyint(1) unsigned DEFAULT 0,
|
||||
`anomalie` tinyint(1) unsigned DEFAULT 0,
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
|
||||
`fk_user_creat` int(10) unsigned DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
|
||||
`fk_user_modif` int(10) unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_operation` (`fk_operation`),
|
||||
KEY `fk_sector` (`fk_sector`),
|
||||
KEY `fk_user` (`fk_user`),
|
||||
KEY `fk_type` (`fk_type`),
|
||||
KEY `fk_type_reglement` (`fk_type_reglement`),
|
||||
KEY `email` (`encrypted_email`),
|
||||
CONSTRAINT `ope_pass_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_pass_ibfk_2` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_pass_ibfk_3` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_pass_ibfk_4` FOREIGN KEY (`fk_type_reglement`) REFERENCES `x_types_reglements` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=19499566 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `ope_pass_histo` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_pass` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`date_histo` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date historique',
|
||||
`sujet` varchar(50) DEFAULT NULL,
|
||||
`remarque` varchar(250) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `ope_pass_histo_fk_pass_IDX` (`fk_pass`) USING BTREE,
|
||||
KEY `ope_pass_histo_date_histo_IDX` (`date_histo`) USING BTREE,
|
||||
CONSTRAINT `ope_pass_histo_ibfk_1` FOREIGN KEY (`fk_pass`) REFERENCES `ope_pass` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=6752 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `ope_sectors` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`fk_old_sector` int(10) unsigned DEFAULT NULL,
|
||||
`libelle` varchar(75) NOT NULL DEFAULT '',
|
||||
`sector` text NOT NULL DEFAULT '',
|
||||
`color` varchar(7) NOT NULL DEFAULT '#4B77BE',
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
|
||||
`fk_user_creat` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
|
||||
`fk_user_modif` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`),
|
||||
KEY `fk_operation` (`fk_operation`),
|
||||
CONSTRAINT `ope_sectors_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=27675 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `ope_users` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`fk_user` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
|
||||
`fk_user_creat` int(10) unsigned DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
|
||||
`fk_user_modif` int(10) unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
KEY `ope_users_ibfk_1` (`fk_operation`),
|
||||
KEY `ope_users_ibfk_2` (`fk_user`),
|
||||
CONSTRAINT `ope_users_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_users_ibfk_2` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=199006 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `ope_users_sectors` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`fk_user` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`fk_sector` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
|
||||
`fk_user_creat` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
|
||||
`fk_user_modif` int(10) unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`),
|
||||
KEY `fk_operation` (`fk_operation`),
|
||||
KEY `fk_user` (`fk_user`),
|
||||
KEY `fk_sector` (`fk_sector`),
|
||||
CONSTRAINT `ope_users_sectors_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_users_sectors_ibfk_2` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_users_sectors_ibfk_3` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=48082 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `operations` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_entite` int(10) unsigned NOT NULL DEFAULT 1,
|
||||
`libelle` varchar(75) NOT NULL DEFAULT '',
|
||||
`date_deb` date NOT NULL DEFAULT '0000-00-00',
|
||||
`date_fin` date NOT NULL DEFAULT '0000-00-00',
|
||||
`chk_distinct_sectors` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
|
||||
`fk_user_creat` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
|
||||
`fk_user_modif` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_entite` (`fk_entite`),
|
||||
KEY `date_deb` (`date_deb`),
|
||||
CONSTRAINT `operations_ibfk_1` FOREIGN KEY (`fk_entite`) REFERENCES `entites` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3121 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `params` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(35) NOT NULL DEFAULT '',
|
||||
`valeur` varchar(255) NOT NULL DEFAULT '',
|
||||
`aide` varchar(150) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `sectors_adresses` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_adresse` varchar(25) DEFAULT NULL COMMENT 'adresses.cp??.id',
|
||||
`osm_id` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`fk_sector` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`osm_name` varchar(50) NOT NULL DEFAULT '',
|
||||
`numero` varchar(5) NOT NULL DEFAULT '',
|
||||
`rue_bis` varchar(5) NOT NULL DEFAULT '',
|
||||
`rue` varchar(60) NOT NULL DEFAULT '',
|
||||
`cp` varchar(5) NOT NULL DEFAULT '',
|
||||
`ville` varchar(60) NOT NULL DEFAULT '',
|
||||
`gps_lat` varchar(20) NOT NULL DEFAULT '',
|
||||
`gps_lng` varchar(20) NOT NULL DEFAULT '',
|
||||
`osm_date_creat` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `sectors_adresses_fk_sector_index` (`fk_sector`),
|
||||
KEY `sectors_adresses_numero_index` (`numero`),
|
||||
KEY `sectors_adresses_rue_index` (`rue`),
|
||||
KEY `sectors_adresses_ville_index` (`ville`),
|
||||
CONSTRAINT `sectors_adresses_ibfk_1` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1562946 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `users` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_entite` int(10) unsigned DEFAULT 1,
|
||||
`fk_role` int(10) unsigned DEFAULT 1,
|
||||
`fk_titre` int(10) unsigned DEFAULT 1,
|
||||
`encrypted_name` varchar(255) DEFAULT NULL,
|
||||
`first_name` varchar(45) DEFAULT NULL,
|
||||
`sect_name` varchar(60) DEFAULT '',
|
||||
`encrypted_user_name` varchar(128) DEFAULT '',
|
||||
`user_pass_hash` varchar(60) DEFAULT NULL,
|
||||
`encrypted_phone` varchar(128) DEFAULT NULL,
|
||||
`encrypted_mobile` varchar(128) DEFAULT NULL,
|
||||
`encrypted_email` varchar(255) DEFAULT '',
|
||||
`chk_alert_email` tinyint(1) unsigned DEFAULT 1,
|
||||
`chk_suivi` tinyint(1) unsigned DEFAULT 0,
|
||||
`date_naissance` date DEFAULT NULL,
|
||||
`date_embauche` date DEFAULT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
|
||||
`fk_user_creat` int(10) unsigned DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
|
||||
`fk_user_modif` int(10) unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_entite` (`fk_entite`),
|
||||
KEY `username` (`encrypted_user_name`),
|
||||
KEY `users_ibfk_2` (`fk_role`),
|
||||
KEY `users_ibfk_3` (`fk_titre`),
|
||||
CONSTRAINT `users_ibfk_1` FOREIGN KEY (`fk_entite`) REFERENCES `entites` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `users_ibfk_2` FOREIGN KEY (`fk_role`) REFERENCES `x_users_roles` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `users_ibfk_3` FOREIGN KEY (`fk_titre`) REFERENCES `x_users_titres` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10027748 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_departements` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`code` varchar(3) DEFAULT NULL,
|
||||
`fk_region` int(10) unsigned DEFAULT 1,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
KEY `x_departements_ibfk_1` (`fk_region`),
|
||||
CONSTRAINT `x_departements_ibfk_1` FOREIGN KEY (`fk_region`) REFERENCES `x_regions` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_devises` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`code` varchar(3) DEFAULT NULL,
|
||||
`symbole` varchar(6) DEFAULT NULL,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_entites_types` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_pays` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`code` varchar(3) DEFAULT NULL,
|
||||
`fk_continent` int(10) unsigned DEFAULT NULL,
|
||||
`fk_devise` int(10) unsigned DEFAULT 1,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
KEY `x_pays_ibfk_1` (`fk_devise`),
|
||||
CONSTRAINT `x_pays_ibfk_1` FOREIGN KEY (`fk_devise`) REFERENCES `x_devises` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Table des pays avec leurs codes' `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_regions` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_pays` int(10) unsigned DEFAULT 1,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`libelle_long` varchar(45) DEFAULT NULL,
|
||||
`table_osm` varchar(45) DEFAULT NULL,
|
||||
`departements` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
KEY `x_regions_ibfk_1` (`fk_pays`),
|
||||
CONSTRAINT `x_regions_ibfk_1` FOREIGN KEY (`fk_pays`) REFERENCES `x_pays` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_types_passages` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(10) DEFAULT NULL,
|
||||
`color_button` varchar(15) DEFAULT NULL,
|
||||
`color_mark` varchar(15) DEFAULT NULL,
|
||||
`color_table` varchar(15) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_types_reglements` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_users_roles` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Les différents rôles des utilisateurs' `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_users_titres` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Les différents titres des utilisateurs' `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `x_villes` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_departement` int(10) unsigned DEFAULT 1,
|
||||
`libelle` varchar(65) DEFAULT NULL,
|
||||
`code_postal` varchar(5) DEFAULT NULL,
|
||||
`code_insee` varchar(5) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
KEY `x_villes_ibfk_1` (`fk_departement`),
|
||||
CONSTRAINT `x_villes_ibfk_1` FOREIGN KEY (`fk_departement`) REFERENCES `x_departements` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=38950 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE TABLE `z_sessions` (
|
||||
`sid` text NOT NULL,
|
||||
`fk_user` int(11) NOT NULL,
|
||||
`role` varchar(10) DEFAULT NULL,
|
||||
`date_modified` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||
`ip` varchar(50) NOT NULL,
|
||||
`browser` varchar(150) NOT NULL,
|
||||
`data` mediumtext DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';
|
||||
|
||||
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `chat_conversations_unread` AS select `r`.`id` AS `id`,`r`.`type` AS `type`,`r`.`title` AS `title`,`r`.`date_creation` AS `date_creation`,`r`.`fk_user` AS `fk_user`,`r`.`fk_entite` AS `fk_entite`,`r`.`statut` AS `statut`,`r`.`description` AS `description`,`r`.`reply_permission` AS `reply_permission`,`r`.`is_pinned` AS `is_pinned`,`r`.`expiry_date` AS `expiry_date`,`r`.`updated_at` AS `updated_at`,count(distinct `m`.`id`) AS `total_messages`,count(distinct `rm`.`id`) AS `read_messages`,count(distinct `m`.`id`) - count(distinct `rm`.`id`) AS `unread_messages`,(select `geo_app`.`chat_messages`.`date_sent` from `chat_messages` where `geo_app`.`chat_messages`.`fk_room` = `r`.`id` order by `geo_app`.`chat_messages`.`date_sent` desc limit 1) AS `last_message_date` from ((`chat_rooms` `r` left join `chat_messages` `m` on(`r`.`id` = `m`.`fk_room`)) left join `chat_read_messages` `rm` on(`m`.`id` = `rm`.`fk_message`)) group by `r`.`id`;
|
||||
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
@@ -1,621 +0,0 @@
|
||||
-- Création de la base de données geo_app si elle n'existe pas
|
||||
DROP DATABASE IF EXISTS `geo_app`;
|
||||
CREATE DATABASE IF NOT EXISTS `geo_app` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- Création de l'utilisateur et attribution des droits
|
||||
CREATE USER IF NOT EXISTS 'geo_app_user'@'localhost' IDENTIFIED BY 'QO:96df*?k{4W6m';
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON `geo_app`.* TO 'geo_app_user'@'localhost';
|
||||
FLUSH PRIVILEGES;
|
||||
|
||||
USE geo_app;
|
||||
|
||||
--
|
||||
-- Table structure for table `email_counter`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `email_counter`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `email_counter` (
|
||||
`id` int unsigned NOT NULL DEFAULT '1',
|
||||
`hour_start` timestamp NULL DEFAULT NULL,
|
||||
`count` int unsigned DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `x_devises`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_devises` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`code` varchar(3) DEFAULT NULL,
|
||||
`symbole` varchar(6) DEFAULT NULL,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `x_entites_types`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `x_entites_types`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_entites_types` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `x_types_passages`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `x_types_passages`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_types_passages` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`color_button` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`color_mark` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`color_table` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `x_types_reglements`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `x_types_reglements`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_types_reglements` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `x_users_roles`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `x_users_roles`;
|
||||
|
||||
CREATE TABLE `x_users_roles` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Les différents rôles des utilisateurs';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `x_users_titres`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_users_titres` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Les différents titres des utilisateurs';
|
||||
|
||||
DROP TABLE IF EXISTS `x_pays`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_pays` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`code` varchar(3) DEFAULT NULL,
|
||||
`fk_continent` int unsigned DEFAULT NULL,
|
||||
`fk_devise` int unsigned DEFAULT '1',
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
CONSTRAINT `x_pays_ibfk_1` FOREIGN KEY (`fk_devise`) REFERENCES `x_devises` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Table des pays avec leurs codes';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `x_regions`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_regions` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_pays` int unsigned DEFAULT '1',
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`libelle_long` varchar(45) DEFAULT NULL,
|
||||
`table_osm` varchar(45) DEFAULT NULL,
|
||||
`departements` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
CONSTRAINT `x_regions_ibfk_1` FOREIGN KEY (`fk_pays`) REFERENCES `x_pays` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `x_departements`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_departements` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`code` varchar(3) DEFAULT NULL,
|
||||
`fk_region` int unsigned DEFAULT '1',
|
||||
`libelle` varchar(45) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
CONSTRAINT `x_departements_ibfk_1` FOREIGN KEY (`fk_region`) REFERENCES `x_regions` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `entites`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `entites` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`encrypted_name` varchar(255) DEFAULT NULL,
|
||||
`adresse1` varchar(45) DEFAULT '',
|
||||
`adresse2` varchar(45) DEFAULT '',
|
||||
`code_postal` varchar(5) DEFAULT '',
|
||||
`ville` varchar(45) DEFAULT '',
|
||||
`fk_region` int unsigned DEFAULT NULL,
|
||||
`fk_type` int unsigned DEFAULT '1',
|
||||
`encrypted_phone` varchar(128) DEFAULT '',
|
||||
`encrypted_mobile` varchar(128) DEFAULT '',
|
||||
`encrypted_email` varchar(255) DEFAULT '',
|
||||
`gps_lat` varchar(20) NOT NULL DEFAULT '',
|
||||
`gps_lng` varchar(20) NOT NULL DEFAULT '',
|
||||
`encrypted_stripe_id` varchar(255) DEFAULT '',
|
||||
`encrypted_iban` varchar(255) DEFAULT '',
|
||||
`encrypted_bic` varchar(128) DEFAULT '',
|
||||
`chk_demo` tinyint(1) unsigned DEFAULT '1',
|
||||
`chk_mdp_manuel` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT 'Gestion des mots de passe manuelle O/N',
|
||||
`chk_copie_mail_recu` tinyint(1) unsigned NOT NULL DEFAULT '0',
|
||||
`chk_accept_sms` tinyint(1) unsigned NOT NULL DEFAULT '0',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`fk_user_creat` int unsigned DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
`fk_user_modif` int unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `entites_ibfk_1` FOREIGN KEY (`fk_region`) REFERENCES `x_regions` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `entites_ibfk_2` FOREIGN KEY (`fk_type`) REFERENCES `x_entites_types` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `x_villes`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `x_villes` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_departement` int unsigned DEFAULT '1',
|
||||
`libelle` varchar(65) DEFAULT NULL,
|
||||
`cp` varchar(5) DEFAULT NULL,
|
||||
`code_insee` varchar(5) DEFAULT NULL,
|
||||
`departement` varchar(65) DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
CONSTRAINT `x_villes_ibfk_1` FOREIGN KEY (`fk_departement`) REFERENCES `x_departements` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `users`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `users` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_entite` int unsigned DEFAULT '1',
|
||||
`fk_role` int unsigned DEFAULT '1',
|
||||
`fk_titre` int unsigned DEFAULT '1',
|
||||
`encrypted_name` varchar(255) DEFAULT NULL,
|
||||
`first_name` varchar(45) DEFAULT NULL,
|
||||
`sect_name` varchar(60) DEFAULT '',
|
||||
`encrypted_user_name` varchar(128) DEFAULT '',
|
||||
`user_pass_hash` varchar(60) DEFAULT NULL,
|
||||
`encrypted_phone` varchar(128) DEFAULT NULL,
|
||||
`encrypted_mobile` varchar(128) DEFAULT NULL,
|
||||
`encrypted_email` varchar(255) DEFAULT '',
|
||||
`chk_alert_email` tinyint(1) unsigned DEFAULT '1',
|
||||
`chk_suivi` tinyint(1) unsigned DEFAULT '0',
|
||||
`date_naissance` date DEFAULT NULL,
|
||||
`date_embauche` date DEFAULT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`fk_user_creat` int unsigned DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
`fk_user_modif` int unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_entite` (`fk_entite`),
|
||||
KEY `username` (`encrypted_user_name`),
|
||||
CONSTRAINT `users_ibfk_1` FOREIGN KEY (`fk_entite`) REFERENCES `entites` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `users_ibfk_2` FOREIGN KEY (`fk_role`) REFERENCES `x_users_roles` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `users_ibfk_3` FOREIGN KEY (`fk_titre`) REFERENCES `x_users_titres` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `operations`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `operations` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_entite` int unsigned NOT NULL DEFAULT '1',
|
||||
`libelle` varchar(75) NOT NULL DEFAULT '',
|
||||
`date_deb` date NOT NULL DEFAULT '0000-00-00',
|
||||
`date_fin` date NOT NULL DEFAULT '0000-00-00',
|
||||
`chk_distinct_sectors` tinyint(1) unsigned NOT NULL DEFAULT '0',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`fk_user_creat` int unsigned NOT NULL DEFAULT '0',
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
`fk_user_modif` int unsigned NOT NULL DEFAULT '0',
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_entite` (`fk_entite`),
|
||||
KEY `date_deb` (`date_deb`),
|
||||
CONSTRAINT `operations_ibfk_1` FOREIGN KEY (`fk_entite`) REFERENCES `entites` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ope_sectors`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `ope_sectors` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int unsigned NOT NULL DEFAULT '0',
|
||||
`fk_old_sector` int unsigned NOT NULL DEFAULT '0',
|
||||
`libelle` varchar(75) NOT NULL DEFAULT '',
|
||||
`sector` text NOT NULL DEFAULT '',
|
||||
`color` varchar(7) NOT NULL DEFAULT '#4B77BE',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`fk_user_creat` int unsigned NOT NULL DEFAULT '0',
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
`fk_user_modif` int unsigned NOT NULL DEFAULT '0',
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`),
|
||||
KEY `fk_operation` (`fk_operation`),
|
||||
CONSTRAINT `ope_sectors_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ope_users`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `ope_users` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int unsigned NOT NULL DEFAULT '0',
|
||||
`fk_user` int unsigned NOT NULL DEFAULT '0',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`fk_user_creat` int unsigned DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
`fk_user_modif` int unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`),
|
||||
CONSTRAINT `ope_users_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_users_ibfk_2` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `email_queue`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `email_queue` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_pass` int unsigned NOT NULL DEFAULT '0',
|
||||
`to_email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`subject` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`body` text COLLATE utf8mb4_unicode_ci,
|
||||
`headers` text COLLATE utf8mb4_unicode_ci,
|
||||
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`status` enum('pending','sent','failed') COLLATE utf8mb4_unicode_ci DEFAULT 'pending',
|
||||
`sent_at` timestamp NULL DEFAULT NULL,
|
||||
`attempts` int unsigned DEFAULT '0',
|
||||
`error_message` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `ope_users_sectors`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `ope_users_sectors` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int unsigned NOT NULL DEFAULT '0',
|
||||
`fk_user` int unsigned NOT NULL DEFAULT '0',
|
||||
`fk_sector` int unsigned NOT NULL DEFAULT '0',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`fk_user_creat` int unsigned NOT NULL DEFAULT '0',
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
`fk_user_modif` int unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`),
|
||||
KEY `fk_operation` (`fk_operation`),
|
||||
KEY `fk_user` (`fk_user`),
|
||||
KEY `fk_sector` (`fk_sector`),
|
||||
CONSTRAINT `ope_users_sectors_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_users_sectors_ibfk_2` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_users_sectors_ibfk_3` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `ope_users_suivis`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `ope_users_suivis` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int unsigned NOT NULL DEFAULT '0',
|
||||
`fk_user` int unsigned NOT NULL DEFAULT '0',
|
||||
`date_suivi` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date du suivi',
|
||||
`gps_lat` varchar(20) NOT NULL DEFAULT '',
|
||||
`gps_lng` varchar(20) NOT NULL DEFAULT '',
|
||||
`vitesse` varchar(20) NOT NULL DEFAULT '',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`fk_user_creat` int unsigned NOT NULL DEFAULT '0',
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
`fk_user_modif` int unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `sectors_adresses`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `sectors_adresses` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_adresse` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'adresses.cp??.id',
|
||||
`osm_id` int unsigned NOT NULL DEFAULT '0',
|
||||
`fk_sector` int unsigned NOT NULL DEFAULT '0',
|
||||
`osm_name` varchar(50) NOT NULL DEFAULT '',
|
||||
`numero` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`rue_bis` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`rue` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`cp` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`ville` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`gps_lat` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`gps_lng` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`osm_date_creat` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `sectors_adresses_fk_sector_index` (`fk_sector`),
|
||||
KEY `sectors_adresses_numero_index` (`numero`),
|
||||
KEY `sectors_adresses_rue_index` (`rue`),
|
||||
KEY `sectors_adresses_ville_index` (`ville`),
|
||||
CONSTRAINT `sectors_adresses_ibfk_1` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS `ope_pass`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `ope_pass` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_operation` int unsigned NOT NULL DEFAULT '0',
|
||||
`fk_sector` int unsigned DEFAULT '0',
|
||||
`fk_user` int unsigned NOT NULL DEFAULT '0',
|
||||
`fk_adresse` varchar(25) DEFAULT '' COMMENT 'adresses.cp??.id',
|
||||
`passed_at` timestamp NULL DEFAULT NULL COMMENT 'Date du passage',
|
||||
`fk_type` int unsigned DEFAULT '0',
|
||||
`numero` varchar(10) NOT NULL DEFAULT '',
|
||||
`rue` varchar(75) NOT NULL DEFAULT '',
|
||||
`rue_bis` varchar(1) NOT NULL DEFAULT '',
|
||||
`ville` varchar(75) NOT NULL DEFAULT '',
|
||||
`fk_habitat` int unsigned DEFAULT '1',
|
||||
`appt` varchar(5) DEFAULT '',
|
||||
`niveau` varchar(5) DEFAULT '',
|
||||
`residence` varchar(75) DEFAULT '',
|
||||
`gps_lat` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`gps_lng` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`encrypted_name` varchar(255) NOT NULL DEFAULT '',
|
||||
`montant` decimal(7,2) NOT NULL DEFAULT '0.00',
|
||||
`fk_type_reglement` int unsigned DEFAULT '1',
|
||||
`remarque` text DEFAULT '',
|
||||
`encrypted_email` varchar(255) DEFAULT '',
|
||||
`nom_recu` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`date_recu` timestamp NULL DEFAULT NULL COMMENT 'Date de réception',
|
||||
`date_creat_recu` timestamp NULL DEFAULT NULL COMMENT 'Date de création du reçu',
|
||||
`date_sent_recu` timestamp NULL DEFAULT NULL COMMENT 'Date envoi du reçu',
|
||||
`email_erreur` varchar(30) DEFAULT '',
|
||||
`chk_email_sent` tinyint(1) unsigned NOT NULL DEFAULT '0',
|
||||
`encrypted_phone` varchar(128) NOT NULL DEFAULT '',
|
||||
`chk_striped` tinyint(1) unsigned DEFAULT '0',
|
||||
`docremis` tinyint(1) unsigned DEFAULT '0',
|
||||
`date_repasser` timestamp NULL DEFAULT NULL COMMENT 'Date prévue pour repasser',
|
||||
`nb_passages` int DEFAULT '1' COMMENT 'Nb passages pour les a repasser',
|
||||
`chk_gps_maj` tinyint(1) unsigned DEFAULT '0',
|
||||
`chk_map_create` tinyint(1) unsigned DEFAULT '0',
|
||||
`chk_mobile` tinyint(1) unsigned DEFAULT '0',
|
||||
`chk_synchro` tinyint(1) unsigned DEFAULT '1' COMMENT 'chk synchro entre web et appli',
|
||||
`chk_api_adresse` tinyint(1) unsigned DEFAULT '0',
|
||||
`chk_maj_adresse` tinyint(1) unsigned DEFAULT '0',
|
||||
`anomalie` tinyint(1) unsigned DEFAULT '0',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
`fk_user_creat` int unsigned DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date de modification',
|
||||
`fk_user_modif` int unsigned DEFAULT NULL,
|
||||
`chk_active` tinyint(1) unsigned NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_operation` (`fk_operation`),
|
||||
KEY `fk_sector` (`fk_sector`),
|
||||
KEY `fk_user` (`fk_user`),
|
||||
KEY `fk_type` (`fk_type`),
|
||||
KEY `fk_type_reglement` (`fk_type_reglement`),
|
||||
KEY `email` (`email`),
|
||||
CONSTRAINT `ope_pass_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_pass_ibfk_2` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_pass_ibfk_3` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `ope_pass_ibfk_4` FOREIGN KEY (`fk_type_reglement`) REFERENCES `x_types_reglements` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `ope_pass_histo`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `ope_pass_histo` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fk_pass` int unsigned NOT NULL DEFAULT '0',
|
||||
`date_histo` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date historique',
|
||||
`sujet` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`remarque` varchar(250) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `ope_pass_histo_fk_pass_IDX` (`fk_pass`) USING BTREE,
|
||||
KEY `ope_pass_histo_date_histo_IDX` (`date_histo`) USING BTREE,
|
||||
CONSTRAINT `ope_pass_histo_ibfk_1` FOREIGN KEY (`fk_pass`) REFERENCES `ope_pass` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
DROP TABLE IF EXISTS `medias`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `medias` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`support` varchar(45) NOT NULL DEFAULT '',
|
||||
`support_id` int unsigned NOT NULL DEFAULT '0',
|
||||
`fichier` varchar(250) NOT NULL DEFAULT '',
|
||||
`description` varchar(100) NOT NULL DEFAULT '',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`fk_user_creat` int unsigned NOT NULL DEFAULT '0',
|
||||
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
`fk_user_modif` int unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id_UNIQUE` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
-- Création des tables pour le système de chat
|
||||
DROP TABLE IF EXISTS `chat_rooms`;
|
||||
-- Table des salles de discussion
|
||||
CREATE TABLE chat_rooms (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
type ENUM('privee', 'groupe', 'liste_diffusion') NOT NULL,
|
||||
date_creation timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
fk_user INT UNSIGNED NOT NULL,
|
||||
fk_entite INT UNSIGNED,
|
||||
statut ENUM('active', 'archive') NOT NULL DEFAULT 'active',
|
||||
description TEXT,
|
||||
INDEX idx_user (fk_user),
|
||||
INDEX idx_entite (fk_entite)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `chat_participants`;
|
||||
-- Table des participants aux salles de discussion
|
||||
CREATE TABLE chat_participants (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
id_room INT UNSIGNED NOT NULL,
|
||||
id_user INT UNSIGNED NOT NULL,
|
||||
role ENUM('administrateur', 'participant', 'en_lecture_seule') NOT NULL DEFAULT 'participant',
|
||||
date_ajout timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date ajout',
|
||||
notification_activee BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
INDEX idx_room (id_room),
|
||||
INDEX idx_user (id_user),
|
||||
CONSTRAINT uc_room_user UNIQUE (id_room, id_user),
|
||||
FOREIGN KEY (id_room) REFERENCES chat_rooms(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS `chat_messages`;
|
||||
-- Table des messages
|
||||
CREATE TABLE chat_messages (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
fk_room INT UNSIGNED NOT NULL,
|
||||
fk_user INT UNSIGNED NOT NULL,
|
||||
content TEXT,
|
||||
date_sent timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date envoi',
|
||||
type ENUM('texte', 'media', 'systeme') NOT NULL DEFAULT 'texte',
|
||||
statut ENUM('envoye', 'livre', 'lu') NOT NULL DEFAULT 'envoye',
|
||||
INDEX idx_room (fk_room),
|
||||
INDEX idx_user (fk_user),
|
||||
INDEX idx_date (date_sent),
|
||||
FOREIGN KEY (fk_room) REFERENCES chat_rooms(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS `chat_listes_diffusion`;
|
||||
-- Table des listes de diffusion
|
||||
CREATE TABLE chat_listes_diffusion (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
fk_room INT UNSIGNED NOT NULL,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
description TEXT,
|
||||
fk_user INT UNSIGNED NOT NULL,
|
||||
date_creation timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
INDEX idx_room (fk_room),
|
||||
INDEX idx_user (fk_user),
|
||||
FOREIGN KEY (fk_room) REFERENCES chat_rooms(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS `chat_read_messages`;
|
||||
-- Table pour suivre la lecture des messages
|
||||
CREATE TABLE chat_read_messages (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
fk_message INT UNSIGNED NOT NULL,
|
||||
fk_user INT UNSIGNED NOT NULL,
|
||||
date_read timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de lecture',
|
||||
INDEX idx_message (fk_message),
|
||||
INDEX idx_user (fk_user),
|
||||
CONSTRAINT uc_message_user UNIQUE (fk_message, fk_user),
|
||||
FOREIGN KEY (fk_message) REFERENCES chat_messages(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS `chat_notifications`;
|
||||
-- Table des notifications
|
||||
CREATE TABLE chat_notifications (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
fk_user INT UNSIGNED NOT NULL,
|
||||
fk_message INT UNSIGNED,
|
||||
fk_room INT UNSIGNED,
|
||||
type VARCHAR(50) NOT NULL,
|
||||
contenu TEXT,
|
||||
date_creation timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création',
|
||||
date_lecture timestamp NULL DEFAULT NULL COMMENT 'Date de lecture',
|
||||
statut ENUM('non_lue', 'lue') NOT NULL DEFAULT 'non_lue',
|
||||
INDEX idx_user (fk_user),
|
||||
INDEX idx_message (fk_message),
|
||||
INDEX idx_room (fk_room),
|
||||
FOREIGN KEY (fk_message) REFERENCES chat_messages(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (fk_room) REFERENCES chat_rooms(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
DROP TABLE IF EXISTS `z_params`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `params` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`libelle` varchar(35) NOT NULL DEFAULT '',
|
||||
`valeur` varchar(255) NOT NULL DEFAULT '',
|
||||
`aide` varchar(150) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `z_sessions`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `z_sessions` (
|
||||
`sid` text NOT NULL,
|
||||
`fk_user` int NOT NULL,
|
||||
`role` varchar(10) DEFAULT NULL,
|
||||
`date_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`ip` varchar(50) NOT NULL,
|
||||
`browser` varchar(150) NOT NULL,
|
||||
`data` mediumtext
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
BIN
api/docs/recu_13718.pdf
Normal file
BIN
api/docs/recu_13718.pdf
Normal file
Binary file not shown.
193
api/docs/traite_batiments.sql
Normal file
193
api/docs/traite_batiments.sql
Normal file
@@ -0,0 +1,193 @@
|
||||
USE batiments;
|
||||
|
||||
-- Table temp pour FFO (nb_niveau, nb_log)
|
||||
DROP TABLE IF EXISTS tmp_ffo_999;
|
||||
CREATE TABLE tmp_ffo_999 (
|
||||
batiment_groupe_id VARCHAR(50),
|
||||
code_departement_insee VARCHAR(5),
|
||||
nb_niveau INT,
|
||||
annee_construction INT,
|
||||
usage_niveau_1_txt VARCHAR(100),
|
||||
mat_mur_txt VARCHAR(100),
|
||||
mat_toit_txt VARCHAR(100),
|
||||
nb_log INT,
|
||||
KEY (batiment_groupe_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
LOAD DATA LOCAL INFILE '/var/osm/csv/batiment_groupe_ffo_bat.csv'
|
||||
INTO TABLE tmp_ffo_999
|
||||
CHARACTER SET 'UTF8mb4'
|
||||
FIELDS TERMINATED BY ','
|
||||
OPTIONALLY ENCLOSED BY '"'
|
||||
IGNORE 1 LINES;
|
||||
|
||||
-- Table temp pour Adresse (lien BAN)
|
||||
DROP TABLE IF EXISTS tmp_adr_999;
|
||||
CREATE TABLE tmp_adr_999 (
|
||||
wkt TEXT,
|
||||
batiment_groupe_id VARCHAR(50),
|
||||
cle_interop_adr VARCHAR(50),
|
||||
code_departement_insee VARCHAR(5),
|
||||
classe VARCHAR(50),
|
||||
lien_valide TINYINT,
|
||||
origine VARCHAR(50),
|
||||
KEY (batiment_groupe_id),
|
||||
KEY (cle_interop_adr)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
LOAD DATA LOCAL INFILE '/var/osm/csv/rel_batiment_groupe_adresse.csv'
|
||||
INTO TABLE tmp_adr_999
|
||||
CHARACTER SET 'UTF8mb4'
|
||||
FIELDS TERMINATED BY ','
|
||||
OPTIONALLY ENCLOSED BY '"'
|
||||
IGNORE 1 LINES;
|
||||
|
||||
-- Table temp pour RNC (copropriétés)
|
||||
DROP TABLE IF EXISTS tmp_rnc_999;
|
||||
CREATE TABLE tmp_rnc_999 (
|
||||
batiment_groupe_id VARCHAR(50),
|
||||
code_departement_insee VARCHAR(5),
|
||||
numero_immat_principal VARCHAR(50),
|
||||
periode_construction_max VARCHAR(50),
|
||||
l_annee_construction VARCHAR(100),
|
||||
nb_lot_garpark INT,
|
||||
nb_lot_tot INT,
|
||||
nb_log INT,
|
||||
nb_lot_tertiaire INT,
|
||||
l_nom_copro VARCHAR(200),
|
||||
l_siret VARCHAR(50),
|
||||
copro_dans_pvd TINYINT,
|
||||
KEY (batiment_groupe_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
LOAD DATA LOCAL INFILE '/var/osm/csv/batiment_groupe_rnc.csv'
|
||||
INTO TABLE tmp_rnc_999
|
||||
CHARACTER SET 'UTF8mb4'
|
||||
FIELDS TERMINATED BY ','
|
||||
OPTIONALLY ENCLOSED BY '"'
|
||||
IGNORE 1 LINES;
|
||||
|
||||
-- Table temp pour BDTOPO (altitude)
|
||||
DROP TABLE IF EXISTS tmp_topo_999;
|
||||
CREATE TABLE tmp_topo_999 (
|
||||
batiment_groupe_id VARCHAR(50),
|
||||
code_departement_insee VARCHAR(5),
|
||||
l_nature VARCHAR(200),
|
||||
l_usage_1 VARCHAR(200),
|
||||
l_usage_2 VARCHAR(200),
|
||||
l_etat VARCHAR(100),
|
||||
hauteur_mean DECIMAL(10,2),
|
||||
max_hauteur DECIMAL(10,2),
|
||||
altitude_sol_mean DECIMAL(10,2),
|
||||
KEY (batiment_groupe_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
LOAD DATA LOCAL INFILE '/var/osm/csv/batiment_groupe_bdtopo_bat.csv'
|
||||
INTO TABLE tmp_topo_999
|
||||
CHARACTER SET 'UTF8mb4'
|
||||
FIELDS TERMINATED BY ','
|
||||
OPTIONALLY ENCLOSED BY '"'
|
||||
IGNORE 1 LINES;
|
||||
|
||||
-- Table temp pour Usage principal
|
||||
DROP TABLE IF EXISTS tmp_usage_999;
|
||||
CREATE TABLE tmp_usage_999 (
|
||||
batiment_groupe_id VARCHAR(50),
|
||||
code_departement_insee VARCHAR(5),
|
||||
usage_principal_bdnb_open VARCHAR(100),
|
||||
KEY (batiment_groupe_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
LOAD DATA LOCAL INFILE '/var/osm/csv/batiment_groupe_synthese_propriete_usage.csv'
|
||||
INTO TABLE tmp_usage_999
|
||||
CHARACTER SET 'UTF8mb4'
|
||||
FIELDS TERMINATED BY ','
|
||||
OPTIONALLY ENCLOSED BY '"'
|
||||
IGNORE 1 LINES;
|
||||
|
||||
-- Table temp pour DLE Enedis (compteurs électriques)
|
||||
DROP TABLE IF EXISTS tmp_dle_999;
|
||||
CREATE TABLE tmp_dle_999 (
|
||||
batiment_groupe_id VARCHAR(50),
|
||||
code_departement_insee VARCHAR(5),
|
||||
millesime VARCHAR(10),
|
||||
nb_pdl_res INT,
|
||||
nb_pdl_pro INT,
|
||||
nb_pdl_tot INT,
|
||||
conso_res DECIMAL(12,2),
|
||||
conso_pro DECIMAL(12,2),
|
||||
conso_tot DECIMAL(12,2),
|
||||
conso_res_par_pdl DECIMAL(12,2),
|
||||
conso_pro_par_pdl DECIMAL(12,2),
|
||||
conso_tot_par_pdl DECIMAL(12,2),
|
||||
KEY (batiment_groupe_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
LOAD DATA LOCAL INFILE '/var/osm/csv/batiment_groupe_dle_elec_multimillesime.csv'
|
||||
INTO TABLE tmp_dle_999
|
||||
CHARACTER SET 'UTF8mb4'
|
||||
FIELDS TERMINATED BY ','
|
||||
OPTIONALLY ENCLOSED BY '"'
|
||||
IGNORE 1 LINES;
|
||||
|
||||
-- Création de la table finale avec jointure et filtre
|
||||
DROP TABLE IF EXISTS bat999;
|
||||
CREATE TABLE bat999 (
|
||||
batiment_groupe_id VARCHAR(50) PRIMARY KEY,
|
||||
code_departement_insee VARCHAR(5),
|
||||
cle_interop_adr VARCHAR(50),
|
||||
nb_niveau INT,
|
||||
nb_log INT,
|
||||
nb_pdl_tot INT,
|
||||
annee_construction INT,
|
||||
residence VARCHAR(200),
|
||||
usage_principal VARCHAR(100),
|
||||
altitude_sol_mean DECIMAL(10,2),
|
||||
gps_lat DECIMAL(10,7),
|
||||
gps_lng DECIMAL(10,7),
|
||||
KEY (cle_interop_adr),
|
||||
KEY (usage_principal),
|
||||
KEY (nb_log)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
INSERT INTO bat999
|
||||
SELECT
|
||||
f.batiment_groupe_id,
|
||||
f.code_departement_insee,
|
||||
a.cle_interop_adr,
|
||||
f.nb_niveau,
|
||||
f.nb_log,
|
||||
d.nb_pdl_tot,
|
||||
f.annee_construction,
|
||||
REPLACE(REPLACE(REPLACE(REPLACE(r.l_nom_copro, '[', ''), ']', ''), '"', ''), ' ', ' ') as residence,
|
||||
u.usage_principal_bdnb_open as usage_principal,
|
||||
t.altitude_sol_mean,
|
||||
NULL as gps_lat,
|
||||
NULL as gps_lng
|
||||
FROM tmp_ffo_999 f
|
||||
INNER JOIN tmp_adr_999 a ON f.batiment_groupe_id = a.batiment_groupe_id AND a.lien_valide = 1
|
||||
LEFT JOIN tmp_rnc_999 r ON f.batiment_groupe_id = r.batiment_groupe_id
|
||||
LEFT JOIN tmp_topo_999 t ON f.batiment_groupe_id = t.batiment_groupe_id
|
||||
LEFT JOIN tmp_usage_999 u ON f.batiment_groupe_id = u.batiment_groupe_id
|
||||
LEFT JOIN tmp_dle_999 d ON f.batiment_groupe_id = d.batiment_groupe_id
|
||||
WHERE u.usage_principal_bdnb_open IN ('Résidentiel individuel', 'Résidentiel collectif', 'Secondaire', 'Tertiaire')
|
||||
AND f.nb_log > 1
|
||||
AND a.cle_interop_adr IS NOT NULL
|
||||
GROUP BY f.batiment_groupe_id;
|
||||
|
||||
-- Mise à jour des coordonnées GPS depuis la base adresses
|
||||
UPDATE bat999 b
|
||||
JOIN adresses.cp999 a ON b.cle_interop_adr = a.id
|
||||
SET b.gps_lat = a.gps_lat, b.gps_lng = a.gps_lng
|
||||
WHERE b.cle_interop_adr IS NOT NULL;
|
||||
|
||||
-- Nettoyage des tables temporaires
|
||||
DROP TABLE IF EXISTS tmp_ffo_999;
|
||||
DROP TABLE IF EXISTS tmp_adr_999;
|
||||
DROP TABLE IF EXISTS tmp_rnc_999;
|
||||
DROP TABLE IF EXISTS tmp_topo_999;
|
||||
DROP TABLE IF EXISTS tmp_usage_999;
|
||||
DROP TABLE IF EXISTS tmp_dle_999;
|
||||
|
||||
-- Historique
|
||||
INSERT INTO _histo SET date_import=NOW(), dept='999', nb_batiments=(SELECT COUNT(*) FROM bat999);
|
||||
Reference in New Issue
Block a user