Compare commits
No commits in common. "f0fbbaf9866bc9dc879a5c9374af2ba6d1fb9a4d" and "48968a8ef8f1552905b0b860bbbbd9e3ce766fd2" have entirely different histories.
f0fbbaf986
...
48968a8ef8
@ -37,7 +37,7 @@ class MyApp extends StatelessWidget {
|
|||||||
'/commandes':
|
'/commandes':
|
||||||
(context) => const MainLayout(
|
(context) => const MainLayout(
|
||||||
currentRoute: '/commandes',
|
currentRoute: '/commandes',
|
||||||
child: OrdersManagementScreen(),
|
child: CategoriesPage(),
|
||||||
),
|
),
|
||||||
// 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,10 +77,7 @@ class _CartPageState extends State<CartPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double _calculateTotal() {
|
double _calculateTotal() {
|
||||||
return _cartItems.fold(
|
return _cartItems.fold(0.0, (sum, item) => sum + (item.prix * item.quantity));
|
||||||
0.0,
|
|
||||||
(sum, item) => sum + (item.prix * item.quantity),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _getTotalArticles() {
|
int _getTotalArticles() {
|
||||||
@ -116,33 +113,30 @@ class _CartPageState extends State<CartPage> {
|
|||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: Text('Annuler', style: TextStyle(color: Colors.grey[600])),
|
child: Text(
|
||||||
|
'Annuler',
|
||||||
|
style: TextStyle(color: Colors.grey[600]),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed:
|
onPressed: _isValidating ? null : () {
|
||||||
_isValidating
|
Navigator.of(context).pop();
|
||||||
? null
|
_validateOrder();
|
||||||
: () {
|
},
|
||||||
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:
|
child: _isValidating
|
||||||
_isValidating
|
? SizedBox(
|
||||||
? SizedBox(
|
width: 16,
|
||||||
width: 16,
|
height: 16,
|
||||||
height: 16,
|
child: CircularProgressIndicator(
|
||||||
child: CircularProgressIndicator(
|
strokeWidth: 2,
|
||||||
strokeWidth: 2,
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(
|
),
|
||||||
Colors.white,
|
)
|
||||||
),
|
: Text('Valider'),
|
||||||
),
|
|
||||||
)
|
|
||||||
: Text('Valider'),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -163,36 +157,29 @@ 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":
|
"items": _cartItems.map((item) => {
|
||||||
_cartItems
|
"menu_id": item.id,
|
||||||
.map(
|
"quantite": item.quantity,
|
||||||
(item) => {
|
"commentaires": item.notes.isNotEmpty ? item.notes : null,
|
||||||
"menu_id": item.id,
|
}).toList(),
|
||||||
"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(
|
Uri.parse('https://restaurant.careeracademy.mg/api/commandes'), // Remplacez par votre URL d'API
|
||||||
'https://restaurant.careeracademy.mg/api/commandes',
|
headers: {
|
||||||
), // Remplacez par votre URL d'API
|
'Content-Type': 'application/json',
|
||||||
headers: {'Content-Type': 'application/json'},
|
},
|
||||||
body: json.encode(orderData),
|
body: json.encode(orderData),
|
||||||
);
|
);
|
||||||
print('response body: ${response.body}');
|
print(orderData);
|
||||||
|
|
||||||
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(
|
_showErrorDialog('Erreur lors de l\'enregistrement de la commande (${response.statusCode})');
|
||||||
'Erreur lors de l\'enregistrement de la commande (${response.statusCode})',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_showErrorDialog('Erreur de connexion: $e');
|
_showErrorDialog('Erreur de connexion: $e');
|
||||||
@ -205,12 +192,11 @@ 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 =
|
List<String> allNotes = _cartItems
|
||||||
_cartItems
|
.where((item) => item.notes.isNotEmpty)
|
||||||
.where((item) => item.notes.isNotEmpty)
|
.map((item) => '${item.nom}: ${item.notes}')
|
||||||
.map((item) => '${item.nom}: ${item.notes}')
|
.toList();
|
||||||
.toList();
|
|
||||||
|
|
||||||
return allNotes.join('; ');
|
return allNotes.join('; ');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,9 +213,7 @@ class _CartPageState extends State<CartPage> {
|
|||||||
Text('Commande validée'),
|
Text('Commande validée'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
content: Text(
|
content: Text('Votre commande a été envoyée en cuisine avec succès !'),
|
||||||
'Votre commande a été envoyée en cuisine avec succès !',
|
|
||||||
),
|
|
||||||
actions: [
|
actions: [
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -297,303 +281,299 @@ 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(color: Colors.black, fontSize: 16),
|
style: TextStyle(
|
||||||
|
color: Colors.black,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: 16),
|
SizedBox(width: 16),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body:
|
body: _cartItems.isEmpty
|
||||||
_cartItems.isEmpty
|
? Center(
|
||||||
? Center(
|
child: Column(
|
||||||
child: Column(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.shopping_cart_outlined,
|
|
||||||
size: 80,
|
|
||||||
color: Colors.grey[400],
|
|
||||||
),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Text(
|
|
||||||
'Votre panier est vide',
|
|
||||||
style: TextStyle(fontSize: 18, color: Colors.grey[600]),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Column(
|
|
||||||
children: [
|
children: [
|
||||||
// Header avec infos table
|
Icon(
|
||||||
Container(
|
Icons.shopping_cart_outlined,
|
||||||
width: double.infinity,
|
size: 80,
|
||||||
padding: EdgeInsets.all(20),
|
color: Colors.grey[400],
|
||||||
color: Colors.white,
|
),
|
||||||
child: Text(
|
SizedBox(height: 16),
|
||||||
'Table ${widget.tableId} • ${widget.personne} personne${widget.personne > 1 ? 's' : ''}',
|
Text(
|
||||||
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
'Votre panier est vide',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
color: Colors.grey[600],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
// Liste des articles
|
),
|
||||||
Expanded(
|
)
|
||||||
child: ListView.separated(
|
: Column(
|
||||||
padding: EdgeInsets.all(16),
|
children: [
|
||||||
itemCount: _cartItems.length,
|
// Header avec infos table
|
||||||
separatorBuilder:
|
Container(
|
||||||
(context, index) => SizedBox(height: 12),
|
width: double.infinity,
|
||||||
itemBuilder: (context, index) {
|
padding: EdgeInsets.all(20),
|
||||||
final item = _cartItems[index];
|
color: Colors.white,
|
||||||
return Container(
|
child: Text(
|
||||||
padding: EdgeInsets.all(16),
|
'Table ${widget.tableId} • ${widget.personne} personne${widget.personne > 1 ? 's' : ''}',
|
||||||
decoration: BoxDecoration(
|
style: TextStyle(
|
||||||
color: Colors.white,
|
fontSize: 16,
|
||||||
borderRadius: BorderRadius.circular(12),
|
color: Colors.grey[600],
|
||||||
boxShadow: [
|
),
|
||||||
BoxShadow(
|
),
|
||||||
color: Colors.black.withOpacity(0.05),
|
),
|
||||||
blurRadius: 5,
|
|
||||||
offset: Offset(0, 2),
|
// Liste des articles
|
||||||
|
Expanded(
|
||||||
|
child: ListView.separated(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
itemCount: _cartItems.length,
|
||||||
|
separatorBuilder: (context, index) => SizedBox(height: 12),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final item = _cartItems[index];
|
||||||
|
return Container(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.05),
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
item.nom,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
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),
|
||||||
child: Column(
|
Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
// Contrôles de quantité
|
||||||
mainAxisAlignment:
|
Row(
|
||||||
MainAxisAlignment.spaceBetween,
|
children: [
|
||||||
children: [
|
IconButton(
|
||||||
Expanded(
|
onPressed: () => _updateQuantity(index, item.quantity - 1),
|
||||||
child: Text(
|
icon: Icon(Icons.remove),
|
||||||
item.nom,
|
style: IconButton.styleFrom(
|
||||||
|
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: () => _removeItem(index),
|
onPressed: () => _updateQuantity(index, item.quantity + 1),
|
||||||
icon: Icon(
|
icon: Icon(Icons.add),
|
||||||
Icons.delete_outline,
|
style: IconButton.styleFrom(
|
||||||
color: Colors.red,
|
backgroundColor: Colors.grey[200],
|
||||||
|
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(
|
||||||
'Notes: ${item.notes}',
|
'${(item.prix * item.quantity).toStringAsFixed(2)} €',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 18,
|
||||||
color: Colors.grey[600],
|
fontWeight: FontWeight.bold,
|
||||||
fontStyle: FontStyle.italic,
|
color: Colors.green[700],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
SizedBox(height: 16),
|
),
|
||||||
Row(
|
],
|
||||||
mainAxisAlignment:
|
),
|
||||||
MainAxisAlignment.spaceBetween,
|
);
|
||||||
children: [
|
},
|
||||||
// Contrôles de quantité
|
),
|
||||||
Row(
|
),
|
||||||
children: [
|
|
||||||
IconButton(
|
// Récapitulatif
|
||||||
onPressed:
|
Container(
|
||||||
() => _updateQuantity(
|
padding: EdgeInsets.all(20),
|
||||||
index,
|
decoration: BoxDecoration(
|
||||||
item.quantity - 1,
|
color: Colors.white,
|
||||||
),
|
border: Border(
|
||||||
icon: Icon(Icons.remove),
|
top: BorderSide(color: Colors.grey[200]!),
|
||||||
style: IconButton.styleFrom(
|
),
|
||||||
backgroundColor: Colors.grey[200],
|
),
|
||||||
minimumSize: Size(40, 40),
|
child: Column(
|
||||||
),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
),
|
children: [
|
||||||
SizedBox(width: 16),
|
Text(
|
||||||
Text(
|
'Récapitulatif',
|
||||||
item.quantity.toString(),
|
style: TextStyle(
|
||||||
style: TextStyle(
|
fontSize: 20,
|
||||||
fontSize: 18,
|
fontWeight: FontWeight.bold,
|
||||||
fontWeight: FontWeight.bold,
|
),
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: 16),
|
||||||
SizedBox(width: 16),
|
Row(
|
||||||
IconButton(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
onPressed:
|
children: [
|
||||||
() => _updateQuantity(
|
Text('Articles:', style: TextStyle(fontSize: 16)),
|
||||||
index,
|
Text(
|
||||||
item.quantity + 1,
|
_getTotalArticles().toString(),
|
||||||
),
|
style: TextStyle(fontSize: 16),
|
||||||
icon: Icon(Icons.add),
|
),
|
||||||
style: IconButton.styleFrom(
|
],
|
||||||
backgroundColor: Colors.grey[200],
|
),
|
||||||
minimumSize: Size(40, 40),
|
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),
|
||||||
),
|
),
|
||||||
// Prix total de l'article
|
),
|
||||||
Text(
|
SizedBox(width: 8),
|
||||||
'${(item.prix * item.quantity).toStringAsFixed(2)} €',
|
Text(
|
||||||
style: TextStyle(
|
'Validation en cours...',
|
||||||
fontSize: 18,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontSize: 16,
|
||||||
color: Colors.green[700],
|
fontWeight: FontWeight.bold,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
] else ...[
|
||||||
|
Icon(Icons.check, size: 20),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Valider la commande',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
// 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)),
|
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -612,4 +592,4 @@ class CartItemModel {
|
|||||||
required this.quantity,
|
required this.quantity,
|
||||||
required this.notes,
|
required this.notes,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1,907 +1 @@
|
|||||||
// 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