From 0b04aea9e44836917b076a339590e362ee494f82 Mon Sep 17 00:00:00 2001 From: andrymodeste Date: Fri, 24 Oct 2025 13:03:09 +0200 Subject: [PATCH] debug --- lib/models/command_detail.dart | 6 ++--- lib/pages/caisse_screen.dart | 25 ++++++++++++--------- lib/pages/commandes_screen.dart | 2 +- lib/pages/encaissement_screen.dart | 35 ++++++++++++++++++------------ lib/pages/facture_screen.dart | 4 +--- lib/pages/historique_commande.dart | 23 ++++++++++---------- lib/services/pdf_service.dart | 2 +- lib/widgets/command_card.dart | 12 ++-------- 8 files changed, 55 insertions(+), 54 deletions(-) diff --git a/lib/models/command_detail.dart b/lib/models/command_detail.dart index 078ffc0..69677cb 100644 --- a/lib/models/command_detail.dart +++ b/lib/models/command_detail.dart @@ -92,7 +92,7 @@ class CommandeDetail { 'statut': statut, 'total_ht': totalHt.toString(), 'total_tva': totalTva.toString(), - 'total_ttc': totalTtc.toString(), + 'total_ttc': totalHt.toString(), 'mode_paiement': modePaiement, 'commentaires': commentaires, 'serveur': serveur, @@ -108,7 +108,7 @@ class CommandeDetail { // Getters pour la compatibilité avec l'ancien code String get commandeId => id.toString(); int get tableNumber => tableId; - double get total => totalTtc; + double get total => totalHt; // Méthodes utilitaires bool get isPaid => statut.toLowerCase() == 'payee'; @@ -156,7 +156,7 @@ class CommandeDetail { @override String toString() { - return 'CommandeDetail{id: $id, numeroCommande: $numeroCommande, statut: $statut, totalTtc: $totalTtc}'; + return 'CommandeDetail{id: $id, numeroCommande: $numeroCommande, statut: $statut, totalHt: $totalHt}'; } } diff --git a/lib/pages/caisse_screen.dart b/lib/pages/caisse_screen.dart index d5eebfb..9bcb339 100644 --- a/lib/pages/caisse_screen.dart +++ b/lib/pages/caisse_screen.dart @@ -10,12 +10,12 @@ import 'information.dart'; class CaisseScreen extends StatefulWidget { final String commandeId; - final int tableNumber; + final String tableName; const CaisseScreen({ super.key, required this.commandeId, - required this.tableNumber, + required this.tableName, }); @override @@ -97,7 +97,7 @@ class _CaisseScreenState extends State { final success = await RestaurantApiService.processPayment( commandeId: widget.commandeId, paymentMethodId: selectedPaymentMethod!.id, - amount: commande!.totalTtc, + amount: commande!.totalHt, ); if (success) { @@ -139,6 +139,8 @@ class _CaisseScreenState extends State { } + + void _showErrorDialog(String message) { showDialog( context: context, @@ -170,7 +172,7 @@ class _CaisseScreenState extends State { ], ), content: Text( - 'Le paiement de ${NumberFormat("#,##0.00", "fr_FR").format(commande!.totalTtc)} MGA a été traité avec succès via ${selectedPaymentMethod!.name}.', + 'Le paiement de ${NumberFormat("#,##0.00", "fr_FR").format(commande!.totalHt)} MGA a été traité avec succès via ${selectedPaymentMethod!.name}.', ), actions: [ TextButton( @@ -187,7 +189,10 @@ class _CaisseScreenState extends State { ); } + + Widget _buildCommandeHeader() { + print(widget.tableName); if (commande == null) return const SizedBox.shrink(); return Container( @@ -222,7 +227,7 @@ class _CaisseScreenState extends State { border: Border.all(color: Colors.blue[200]!), ), child: Text( - 'Table ${widget.tableNumber}', + '${widget.tableName}', style: TextStyle( color: Colors.blue[700], fontSize: 12, @@ -255,7 +260,7 @@ class _CaisseScreenState extends State { ), ), Text( - '${NumberFormat("#,##0.00", "fr_FR").format(commande!.totalTtc)} MGA', + '${NumberFormat("#,##0.00", "fr_FR").format(commande!.totalHt)} MGA', style: const TextStyle( fontSize: 18, fontWeight: FontWeight.bold, @@ -383,7 +388,7 @@ Widget _buildPaymentSection() { ), const SizedBox(height: 8), Text( - '${NumberFormat("#,##0.00", "fr_FR").format(commande?.totalTtc ?? 0)} MGA', + '${NumberFormat("#,##0.00", "fr_FR").format(commande?.totalHt ?? 0)} MGA', style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 20, @@ -400,7 +405,7 @@ Widget _buildPaymentSection() { onChanged: (value) { setState(() { montantDonne = double.tryParse(value) ?? 0.0; - rendu = montantDonne - (commande?.totalTtc ?? 0.0); + rendu = montantDonne - (commande?.totalHt ?? 0.0); }); }, ), @@ -449,7 +454,7 @@ Widget _buildPaymentSection() { // Modification de _buildPaymentMethodCard pour accepter setState de la StatefulBuilder Widget _buildPaymentMethodCard(PaymentMethod method, bool isSelected) { - final amount = commande?.totalTtc ?? 0.0; + final amount = commande?.totalHt ?? 0.0; return Container( margin: const EdgeInsets.only(bottom: 12), @@ -596,7 +601,7 @@ Widget _buildPaymentMethodCard(PaymentMethod method, bool isSelected) { const SizedBox(width: 8), Text( selectedPaymentMethod != null - ? 'Payer ${NumberFormat("#,##0.00", "fr_FR").format(commande?.totalTtc)} MGA' + ? 'Payer ${NumberFormat("#,##0.00", "fr_FR").format(commande?.totalHt)} MGA' : 'Sélectionnez une méthode de paiement', style: const TextStyle( fontSize: 16, diff --git a/lib/pages/commandes_screen.dart b/lib/pages/commandes_screen.dart index e66d28a..9803b76 100644 --- a/lib/pages/commandes_screen.dart +++ b/lib/pages/commandes_screen.dart @@ -326,7 +326,7 @@ Future deleteOrder(Order order) async { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - '${order.tablename} - ${NumberFormat("#,##0.00", "fr_FR").format(order.totalTtc)} MGA', + '${order.tablename} - ${NumberFormat("#,##0.00", "fr_FR").format(order.totalHt)} MGA', ), ], ), diff --git a/lib/pages/encaissement_screen.dart b/lib/pages/encaissement_screen.dart index b733777..6cac91a 100644 --- a/lib/pages/encaissement_screen.dart +++ b/lib/pages/encaissement_screen.dart @@ -24,20 +24,27 @@ class _EncaissementScreenState extends State { _loadCommandes(); } - Future _loadCommandes() async { - setState(() => isLoading = true); +Future _loadCommandes() async { + if (!mounted) return; // Vérifier si le widget est encore monté + + setState(() => isLoading = true); - try { - final result = await RestaurantApiService.getCommandes(); - setState(() { - commandes = result.where((c) => !c.isEncashed).toList(); - isLoading = false; - }); - } catch (e) { - setState(() => isLoading = false); - _showErrorSnackBar('Erreur lors du chargement: $e'); - } + try { + final result = await RestaurantApiService.getCommandes(); + + if (!mounted) return; // Vérifier à nouveau avant setState + + setState(() { + commandes = result; + isLoading = false; + }); + } catch (e) { + if (!mounted) return; // Vérifier avant setState + + setState(() => isLoading = false); + _showErrorSnackBar('Erreur lors du chargement: $e'); } +} // Dans encaissement_screen.dart, modifier la méthode _allerAlaCaisse: Future _allerAlaCaisse(TableOrder commande) async { @@ -47,8 +54,8 @@ class _EncaissementScreenState extends State { MaterialPageRoute( builder: (context) => CaisseScreen( - commandeId: commande.tableNumber.toString(), - tableNumber: commande.tableNumber, + commandeId: commande.id.toString(), + tableName: commande.tablename.toString(), ), ), ); diff --git a/lib/pages/facture_screen.dart b/lib/pages/facture_screen.dart index 8ee1d60..87e54e6 100644 --- a/lib/pages/facture_screen.dart +++ b/lib/pages/facture_screen.dart @@ -59,9 +59,7 @@ class _FactureScreenState extends State { leading: IconButton( icon: const Icon(Icons.arrow_back, color: Colors.black), onPressed: () { - // Retourner 2 fois en arrière (facture -> caisse -> liste commandes) - Navigator.of(context).pop(); - Navigator.of(context).pop(true); // true pour indiquer le succès + Navigator.pushNamedAndRemoveUntil(context, '/encaissement', (route) => false); }, ), title: const Text( diff --git a/lib/pages/historique_commande.dart b/lib/pages/historique_commande.dart index 1bbad20..bd981a1 100644 --- a/lib/pages/historique_commande.dart +++ b/lib/pages/historique_commande.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; +import 'package:intl/intl.dart'; + class OrderHistoryPage extends StatefulWidget { @override _OrderHistoryPageState createState() => _OrderHistoryPageState(); @@ -612,7 +614,7 @@ Widget _buildTableView() { cells: [ DataCell(Text(commande.numeroCommande ?? '-')), DataCell(Text(commande.tablename ?? '-')), - DataCell(Text(_formatPrice(commande.totalTtc ?? 0))), + DataCell(Text(NumberFormat("#,##0.00", "fr_FR").format(commande.totalHt ?? 0))), DataCell( IconButton( icon: Icon(Icons.info, color: Color(0xFF4CAF50)), @@ -643,11 +645,11 @@ void _showCommandeDetails(CommandeData commande) { Text( 'Date de paiement: ${commande.datePaiement != null ? _formatDateTime(commande.datePaiement!) : "-"}', ), - Text('Total TTC: ${_formatPrice(commande.totalTtc ?? 0)}'), + Text('Total: ${NumberFormat("#,##0.00", "fr_FR").format(commande.totalHt ?? 0)}'), SizedBox(height: 10), const Text('Articles:', style: TextStyle(fontWeight: FontWeight.bold)), ...?commande.items?.map((item) => Text( - '${item.quantite} × ${item.menuNom} - ${_formatPrice(item.totalItem)}')), + '${item.quantite} × ${item.menuNom} - ${NumberFormat("#,##0.00", "fr_FR").format(item.totalItem)}')), ], ), ), @@ -898,7 +900,7 @@ void _showCommandeDetails(CommandeData commande) { ), ), Text( - '${item.quantite} × ${_formatPrice(item.prixUnitaire)}', + '${item.quantite} × ${NumberFormat("#,##0.00", "fr_FR").format(item.prixUnitaire)}', style: TextStyle( fontSize: 10, color: Colors.grey, @@ -908,7 +910,7 @@ void _showCommandeDetails(CommandeData commande) { ), ), Text( - _formatPrice(item.totalItem), + NumberFormat("#,##0.00", "fr_FR").format(item.totalItem), style: TextStyle( fontSize: 13, fontWeight: FontWeight.bold, @@ -965,7 +967,7 @@ void _showCommandeDetails(CommandeData commande) { ), if ((commande.totalTva ?? 0) > 0) Text( - 'TVA: ${_formatPrice(commande.totalTva ?? 0)}', + 'TVA: ${NumberFormat("#,##0.00", "fr_FR").format(commande.totalTva ?? 0)}', style: TextStyle( fontSize: 9, color: Colors.grey.shade500, @@ -990,7 +992,7 @@ void _showCommandeDetails(CommandeData commande) { size: 14, ), Text( - _formatPrice(commande.totalTtc ?? 0), + NumberFormat("#,##0.00", "fr_FR").format(commande.totalHt ?? 0), style: TextStyle( fontSize: 14, fontWeight: FontWeight.bold, @@ -1009,9 +1011,6 @@ void _showCommandeDetails(CommandeData commande) { return '${dateTime.day.toString().padLeft(2, '0')}/${dateTime.month.toString().padLeft(2, '0')}/${dateTime.year} à ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}'; } - String _formatPrice(double priceInCents) { - return '${(priceInCents / 100).toStringAsFixed(2)} Ar'; - } String _getMenuIcon(String menuNom) { String lowerName = menuNom.toLowerCase(); @@ -1121,7 +1120,7 @@ class CommandeData { final datePaiement = _parseDateTime(json['date_paiement']) ?? _parseDateTime(json['date_service']); - final totalTtc = _parseDouble(json['total_ttc']) ?? _parseDouble(json['total']); + final totalHt = _parseDouble(json['total_ttc']) ?? _parseDouble(json['total']); final modePaiement = json['mode_paiement']?.toString() ?? json['payment_method']?.toString(); @@ -1136,7 +1135,7 @@ class CommandeData { statut: json['statut']?.toString(), totalHt: _parseDouble(json['total_ht']), totalTva: _parseDouble(json['total_tva']), - totalTtc: totalTtc, + totalTtc: totalHt, modePaiement: modePaiement, commentaires: json['commentaires']?.toString(), serveur: serveur, diff --git a/lib/services/pdf_service.dart b/lib/services/pdf_service.dart index d213b6b..1f0d6c4 100644 --- a/lib/services/pdf_service.dart +++ b/lib/services/pdf_service.dart @@ -259,7 +259,7 @@ final restaurantContent = template.content ?? 'Adresse inconnue'; ), ), pw.Text( - '${NumberFormat("#,##0.00", "fr_FR").format(commande.totalTtc)}AR', + '${NumberFormat("#,##0.00", "fr_FR").format(commande.totalHt)}AR', style: pw.TextStyle( fontSize: titleSize, fontWeight: pw.FontWeight.bold, diff --git a/lib/widgets/command_card.dart b/lib/widgets/command_card.dart index 561fa53..f14a8b5 100644 --- a/lib/widgets/command_card.dart +++ b/lib/widgets/command_card.dart @@ -4,7 +4,7 @@ import 'package:itrimobe/models/tables_order.dart'; class CommandeCard extends StatelessWidget { final TableOrder commande; - final Future Function() onAllerCaisse; // Changé en Future Function() + final VoidCallback onAllerCaisse; // Retour à VoidCallback simple final VoidCallback? onRefresh; const CommandeCard({ @@ -111,15 +111,7 @@ class CommandeCard extends StatelessWidget { ], ), ElevatedButton.icon( - onPressed: () async { - // Attendre que la navigation soit terminée - await onAllerCaisse(); - - // Rafraîchir la page - if (onRefresh != null) { - onRefresh!(); - } - }, + onPressed: onAllerCaisse, // Juste appeler le callback icon: Icon(Icons.point_of_sale, size: 18), label: Text('Aller à la caisse'), style: ElevatedButton.styleFrom(