mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
enum TransactionType { income, expense }
|
||||
enum TransactionType { income, expense, transfer }
|
||||
|
||||
enum RecurrenceType { none, daily, weekly, monthly }
|
||||
|
||||
@@ -33,41 +33,39 @@ class Transaction {
|
||||
});
|
||||
|
||||
factory Transaction.fromJson(Map<String, dynamic> json) => Transaction(
|
||||
id: json['id'] as String,
|
||||
amount: (json['amount'] as num).toDouble(),
|
||||
category: json['category'] as String,
|
||||
type: TransactionType.values.firstWhere(
|
||||
(e) => e.name == json['type'],
|
||||
),
|
||||
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',
|
||||
accountId: json['accountId'] as int,
|
||||
);
|
||||
id: json['id'] as String,
|
||||
amount: (json['amount'] as num).toDouble(),
|
||||
category: json['category'] as String,
|
||||
type: TransactionType.values.firstWhere((e) => e.name == json['type']),
|
||||
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',
|
||||
accountId: json['accountId'] as int,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'amount': amount,
|
||||
'category': category,
|
||||
'type': type.name,
|
||||
'date': date.toIso8601String(),
|
||||
'note': note,
|
||||
'recurrence': recurrence.name,
|
||||
'lastOccurrence': lastOccurrence?.toIso8601String(),
|
||||
'currency': currency,
|
||||
'currencyCode': currencyCode,
|
||||
'accountId': accountId,
|
||||
};
|
||||
'id': id,
|
||||
'amount': amount,
|
||||
'category': category,
|
||||
'type': type.name,
|
||||
'date': date.toIso8601String(),
|
||||
'note': note,
|
||||
'recurrence': recurrence.name,
|
||||
'lastOccurrence': lastOccurrence?.toIso8601String(),
|
||||
'currency': currency,
|
||||
'currencyCode': currencyCode,
|
||||
'accountId': accountId,
|
||||
};
|
||||
|
||||
Transaction copyWith({
|
||||
String? id,
|
||||
@@ -81,18 +79,17 @@ class Transaction {
|
||||
String? currency,
|
||||
String? currencyCode,
|
||||
int? accountId,
|
||||
}) =>
|
||||
Transaction(
|
||||
id: id ?? this.id,
|
||||
amount: amount ?? this.amount,
|
||||
category: category ?? this.category,
|
||||
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,
|
||||
accountId: accountId ?? this.accountId,
|
||||
);
|
||||
}) => Transaction(
|
||||
id: id ?? this.id,
|
||||
amount: amount ?? this.amount,
|
||||
category: category ?? this.category,
|
||||
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,
|
||||
accountId: accountId ?? this.accountId,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user