-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from enrique-lozano/feat/transaction-tags
Introduce transaction tags!
- Loading branch information
Showing
27 changed files
with
1,596 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Here are the files that contains the SQL scripts to go from a version to another. | ||
|
||
The name of this files will be v2.sql, v3.sql... and so on, where the number represent the target version. _DO NOT_ modify the `dbVersion` param of the `appData` table, this param is autoupdated when a migration occurs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
INSERT INTO userSettings VALUES ('accentColor', 'auto'), | ||
('amoledMode', '0'); | ||
('amoledMode', '0'); | ||
|
||
CREATE TABLE IF NOT EXISTS tags ( | ||
id TEXT NOT NULL PRIMARY KEY, | ||
name TEXT UNIQUE NOT NULL, | ||
color TEXT NOT NULL, | ||
description TEXT | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS transactionTags ( | ||
transactionID TEXT NOT NULL REFERENCES transactions(id) ON DELETE CASCADE ON UPDATE CASCADE, | ||
tagID TEXT NOT NULL REFERENCES tags(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
lib/app/stats/widgets/movements_distribution/tags_stats.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:monekin/app/stats/widgets/movements_distribution/chart_by_categories.dart'; | ||
import 'package:monekin/core/database/services/tags/tags_service.dart'; | ||
import 'package:monekin/core/database/services/transaction/transaction_service.dart'; | ||
import 'package:monekin/core/models/tags/tag.dart'; | ||
import 'package:monekin/core/models/transaction/transaction.dart'; | ||
import 'package:monekin/core/presentation/widgets/number_ui_formatters/currency_displayer.dart'; | ||
import 'package:monekin/core/presentation/widgets/transaction_filter/transaction_filters.dart'; | ||
import 'package:monekin/i18n/translations.g.dart'; | ||
|
||
class TagStats extends StatelessWidget { | ||
const TagStats({super.key, required this.filters}); | ||
|
||
final TransactionFilters filters; | ||
|
||
TrDistributionChartItem<Tag> getTagInfo( | ||
Tag tag, List<MoneyTransaction> transactions) { | ||
transactions = transactions | ||
.where((element) => element.tags.any((elTag) => elTag.id == tag.id)) | ||
.toList(); | ||
|
||
return TrDistributionChartItem<Tag>( | ||
category: tag, | ||
transactions: transactions, | ||
value: transactions.map((e) => e.currentValueInPreferredCurrency).sum, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final t = Translations.of(context); | ||
|
||
return StreamBuilder( | ||
stream: TransactionService.instance.getTransactions(filters: filters), | ||
builder: (context, trSnapshot) { | ||
if (!trSnapshot.hasData) { | ||
return const LinearProgressIndicator(); | ||
} | ||
|
||
if (trSnapshot.data!.isEmpty) { | ||
return Padding( | ||
padding: const EdgeInsets.all(24), | ||
child: Text(t.general.insufficient_data), | ||
); | ||
} | ||
|
||
return StreamBuilder( | ||
stream: TagService.instance.getTags(), | ||
builder: (context, tagsSnapshot) { | ||
if (!tagsSnapshot.hasData) { | ||
return const LinearProgressIndicator(); | ||
} | ||
|
||
final tags = tagsSnapshot.data!; | ||
|
||
final tagsInfo = tags | ||
.map((e) => getTagInfo(e, trSnapshot.data!)) | ||
.where((element) => element.transactions.isNotEmpty) | ||
.toList(); | ||
|
||
tagsInfo.sort((a, b) => a.value.compareTo(b.value)); | ||
|
||
if (tags.isEmpty || tagsInfo.isEmpty) { | ||
return Padding( | ||
padding: const EdgeInsets.all(24), | ||
child: Text(tags.isEmpty | ||
? t.tags.empty_list | ||
: t.general.insufficient_data), | ||
); | ||
} | ||
|
||
return ListView.builder( | ||
itemCount: tagsInfo.length, | ||
shrinkWrap: true, | ||
physics: const NeverScrollableScrollPhysics(), | ||
itemBuilder: (context, index) { | ||
final dataTag = tagsInfo[index]; | ||
|
||
return ListTile( | ||
title: Text(dataTag.category.name), | ||
subtitle: Text( | ||
'${dataTag.transactions.length} ${t.transaction.display(n: dataTag.transactions.length)}' | ||
.toLowerCase(), | ||
), | ||
trailing: | ||
CurrencyDisplayer(amountToConvert: dataTag.value), | ||
leading: dataTag.category.displayIcon(), | ||
); | ||
}, | ||
); | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.