@@ -14,6 +14,7 @@ class BankAccountFields extends BaseEntityFields {
1414 static String color = 'color' ;
1515 static String startingValue = 'startingValue' ;
1616 static String active = 'active' ;
17+ static String countNetWorth = 'countNetWorth' ;
1718 static String mainAccount = 'mainAccount' ;
1819 static String total = 'total' ;
1920 static String createdAt = BaseEntityFields .getCreatedAt;
@@ -26,6 +27,7 @@ class BankAccountFields extends BaseEntityFields {
2627 color,
2728 startingValue,
2829 active,
30+ countNetWorth,
2931 mainAccount,
3032 BaseEntityFields .createdAt,
3133 BaseEntityFields .updatedAt
@@ -38,6 +40,7 @@ class BankAccount extends BaseEntity {
3840 final int color;
3941 final num startingValue;
4042 final bool active;
43+ final bool countNetWorth;
4144 final bool mainAccount;
4245 final num ? total;
4346
@@ -48,46 +51,52 @@ class BankAccount extends BaseEntity {
4851 required this .color,
4952 required this .startingValue,
5053 required this .active,
54+ required this .countNetWorth,
5155 required this .mainAccount,
5256 this .total,
5357 super .createdAt,
5458 super .updatedAt,
5559 });
5660
57- BankAccount copy (
58- {int ? id,
59- String ? name,
60- String ? symbol,
61- int ? color,
62- num ? startingValue,
63- bool ? active,
64- bool ? mainAccount,
65- DateTime ? createdAt,
66- DateTime ? updatedAt,}) =>
61+ BankAccount copy ({
62+ int ? id,
63+ String ? name,
64+ String ? symbol,
65+ int ? color,
66+ num ? startingValue,
67+ bool ? active,
68+ bool ? countNetWorth,
69+ bool ? mainAccount,
70+ DateTime ? createdAt,
71+ DateTime ? updatedAt,
72+ }) =>
6773 BankAccount (
68- id: id ?? this .id,
69- name: name ?? this .name,
70- symbol: symbol ?? this .symbol,
71- color: color ?? this .color,
72- startingValue: startingValue ?? this .startingValue,
73- active: active ?? this .active,
74- mainAccount: mainAccount ?? this .mainAccount,
75- createdAt: createdAt ?? this .createdAt,
76- updatedAt: updatedAt ?? this .updatedAt,
77- total: total
78- );
74+ id: id ?? this .id,
75+ name: name ?? this .name,
76+ symbol: symbol ?? this .symbol,
77+ color: color ?? this .color,
78+ startingValue: startingValue ?? this .startingValue,
79+ active: active ?? this .active,
80+ countNetWorth: countNetWorth ?? this .countNetWorth,
81+ mainAccount: mainAccount ?? this .mainAccount,
82+ createdAt: createdAt ?? this .createdAt,
83+ updatedAt: updatedAt ?? this .updatedAt,
84+ total: total,
85+ );
7986
8087 static BankAccount fromJson (Map <String , Object ?> json) => BankAccount (
81- id: json[BaseEntityFields .id] as int ,
82- name: json[BankAccountFields .name] as String ,
83- symbol: json[BankAccountFields .symbol] as String ,
84- color: json[BankAccountFields .color] as int ,
85- startingValue: json[BankAccountFields .startingValue] as num ,
86- active: json[BankAccountFields .active] == 1 ? true : false ,
87- mainAccount: json[BankAccountFields .mainAccount] == 1 ? true : false ,
88- total: json[BankAccountFields .total] as num ? ,
89- createdAt: DateTime .parse (json[BaseEntityFields .createdAt] as String ),
90- updatedAt: DateTime .parse (json[BaseEntityFields .updatedAt] as String ));
88+ id: json[BaseEntityFields .id] as int ,
89+ name: json[BankAccountFields .name] as String ,
90+ symbol: json[BankAccountFields .symbol] as String ,
91+ color: json[BankAccountFields .color] as int ,
92+ startingValue: json[BankAccountFields .startingValue] as num ,
93+ active: json[BankAccountFields .active] == 1 ? true : false ,
94+ countNetWorth: json[BankAccountFields .countNetWorth] == 1 ? true : false ,
95+ mainAccount: json[BankAccountFields .mainAccount] == 1 ? true : false ,
96+ total: json[BankAccountFields .total] as num ? ,
97+ createdAt: DateTime .parse (json[BaseEntityFields .createdAt] as String ),
98+ updatedAt: DateTime .parse (json[BaseEntityFields .updatedAt] as String ),
99+ );
91100
92101 Map <String , Object ?> toJson ({bool update = false }) => {
93102 BaseEntityFields .id: id,
@@ -96,9 +105,11 @@ class BankAccount extends BaseEntity {
96105 BankAccountFields .color: color,
97106 BankAccountFields .startingValue: startingValue,
98107 BankAccountFields .active: active ? 1 : 0 ,
108+ BankAccountFields .countNetWorth: countNetWorth ? 1 : 0 ,
99109 BankAccountFields .mainAccount: mainAccount ? 1 : 0 ,
100- BaseEntityFields .createdAt:
101- update ? createdAt? .toIso8601String () : DateTime .now ().toIso8601String (),
110+ BaseEntityFields .createdAt: update
111+ ? createdAt? .toIso8601String ()
112+ : DateTime .now ().toIso8601String (),
102113 BaseEntityFields .updatedAt: DateTime .now ().toIso8601String (),
103114 };
104115}
@@ -152,7 +163,8 @@ class BankAccountMethods extends SossoldiDatabase {
152163
153164 final orderByASC = '${BankAccountFields .createdAt } ASC' ;
154165 final where = '${BankAccountFields .active } = 1 ' ;
155- final recurringFilter = '(t.${TransactionFields .recurring } = 0 OR t.${TransactionFields .recurring } IS NULL)' ;
166+ final recurringFilter =
167+ '(t.${TransactionFields .recurring } = 0 OR t.${TransactionFields .recurring } IS NULL)' ;
156168
157169 final result = await db.rawQuery ('''
158170 SELECT b.*, (b.${BankAccountFields .startingValue } +
@@ -207,15 +219,19 @@ class BankAccountMethods extends SossoldiDatabase {
207219 Future <int > deleteById (int id) async {
208220 final db = await database;
209221
210- return await db.delete (bankAccountTable, where: '${BankAccountFields .id } = ?' , whereArgs: [id]);
222+ return await db.delete (
223+ bankAccountTable,
224+ where: '${BankAccountFields .id } = ?' ,
225+ whereArgs: [id],
226+ );
211227 }
212228
213229 Future <int > deactivateById (int id) async {
214230 final db = await database;
215231
216232 return await db.update (
217233 bankAccountTable,
218- {' active' : 0 },
234+ {BankAccountFields . active: 0 , BankAccountFields .mainAccount : 0 },
219235 where: '${BankAccountFields .id } = ?' ,
220236 whereArgs: [id],
221237 );
@@ -225,8 +241,11 @@ class BankAccountMethods extends SossoldiDatabase {
225241 final db = await database;
226242
227243 //get account infos first
228- final result =
229- await db.query (bankAccountTable, where: '${BankAccountFields .id } = $id ' , limit: 1 );
244+ final result = await db.query (
245+ bankAccountTable,
246+ where: '${BankAccountFields .id } = $id ' ,
247+ limit: 1 ,
248+ );
230249 final singleObject = result.isNotEmpty ? result[0 ] : null ;
231250
232251 if (singleObject != null ) {
@@ -323,14 +342,16 @@ class BankAccountMethods extends SossoldiDatabase {
323342 double runningTotal = statritngValue[0 ]['Value' ] as double ;
324343
325344 var result = resultQuery.map ((e) {
326- runningTotal += double .parse (e['income' ].toString ()) - double .parse (e['expense' ].toString ());
345+ runningTotal += double .parse (e['income' ].toString ()) -
346+ double .parse (e['expense' ].toString ());
327347 return {"day" : e["day" ], "balance" : runningTotal};
328348 }).toList ();
329349
330350 if (dateRangeStart != null ) {
331351 return result
332- .where ((element) => dateRangeStart
333- .isBefore (DateTime .parse (element["day" ].toString ()).add (const Duration (days: 1 ))))
352+ .where ((element) => dateRangeStart.isBefore (
353+ DateTime .parse (element["day" ].toString ())
354+ .add (const Duration (days: 1 ))))
334355 .toList ();
335356 }
336357
0 commit comments