40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
/// Type d'un mouvement de points dans l'historique.
|
|
class TypeMouvement {
|
|
static const facture = 'facture';
|
|
static const recompense = 'recompense';
|
|
static const ajustement = 'ajustement';
|
|
}
|
|
|
|
/// Une ligne d'historique : gain (facture) ou dépense (récompense).
|
|
class Mouvement {
|
|
final String id;
|
|
final String type;
|
|
final double? montantEuros;
|
|
final double points; // signé
|
|
final String libelle;
|
|
final DateTime date;
|
|
|
|
const Mouvement({
|
|
required this.id,
|
|
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(),
|
|
type: (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),
|
|
);
|
|
}
|
|
}
|