push android
This commit is contained in:
parent
a23321274a
commit
6dd215e417
@ -209,7 +209,7 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Préparer les données des nouveaux articles
|
// Préparer les données des nouveaux articles
|
||||||
// 1. Construire la liste des items sans commande_id à l’intérieur
|
// 1. Construire la liste des items sans commande_id à l'intérieur
|
||||||
List<Map<String, dynamic>> items =
|
List<Map<String, dynamic>> items =
|
||||||
_newCartItems.map((cartItem) {
|
_newCartItems.map((cartItem) {
|
||||||
return {
|
return {
|
||||||
@ -236,9 +236,6 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
|
|||||||
body: json.encode(body),
|
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) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
final responseData = json.decode(response.body);
|
final responseData = json.decode(response.body);
|
||||||
@ -249,6 +246,7 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
|
|||||||
} else {
|
} else {
|
||||||
throw Exception('API returned success: false');
|
throw Exception('API returned success: false');
|
||||||
}
|
}
|
||||||
|
Navigator.pushReplacementNamed(context, '/commandes');
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Failed to add items: ${response.statusCode}');
|
throw Exception('Failed to add items: ${response.statusCode}');
|
||||||
}
|
}
|
||||||
@ -280,10 +278,20 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
|
|||||||
actions: [
|
actions: [
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Retourner à la page précédente avec un indicateur de succès
|
// Fermer le dialog
|
||||||
Navigator.of(context).pop();
|
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'),
|
child: Text('OK'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -365,59 +373,6 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 16),
|
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(
|
Text(
|
||||||
'Nouveaux articles à ajouter: ${_getTotalNewArticles()}',
|
'Nouveaux articles à ajouter: ${_getTotalNewArticles()}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@ -749,7 +704,7 @@ class _ValidateAddItemsPageState extends State<ValidateAddItemsPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Réutiliser la même classe CartItemModel
|
// Classe CartItemModel
|
||||||
class CartItemModel {
|
class CartItemModel {
|
||||||
final int id;
|
final int id;
|
||||||
final String nom;
|
final String nom;
|
||||||
@ -765,3 +720,90 @@ class CartItemModel {
|
|||||||
required this.notes,
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@ -398,21 +398,6 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> {
|
|||||||
),
|
),
|
||||||
toolbarHeight: 80,
|
toolbarHeight: 80,
|
||||||
actions: [
|
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(
|
IconButton(
|
||||||
icon: const Icon(Icons.refresh, color: Colors.grey),
|
icon: const Icon(Icons.refresh, color: Colors.grey),
|
||||||
onPressed: loadOrders,
|
onPressed: loadOrders,
|
||||||
@ -530,6 +515,7 @@ class _OrdersManagementScreenState extends State<OrdersManagementScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class OrderCard extends StatelessWidget {
|
class OrderCard extends StatelessWidget {
|
||||||
final Order order;
|
final Order order;
|
||||||
final Function(Order, String, {String? modePaiement}) onStatusUpdate;
|
final Function(Order, String, {String? modePaiement}) onStatusUpdate;
|
||||||
@ -663,19 +649,20 @@ class OrderCard extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'${item.quantite}x ${item.menuId}', // You might want to resolve menu name
|
'${item.quantite}x ${item.nom}', // 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
|
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Colors.black87,
|
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(
|
Text(
|
||||||
'${order.totalTtc.toStringAsFixed(2)} MGA',
|
'${order.totalHt.toStringAsFixed(2)} MGA',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@ -935,14 +922,20 @@ class OrderItem {
|
|||||||
final int menuId;
|
final int menuId;
|
||||||
final int quantite;
|
final int quantite;
|
||||||
final String? commentaires;
|
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) {
|
factory OrderItem.fromJson(Map<String, dynamic> json) {
|
||||||
return OrderItem(
|
return OrderItem(
|
||||||
menuId: json['menu_id'],
|
menuId: json['menu_id'],
|
||||||
quantite: json['quantite'],
|
quantite: json['quantite'],
|
||||||
commentaires: json['commentaires'],
|
commentaires: json['commentaires'],
|
||||||
|
nom: json['menu_nom'],
|
||||||
|
pu: json['menu_prix_actuel'] != null
|
||||||
|
? double.tryParse(json['menu_prix_actuel'].toString())
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 {
|
Future<void> _addTable() async {
|
||||||
// Add table logic
|
// Add table logic
|
||||||
final result = await showDialog<Map<String, dynamic>>(
|
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)
|
// Add button (desktop only)
|
||||||
if (isDesktop)
|
if (isDesktop)
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user