From b20000ce1390c338cbd5bb4442872dbe8647f327 Mon Sep 17 00:00:00 2001 From: andrymodeste Date: Sat, 2 Aug 2025 13:50:30 +0200 Subject: [PATCH] status --- lib/pages/cart_page.dart | 16 +++++- lib/pages/commandes_screen.dart | 57 ++++++++++--------- lib/pages/tables.dart | 8 ++- .../flutter/generated_plugin_registrant.cc | 3 - windows/flutter/generated_plugins.cmake | 1 - 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/lib/pages/cart_page.dart b/lib/pages/cart_page.dart index d8f53fb..1047bf9 100644 --- a/lib/pages/cart_page.dart +++ b/lib/pages/cart_page.dart @@ -183,10 +183,11 @@ class _CartPageState extends State { headers: {'Content-Type': 'application/json'}, body: json.encode(orderData), ); - print('response body: ${response.body}'); + // print('response body: ${response.body}'); if (response.statusCode == 200 || response.statusCode == 201) { // Succès + _updateTableStatus(); _showSuccessDialog(); } else { // Erreur @@ -249,6 +250,19 @@ class _CartPageState extends State { ); } + Future _updateTableStatus() async { + try { + final updateResponse = await http.put( + Uri.parse('https://restaurant.careeracademy.mg/api/tables/${widget.tableId}'), + headers: {'Content-Type': 'application/json'}, + body: json.encode({"status": "occupied"}), + ); + } catch (e) { + print("Erreur lors de la mise à jour du statut de la table: $e"); + } +} + + void _showErrorDialog(String message) { showDialog( context: context, diff --git a/lib/pages/commandes_screen.dart b/lib/pages/commandes_screen.dart index d1c7c23..83a7264 100644 --- a/lib/pages/commandes_screen.dart +++ b/lib/pages/commandes_screen.dart @@ -138,6 +138,8 @@ class _OrdersManagementScreenState extends State { return null; } + + Future updateOrderStatus( Order order, String newStatus, { @@ -285,6 +287,9 @@ class _OrdersManagementScreenState extends State { } } + + + List get activeOrders { return orders .where( @@ -311,29 +316,6 @@ class _OrdersManagementScreenState extends State { Text( 'Table ${order.tableId} - ${order.totalTtc.toStringAsFixed(2)} MGA', ), - const SizedBox(height: 16), - const Text('Mode de paiement:'), - const SizedBox(height: 8), - DropdownButton( - value: selectedPaymentMethod, - isExpanded: true, - items: const [ - DropdownMenuItem( - value: 'carte', - child: Text('Carte bancaire'), - ), - DropdownMenuItem( - value: 'especes', - child: Text('Espèces'), - ), - DropdownMenuItem(value: 'cheque', child: Text('Chèque')), - ], - onChanged: (value) { - setState(() { - selectedPaymentMethod = value!; - }); - }, - ), ], ), actions: [ @@ -342,22 +324,28 @@ class _OrdersManagementScreenState extends State { child: const Text('Annuler'), ), ElevatedButton( - onPressed: () { + onPressed: () async { Navigator.of(context).pop(); - updateOrderStatus( + + // 1. Mettre à jour le statut de la commande + await updateOrderStatus( order, "payee", modePaiement: selectedPaymentMethod, ); + + // 2. Rendre la table disponible + await updateTableStatus(order.tableId, "available"); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.green, ), child: const Text( - 'Confirmer le paiement', + 'Mettre en caisse', style: TextStyle(color: Colors.white), ), ), + ], ); }, @@ -366,6 +354,23 @@ class _OrdersManagementScreenState extends State { ); } + Future updateTableStatus(int tableId, String newStatus) async { + const String apiUrl = 'https://restaurant.careeracademy.mg/api/tables'; // ← adapte l’URL si besoin + + final response = await http.put( + Uri.parse('$apiUrl/$tableId'), + headers: {'Content-Type': 'application/json'}, + body: jsonEncode({'status': newStatus}), + ); + + if (response.statusCode != 200) { + print('Erreur lors de la mise à jour du statut de la table'); + throw Exception('Erreur: ${response.body}'); + } else { + print('✅ Table $tableId mise à jour en $newStatus'); + } +} + @override Widget build(BuildContext context) { return Scaffold( diff --git a/lib/pages/tables.dart b/lib/pages/tables.dart index c01ff9d..2b58088 100644 --- a/lib/pages/tables.dart +++ b/lib/pages/tables.dart @@ -60,7 +60,7 @@ class _TablesScreenState extends State { } else { setState(() => isLoading = false); if (kDebugMode) { - print('Erreur API: ${response.statusCode}'); + // print('Erreur API: ${response.statusCode}'); } } } catch (e) { @@ -308,8 +308,8 @@ class _TablesScreenState extends State { mainAxisSpacing: 12, childAspectRatio: isDesktop - ? 0.8 - : 0.6, // Modifié ici pour diminuer la taille + ? 1.7 + : 2.1, ), itemCount: tables.length, itemBuilder: (context, index) { @@ -408,6 +408,7 @@ class _TablesScreenState extends State { ), ), ), + const SizedBox(height: 12), Row( children: [ Text( @@ -440,6 +441,7 @@ class _TablesScreenState extends State { ), ], ), + const SizedBox(height: 15), // const Spacer(), SizedBox( width: double.infinity, diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 48de52b..8b6d468 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,6 @@ #include "generated_plugin_registrant.h" -#include void RegisterPlugins(flutter::PluginRegistry* registry) { - PermissionHandlerWindowsPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 0e69e40..b93c4c3 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - permission_handler_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST