Browse Source

Change DA to MGA

master
Stephane 6 months ago
parent
commit
da03076411
  1. 39
      lib/Views/newCommand.dart

39
lib/Views/newCommand.dart

@ -45,7 +45,7 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: const CustomAppBar(title: 'Nouvelle Commande'),
drawer: CustomDrawer(),
drawer: CustomDrawer(),
body: Column(
children: [
// Header avec logo et titre
@ -126,7 +126,7 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
],
),
),
// Contenu principal
Expanded(
child: SingleChildScrollView(
@ -221,7 +221,8 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
if (value == null || value.isEmpty) {
return 'Veuillez entrer un email';
}
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(value)) {
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$')
.hasMatch(value)) {
return 'Veuillez entrer un email valide';
}
return null;
@ -297,7 +298,7 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
itemBuilder: (context, index) {
final product = _products[index];
final quantity = _quantites[product.id] ?? 0;
return Card(
margin: const EdgeInsets.symmetric(vertical: 8),
elevation: 2,
@ -316,7 +317,7 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
color: Colors.blue.shade50,
borderRadius: BorderRadius.circular(8),
),
child: const Icon(Icons.shopping_bag,
child: const Icon(Icons.shopping_bag,
color: Colors.blue),
),
title: Text(
@ -328,7 +329,7 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
children: [
const SizedBox(height: 4),
Text(
'${product.price.toStringAsFixed(2)} DA',
'${product.price.toStringAsFixed(2)} MGA',
style: TextStyle(
color: Colors.green.shade700,
fontWeight: FontWeight.w600,
@ -364,12 +365,14 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
),
Text(
quantity.toString(),
style: const TextStyle(fontWeight: FontWeight.bold),
style: const TextStyle(
fontWeight: FontWeight.bold),
),
IconButton(
icon: const Icon(Icons.add, size: 18),
onPressed: () {
if (product.stock == null || quantity < product.stock!) {
if (product.stock == null ||
quantity < product.stock!) {
setState(() {
_quantites[product.id!] = quantity + 1;
});
@ -397,7 +400,7 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
Widget _buildCartSection() {
final itemsInCart = _quantites.entries.where((e) => e.value > 0).toList();
if (itemsInCart.isEmpty) {
return Card(
elevation: 4,
@ -454,9 +457,10 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
child: const Icon(Icons.shopping_bag, size: 20),
),
title: Text(product.name),
subtitle: Text('${entry.value} x ${product.price.toStringAsFixed(2)} DA'),
subtitle: Text(
'${entry.value} x ${product.price.toStringAsFixed(2)} MGA'),
trailing: Text(
'${(entry.value * product.price).toStringAsFixed(2)} DA',
'${(entry.value * product.price).toStringAsFixed(2)} MGA',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.blue.shade800,
@ -499,7 +503,7 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
Text(
'${total.toStringAsFixed(2)} DA',
'${total.toStringAsFixed(2)} MGA',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
@ -559,11 +563,11 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
// Calculer le total et préparer les détails
double total = 0;
final details = <DetailCommande>[];
for (final entry in itemsInCart) {
final product = _products.firstWhere((p) => p.id == entry.key);
total += entry.value * product.price;
details.add(DetailCommande(
commandeId: 0, // Valeur temporaire, sera remplacée dans la transaction
produitId: product.id!,
@ -585,7 +589,7 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
try {
// Enregistrer la commande dans la base de données
await _database.createCommandeComplete(client, commande, details);
Get.snackbar(
'Succès',
'Votre commande a été enregistrée',
@ -593,13 +597,12 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
backgroundColor: Colors.green,
colorText: Colors.white,
);
// Réinitialiser le formulaire
_formKey.currentState!.reset();
setState(() {
_quantites.clear();
});
} catch (e) {
Get.snackbar(
'Erreur',
@ -620,4 +623,4 @@ class _NouvelleCommandePageState extends State<NouvelleCommandePage> {
_adresseController.dispose();
super.dispose();
}
}
}

Loading…
Cancel
Save