import 'package:em2rp/models/event_model.dart'; /// Helper pour la gestion des prix HT et TTC class PriceHelpers { /// Taux de TVA par défaut (20%) static const double defaultTaxRate = 0.20; /// Calcule le prix TTC à partir du prix HT static double calculateTTC(double priceHT, {double taxRate = defaultTaxRate}) { return priceHT * (1 + taxRate); } /// Calcule le prix HT à partir du prix TTC static double calculateHT(double priceTTC, {double taxRate = defaultTaxRate}) { return priceTTC / (1 + taxRate); } /// Calcule le montant de TVA static double calculateTax(double priceHT, {double taxRate = defaultTaxRate}) { return priceHT * taxRate; } /// Formate un prix en euros avec deux décimales static String formatPrice(double price) { return '${price.toStringAsFixed(2)} €'; } /// Retourne un objet EventPricing avec HT, TVA et TTC calculés static EventPricing getPricing(EventModel event, {double taxRate = defaultTaxRate}) { // basePrice dans Firestore est le prix TTC (avec TVA 20% déjà incluse) final priceTTC = event.basePrice; final priceHT = calculateHT(priceTTC, taxRate: taxRate); final taxAmount = calculateTax(priceHT, taxRate: taxRate); return EventPricing( priceHT: priceHT, taxAmount: taxAmount, priceTTC: priceTTC, taxRate: taxRate, ); } } /// Classe pour stocker les différentes composantes du prix d'un événement class EventPricing { final double priceHT; final double taxAmount; final double priceTTC; final double taxRate; const EventPricing({ required this.priceHT, required this.taxAmount, required this.priceTTC, required this.taxRate, }); /// Retourne le taux de TVA en pourcentage (ex: 20.0 pour 20%) double get taxRatePercentage => taxRate * 100; /// Formate le prix HT String get formattedHT => PriceHelpers.formatPrice(priceHT); /// Formate le montant de TVA String get formattedTax => PriceHelpers.formatPrice(taxAmount); /// Formate le prix TTC String get formattedTTC => PriceHelpers.formatPrice(priceTTC); /// Retourne un résumé complet du pricing String get summary => 'HT: $formattedHT | TVA (${taxRatePercentage.toStringAsFixed(0)}%): $formattedTax | TTC: $formattedTTC'; } /// Widget helper pour afficher les prix class PriceDisplay { /// Génère un Map avec les composantes de prix pour affichage static Map getPriceComponents(EventModel event) { final pricing = PriceHelpers.getPricing(event); return { 'HT': pricing.formattedHT, 'TVA': '${pricing.formattedTax} (${pricing.taxRatePercentage.toStringAsFixed(0)}%)', 'TTC': pricing.formattedTTC, }; } }