debug
This commit is contained in:
parent
7d2c6f5965
commit
0b04aea9e4
@ -92,7 +92,7 @@ class CommandeDetail {
|
|||||||
'statut': statut,
|
'statut': statut,
|
||||||
'total_ht': totalHt.toString(),
|
'total_ht': totalHt.toString(),
|
||||||
'total_tva': totalTva.toString(),
|
'total_tva': totalTva.toString(),
|
||||||
'total_ttc': totalTtc.toString(),
|
'total_ttc': totalHt.toString(),
|
||||||
'mode_paiement': modePaiement,
|
'mode_paiement': modePaiement,
|
||||||
'commentaires': commentaires,
|
'commentaires': commentaires,
|
||||||
'serveur': serveur,
|
'serveur': serveur,
|
||||||
@ -108,7 +108,7 @@ class CommandeDetail {
|
|||||||
// Getters pour la compatibilité avec l'ancien code
|
// Getters pour la compatibilité avec l'ancien code
|
||||||
String get commandeId => id.toString();
|
String get commandeId => id.toString();
|
||||||
int get tableNumber => tableId;
|
int get tableNumber => tableId;
|
||||||
double get total => totalTtc;
|
double get total => totalHt;
|
||||||
|
|
||||||
// Méthodes utilitaires
|
// Méthodes utilitaires
|
||||||
bool get isPaid => statut.toLowerCase() == 'payee';
|
bool get isPaid => statut.toLowerCase() == 'payee';
|
||||||
@ -156,7 +156,7 @@ class CommandeDetail {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
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 {
|
class CaisseScreen extends StatefulWidget {
|
||||||
final String commandeId;
|
final String commandeId;
|
||||||
final int tableNumber;
|
final String tableName;
|
||||||
|
|
||||||
const CaisseScreen({
|
const CaisseScreen({
|
||||||
super.key,
|
super.key,
|
||||||
required this.commandeId,
|
required this.commandeId,
|
||||||
required this.tableNumber,
|
required this.tableName,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -97,7 +97,7 @@ class _CaisseScreenState extends State<CaisseScreen> {
|
|||||||
final success = await RestaurantApiService.processPayment(
|
final success = await RestaurantApiService.processPayment(
|
||||||
commandeId: widget.commandeId,
|
commandeId: widget.commandeId,
|
||||||
paymentMethodId: selectedPaymentMethod!.id,
|
paymentMethodId: selectedPaymentMethod!.id,
|
||||||
amount: commande!.totalTtc,
|
amount: commande!.totalHt,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
@ -139,6 +139,8 @@ class _CaisseScreenState extends State<CaisseScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _showErrorDialog(String message) {
|
void _showErrorDialog(String message) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@ -170,7 +172,7 @@ class _CaisseScreenState extends State<CaisseScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
content: Text(
|
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: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
@ -187,7 +189,10 @@ class _CaisseScreenState extends State<CaisseScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Widget _buildCommandeHeader() {
|
Widget _buildCommandeHeader() {
|
||||||
|
print(widget.tableName);
|
||||||
if (commande == null) return const SizedBox.shrink();
|
if (commande == null) return const SizedBox.shrink();
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
@ -222,7 +227,7 @@ class _CaisseScreenState extends State<CaisseScreen> {
|
|||||||
border: Border.all(color: Colors.blue[200]!),
|
border: Border.all(color: Colors.blue[200]!),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Table ${widget.tableNumber}',
|
'${widget.tableName}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.blue[700],
|
color: Colors.blue[700],
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
@ -255,7 +260,7 @@ class _CaisseScreenState extends State<CaisseScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'${NumberFormat("#,##0.00", "fr_FR").format(commande!.totalTtc)} MGA',
|
'${NumberFormat("#,##0.00", "fr_FR").format(commande!.totalHt)} MGA',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@ -383,7 +388,7 @@ Widget _buildPaymentSection() {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'${NumberFormat("#,##0.00", "fr_FR").format(commande?.totalTtc ?? 0)} MGA',
|
'${NumberFormat("#,##0.00", "fr_FR").format(commande?.totalHt ?? 0)} MGA',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
@ -400,7 +405,7 @@ Widget _buildPaymentSection() {
|
|||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
montantDonne = double.tryParse(value) ?? 0.0;
|
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
|
// Modification de _buildPaymentMethodCard pour accepter setState de la StatefulBuilder
|
||||||
Widget _buildPaymentMethodCard(PaymentMethod method, bool isSelected) {
|
Widget _buildPaymentMethodCard(PaymentMethod method, bool isSelected) {
|
||||||
final amount = commande?.totalTtc ?? 0.0;
|
final amount = commande?.totalHt ?? 0.0;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.only(bottom: 12),
|
margin: const EdgeInsets.only(bottom: 12),
|
||||||
@ -596,7 +601,7 @@ Widget _buildPaymentMethodCard(PaymentMethod method, bool isSelected) {
|
|||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(
|
Text(
|
||||||
selectedPaymentMethod != null
|
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',
|
: 'Sélectionnez une méthode de paiement',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
|||||||
@ -326,7 +326,7 @@ Future<void> deleteOrder(Order order) async {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
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();
|
_loadCommandes();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadCommandes() async {
|
Future<void> _loadCommandes() async {
|
||||||
|
if (!mounted) return; // Vérifier si le widget est encore monté
|
||||||
|
|
||||||
setState(() => isLoading = true);
|
setState(() => isLoading = true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final result = await RestaurantApiService.getCommandes();
|
final result = await RestaurantApiService.getCommandes();
|
||||||
|
|
||||||
|
if (!mounted) return; // Vérifier à nouveau avant setState
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
commandes = result.where((c) => !c.isEncashed).toList();
|
commandes = result;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (!mounted) return; // Vérifier avant setState
|
||||||
|
|
||||||
setState(() => isLoading = false);
|
setState(() => isLoading = false);
|
||||||
_showErrorSnackBar('Erreur lors du chargement: $e');
|
_showErrorSnackBar('Erreur lors du chargement: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dans encaissement_screen.dart, modifier la méthode _allerAlaCaisse:
|
// Dans encaissement_screen.dart, modifier la méthode _allerAlaCaisse:
|
||||||
Future<void> _allerAlaCaisse(TableOrder commande) async {
|
Future<void> _allerAlaCaisse(TableOrder commande) async {
|
||||||
@ -47,8 +54,8 @@ class _EncaissementScreenState extends State<EncaissementScreen> {
|
|||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder:
|
builder:
|
||||||
(context) => CaisseScreen(
|
(context) => CaisseScreen(
|
||||||
commandeId: commande.tableNumber.toString(),
|
commandeId: commande.id.toString(),
|
||||||
tableNumber: commande.tableNumber,
|
tableName: commande.tablename.toString(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -59,9 +59,7 @@ class _FactureScreenState extends State<FactureScreen> {
|
|||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Retourner 2 fois en arrière (facture -> caisse -> liste commandes)
|
Navigator.pushNamedAndRemoveUntil(context, '/encaissement', (route) => false);
|
||||||
Navigator.of(context).pop();
|
|
||||||
Navigator.of(context).pop(true); // true pour indiquer le succès
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
title: const Text(
|
title: const Text(
|
||||||
|
|||||||
@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class OrderHistoryPage extends StatefulWidget {
|
class OrderHistoryPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_OrderHistoryPageState createState() => _OrderHistoryPageState();
|
_OrderHistoryPageState createState() => _OrderHistoryPageState();
|
||||||
@ -612,7 +614,7 @@ Widget _buildTableView() {
|
|||||||
cells: [
|
cells: [
|
||||||
DataCell(Text(commande.numeroCommande ?? '-')),
|
DataCell(Text(commande.numeroCommande ?? '-')),
|
||||||
DataCell(Text(commande.tablename ?? '-')),
|
DataCell(Text(commande.tablename ?? '-')),
|
||||||
DataCell(Text(_formatPrice(commande.totalTtc ?? 0))),
|
DataCell(Text(NumberFormat("#,##0.00", "fr_FR").format(commande.totalHt ?? 0))),
|
||||||
DataCell(
|
DataCell(
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.info, color: Color(0xFF4CAF50)),
|
icon: Icon(Icons.info, color: Color(0xFF4CAF50)),
|
||||||
@ -643,11 +645,11 @@ void _showCommandeDetails(CommandeData commande) {
|
|||||||
Text(
|
Text(
|
||||||
'Date de paiement: ${commande.datePaiement != null ? _formatDateTime(commande.datePaiement!) : "-"}',
|
'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),
|
SizedBox(height: 10),
|
||||||
const Text('Articles:', style: TextStyle(fontWeight: FontWeight.bold)),
|
const Text('Articles:', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||||
...?commande.items?.map((item) => Text(
|
...?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(
|
Text(
|
||||||
'${item.quantite} × ${_formatPrice(item.prixUnitaire)}',
|
'${item.quantite} × ${NumberFormat("#,##0.00", "fr_FR").format(item.prixUnitaire)}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 10,
|
fontSize: 10,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
@ -908,7 +910,7 @@ void _showCommandeDetails(CommandeData commande) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
_formatPrice(item.totalItem),
|
NumberFormat("#,##0.00", "fr_FR").format(item.totalItem),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@ -965,7 +967,7 @@ void _showCommandeDetails(CommandeData commande) {
|
|||||||
),
|
),
|
||||||
if ((commande.totalTva ?? 0) > 0)
|
if ((commande.totalTva ?? 0) > 0)
|
||||||
Text(
|
Text(
|
||||||
'TVA: ${_formatPrice(commande.totalTva ?? 0)}',
|
'TVA: ${NumberFormat("#,##0.00", "fr_FR").format(commande.totalTva ?? 0)}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 9,
|
fontSize: 9,
|
||||||
color: Colors.grey.shade500,
|
color: Colors.grey.shade500,
|
||||||
@ -990,7 +992,7 @@ void _showCommandeDetails(CommandeData commande) {
|
|||||||
size: 14,
|
size: 14,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
_formatPrice(commande.totalTtc ?? 0),
|
NumberFormat("#,##0.00", "fr_FR").format(commande.totalHt ?? 0),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.bold,
|
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')}';
|
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 _getMenuIcon(String menuNom) {
|
||||||
String lowerName = menuNom.toLowerCase();
|
String lowerName = menuNom.toLowerCase();
|
||||||
@ -1121,7 +1120,7 @@ class CommandeData {
|
|||||||
|
|
||||||
final datePaiement = _parseDateTime(json['date_paiement']) ?? _parseDateTime(json['date_service']);
|
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();
|
final modePaiement = json['mode_paiement']?.toString() ?? json['payment_method']?.toString();
|
||||||
|
|
||||||
@ -1136,7 +1135,7 @@ class CommandeData {
|
|||||||
statut: json['statut']?.toString(),
|
statut: json['statut']?.toString(),
|
||||||
totalHt: _parseDouble(json['total_ht']),
|
totalHt: _parseDouble(json['total_ht']),
|
||||||
totalTva: _parseDouble(json['total_tva']),
|
totalTva: _parseDouble(json['total_tva']),
|
||||||
totalTtc: totalTtc,
|
totalTtc: totalHt,
|
||||||
modePaiement: modePaiement,
|
modePaiement: modePaiement,
|
||||||
commentaires: json['commentaires']?.toString(),
|
commentaires: json['commentaires']?.toString(),
|
||||||
serveur: serveur,
|
serveur: serveur,
|
||||||
|
|||||||
@ -259,7 +259,7 @@ final restaurantContent = template.content ?? 'Adresse inconnue';
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
pw.Text(
|
pw.Text(
|
||||||
'${NumberFormat("#,##0.00", "fr_FR").format(commande.totalTtc)}AR',
|
'${NumberFormat("#,##0.00", "fr_FR").format(commande.totalHt)}AR',
|
||||||
style: pw.TextStyle(
|
style: pw.TextStyle(
|
||||||
fontSize: titleSize,
|
fontSize: titleSize,
|
||||||
fontWeight: pw.FontWeight.bold,
|
fontWeight: pw.FontWeight.bold,
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import 'package:itrimobe/models/tables_order.dart';
|
|||||||
|
|
||||||
class CommandeCard extends StatelessWidget {
|
class CommandeCard extends StatelessWidget {
|
||||||
final TableOrder commande;
|
final TableOrder commande;
|
||||||
final Future<void> Function() onAllerCaisse; // Changé en Future<void> Function()
|
final VoidCallback onAllerCaisse; // Retour à VoidCallback simple
|
||||||
final VoidCallback? onRefresh;
|
final VoidCallback? onRefresh;
|
||||||
|
|
||||||
const CommandeCard({
|
const CommandeCard({
|
||||||
@ -111,15 +111,7 @@ class CommandeCard extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
onPressed: () async {
|
onPressed: onAllerCaisse, // Juste appeler le callback
|
||||||
// Attendre que la navigation soit terminée
|
|
||||||
await onAllerCaisse();
|
|
||||||
|
|
||||||
// Rafraîchir la page
|
|
||||||
if (onRefresh != null) {
|
|
||||||
onRefresh!();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
icon: Icon(Icons.point_of_sale, size: 18),
|
icon: Icon(Icons.point_of_sale, size: 18),
|
||||||
label: Text('Aller à la caisse'),
|
label: Text('Aller à la caisse'),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user