mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -2,6 +2,8 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
enum TransactionType { income, expense }
|
||||
|
||||
enum RecurrenceType { none, daily, weekly, monthly }
|
||||
|
||||
@immutable
|
||||
class Transaction {
|
||||
final String id;
|
||||
@@ -10,6 +12,10 @@ class Transaction {
|
||||
final TransactionType type;
|
||||
final DateTime date;
|
||||
final String? note;
|
||||
final RecurrenceType recurrence;
|
||||
final DateTime? lastOccurrence;
|
||||
final String currency;
|
||||
final String currencyCode;
|
||||
|
||||
const Transaction({
|
||||
required this.id,
|
||||
@@ -18,6 +24,10 @@ class Transaction {
|
||||
required this.type,
|
||||
required this.date,
|
||||
this.note,
|
||||
this.recurrence = RecurrenceType.none,
|
||||
this.lastOccurrence,
|
||||
this.currency = '\$',
|
||||
this.currencyCode = 'USD',
|
||||
});
|
||||
|
||||
factory Transaction.fromJson(Map<String, dynamic> json) => Transaction(
|
||||
@@ -29,6 +39,17 @@ class Transaction {
|
||||
),
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
note: json['note'] as String?,
|
||||
recurrence: json['recurrence'] != null
|
||||
? RecurrenceType.values.firstWhere(
|
||||
(e) => e.name == json['recurrence'],
|
||||
orElse: () => RecurrenceType.none,
|
||||
)
|
||||
: RecurrenceType.none,
|
||||
lastOccurrence: json['lastOccurrence'] != null
|
||||
? DateTime.parse(json['lastOccurrence'] as String)
|
||||
: null,
|
||||
currency: json['currency'] as String? ?? '\$',
|
||||
currencyCode: json['currencyCode'] as String? ?? 'USD',
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
@@ -38,6 +59,10 @@ class Transaction {
|
||||
'type': type.name,
|
||||
'date': date.toIso8601String(),
|
||||
'note': note,
|
||||
'recurrence': recurrence.name,
|
||||
'lastOccurrence': lastOccurrence?.toIso8601String(),
|
||||
'currency': currency,
|
||||
'currencyCode': currencyCode,
|
||||
};
|
||||
|
||||
Transaction copyWith({
|
||||
@@ -47,6 +72,10 @@ class Transaction {
|
||||
TransactionType? type,
|
||||
DateTime? date,
|
||||
String? note,
|
||||
RecurrenceType? recurrence,
|
||||
DateTime? lastOccurrence,
|
||||
String? currency,
|
||||
String? currencyCode,
|
||||
}) =>
|
||||
Transaction(
|
||||
id: id ?? this.id,
|
||||
@@ -55,5 +84,9 @@ class Transaction {
|
||||
type: type ?? this.type,
|
||||
date: date ?? this.date,
|
||||
note: note ?? this.note,
|
||||
recurrence: recurrence ?? this.recurrence,
|
||||
lastOccurrence: lastOccurrence ?? this.lastOccurrence,
|
||||
currency: currency ?? this.currency,
|
||||
currencyCode: currencyCode ?? this.currencyCode,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user