56 lines
1.7 KiB
Dart
56 lines
1.7 KiB
Dart
/// Type d'un mouvement de points dans l'historique d'un client.
|
|
class TypeMouvement {
|
|
static const facture = 'facture'; // gain de points suite à un achat
|
|
static const recompense = 'recompense'; // dépense de points sur une récompense
|
|
static const ajustement = 'ajustement'; // correction manuelle (+/-)
|
|
}
|
|
|
|
/// Une ligne d'historique : gain (facture) ou dépense (récompense) de points
|
|
/// pour un client donné.
|
|
class Mouvement {
|
|
final String id;
|
|
final String clientId;
|
|
|
|
/// Voir [TypeMouvement].
|
|
final String type;
|
|
|
|
/// Montant de la facture en euros (uniquement pour [TypeMouvement.facture]).
|
|
final double? montantEuros;
|
|
|
|
/// Points crédités (positif) ou débités (négatif).
|
|
final double points;
|
|
|
|
/// Libellé lisible, ex : « Facture 25,00 € » ou « Café offert ».
|
|
final String libelle;
|
|
|
|
/// Date du mouvement.
|
|
final DateTime date;
|
|
|
|
const Mouvement({
|
|
required this.id,
|
|
required this.clientId,
|
|
required this.type,
|
|
this.montantEuros,
|
|
required this.points,
|
|
required this.libelle,
|
|
required this.date,
|
|
});
|
|
|
|
bool get estGain => points >= 0;
|
|
|
|
factory Mouvement.fromMap(Map<String, dynamic> map) {
|
|
return Mouvement(
|
|
id: map['id'].toString(),
|
|
clientId: (map['client'] ?? '').toString(),
|
|
type: (map['type'] as String?)?.isNotEmpty == true
|
|
? map['type'] as String
|
|
: TypeMouvement.ajustement,
|
|
montantEuros: (map['montant_euros'] as num?)?.toDouble(),
|
|
points: (map['points'] as num?)?.toDouble() ?? 0,
|
|
libelle: (map['libelle'] as String?) ?? '',
|
|
date: DateTime.tryParse(map['created']?.toString() ?? '')?.toLocal() ??
|
|
DateTime.fromMillisecondsSinceEpoch(0),
|
|
);
|
|
}
|
|
}
|