Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/herald/app_locale.dart';
5 : import 'package:app_finance/_classes/storage/app_data.dart';
6 : import 'package:app_finance/_classes/structure/abstract_app_data.dart';
7 : import 'package:app_finance/_mixins/storage_mixin.dart';
8 : import 'package:flutter/material.dart';
9 : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
10 : import 'package:intl/intl.dart';
11 :
12 : class InvoiceAppData extends AbstractAppData with StorageMixin {
13 : String account;
14 : String? accountFrom;
15 :
16 1 : InvoiceAppData({
17 : required super.title,
18 : required this.account,
19 : this.accountFrom,
20 : super.uuid,
21 : super.details,
22 : super.description,
23 : super.color,
24 : super.currency,
25 : super.updatedAt,
26 : super.createdAt,
27 : super.createdAtFormatted,
28 : super.hidden,
29 : });
30 :
31 0 : @override
32 : String getClassName() => 'InvoiceAppData';
33 :
34 0 : @override
35 : AppDataType getType() => AppDataType.invoice;
36 :
37 1 : @override
38 : InvoiceAppData clone() {
39 1 : return InvoiceAppData(
40 1 : account: account,
41 1 : accountFrom: accountFrom,
42 1 : uuid: super.uuid,
43 1 : title: super.title,
44 1 : details: super.details,
45 1 : description: super.description,
46 1 : color: super.color,
47 1 : currency: super.currency,
48 1 : createdAt: super.createdAt,
49 1 : hidden: super.hidden,
50 : );
51 : }
52 :
53 0 : factory InvoiceAppData.fromJson(Map<String, dynamic> json) {
54 0 : return InvoiceAppData(
55 0 : uuid: json['uuid'],
56 0 : title: json['title'],
57 0 : account: json['account'],
58 0 : accountFrom: json['accountFrom'],
59 0 : details: 0.0 + (json['details'] ?? 0),
60 0 : description: json['description'],
61 0 : color: json['color'] != null ? MaterialColor(json['color'], const <int, Color>{}) : null,
62 0 : currency: CurrencyProvider.find(json['currency']),
63 0 : createdAt: DateTime.parse(json['createdAt']),
64 0 : updatedAt: DateTime.parse(json['updatedAt']),
65 0 : hidden: json['hidden'],
66 : );
67 : }
68 :
69 0 : @override
70 0 : Map<String, dynamic> toJson() => {
71 0 : ...super.toJson(),
72 0 : 'account': account,
73 0 : 'accountFrom': accountFrom,
74 : };
75 :
76 0 : String get detailsFormatted => (super.details as double).toCurrency(currency: currency, withPattern: false);
77 :
78 0 : @override
79 0 : String get description => DateFormat.MMMMd(AppLocale.code).format(super.createdAt);
80 :
81 0 : @override
82 0 : IconData? get icon => getState().getByUuid(account).icon;
83 :
84 0 : String get accountNamed => getState().getByUuid(account).title;
85 :
86 0 : String? get accountFromNamed => accountFrom != null ? getState().getByUuid(accountFrom!).title : null;
87 : }
|