diff --git a/lib/pages/commande_item_validation.dart b/lib/pages/commande_item_validation.dart index e8f5e6b..8194210 100644 --- a/lib/pages/commande_item_validation.dart +++ b/lib/pages/commande_item_validation.dart @@ -209,7 +209,7 @@ class _ValidateAddItemsPageState extends State { try { // Préparer les données des nouveaux articles - // 1. Construire la liste des items sans commande_id à l’intérieur + // 1. Construire la liste des items sans commande_id à l'intérieur List> items = _newCartItems.map((cartItem) { return { @@ -236,9 +236,6 @@ class _ValidateAddItemsPageState extends State { body: json.encode(body), ); - // 4. Afficher la réponse backend - final responseData = jsonDecode(response.body); - print('✅ Réponse backend : $responseData'); if (response.statusCode == 200 || response.statusCode == 201) { final responseData = json.decode(response.body); @@ -249,6 +246,7 @@ class _ValidateAddItemsPageState extends State { } else { throw Exception('API returned success: false'); } + Navigator.pushReplacementNamed(context, '/commandes'); } else { throw Exception('Failed to add items: ${response.statusCode}'); } @@ -280,10 +278,20 @@ class _ValidateAddItemsPageState extends State { actions: [ ElevatedButton( onPressed: () { - // Retourner à la page précédente avec un indicateur de succès + // Fermer le dialog Navigator.of(context).pop(); - Navigator.of(context).pop(true); + + // Retourner à la page précédente avec un indicateur de succès et de rechargement + Navigator.of(context).pop({ + 'success': true, + 'shouldReload': true, + 'message': 'Articles ajoutés avec succès à la commande ${widget.numeroCommande}' + }); }, + style: ElevatedButton.styleFrom( + backgroundColor: Colors.green[700], + foregroundColor: Colors.white, + ), child: Text('OK'), ), ], @@ -365,59 +373,6 @@ class _ValidateAddItemsPageState extends State { ), ), SizedBox(height: 16), - - // Résumé des articles existants - // if (widget.commandeDetails != null && widget.commandeDetails!['items'] != null) ...[ - // Text( - // 'Articles déjà commandés:', - // style: TextStyle( - // fontSize: 16, - // fontWeight: FontWeight.w600, - // color: Colors.grey[700], - // ), - // ), - // SizedBox(height: 8), - // ...widget.commandeDetails!['items'].map((item) { - // final nom = item['menu_nom'] ?? 'Inconnu'; - // final quantite = item['quantite'] ?? 1; - // // Correction: utiliser 'menu_prix_actuel' au lieu de 'menu_prix' - // final prix = _parsePrice(item['menu_prix_actuel'] ?? item['prix_unitaire']); - - // return Padding( - // padding: const EdgeInsets.symmetric(vertical: 2), - // child: Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // Expanded( - // child: Text( - // '$nom x$quantite', - // style: TextStyle(fontSize: 14, color: Colors.grey[600]), - // ), - // ), - // Text( - // '${(prix * quantite).toStringAsFixed(2)} MGA', - // style: TextStyle(fontSize: 14, color: Colors.grey[600]), - // ), - // ], - // ), - // ); - // }).toList(), - // SizedBox(height: 8), - // Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // Text( - // 'Sous-total existant:', - // style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500), - // ), - // Text( - // '${_calculateExistingItemsTotal().toStringAsFixed(2)} MGA', - // style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500), - // ), - // ], - // ), - // Divider(height: 20), - // ], Text( 'Nouveaux articles à ajouter: ${_getTotalNewArticles()}', style: TextStyle( @@ -749,7 +704,7 @@ class _ValidateAddItemsPageState extends State { } } -// Réutiliser la même classe CartItemModel +// Classe CartItemModel class CartItemModel { final int id; final String nom; @@ -765,3 +720,90 @@ class CartItemModel { required this.notes, }); } + +/* +=============================================== +UTILISATION DANS LA PAGE QUI APPELLE ValidateAddItemsPage +=============================================== + +// Exemple d'utilisation dans votre page précédente : + +class CommandeDetailsPage extends StatefulWidget { + // ... vos propriétés +} + +class _CommandeDetailsPageState extends State { + // ... vos variables d'état + bool _isLoading = false; + + // Méthode pour naviguer vers ValidateAddItemsPage + Future _navigateToValidateAddItems() async { + final result = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ValidateAddItemsPage( + commandeId: widget.commandeId, + numeroCommande: widget.numeroCommande, + newItems: selectedItems, // vos articles sélectionnés + commandeDetails: commandeDetails, // détails de la commande + ), + ), + ); + + // Vérifier si un rechargement est nécessaire + if (result != null && result is Map && result['shouldReload'] == true) { + // Afficher un message de succès + if (result['message'] != null) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(result['message']), + backgroundColor: Colors.green[700], + duration: Duration(seconds: 3), + ), + ); + } + + // Recharger les données de la commande + await _refreshCommandeData(); + } + } + + // Méthode pour recharger les données + Future _refreshCommandeData() async { + setState(() { + _isLoading = true; + }); + + try { + // Votre logique de rechargement des données ici + // Par exemple : + // await _loadCommandeDetails(); + // await _loadCommandeItems(); + + print('🔄 Données rechargées avec succès'); + } catch (e) { + print('❌ Erreur lors du rechargement : $e'); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Erreur lors du rechargement des données'), + backgroundColor: Colors.red, + ), + ); + } finally { + setState(() { + _isLoading = false; + }); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + // ... votre UI + body: _isLoading + ? Center(child: CircularProgressIndicator()) + : // ... votre contenu normal + ); + } +} +*/ \ No newline at end of file diff --git a/lib/pages/commandes_screen.dart b/lib/pages/commandes_screen.dart index 49af7c0..2c63a8d 100644 --- a/lib/pages/commandes_screen.dart +++ b/lib/pages/commandes_screen.dart @@ -398,21 +398,6 @@ class _OrdersManagementScreenState extends State { ), toolbarHeight: 80, actions: [ - IconButton( - icon: const Icon(Icons.kitchen, color: Colors.grey), - onPressed: loadKitchenOrders, - tooltip: 'Commandes cuisine', - ), - IconButton( - icon: const Icon(Icons.bar_chart, color: Colors.grey), - onPressed: loadOrderStats, - tooltip: 'Statistiques', - ), - IconButton( - icon: const Icon(Icons.add, color: Colors.green), - onPressed: createNewOrder, - tooltip: 'Nouvelle commande', - ), IconButton( icon: const Icon(Icons.refresh, color: Colors.grey), onPressed: loadOrders, @@ -530,6 +515,7 @@ class _OrdersManagementScreenState extends State { } } + class OrderCard extends StatelessWidget { final Order order; final Function(Order, String, {String? modePaiement}) onStatusUpdate; @@ -663,19 +649,20 @@ class OrderCard extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - '${item.quantite}x ${item.menuId}', // You might want to resolve menu name - style: const TextStyle( - fontSize: 14, - color: Colors.black87, - ), - ), - Text( - '${(item.quantite * 8.00).toStringAsFixed(2)} MGA', // Placeholder price + '${item.quantite}x ${item.nom}', // You might want to resolve menu name style: const TextStyle( fontSize: 14, color: Colors.black87, ), ), + Text( + '${(item.pu ?? 0) * item.quantite} MGA', + style: const TextStyle( + fontSize: 14, + color: Colors.black87, + ), + ), + ], ), ), @@ -703,7 +690,7 @@ class OrderCard extends StatelessWidget { ), ), Text( - '${order.totalTtc.toStringAsFixed(2)} MGA', + '${order.totalHt.toStringAsFixed(2)} MGA', style: const TextStyle( fontSize: 16, fontWeight: FontWeight.bold, @@ -935,14 +922,20 @@ class OrderItem { final int menuId; final int quantite; final String? commentaires; + final String? nom; + final double? pu; - OrderItem({required this.menuId, required this.quantite, this.commentaires}); + OrderItem({required this.menuId, required this.quantite, this.commentaires, this.nom, this.pu}); factory OrderItem.fromJson(Map json) { return OrderItem( menuId: json['menu_id'], quantite: json['quantite'], commentaires: json['commentaires'], + nom: json['menu_nom'], + pu: json['menu_prix_actuel'] != null + ? double.tryParse(json['menu_prix_actuel'].toString()) + : null, ); } } diff --git a/lib/pages/tables.dart b/lib/pages/tables.dart index 389e631..9583403 100644 --- a/lib/pages/tables.dart +++ b/lib/pages/tables.dart @@ -71,6 +71,14 @@ class _TablesScreenState extends State { } } + // Fonction pour actualiser les tables + Future _reloadTables() async { + setState(() { + isLoading = true; + }); + await fetchTables(); + } + Future _addTable() async { // Add table logic final result = await showDialog>( @@ -273,6 +281,13 @@ class _TablesScreenState extends State { ], ), ), + // Reload button + IconButton( + icon: const Icon(Icons.refresh, color: Colors.grey), + onPressed: _reloadTables, + tooltip: 'Actualiser', + ), + const SizedBox(width: 8), // Add button (desktop only) if (isDesktop) ElevatedButton.icon( @@ -653,4 +668,4 @@ class _AddEditTableDialogState extends State<_AddEditTableDialog> { ], ); } -} +} \ No newline at end of file