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