2023-07-19 02:16:13 -06:00
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
|
|
|
|
import '../global/utils.dart';
|
|
|
|
|
|
|
|
part 'transaction_model.g.dart';
|
|
|
|
|
|
|
|
enum TransactionType {
|
|
|
|
income,
|
|
|
|
expense,
|
|
|
|
}
|
|
|
|
|
|
|
|
@JsonSerializable()
|
|
|
|
class Transaction {
|
|
|
|
const Transaction({
|
|
|
|
this.id,
|
|
|
|
required this.amount,
|
2023-07-22 21:29:32 -06:00
|
|
|
required this.type,
|
2023-07-19 02:16:13 -06:00
|
|
|
required this.budgetId,
|
2023-07-22 21:29:32 -06:00
|
|
|
this.budgetCategoryId,
|
2023-08-17 13:34:30 -06:00
|
|
|
required this.createdByUserId,
|
2023-07-19 02:16:13 -06:00
|
|
|
required this.date,
|
2023-07-22 21:29:32 -06:00
|
|
|
this.memo,
|
2023-07-19 02:16:13 -06:00
|
|
|
this.createdAt,
|
2023-07-22 21:29:32 -06:00
|
|
|
this.updatedAt,
|
|
|
|
this.hide = false,
|
2023-07-19 02:16:13 -06:00
|
|
|
});
|
|
|
|
|
2023-07-22 21:29:32 -06:00
|
|
|
final int? id, budgetCategoryId;
|
2023-08-17 13:34:30 -06:00
|
|
|
final int budgetId, createdByUserId;
|
2023-07-19 02:16:13 -06:00
|
|
|
final double amount;
|
2023-07-22 21:29:32 -06:00
|
|
|
final String? memo;
|
|
|
|
final TransactionType type;
|
|
|
|
|
|
|
|
@JsonKey(fromJson: boolFromJson, toJson: boolToJson)
|
|
|
|
final bool hide;
|
2023-07-19 02:16:13 -06:00
|
|
|
|
|
|
|
@JsonKey(fromJson: dateFromJson, toJson: dateToJson)
|
|
|
|
final DateTime date;
|
|
|
|
|
|
|
|
@JsonKey(fromJson: dateFromJson, toJson: dateToJson)
|
|
|
|
final DateTime? createdAt;
|
|
|
|
|
2023-07-22 21:29:32 -06:00
|
|
|
@JsonKey(fromJson: dateFromJson, toJson: dateToJson)
|
|
|
|
final DateTime? updatedAt;
|
|
|
|
|
2023-07-19 02:16:13 -06:00
|
|
|
factory Transaction.fromJson(Map<String, dynamic> json) =>
|
|
|
|
_$TransactionFromJson(json);
|
|
|
|
|
2023-07-22 21:29:32 -06:00
|
|
|
factory Transaction.copyWith(Transaction trans, Map<String, dynamic> data) =>
|
|
|
|
Transaction(
|
|
|
|
id: data['id'] ?? trans.id,
|
|
|
|
amount: data['amount'] ?? trans.amount,
|
|
|
|
type: data['type'] ?? trans.type,
|
|
|
|
budgetId: data['budget_id'] ?? trans.budgetId,
|
|
|
|
budgetCategoryId: data['budget_category_id'] ?? trans.budgetCategoryId,
|
2023-08-17 13:34:30 -06:00
|
|
|
createdByUserId: data['created_by_user_id'] ?? trans.createdByUserId,
|
2023-07-22 21:29:32 -06:00
|
|
|
date: data['date'] ?? trans.date,
|
|
|
|
memo: data['memo'] ?? trans.memo,
|
|
|
|
createdAt: data['created_at'] ?? trans.createdAt,
|
|
|
|
updatedAt: data['updated_at'] ?? trans.updatedAt,
|
|
|
|
hide: data['hide'] ?? trans.hide,
|
|
|
|
);
|
|
|
|
|
2023-07-19 02:16:13 -06:00
|
|
|
Map<String, dynamic> toJson() => _$TransactionToJson(this);
|
|
|
|
}
|