status
This commit is contained in:
parent
d0687aa924
commit
b20000ce13
@ -183,10 +183,11 @@ class _CartPageState extends State<CartPage> {
|
|||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: json.encode(orderData),
|
body: json.encode(orderData),
|
||||||
);
|
);
|
||||||
print('response body: ${response.body}');
|
// print('response body: ${response.body}');
|
||||||
|
|
||||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
// Succès
|
// Succès
|
||||||
|
_updateTableStatus();
|
||||||
_showSuccessDialog();
|
_showSuccessDialog();
|
||||||
} else {
|
} else {
|
||||||
// Erreur
|
// 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) {
|
void _showErrorDialog(String message) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
@ -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(
|
||||||
|
|||||||
@ -60,7 +60,7 @@ class _TablesScreenState extends State<TablesScreen> {
|
|||||||
} else {
|
} else {
|
||||||
setState(() => isLoading = false);
|
setState(() => isLoading = false);
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
print('Erreur API: ${response.statusCode}');
|
// print('Erreur API: ${response.statusCode}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -308,8 +308,8 @@ class _TablesScreenState extends State<TablesScreen> {
|
|||||||
mainAxisSpacing: 12,
|
mainAxisSpacing: 12,
|
||||||
childAspectRatio:
|
childAspectRatio:
|
||||||
isDesktop
|
isDesktop
|
||||||
? 0.8
|
? 1.7
|
||||||
: 0.6, // Modifié ici pour diminuer la taille
|
: 2.1,
|
||||||
),
|
),
|
||||||
itemCount: tables.length,
|
itemCount: tables.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
@ -408,6 +408,7 @@ class _TablesScreenState extends State<TablesScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
@ -440,6 +441,7 @@ class _TablesScreenState extends State<TablesScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
// const Spacer(),
|
// const Spacer(),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
|
|||||||
@ -6,9 +6,6 @@
|
|||||||
|
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <permission_handler_windows/permission_handler_windows_plugin.h>
|
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
PermissionHandlerWindowsPluginRegisterWithRegistrar(
|
|
||||||
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
permission_handler_windows
|
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user