Browse Source

push android

master
andrymodeste 4 months ago
parent
commit
6dd215e417
  1. 162
      lib/pages/commande_item_validation.dart
  2. 43
      lib/pages/commandes_screen.dart
  3. 17
      lib/pages/tables.dart

162
lib/pages/commande_item_validation.dart

@ -209,7 +209,7 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
try {
// Préparer les données des nouveaux articles
// 1. Construire la liste des items sans commande_id à lintérieur
// 1. Construire la liste des items sans commande_id à l'intérieur
List<Map<String, dynamic>> items =
_newCartItems.map((cartItem) {
return {
@ -236,9 +236,6 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
body: json.encode(body),
);
// 4. Afficher la réponse backend
final responseData = jsonDecode(response.body);
print('✅ Réponse backend : $responseData');
if (response.statusCode == 200 || response.statusCode == 201) {
final responseData = json.decode(response.body);
@ -249,6 +246,7 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
} else {
throw Exception('API returned success: false');
}
Navigator.pushReplacementNamed(context, '/commandes');
} else {
throw Exception('Failed to add items: ${response.statusCode}');
}
@ -280,10 +278,20 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
actions: [
ElevatedButton(
onPressed: () {
// Retourner à la page précédente avec un indicateur de succès
// Fermer le dialog
Navigator.of(context).pop();
Navigator.of(context).pop(true);
// Retourner à la page précédente avec un indicateur de succès et de rechargement
Navigator.of(context).pop({
'success': true,
'shouldReload': true,
'message': 'Articles ajoutés avec succès à la commande ${widget.numeroCommande}'
});
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green[700],
foregroundColor: Colors.white,
),
child: Text('OK'),
),
],
@ -365,59 +373,6 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
),
),
SizedBox(height: 16),
// Résumé des articles existants
// if (widget.commandeDetails != null && widget.commandeDetails!['items'] != null) ...[
// Text(
// 'Articles déjà commandés:',
// style: TextStyle(
// fontSize: 16,
// fontWeight: FontWeight.w600,
// color: Colors.grey[700],
// ),
// ),
// SizedBox(height: 8),
// ...widget.commandeDetails!['items'].map<Widget>((item) {
// final nom = item['menu_nom'] ?? 'Inconnu';
// final quantite = item['quantite'] ?? 1;
// // Correction: utiliser 'menu_prix_actuel' au lieu de 'menu_prix'
// final prix = _parsePrice(item['menu_prix_actuel'] ?? item['prix_unitaire']);
// return Padding(
// padding: const EdgeInsets.symmetric(vertical: 2),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Expanded(
// child: Text(
// '$nom x$quantite',
// style: TextStyle(fontSize: 14, color: Colors.grey[600]),
// ),
// ),
// Text(
// '${(prix * quantite).toStringAsFixed(2)} MGA',
// style: TextStyle(fontSize: 14, color: Colors.grey[600]),
// ),
// ],
// ),
// );
// }).toList(),
// SizedBox(height: 8),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Text(
// 'Sous-total existant:',
// style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
// ),
// Text(
// '${_calculateExistingItemsTotal().toStringAsFixed(2)} MGA',
// style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
// ),
// ],
// ),
// Divider(height: 20),
// ],
Text(
'Nouveaux articles à ajouter: ${_getTotalNewArticles()}',
style: TextStyle(
@ -749,7 +704,7 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
}
}
// Réutiliser la même classe CartItemModel
// Classe CartItemModel
class CartItemModel {
final int id;
final String nom;
@ -765,3 +720,90 @@ class CartItemModel {
required this.notes,
});
}
/*
===============================================
UTILISATION DANS LA PAGE QUI APPELLE ValidateAddItemsPage
===============================================
// Exemple d'utilisation dans votre page précédente :
class CommandeDetailsPage extends StatefulWidget {
// ... vos propriétés
}
class _CommandeDetailsPageState extends State<CommandeDetailsPage> {
// ... vos variables d'état
bool _isLoading = false;
// Méthode pour naviguer vers ValidateAddItemsPage
Future<void> _navigateToValidateAddItems() async {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ValidateAddItemsPage(
commandeId: widget.commandeId,
numeroCommande: widget.numeroCommande,
newItems: selectedItems, // vos articles sélectionnés
commandeDetails: commandeDetails, // détails de la commande
),
),
);
// Vérifier si un rechargement est nécessaire
if (result != null && result is Map && result['shouldReload'] == true) {
// Afficher un message de succès
if (result['message'] != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(result['message']),
backgroundColor: Colors.green[700],
duration: Duration(seconds: 3),
),
);
}
// Recharger les données de la commande
await _refreshCommandeData();
}
}
// Méthode pour recharger les données
Future<void> _refreshCommandeData() async {
setState(() {
_isLoading = true;
});
try {
// Votre logique de rechargement des données ici
// Par exemple :
// await _loadCommandeDetails();
// await _loadCommandeItems();
print('🔄 Données rechargées avec succès');
} catch (e) {
print('❌ Erreur lors du rechargement : $e');
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Erreur lors du rechargement des données'),
backgroundColor: Colors.red,
),
);
} finally {
setState(() {
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
// ... votre UI
body: _isLoading
? Center(child: CircularProgressIndicator())
: // ... votre contenu normal
);
}
}
*/

