Browse Source

status

master
andrymodeste 4 months ago
parent
commit
b20000ce13
  1. 16
      lib/pages/cart_page.dart
  2. 57
      lib/pages/commandes_screen.dart
  3. 8
      lib/pages/tables.dart
  4. 3
      windows/flutter/generated_plugin_registrant.cc
  5. 1
      windows/flutter/generated_plugins.cmake

16
lib/pages/cart_page.dart

@ -183,10 +183,11 @@ class _CartPageState extends State<CartPage> {
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<CartPage> {
);
}
Future<void> _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,

57
lib/pages/commandes_screen.dart

@ -138,6 +138,8 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> {
return null;
}
Future<void> updateOrderStatus(
Order order,
String newStatus, {
@ -285,6 +287,9 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> {
}
}
List<Order> get activeOrders {
return orders
.where(
@ -311,29 +316,6 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> {
Text(
'Table ${order.tableId} - ${order.totalTtc.toStringAsFixed(2)} MGA',
),
const SizedBox(height: 16),
const Text('Mode de paiement:'),
const SizedBox(height: 8),
DropdownButton<String>(
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<OrdersManagementScreen> {
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<OrdersManagementScreen> {
);
}
Future<void> updateTableStatus(int tableId, String newStatus) async {
const String apiUrl = 'https://restaurant.careeracademy.mg/api/tables'; // adapte lURL 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(

8
lib/pages/tables.dart

@ -60,7 +60,7 @@ class _TablesScreenState extends State<TablesScreen> {
} 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<TablesScreen> {
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<TablesScreen> {
),
),
),
const SizedBox(height: 12),
Row(
children: [
Text(
@ -440,6 +441,7 @@ class _TablesScreenState extends State<TablesScreen> {
),
],
),
const SizedBox(height: 15),
// const Spacer(),
SizedBox(
width: double.infinity,

3
windows/flutter/generated_plugin_registrant.cc

@ -6,9 +6,6 @@
#include "generated_plugin_registrant.h"
#include <permission_handler_windows/permission_handler_windows_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
}

1
windows/flutter/generated_plugins.cmake

@ -3,7 +3,6 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
permission_handler_windows
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

Loading…
Cancel
Save