2024-06-30 20:25:36 +02:00
|
|
|
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-01-08 21:19:15 +01:00
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
import 'package:prasule/api/category.dart';
|
|
|
|
import 'package:prasule/api/entry_data.dart';
|
|
|
|
import 'package:prasule/api/wallet_entry.dart';
|
|
|
|
|
|
|
|
part 'recurring_entry.g.dart';
|
|
|
|
|
|
|
|
/// This is a [WalletSingleEntry] that is automatically recurring
|
|
|
|
@JsonSerializable()
|
|
|
|
class RecurringWalletEntry extends WalletSingleEntry {
|
|
|
|
/// This is a [WalletSingleEntry] that is automatically recurring
|
|
|
|
RecurringWalletEntry({
|
|
|
|
required super.data,
|
|
|
|
required super.type,
|
|
|
|
required super.date,
|
|
|
|
required super.category,
|
|
|
|
required super.id,
|
|
|
|
required this.lastRunDate,
|
|
|
|
required this.recurType,
|
|
|
|
this.repeatAfter = 1,
|
|
|
|
});
|
|
|
|
|
2024-07-17 16:44:02 +02:00
|
|
|
/// Generates a class instance from a Map
|
2024-01-08 21:19:15 +01:00
|
|
|
factory RecurringWalletEntry.fromJson(Map<String, dynamic> json) =>
|
|
|
|
_$RecurringWalletEntryFromJson(json);
|
|
|
|
|
2024-07-17 16:44:02 +02:00
|
|
|
/// Converts the data in this instance into a Map
|
2024-01-08 21:19:15 +01:00
|
|
|
@override
|
|
|
|
Map<String, dynamic> toJson() => _$RecurringWalletEntryToJson(this);
|
|
|
|
|
|
|
|
/// Last date the recurring entry was added into the single entry list
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: DateTime.now)
|
2024-01-08 21:19:15 +01:00
|
|
|
DateTime lastRunDate;
|
|
|
|
|
|
|
|
/// After how many {recurType} should the entry recur
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: 1)
|
2024-01-08 21:19:15 +01:00
|
|
|
int repeatAfter;
|
|
|
|
|
|
|
|
/// What type of recurrence should happen
|
2024-07-17 17:37:41 +02:00
|
|
|
@JsonKey(defaultValue: RecurType.month)
|
2024-01-08 21:19:15 +01:00
|
|
|
RecurType recurType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// How a [RecurringWalletEntry] should recur
|
|
|
|
@JsonEnum()
|
|
|
|
enum RecurType {
|
|
|
|
/// Will recur every {repeatAfter} months
|
|
|
|
month,
|
|
|
|
|
|
|
|
/// Will recur every {repeatAfter} years
|
|
|
|
year,
|
|
|
|
|
|
|
|
/// Will recur every {repeatAfter} days
|
|
|
|
day
|
|
|
|
}
|