43
lib/pages/commandes_screen.dart

@ -398,21 +398,6 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> {
),
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,
@ -530,6 +515,7 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> {
}
}
class OrderCard extends StatelessWidget {
final Order order;
final Function(Order, String, {String? modePaiement}) onStatusUpdate;
@ -663,19 +649,20 @@ class OrderCard extends StatelessWidget {
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)} MGA', // Placeholder price
'${item.quantite}x ${item.nom}', // You might want to resolve menu name
style: const TextStyle(
fontSize: 14,
color: Colors.black87,
),
),
Text(
'${(item.pu ?? 0) * item.quantite} MGA',
style: const TextStyle(
fontSize: 14,
color: Colors.black87,
),
),
],
),
),
@ -703,7 +690,7 @@ class OrderCard extends StatelessWidget {
),
),
Text(
'${order.totalTtc.toStringAsFixed(2)} MGA',
'${order.totalHt.toStringAsFixed(2)} MGA',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
@ -935,14 +922,20 @@ class OrderItem {
final int menuId;
final int quantite;
final String? commentaires;
final String? nom;
final double? pu;
OrderItem({required this.menuId, required this.quantite, this.commentaires});
OrderItem({required this.menuId, required this.quantite, this.commentaires, this.nom, this.pu});
factory OrderItem.fromJson(Map<String, dynamic> json) {
return OrderItem(
menuId: json['menu_id'],
quantite: json['quantite'],
commentaires: json['commentaires'],
nom: json['menu_nom'],
pu: json['menu_prix_actuel'] != null
? double.tryParse(json['menu_prix_actuel'].toString())
: null,
);
}
}

17
lib/pages/tables.dart

@ -71,6 +71,14 @@ class _TablesScreenState extends State<TablesScreen> {
}
}
// Fonction pour actualiser les tables
Future<void> _reloadTables() async {
setState(() {
isLoading = true;
});
await fetchTables();
}
Future<void> _addTable() async {
// Add table logic
final result = await showDialog<Map<String, dynamic>>(
@ -273,6 +281,13 @@ class _TablesScreenState extends State<TablesScreen> {
],
),
),
// Reload button
IconButton(
icon: const Icon(Icons.refresh, color: Colors.grey),
onPressed: _reloadTables,
tooltip: 'Actualiser',
),
const SizedBox(width: 8),
// Add button (desktop only)
if (isDesktop)
ElevatedButton.icon(
@ -653,4 +668,4 @@ class _AddEditTableDialogState extends State<_AddEditTableDialog> {
],
);
}
}
}
Loading…
Cancel
Save