2023-09-08 11:50:21 +02:00
|
|
|
import 'package:currency_picker/currency_picker.dart';
|
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
import 'package:prasule/api/category.dart';
|
2023-12-07 21:20:52 +01:00
|
|
|
import 'package:prasule/api/recurring_entry.dart';
|
2023-10-09 17:28:05 +02:00
|
|
|
import 'package:prasule/api/walletentry.dart';
|
2023-09-08 11:50:21 +02:00
|
|
|
part 'wallet.g.dart';
|
|
|
|
|
|
|
|
Currency _currencyFromJson(Map<String, dynamic> data) =>
|
|
|
|
Currency.from(json: data);
|
|
|
|
|
|
|
|
@JsonSerializable()
|
|
|
|
class Wallet {
|
|
|
|
final String name;
|
|
|
|
final List<WalletCategory> categories;
|
2023-10-09 17:28:05 +02:00
|
|
|
final List<WalletSingleEntry> entries;
|
2023-12-07 21:20:52 +01:00
|
|
|
final List<RecurringEntry> recurringEntries;
|
2023-11-21 20:23:14 +01:00
|
|
|
double starterBalance;
|
2023-09-08 11:50:21 +02:00
|
|
|
@JsonKey(fromJson: _currencyFromJson)
|
|
|
|
final Currency currency;
|
|
|
|
|
|
|
|
Wallet(
|
|
|
|
{required this.name,
|
|
|
|
required this.currency,
|
|
|
|
this.categories = const [],
|
|
|
|
this.entries = const [],
|
2023-12-07 21:20:52 +01:00
|
|
|
this.starterBalance = 0,
|
|
|
|
this.recurringEntries = const []});
|
2023-09-08 11:50:21 +02:00
|
|
|
|
|
|
|
/// Connect the generated [_$WalletEntry] function to the `fromJson`
|
|
|
|
/// factory.
|
|
|
|
factory Wallet.fromJson(Map<String, dynamic> json) => _$WalletFromJson(json);
|
|
|
|
|
|
|
|
/// Connect the generated [_$PersonToJson] function to the `toJson` method.
|
|
|
|
Map<String, dynamic> toJson() => _$WalletToJson(this);
|
2023-11-01 17:58:05 +01:00
|
|
|
|
|
|
|
/// Getter for the next unused unique number ID in the wallet's entry list
|
|
|
|
int get nextId {
|
|
|
|
var id = 1;
|
|
|
|
while (entries.where((element) => element.id == id).isNotEmpty) {
|
|
|
|
id++; // create unique ID
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
2023-11-21 20:23:14 +01:00
|
|
|
|
|
|
|
static final Wallet empty = Wallet(
|
|
|
|
name: "Empty",
|
|
|
|
currency: Currency.from(
|
|
|
|
json: {
|
|
|
|
"code": "USD",
|
|
|
|
"name": "United States Dollar",
|
|
|
|
"symbol": "\$",
|
|
|
|
"flag": "USD",
|
|
|
|
"decimal_digits": 2,
|
|
|
|
"number": 840,
|
|
|
|
"name_plural": "US dollars",
|
|
|
|
"thousands_separator": ",",
|
|
|
|
"decimal_separator": ".",
|
|
|
|
"space_between_amount_and_symbol": false,
|
|
|
|
"symbol_on_left": true,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2023-09-08 11:50:21 +02:00
|
|
|
}
|