Compare commits
3 Commits
48968a8ef8
...
f0fbbaf986
| Author | SHA1 | Date | |
|---|---|---|---|
| f0fbbaf986 | |||
| a23a15191d | |||
| fa8d4429d6 |
@ -37,7 +37,7 @@ class MyApp extends StatelessWidget {
|
|||||||
'/commandes':
|
'/commandes':
|
||||||
(context) => const MainLayout(
|
(context) => const MainLayout(
|
||||||
currentRoute: '/commandes',
|
currentRoute: '/commandes',
|
||||||
child: CategoriesPage(),
|
child: OrdersManagementScreen(),
|
||||||
),
|
),
|
||||||
// Uncomment and update these as needed:
|
// Uncomment and update these as needed:
|
||||||
// '/commandes': (context) => const MainLayout(
|
// '/commandes': (context) => const MainLayout(
|
||||||
|
|||||||
@ -31,10 +31,10 @@ class _CartPageState extends State<CartPage> {
|
|||||||
void _processCartItems() {
|
void _processCartItems() {
|
||||||
// Grouper les articles identiques
|
// Grouper les articles identiques
|
||||||
Map<String, CartItemModel> groupedItems = {};
|
Map<String, CartItemModel> groupedItems = {};
|
||||||
|
|
||||||
for (var item in widget.cartItems) {
|
for (var item in widget.cartItems) {
|
||||||
String key = "${item['id']}_${item['notes'] ?? ''}";
|
String key = "${item['id']}_${item['notes'] ?? ''}";
|
||||||
|
|
||||||
if (groupedItems.containsKey(key)) {
|
if (groupedItems.containsKey(key)) {
|
||||||
groupedItems[key]!.quantity++;
|
groupedItems[key]!.quantity++;
|
||||||
} else {
|
} else {
|
||||||
@ -47,7 +47,7 @@ class _CartPageState extends State<CartPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_cartItems = groupedItems.values.toList();
|
_cartItems = groupedItems.values.toList();
|
||||||
});
|
});
|
||||||
@ -77,7 +77,10 @@ class _CartPageState extends State<CartPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double _calculateTotal() {
|
double _calculateTotal() {
|
||||||
return _cartItems.fold(0.0, (sum, item) => sum + (item.prix * item.quantity));
|
return _cartItems.fold(
|
||||||
|
0.0,
|
||||||
|
(sum, item) => sum + (item.prix * item.quantity),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _getTotalArticles() {
|
int _getTotalArticles() {
|
||||||
@ -113,30 +116,33 @@ class _CartPageState extends State<CartPage> {
|
|||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: Text(
|
child: Text('Annuler', style: TextStyle(color: Colors.grey[600])),
|
||||||
'Annuler',
|
|
||||||
style: TextStyle(color: Colors.grey[600]),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: _isValidating ? null : () {
|
onPressed:
|
||||||
Navigator.of(context).pop();
|
_isValidating
|
||||||
_validateOrder();
|
? null
|
||||||
},
|
: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
_validateOrder();
|
||||||
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.green[700],
|
backgroundColor: Colors.green[700],
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
),
|
),
|
||||||
child: _isValidating
|
child:
|
||||||
? SizedBox(
|
_isValidating
|
||||||
width: 16,
|
? SizedBox(
|
||||||
height: 16,
|
width: 16,
|
||||||
child: CircularProgressIndicator(
|
height: 16,
|
||||||
strokeWidth: 2,
|
child: CircularProgressIndicator(
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
strokeWidth: 2,
|
||||||
),
|
valueColor: AlwaysStoppedAnimation<Color>(
|
||||||
)
|
Colors.white,
|
||||||
: Text('Valider'),
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Text('Valider'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -157,29 +163,36 @@ class _CartPageState extends State<CartPage> {
|
|||||||
"reservation_id": 1, // Peut être null si pas de réservation
|
"reservation_id": 1, // Peut être null si pas de réservation
|
||||||
"serveur": "Serveur par défaut", // Valeur par défaut comme demandé
|
"serveur": "Serveur par défaut", // Valeur par défaut comme demandé
|
||||||
"commentaires": _getOrderComments(),
|
"commentaires": _getOrderComments(),
|
||||||
"items": _cartItems.map((item) => {
|
"items":
|
||||||
"menu_id": item.id,
|
_cartItems
|
||||||
"quantite": item.quantity,
|
.map(
|
||||||
"commentaires": item.notes.isNotEmpty ? item.notes : null,
|
(item) => {
|
||||||
}).toList(),
|
"menu_id": item.id,
|
||||||
|
"quantite": item.quantity,
|
||||||
|
"commentaires": item.notes.isNotEmpty ? item.notes : null,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Appel API pour créer la commande
|
// Appel API pour créer la commande
|
||||||
final response = await http.post(
|
final response = await http.post(
|
||||||
Uri.parse('https://restaurant.careeracademy.mg/api/commandes'), // Remplacez par votre URL d'API
|
Uri.parse(
|
||||||
headers: {
|
'https://restaurant.careeracademy.mg/api/commandes',
|
||||||
'Content-Type': 'application/json',
|
), // Remplacez par votre URL d'API
|
||||||
},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: json.encode(orderData),
|
body: json.encode(orderData),
|
||||||
);
|
);
|
||||||
print(orderData);
|
print('response body: ${response.body}');
|
||||||
|
|
||||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
// Succès
|
// Succès
|
||||||
_showSuccessDialog();
|
_showSuccessDialog();
|
||||||
} else {
|
} else {
|
||||||
// Erreur
|
// Erreur
|
||||||
_showErrorDialog('Erreur lors de l\'enregistrement de la commande (${response.statusCode})');
|
_showErrorDialog(
|
||||||
|
'Erreur lors de l\'enregistrement de la commande (${response.statusCode})',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_showErrorDialog('Erreur de connexion: $e');
|
_showErrorDialog('Erreur de connexion: $e');
|
||||||
@ -192,11 +205,12 @@ class _CartPageState extends State<CartPage> {
|
|||||||
|
|
||||||
String _getOrderComments() {
|
String _getOrderComments() {
|
||||||
// Concaténer toutes les notes des articles pour les commentaires généraux
|
// Concaténer toutes les notes des articles pour les commentaires généraux
|
||||||
List<String> allNotes = _cartItems
|
List<String> allNotes =
|
||||||
.where((item) => item.notes.isNotEmpty)
|
_cartItems
|
||||||
.map((item) => '${item.nom}: ${item.notes}')
|
.where((item) => item.notes.isNotEmpty)
|
||||||
.toList();
|
.map((item) => '${item.nom}: ${item.notes}')
|
||||||
|
.toList();
|
||||||
|
|
||||||
return allNotes.join('; ');
|
return allNotes.join('; ');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +227,9 @@ class _CartPageState extends State<CartPage> {
|
|||||||
Text('Commande validée'),
|
Text('Commande validée'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
content: Text('Votre commande a été envoyée en cuisine avec succès !'),
|
content: Text(
|
||||||
|
'Votre commande a été envoyée en cuisine avec succès !',
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -281,299 +297,303 @@ class _CartPageState extends State<CartPage> {
|
|||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Retour au menu',
|
'Retour au menu',
|
||||||
style: TextStyle(
|
style: TextStyle(color: Colors.black, fontSize: 16),
|
||||||
color: Colors.black,
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: 16),
|
SizedBox(width: 16),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: _cartItems.isEmpty
|
body:
|
||||||
? Center(
|
_cartItems.isEmpty
|
||||||
child: Column(
|
? Center(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
child: Column(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
Icon(
|
children: [
|
||||||
Icons.shopping_cart_outlined,
|
Icon(
|
||||||
size: 80,
|
Icons.shopping_cart_outlined,
|
||||||
color: Colors.grey[400],
|
size: 80,
|
||||||
),
|
color: Colors.grey[400],
|
||||||
SizedBox(height: 16),
|
|
||||||
Text(
|
|
||||||
'Votre panier est vide',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
color: Colors.grey[600],
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: 16),
|
||||||
],
|
Text(
|
||||||
),
|
'Votre panier est vide',
|
||||||
)
|
style: TextStyle(fontSize: 18, color: Colors.grey[600]),
|
||||||
: Column(
|
|
||||||
children: [
|
|
||||||
// Header avec infos table
|
|
||||||
Container(
|
|
||||||
width: double.infinity,
|
|
||||||
padding: EdgeInsets.all(20),
|
|
||||||
color: Colors.white,
|
|
||||||
child: Text(
|
|
||||||
'Table ${widget.tableId} • ${widget.personne} personne${widget.personne > 1 ? 's' : ''}',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.grey[600],
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
|
)
|
||||||
// Liste des articles
|
: Column(
|
||||||
Expanded(
|
children: [
|
||||||
child: ListView.separated(
|
// Header avec infos table
|
||||||
padding: EdgeInsets.all(16),
|
Container(
|
||||||
itemCount: _cartItems.length,
|
width: double.infinity,
|
||||||
separatorBuilder: (context, index) => SizedBox(height: 12),
|
padding: EdgeInsets.all(20),
|
||||||
itemBuilder: (context, index) {
|
color: Colors.white,
|
||||||
final item = _cartItems[index];
|
child: Text(
|
||||||
return Container(
|
'Table ${widget.tableId} • ${widget.personne} personne${widget.personne > 1 ? 's' : ''}',
|
||||||
padding: EdgeInsets.all(16),
|
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
||||||
decoration: BoxDecoration(
|
),
|
||||||
color: Colors.white,
|
),
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
boxShadow: [
|
// Liste des articles
|
||||||
BoxShadow(
|
Expanded(
|
||||||
color: Colors.black.withOpacity(0.05),
|
child: ListView.separated(
|
||||||
blurRadius: 5,
|
padding: EdgeInsets.all(16),
|
||||||
offset: Offset(0, 2),
|
itemCount: _cartItems.length,
|
||||||
),
|
separatorBuilder:
|
||||||
],
|
(context, index) => SizedBox(height: 12),
|
||||||
),
|
itemBuilder: (context, index) {
|
||||||
child: Column(
|
final item = _cartItems[index];
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
return Container(
|
||||||
children: [
|
padding: EdgeInsets.all(16),
|
||||||
Row(
|
decoration: BoxDecoration(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
color: Colors.white,
|
||||||
children: [
|
borderRadius: BorderRadius.circular(12),
|
||||||
Expanded(
|
boxShadow: [
|
||||||
child: Text(
|
BoxShadow(
|
||||||
item.nom,
|
color: Colors.black.withOpacity(0.05),
|
||||||
style: TextStyle(
|
blurRadius: 5,
|
||||||
fontSize: 18,
|
offset: Offset(0, 2),
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () => _removeItem(index),
|
|
||||||
icon: Icon(
|
|
||||||
Icons.delete_outline,
|
|
||||||
color: Colors.red,
|
|
||||||
),
|
|
||||||
constraints: BoxConstraints(),
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'${item.prix.toStringAsFixed(2)} € l\'unité',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.grey[600],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (item.notes.isNotEmpty) ...[
|
|
||||||
SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
'Notes: ${item.notes}',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.grey[600],
|
|
||||||
fontStyle: FontStyle.italic,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
SizedBox(height: 16),
|
),
|
||||||
Row(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// Contrôles de quantité
|
Row(
|
||||||
Row(
|
mainAxisAlignment:
|
||||||
children: [
|
MainAxisAlignment.spaceBetween,
|
||||||
IconButton(
|
children: [
|
||||||
onPressed: () => _updateQuantity(index, item.quantity - 1),
|
Expanded(
|
||||||
icon: Icon(Icons.remove),
|
child: Text(
|
||||||
style: IconButton.styleFrom(
|
item.nom,
|
||||||
backgroundColor: Colors.grey[200],
|
|
||||||
minimumSize: Size(40, 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(width: 16),
|
|
||||||
Text(
|
|
||||||
item.quantity.toString(),
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: 16),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => _updateQuantity(index, item.quantity + 1),
|
onPressed: () => _removeItem(index),
|
||||||
icon: Icon(Icons.add),
|
icon: Icon(
|
||||||
style: IconButton.styleFrom(
|
Icons.delete_outline,
|
||||||
backgroundColor: Colors.grey[200],
|
color: Colors.red,
|
||||||
minimumSize: Size(40, 40),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
constraints: BoxConstraints(),
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${item.prix.toStringAsFixed(2)} € l\'unité',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Colors.grey[600],
|
||||||
),
|
),
|
||||||
// Prix total de l'article
|
),
|
||||||
|
if (item.notes.isNotEmpty) ...[
|
||||||
|
SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'${(item.prix * item.quantity).toStringAsFixed(2)} €',
|
'Notes: ${item.notes}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.bold,
|
color: Colors.grey[600],
|
||||||
color: Colors.green[700],
|
fontStyle: FontStyle.italic,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
// Contrôles de quantité
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
onPressed:
|
||||||
|
() => _updateQuantity(
|
||||||
|
index,
|
||||||
|
item.quantity - 1,
|
||||||
|
),
|
||||||
|
icon: Icon(Icons.remove),
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
backgroundColor: Colors.grey[200],
|
||||||
|
minimumSize: Size(40, 40),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 16),
|
||||||
|
Text(
|
||||||
|
item.quantity.toString(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 16),
|
||||||
|
IconButton(
|
||||||
|
onPressed:
|
||||||
|
() => _updateQuantity(
|
||||||
|
index,
|
||||||
|
item.quantity + 1,
|
||||||
|
),
|
||||||
|
icon: Icon(Icons.add),
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
backgroundColor: Colors.grey[200],
|
||||||
|
minimumSize: Size(40, 40),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
// Prix total de l'article
|
||||||
|
Text(
|
||||||
|
'${(item.prix * item.quantity).toStringAsFixed(2)} €',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.green[700],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Récapitulatif
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.all(20),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
border: Border(top: BorderSide(color: Colors.grey[200]!)),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Récapitulatif',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text('Articles:', style: TextStyle(fontSize: 16)),
|
||||||
|
Text(
|
||||||
|
_getTotalArticles().toString(),
|
||||||
|
style: TextStyle(fontSize: 16),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
SizedBox(height: 8),
|
||||||
},
|
Row(
|
||||||
),
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
),
|
children: [
|
||||||
|
Text('Table:', style: TextStyle(fontSize: 16)),
|
||||||
// Récapitulatif
|
Text(
|
||||||
Container(
|
widget.tableId.toString(),
|
||||||
padding: EdgeInsets.all(20),
|
style: TextStyle(fontSize: 16),
|
||||||
decoration: BoxDecoration(
|
),
|
||||||
color: Colors.white,
|
],
|
||||||
border: Border(
|
),
|
||||||
top: BorderSide(color: Colors.grey[200]!),
|
SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text('Personnes:', style: TextStyle(fontSize: 16)),
|
||||||
|
Text(
|
||||||
|
widget.personne.toString(),
|
||||||
|
style: TextStyle(fontSize: 16),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Divider(),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Total:',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${_calculateTotal().toStringAsFixed(2)} €',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(height: 20),
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed:
|
||||||
|
_cartItems.isNotEmpty && !_isValidating
|
||||||
|
? _showConfirmationDialog
|
||||||
|
: null,
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.green[700],
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 16),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
disabledBackgroundColor: Colors.grey[300],
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
if (_isValidating) ...[
|
||||||
|
SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
valueColor: AlwaysStoppedAnimation<Color>(
|
||||||
|
Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Validation en cours...',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
] else ...[
|
||||||
|
Icon(Icons.check, size: 20),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Valider la commande',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Column(
|
],
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
),
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Récapitulatif',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text('Articles:', style: TextStyle(fontSize: 16)),
|
|
||||||
Text(
|
|
||||||
_getTotalArticles().toString(),
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(height: 8),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text('Table:', style: TextStyle(fontSize: 16)),
|
|
||||||
Text(
|
|
||||||
widget.tableId.toString(),
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(height: 8),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text('Personnes:', style: TextStyle(fontSize: 16)),
|
|
||||||
Text(
|
|
||||||
widget.personne.toString(),
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Divider(),
|
|
||||||
SizedBox(height: 8),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Total:',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'${_calculateTotal().toStringAsFixed(2)} €',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(height: 20),
|
|
||||||
SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: _cartItems.isNotEmpty && !_isValidating
|
|
||||||
? _showConfirmationDialog
|
|
||||||
: null,
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.green[700],
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 16),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
disabledBackgroundColor: Colors.grey[300],
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
if (_isValidating) ...[
|
|
||||||
SizedBox(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2,
|
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
'Validation en cours...',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
] else ...[
|
|
||||||
Icon(Icons.check, size: 20),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
'Valider la commande',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,4 +612,4 @@ class CartItemModel {
|
|||||||
required this.quantity,
|
required this.quantity,
|
||||||
required this.notes,
|
required this.notes,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +1,907 @@
|
|||||||
// TODO Implement this library.
|
// TODO Implement this library.
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class OrdersManagementScreen extends StatefulWidget {
|
||||||
|
const OrdersManagementScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<OrdersManagementScreen> createState() => _OrdersManagementScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _OrdersManagementScreenState extends State<OrdersManagementScreen> {
|
||||||
|
List<Order> orders = [];
|
||||||
|
bool isLoading = true;
|
||||||
|
String? errorMessage;
|
||||||
|
final String baseUrl = 'https://restaurant.careeracademy.mg/api';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
loadOrders();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> loadOrders() async {
|
||||||
|
try {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
errorMessage = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get all orders with filtering for active ones only
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse('$baseUrl/commandes?statut=en_attente,en_preparation'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final responseData = json.decode(response.body);
|
||||||
|
|
||||||
|
if (responseData['success'] == true) {
|
||||||
|
final List<dynamic> commandesData = responseData['data']['commandes'];
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
orders =
|
||||||
|
commandesData
|
||||||
|
.map((orderData) => Order.fromJson(orderData))
|
||||||
|
.toList();
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw Exception('API returned success: false');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Exception('Failed to load orders: ${response.statusCode}');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
errorMessage = 'Erreur de chargement: $e';
|
||||||
|
});
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Error loading orders: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> loadKitchenOrders() async {
|
||||||
|
try {
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse('$baseUrl/commandes/kitchen'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
json.decode(response.body);
|
||||||
|
// Handle kitchen orders
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Kitchen orders loaded');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Error loading kitchen orders: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> loadOrderStats() async {
|
||||||
|
try {
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse('$baseUrl/commandes/stats'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
json.decode(response.body);
|
||||||
|
// Handle stats
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Order stats loaded');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print('Error loading stats: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Order?> getOrderById(int orderId) async {
|
||||||
|
try {
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse('$baseUrl/commandes/$orderId'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final responseData = json.decode(response.body);
|
||||||
|
|
||||||
|
if (responseData['success'] == true) {
|
||||||
|
return Order.fromJson(responseData['data']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print('Error getting order: $e');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateOrderStatus(
|
||||||
|
Order order,
|
||||||
|
String newStatus, {
|
||||||
|
String? modePaiement,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
final Map<String, dynamic> updateData = {'statut': newStatus};
|
||||||
|
|
||||||
|
if (modePaiement != null) {
|
||||||
|
updateData['mode_paiement'] = modePaiement;
|
||||||
|
}
|
||||||
|
|
||||||
|
final response = await http.put(
|
||||||
|
Uri.parse('$baseUrl/commandes/${order.id}/status'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
},
|
||||||
|
body: json.encode(updateData),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final responseData = json.decode(response.body);
|
||||||
|
|
||||||
|
if (responseData['success'] == true) {
|
||||||
|
setState(() {
|
||||||
|
order.statut = newStatus;
|
||||||
|
order.modePaiement = modePaiement;
|
||||||
|
order.updatedAt = DateTime.now();
|
||||||
|
if (newStatus == "payee") {
|
||||||
|
order.dateService = DateTime.now();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Commande mise à jour avec succès'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove from active orders list if status changed to completed
|
||||||
|
if (newStatus == "payee" || newStatus == "annulee") {
|
||||||
|
loadOrders(); // Refresh the list
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Exception('API returned success: false');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Exception('Failed to update order: ${response.statusCode}');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Erreur lors de la mise à jour: $e'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
print('Error updating order: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> createNewOrder() async {
|
||||||
|
// Sample order creation - you can customize this
|
||||||
|
try {
|
||||||
|
final Map<String, dynamic> newOrderData = {
|
||||||
|
'client_id': 1,
|
||||||
|
'table_id': 1,
|
||||||
|
'reservation_id': 1,
|
||||||
|
'serveur': 'Marie',
|
||||||
|
'commentaires': 'Nouvelle commande',
|
||||||
|
'items': [
|
||||||
|
{'menu_id': 1, 'quantite': 2, 'commentaires': 'Bien cuit'},
|
||||||
|
{'menu_id': 2, 'quantite': 1, 'commentaires': ''},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.post(
|
||||||
|
Uri.parse('$baseUrl/commandes'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
},
|
||||||
|
body: json.encode(newOrderData),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 201) {
|
||||||
|
final responseData = json.decode(response.body);
|
||||||
|
|
||||||
|
if (responseData['success'] == true) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Nouvelle commande créée avec succès'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
loadOrders(); // Refresh the list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Erreur lors de la création: $e'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
print('Error creating order: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteOrder(Order order) async {
|
||||||
|
try {
|
||||||
|
final response = await http.delete(
|
||||||
|
Uri.parse('$baseUrl/commandes/${order.id}'),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final responseData = json.decode(response.body);
|
||||||
|
|
||||||
|
if (responseData['success'] == true) {
|
||||||
|
setState(() {
|
||||||
|
orders.remove(order);
|
||||||
|
});
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Commande supprimée avec succès'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Erreur lors de la suppression: $e'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
print('Error deleting order: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Order> get activeOrders {
|
||||||
|
return orders
|
||||||
|
.where(
|
||||||
|
(order) =>
|
||||||
|
order.statut == "en_attente" || order.statut == "en_preparation",
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void processPayment(Order order) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
String selectedPaymentMethod = 'carte';
|
||||||
|
|
||||||
|
return StatefulBuilder(
|
||||||
|
builder: (context, setState) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Mettre en caisse'),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Table ${order.tableId} - ${order.totalTtc.toStringAsFixed(2)} €',
|
||||||
|
),
|
||||||
|
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: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: const Text('Annuler'),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
updateOrderStatus(
|
||||||
|
order,
|
||||||
|
"payee",
|
||||||
|
modePaiement: selectedPaymentMethod,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'Confirmer le paiement',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFF8F9FA),
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
elevation: 1,
|
||||||
|
title: const Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Gestion des commandes',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.black87,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'Suivez et gérez toutes les commandes',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
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,
|
||||||
|
tooltip: 'Actualiser',
|
||||||
|
),
|
||||||
|
// IconButton(
|
||||||
|
// icon: const Icon(Icons.logout, color: Colors.grey),
|
||||||
|
// onPressed: () {
|
||||||
|
// Navigator.of(context).pop();
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(24.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// Active orders header
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.access_time, size: 20, color: Colors.black87),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Commandes actives (${activeOrders.length})',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Content
|
||||||
|
Expanded(child: _buildContent()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildContent() {
|
||||||
|
if (isLoading) {
|
||||||
|
return const Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
CircularProgressIndicator(color: Colors.green),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Chargement des commandes...',
|
||||||
|
style: TextStyle(color: Colors.grey),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMessage != null) {
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.error_outline, size: 64, color: Colors.red),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
errorMessage!,
|
||||||
|
style: const TextStyle(fontSize: 16, color: Colors.red),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: loadOrders,
|
||||||
|
child: const Text('Réessayer'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeOrders.isEmpty) {
|
||||||
|
return const Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.restaurant_menu, size: 64, color: Colors.grey),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Aucune commande active',
|
||||||
|
style: TextStyle(fontSize: 18, color: Colors.grey),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RefreshIndicator(
|
||||||
|
onRefresh: loadOrders,
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: activeOrders.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final order = activeOrders[index];
|
||||||
|
return OrderCard(
|
||||||
|
order: order,
|
||||||
|
onStatusUpdate: updateOrderStatus,
|
||||||
|
onProcessPayment: processPayment,
|
||||||
|
onDelete: deleteOrder,
|
||||||
|
onViewDetails: () => getOrderById(order.id),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderCard extends StatelessWidget {
|
||||||
|
final Order order;
|
||||||
|
final Function(Order, String, {String? modePaiement}) onStatusUpdate;
|
||||||
|
final Function(Order) onProcessPayment;
|
||||||
|
final Function(Order) onDelete;
|
||||||
|
final VoidCallback onViewDetails;
|
||||||
|
|
||||||
|
const OrderCard({
|
||||||
|
Key? key,
|
||||||
|
required this.order,
|
||||||
|
required this.onStatusUpdate,
|
||||||
|
required this.onProcessPayment,
|
||||||
|
required this.onDelete,
|
||||||
|
required this.onViewDetails,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
String _formatTime(DateTime dateTime) {
|
||||||
|
return '${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')} •${dateTime.day.toString().padLeft(2, '0')}/${dateTime.month.toString().padLeft(2, '0')}/${dateTime.year} •1 personne';
|
||||||
|
}
|
||||||
|
|
||||||
|
Color _getStatusColor(String status) {
|
||||||
|
switch (status) {
|
||||||
|
case 'en_attente':
|
||||||
|
return Colors.green;
|
||||||
|
case 'en_preparation':
|
||||||
|
return Colors.orange;
|
||||||
|
case 'servie':
|
||||||
|
return Colors.blue;
|
||||||
|
case 'payee':
|
||||||
|
return Colors.grey;
|
||||||
|
default:
|
||||||
|
return Colors.grey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getStatusText(String status) {
|
||||||
|
switch (status) {
|
||||||
|
case 'en_attente':
|
||||||
|
return 'En cours';
|
||||||
|
case 'en_preparation':
|
||||||
|
return 'En préparation';
|
||||||
|
case 'servie':
|
||||||
|
return 'Servie';
|
||||||
|
case 'payee':
|
||||||
|
return 'Payée';
|
||||||
|
default:
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.only(bottom: 16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: Colors.grey.shade200),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// Header row
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
GestureDetector(
|
||||||
|
onTap: onViewDetails,
|
||||||
|
child: Text(
|
||||||
|
'Table ${order.tableId}',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12,
|
||||||
|
vertical: 4,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: _getStatusColor(order.statut),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
_getStatusText(order.statut),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
|
// Time and details
|
||||||
|
Text(
|
||||||
|
_formatTime(order.dateCommande),
|
||||||
|
style: const TextStyle(color: Colors.grey, fontSize: 14),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
|
// Order number and server
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
order.numeroCommande,
|
||||||
|
style: const TextStyle(fontSize: 12, color: Colors.black54),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'Serveur: ${order.serveur}',
|
||||||
|
style: const TextStyle(fontSize: 12, color: Colors.black54),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Order items placeholder
|
||||||
|
if (order.items.isNotEmpty)
|
||||||
|
...order.items.map(
|
||||||
|
(item) => Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 4),
|
||||||
|
child: Row(
|
||||||
|
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)} €', // Placeholder price
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
const Text(
|
||||||
|
'Détails de la commande...',
|
||||||
|
style: TextStyle(fontSize: 14, color: Colors.black87),
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
const Divider(),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
|
// Total row
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'Total',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${order.totalTtc.toStringAsFixed(2)} €',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.green,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Action buttons
|
||||||
|
if (order.statut == 'en_attente' ||
|
||||||
|
order.statut == 'en_preparation')
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
flex: 3,
|
||||||
|
child: ElevatedButton.icon(
|
||||||
|
onPressed: () => onProcessPayment(order),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.point_of_sale,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
label: const Text(
|
||||||
|
'Mettre en caisse',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
elevation: 0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
if (order.statut == 'en_attente')
|
||||||
|
Expanded(
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed:
|
||||||
|
() => onStatusUpdate(order, 'en_preparation'),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.orange,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'Préparer',
|
||||||
|
style: TextStyle(color: Colors.white, fontSize: 12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: Colors.red.shade200),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder:
|
||||||
|
(context) => AlertDialog(
|
||||||
|
title: const Text('Supprimer la commande'),
|
||||||
|
content: const Text(
|
||||||
|
'Êtes-vous sûr de vouloir supprimer cette commande ?',
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('Annuler'),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
onDelete(order);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'Supprimer',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
icon: Icon(
|
||||||
|
Icons.delete,
|
||||||
|
color: Colors.red.shade400,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updated Order model to include items
|
||||||
|
class Order {
|
||||||
|
final int id;
|
||||||
|
final int clientId;
|
||||||
|
final int tableId;
|
||||||
|
final int? reservationId;
|
||||||
|
final String numeroCommande;
|
||||||
|
String statut;
|
||||||
|
final double totalHt;
|
||||||
|
final double totalTva;
|
||||||
|
final double totalTtc;
|
||||||
|
String? modePaiement;
|
||||||
|
final String? commentaires;
|
||||||
|
final String serveur;
|
||||||
|
final DateTime dateCommande;
|
||||||
|
DateTime? dateService;
|
||||||
|
final DateTime createdAt;
|
||||||
|
DateTime updatedAt;
|
||||||
|
final List<OrderItem> items;
|
||||||
|
|
||||||
|
Order({
|
||||||
|
required this.id,
|
||||||
|
required this.clientId,
|
||||||
|
required this.tableId,
|
||||||
|
this.reservationId,
|
||||||
|
required this.numeroCommande,
|
||||||
|
required this.statut,
|
||||||
|
required this.totalHt,
|
||||||
|
required this.totalTva,
|
||||||
|
required this.totalTtc,
|
||||||
|
this.modePaiement,
|
||||||
|
this.commentaires,
|
||||||
|
required this.serveur,
|
||||||
|
required this.dateCommande,
|
||||||
|
this.dateService,
|
||||||
|
required this.createdAt,
|
||||||
|
required this.updatedAt,
|
||||||
|
this.items = const [],
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Order.fromJson(Map<String, dynamic> json) {
|
||||||
|
List<OrderItem> orderItems = [];
|
||||||
|
if (json['items'] != null) {
|
||||||
|
orderItems =
|
||||||
|
(json['items'] as List)
|
||||||
|
.map((item) => OrderItem.fromJson(item))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Order(
|
||||||
|
id: json['id'],
|
||||||
|
clientId: json['client_id'],
|
||||||
|
tableId: json['table_id'],
|
||||||
|
reservationId: json['reservation_id'],
|
||||||
|
numeroCommande: json['numero_commande'],
|
||||||
|
statut: json['statut'],
|
||||||
|
totalHt: double.parse(json['total_ht'].toString()),
|
||||||
|
totalTva: double.parse(json['total_tva'].toString()),
|
||||||
|
totalTtc: double.parse(json['total_ttc'].toString()),
|
||||||
|
modePaiement: json['mode_paiement'],
|
||||||
|
commentaires: json['commentaires'],
|
||||||
|
serveur: json['serveur'],
|
||||||
|
dateCommande: DateTime.parse(json['date_commande']),
|
||||||
|
dateService:
|
||||||
|
json['date_service'] != null
|
||||||
|
? DateTime.parse(json['date_service'])
|
||||||
|
: null,
|
||||||
|
createdAt: DateTime.parse(json['created_at']),
|
||||||
|
updatedAt: DateTime.parse(json['updated_at']),
|
||||||
|
items: orderItems,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderItem {
|
||||||
|
final int menuId;
|
||||||
|
final int quantite;
|
||||||
|
final String? commentaires;
|
||||||
|
|
||||||
|
OrderItem({required this.menuId, required this.quantite, this.commentaires});
|
||||||
|
|
||||||
|
factory OrderItem.fromJson(Map<String, dynamic> json) {
|
||||||
|
return OrderItem(
|
||||||
|
menuId: json['menu_id'],
|
||||||
|
quantite: json['quantite'],
|
||||||
|
commentaires: json['commentaires'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user