Browse Source

Change DA to MGA

master
Stephane 6 months ago
parent
commit
38af810b79
  1. 185
      lib/Views/commandManagement.dart

185
lib/Views/commandManagement.dart

@ -27,7 +27,8 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
StatutCommande? _selectedStatut; StatutCommande? _selectedStatut;
DateTime? _selectedDate; DateTime? _selectedDate;
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
bool _showCancelledOrders = false; // Nouveau: contrôle l'affichage des commandes annulées bool _showCancelledOrders =
false; // Nouveau: contrôle l'affichage des commandes annulées
@override @override
void initState() { void initState() {
@ -43,26 +44,33 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
_filterCommandes(); _filterCommandes();
}); });
} }
Future<Uint8List> loadImage() async { Future<Uint8List> loadImage() async {
final data = await rootBundle.load('assets/youmaz2.png'); final data = await rootBundle.load('assets/youmaz2.png');
return data.buffer.asUint8List(); return data.buffer.asUint8List();
} }
void _filterCommandes() { void _filterCommandes() {
final query = _searchController.text.toLowerCase(); final query = _searchController.text.toLowerCase();
setState(() { setState(() {
_filteredCommandes = _commandes.where((commande) { _filteredCommandes = _commandes.where((commande) {
final matchesSearch = commande.clientNomComplet.toLowerCase().contains(query) || final matchesSearch =
commande.id.toString().contains(query); commande.clientNomComplet.toLowerCase().contains(query) ||
final matchesStatut = _selectedStatut == null || commande.statut == _selectedStatut; commande.id.toString().contains(query);
final matchesStatut =
_selectedStatut == null || commande.statut == _selectedStatut;
final matchesDate = _selectedDate == null || final matchesDate = _selectedDate == null ||
DateFormat('yyyy-MM-dd').format(commande.dateCommande) == DateFormat('yyyy-MM-dd').format(commande.dateCommande) ==
DateFormat('yyyy-MM-dd').format(_selectedDate!); DateFormat('yyyy-MM-dd').format(_selectedDate!);
// Nouveau: filtrer les commandes annulées selon le toggle // Nouveau: filtrer les commandes annulées selon le toggle
final shouldShowCancelled = _showCancelledOrders || commande.statut != StatutCommande.annulee; final shouldShowCancelled =
_showCancelledOrders || commande.statut != StatutCommande.annulee;
return matchesSearch && matchesStatut && matchesDate && shouldShowCancelled;
return matchesSearch &&
matchesStatut &&
matchesDate &&
shouldShowCancelled;
}).toList(); }).toList();
}); });
} }
@ -70,11 +78,11 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
Future<void> _updateStatut(int commandeId, StatutCommande newStatut) async { Future<void> _updateStatut(int commandeId, StatutCommande newStatut) async {
await _database.updateStatutCommande(commandeId, newStatut); await _database.updateStatutCommande(commandeId, newStatut);
await _loadCommandes(); await _loadCommandes();
// Amélioration: message plus spécifique selon le statut // Amélioration: message plus spécifique selon le statut
String message = 'Statut de la commande mis à jour'; String message = 'Statut de la commande mis à jour';
Color backgroundColor = Colors.green; Color backgroundColor = Colors.green;
switch (newStatut) { switch (newStatut) {
case StatutCommande.annulee: case StatutCommande.annulee:
message = 'Commande annulée avec succès'; message = 'Commande annulée avec succès';
@ -91,7 +99,7 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
default: default:
break; break;
} }
Get.snackbar( Get.snackbar(
'Succès', 'Succès',
message, message,
@ -109,7 +117,7 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
final pdf = pw.Document(); final pdf = pw.Document();
final imageBytes = await loadImage(); // Charge les données de l'image final imageBytes = await loadImage(); // Charge les données de l'image
final image = pw.MemoryImage(imageBytes); final image = pw.MemoryImage(imageBytes);
// Amélioration: styles plus professionnels // Amélioration: styles plus professionnels
final headerStyle = pw.TextStyle( final headerStyle = pw.TextStyle(
fontSize: 18, fontSize: 18,
@ -148,12 +156,11 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
width: 100, width: 100,
height: 80, height: 80,
decoration: pw.BoxDecoration( decoration: pw.BoxDecoration(
border: pw.Border.all(color: PdfColors.blue900, width: 2), border:
pw.Border.all(color: PdfColors.blue900, width: 2),
borderRadius: pw.BorderRadius.circular(8), borderRadius: pw.BorderRadius.circular(8),
), ),
child: pw.Center( child: pw.Center(child: pw.Image(image)),
child: pw.Image(image)
),
), ),
pw.SizedBox(height: 10), pw.SizedBox(height: 10),
pw.Text('guycom', style: headerStyle), pw.Text('guycom', style: headerStyle),
@ -175,7 +182,8 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
child: pw.Column( child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start, crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [ children: [
pw.Text('FACTURE', pw.Text(
'FACTURE',
style: pw.TextStyle( style: pw.TextStyle(
fontSize: 20, fontSize: 20,
fontWeight: pw.FontWeight.bold, fontWeight: pw.FontWeight.bold,
@ -184,7 +192,8 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
pw.SizedBox(height: 8), pw.SizedBox(height: 8),
pw.Text('N°: ${commande.id}', style: titleStyle), pw.Text('N°: ${commande.id}', style: titleStyle),
pw.Text('Date: ${DateFormat('dd/MM/yyyy').format(commande.dateCommande)}'), pw.Text(
'Date: ${DateFormat('dd/MM/yyyy').format(commande.dateCommande)}'),
], ],
), ),
), ),
@ -192,9 +201,9 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
], ],
), ),
pw.SizedBox(height: 30), pw.SizedBox(height: 30),
// Informations client // Informations client
pw.Container( pw.Container(
width: double.infinity, width: double.infinity,
@ -208,38 +217,45 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
children: [ children: [
pw.Text('FACTURÉ À:', style: titleStyle), pw.Text('FACTURÉ À:', style: titleStyle),
pw.SizedBox(height: 5), pw.SizedBox(height: 5),
pw.Text(client?.nomComplet ?? 'Client inconnu', pw.Text(client?.nomComplet ?? 'Client inconnu',
style: pw.TextStyle(fontSize: 12)), style: pw.TextStyle(fontSize: 12)),
if (client?.telephone != null) if (client?.telephone != null)
pw.Text('Tél: ${client!.telephone}', pw.Text('Tél: ${client!.telephone}',
style: pw.TextStyle(fontSize: 10, color: PdfColors.grey600)), style: pw.TextStyle(
fontSize: 10, color: PdfColors.grey600)),
], ],
), ),
), ),
pw.SizedBox(height: 30), pw.SizedBox(height: 30),
// Tableau des produits // Tableau des produits
pw.Text('DÉTAILS DE LA COMMANDE', style: titleStyle), pw.Text('DÉTAILS DE LA COMMANDE', style: titleStyle),
pw.SizedBox(height: 10), pw.SizedBox(height: 10),
pw.Table( pw.Table(
border: pw.TableBorder.all(color: PdfColors.grey400, width: 0.5), border:
pw.TableBorder.all(color: PdfColors.grey400, width: 0.5),
children: [ children: [
pw.TableRow( pw.TableRow(
decoration: const pw.BoxDecoration(color: PdfColors.blue900), decoration:
const pw.BoxDecoration(color: PdfColors.blue900),
children: [ children: [
_buildTableCell('Produit', titleStyle.copyWith(color: PdfColors.white)), _buildTableCell('Produit',
_buildTableCell('Qté', titleStyle.copyWith(color: PdfColors.white)), titleStyle.copyWith(color: PdfColors.white)),
_buildTableCell('Prix unit.', titleStyle.copyWith(color: PdfColors.white)), _buildTableCell(
_buildTableCell('Total', titleStyle.copyWith(color: PdfColors.white)), 'Qté', titleStyle.copyWith(color: PdfColors.white)),
_buildTableCell('Prix unit.',
titleStyle.copyWith(color: PdfColors.white)),
_buildTableCell(
'Total', titleStyle.copyWith(color: PdfColors.white)),
], ],
), ),
...details.asMap().entries.map((entry) { ...details.asMap().entries.map((entry) {
final index = entry.key; final index = entry.key;
final detail = entry.value; final detail = entry.value;
final isEven = index % 2 == 0; final isEven = index % 2 == 0;
return pw.TableRow( return pw.TableRow(
decoration: pw.BoxDecoration( decoration: pw.BoxDecoration(
color: isEven ? PdfColors.white : PdfColors.grey50, color: isEven ? PdfColors.white : PdfColors.grey50,
@ -247,16 +263,18 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
children: [ children: [
_buildTableCell(detail.produitNom ?? 'Produit inconnu'), _buildTableCell(detail.produitNom ?? 'Produit inconnu'),
_buildTableCell(detail.quantite.toString()), _buildTableCell(detail.quantite.toString()),
_buildTableCell('${detail.prixUnitaire.toStringAsFixed(2)} DA'), _buildTableCell(
_buildTableCell('${detail.sousTotal.toStringAsFixed(2)} DA'), '${detail.prixUnitaire.toStringAsFixed(2)} DA'),
_buildTableCell(
'${detail.sousTotal.toStringAsFixed(2)} DA'),
], ],
); );
}), }),
], ],
), ),
pw.SizedBox(height: 20), pw.SizedBox(height: 20),
// Total // Total
pw.Container( pw.Container(
alignment: pw.Alignment.centerRight, alignment: pw.Alignment.centerRight,
@ -276,9 +294,9 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
), ),
), ),
pw.Spacer(), pw.Spacer(),
// Pied de page // Pied de page
pw.Container( pw.Container(
width: double.infinity, width: double.infinity,
@ -301,7 +319,8 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
pw.SizedBox(height: 5), pw.SizedBox(height: 5),
pw.Text( pw.Text(
'Cette facture est générée automatiquement par le système Youmaz Gestion', 'Cette facture est générée automatiquement par le système Youmaz Gestion',
style: pw.TextStyle(fontSize: 8, color: PdfColors.grey600), style:
pw.TextStyle(fontSize: 8, color: PdfColors.grey600),
), ),
], ],
), ),
@ -444,9 +463,9 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
], ],
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
// Barre de recherche améliorée // Barre de recherche améliorée
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -464,7 +483,8 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
controller: _searchController, controller: _searchController,
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Rechercher par client ou numéro de commande', labelText: 'Rechercher par client ou numéro de commande',
prefixIcon: Icon(Icons.search, color: Colors.blue.shade800), prefixIcon:
Icon(Icons.search, color: Colors.blue.shade800),
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none, borderSide: BorderSide.none,
@ -478,9 +498,9 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
// Filtres améliorés // Filtres améliorés
Row( Row(
children: [ children: [
@ -501,7 +521,8 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
value: _selectedStatut, value: _selectedStatut,
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Filtrer par statut', labelText: 'Filtrer par statut',
prefixIcon: Icon(Icons.filter_list, color: Colors.blue.shade600), prefixIcon: Icon(Icons.filter_list,
color: Colors.blue.shade600),
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none, borderSide: BorderSide.none,
@ -540,9 +561,9 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
), ),
), ),
const SizedBox(width: 12), const SizedBox(width: 12),
Expanded( Expanded(
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -590,19 +611,21 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
}); });
} }
}, },
icon: Icon(Icons.calendar_today, color: Colors.blue.shade600), icon: Icon(Icons.calendar_today,
color: Colors.blue.shade600),
label: Text( label: Text(
_selectedDate == null _selectedDate == null
? 'Date' ? 'Date'
: DateFormat('dd/MM/yyyy').format(_selectedDate!), : DateFormat('dd/MM/yyyy')
.format(_selectedDate!),
style: const TextStyle(color: Colors.black87), style: const TextStyle(color: Colors.black87),
), ),
), ),
), ),
), ),
const SizedBox(width: 12), const SizedBox(width: 12),
// Bouton reset // Bouton reset
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -631,9 +654,9 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
], ],
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
// Toggle pour afficher/masquer les commandes annulées // Toggle pour afficher/masquer les commandes annulées
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -647,7 +670,8 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
], ],
), ),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row( child: Row(
children: [ children: [
Icon( Icon(
@ -680,7 +704,7 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
], ],
), ),
), ),
// Liste des commandes // Liste des commandes
Expanded( Expanded(
child: _filteredCommandes.isEmpty child: _filteredCommandes.isEmpty
@ -756,9 +780,10 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
Icon( Icon(
_getStatutIcon(commande.statut), _getStatutIcon(commande.statut),
size: 20, size: 20,
color: commande.statut == StatutCommande.annulee color:
? Colors.red commande.statut == StatutCommande.annulee
: Colors.blue.shade600, ? Colors.red
: Colors.blue.shade600,
), ),
Text( Text(
'#${commande.id}', '#${commande.id}',
@ -790,7 +815,8 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
const SizedBox(width: 4), const SizedBox(width: 4),
Text( Text(
DateFormat('dd/MM/yyyy').format(commande.dateCommande), DateFormat('dd/MM/yyyy')
.format(commande.dateCommande),
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
color: Colors.grey.shade600, color: Colors.grey.shade600,
@ -811,8 +837,9 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
style: TextStyle( style: TextStyle(
fontSize: 11, fontSize: 11,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: commande.statut == StatutCommande.annulee color: commande.statut ==
? Colors.red StatutCommande.annulee
? Colors.red
: Colors.blue.shade700, : Colors.blue.shade700,
), ),
), ),
@ -829,7 +856,7 @@ class _GestionCommandesPageState extends State<GestionCommandesPage> {
), ),
const SizedBox(width: 4), const SizedBox(width: 4),
Text( Text(
'${commande.montantTotal.toStringAsFixed(2)} DA', '${commande.montantTotal.toStringAsFixed(2)} MGA',
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -981,13 +1008,16 @@ class _CommandeDetails extends StatelessWidget {
], ],
), ),
...details.map((detail) => TableRow( ...details.map((detail) => TableRow(
children: [ children: [
_buildTableCell(detail.produitNom ?? 'Produit inconnu'), _buildTableCell(
_buildTableCell('${detail.quantite}'), detail.produitNom ?? 'Produit inconnu'),
_buildTableCell('${detail.prixUnitaire.toStringAsFixed(2)} DA'), _buildTableCell('${detail.quantite}'),
_buildTableCell('${detail.sousTotal.toStringAsFixed(2)} DA'), _buildTableCell(
], '${detail.prixUnitaire.toStringAsFixed(2)} MGA'),
)), _buildTableCell(
'${detail.sousTotal.toStringAsFixed(2)} MGA'),
],
)),
], ],
), ),
), ),
@ -1010,7 +1040,7 @@ class _CommandeDetails extends StatelessWidget {
), ),
), ),
Text( Text(
'${commande.montantTotal.toStringAsFixed(2)} DA', '${commande.montantTotal.toStringAsFixed(2)} MGA',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 18, fontSize: 18,
@ -1204,7 +1234,8 @@ class _CommandeActions extends StatelessWidget {
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(Icons.check_circle, color: Colors.green.shade600, size: 16), Icon(Icons.check_circle,
color: Colors.green.shade600, size: 16),
const SizedBox(width: 8), const SizedBox(width: 8),
Text( Text(
'Commande livrée', 'Commande livrée',
@ -1326,4 +1357,4 @@ class _CommandeActions extends StatelessWidget {
}, },
); );
} }
} }

Loading…
Cancel
Save