|
|
|
@ -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 à l’inté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 |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |