debug
This commit is contained in:
parent
7d2c6f5965
commit
0b04aea9e4
@ -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}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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<CaisseScreen> {
|
||||
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<CaisseScreen> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void _showErrorDialog(String message) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@ -170,7 +172,7 @@ class _CaisseScreenState extends State<CaisseScreen> {
|
||||
],
|
||||
),
|
||||
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<CaisseScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Widget _buildCommandeHeader() {
|
||||
print(widget.tableName);
|
||||
if (commande == null) return const SizedBox.shrink();
|
||||
|
||||
return Container(
|
||||
@ -222,7 +227,7 @@ class _CaisseScreenState extends State<CaisseScreen> {
|
||||
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<CaisseScreen> {
|
||||
),
|
||||
),
|
||||
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,
|
||||
|
||||
@ -326,7 +326,7 @@ Future<void> 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',
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -24,20 +24,27 @@ class _EncaissementScreenState extends State<EncaissementScreen> {
|
||||
_loadCommandes();
|
||||
}
|
||||
|
||||
Future<void> _loadCommandes() async {
|
||||
setState(() => isLoading = true);
|
||||
Future<void> _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<void> _allerAlaCaisse(TableOrder commande) async {
|
||||
@ -47,8 +54,8 @@ class _EncaissementScreenState extends State<EncaissementScreen> {
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
(context) => CaisseScreen(
|
||||
commandeId: commande.tableNumber.toString(),
|
||||
tableNumber: commande.tableNumber,
|
||||
commandeId: commande.id.toString(),
|
||||
tableName: commande.tablename.toString(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@ -59,9 +59,7 @@ class _FactureScreenState extends State<FactureScreen> {
|
||||
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(
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -4,7 +4,7 @@ import 'package:itrimobe/models/tables_order.dart';
|
||||
|
||||
class CommandeCard extends StatelessWidget {
|
||||
final TableOrder commande;
|
||||
final Future<void> Function() onAllerCaisse; // Changé en Future<void> 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(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user