|
|
@ -138,6 +138,8 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> updateOrderStatus( |
|
|
Future<void> updateOrderStatus( |
|
|
Order order, |
|
|
Order order, |
|
|
String newStatus, { |
|
|
String newStatus, { |
|
|
@ -285,6 +287,9 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Order> get activeOrders { |
|
|
List<Order> get activeOrders { |
|
|
return orders |
|
|
return orders |
|
|
.where( |
|
|
.where( |
|
|
@ -311,29 +316,6 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> { |
|
|
Text( |
|
|
Text( |
|
|
'Table ${order.tableId} - ${order.totalTtc.toStringAsFixed(2)} MGA', |
|
|
'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: [ |
|
|
actions: [ |
|
|
@ -342,22 +324,28 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> { |
|
|
child: const Text('Annuler'), |
|
|
child: const Text('Annuler'), |
|
|
), |
|
|
), |
|
|
ElevatedButton( |
|
|
ElevatedButton( |
|
|
onPressed: () { |
|
|
onPressed: () async { |
|
|
Navigator.of(context).pop(); |
|
|
Navigator.of(context).pop(); |
|
|
updateOrderStatus( |
|
|
|
|
|
|
|
|
// 1. Mettre à jour le statut de la commande |
|
|
|
|
|
await updateOrderStatus( |
|
|
order, |
|
|
order, |
|
|
"payee", |
|
|
"payee", |
|
|
modePaiement: selectedPaymentMethod, |
|
|
modePaiement: selectedPaymentMethod, |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 2. Rendre la table disponible |
|
|
|
|
|
await updateTableStatus(order.tableId, "available"); |
|
|
}, |
|
|
}, |
|
|
style: ElevatedButton.styleFrom( |
|
|
style: ElevatedButton.styleFrom( |
|
|
backgroundColor: Colors.green, |
|
|
backgroundColor: Colors.green, |
|
|
), |
|
|
), |
|
|
child: const Text( |
|
|
child: const Text( |
|
|
'Confirmer le paiement', |
|
|
'Mettre en caisse', |
|
|
style: TextStyle(color: Colors.white), |
|
|
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 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 |
|
|
@override |
|
|
Widget build(BuildContext context) { |
|
|
Widget build(BuildContext context) { |
|
|
return Scaffold( |
|
|
return Scaffold( |
|
|
|