Improved layout, fixed transaction popup
This commit is contained in:
@@ -41,8 +41,13 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
super(const AccountState()) {
|
||||
on<AccountImportJSON>(_onAccountImportJSON);
|
||||
on<AccountImportCSV>(_onAccountImportCSV);
|
||||
on<SubAccountLoad>(_onSubAccountLoad);
|
||||
// on<AccountExportJSON>(_onAccountImportJSON);
|
||||
// on<AccountExportCSV>(_onAccountImportJSON);
|
||||
|
||||
_accountRepository
|
||||
.getSubAccountsStream()
|
||||
.listen((subAccounts) => add(SubAccountLoad(subAccounts)));
|
||||
}
|
||||
|
||||
double _universalConvertToDouble(dynamic value) {
|
||||
@@ -69,6 +74,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
final List<List<dynamic>> csvList = const CsvToListConverter(fieldDelimiter: '|', eol: '\n').convert(csvFileContent);
|
||||
|
||||
final Map<String, Category> categoriesMap = {};
|
||||
final Set<String> subAccounts = {};
|
||||
|
||||
final transactions = csvList
|
||||
.map((line) {
|
||||
@@ -88,6 +94,8 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
}
|
||||
}
|
||||
|
||||
subAccounts.add(line[3]);
|
||||
|
||||
return Transaction(
|
||||
uuid: const Uuid().v8(),
|
||||
date: DateTime.parse(line[0]),
|
||||
@@ -99,7 +107,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
.toList();
|
||||
|
||||
await _accountRepository.deleteAccount();
|
||||
final account = Account(transactions: transactions, categories: categoriesMap.values.toList());
|
||||
final account = Account(transactions: transactions, categories: categoriesMap.values.toList(), subAccounts: subAccounts);
|
||||
await _accountRepository.saveAccount(account);
|
||||
}
|
||||
}
|
||||
@@ -119,4 +127,12 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
await _accountRepository.saveTransactions(transactions);
|
||||
}
|
||||
}
|
||||
|
||||
_onSubAccountLoad(
|
||||
SubAccountLoad event, Emitter<AccountState> emit
|
||||
) {
|
||||
emit(
|
||||
state.copyWith(event.subAccounts)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,3 +22,11 @@ final class AccountExportJSON extends AccountEvent {
|
||||
final class AccountExportCSV extends AccountEvent {
|
||||
const AccountExportCSV();
|
||||
}
|
||||
|
||||
final class SubAccountLoad extends AccountEvent {
|
||||
final Set<String> subAccounts;
|
||||
const SubAccountLoad(this.subAccounts);
|
||||
|
||||
@override
|
||||
List<Object> get props => [subAccounts];
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
part of 'account_bloc.dart';
|
||||
|
||||
final class AccountState extends Equatable {
|
||||
const AccountState();
|
||||
final Set<String> subAccounts;
|
||||
|
||||
AccountState copyWith() {
|
||||
return const AccountState();
|
||||
const AccountState({
|
||||
this.subAccounts = const {},
|
||||
});
|
||||
|
||||
AccountState copyWith(Set<String>? subAccounts) {
|
||||
return AccountState(
|
||||
subAccounts: subAccounts ?? this.subAccounts,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
List<Object?> get props => [subAccounts];
|
||||
}
|
||||
|
||||
@@ -96,22 +96,21 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
|
||||
ChartState _computeStateScopedStats(ChartState state) {
|
||||
double globalTotal = 0;
|
||||
double scoppedTotal = 0;
|
||||
List<ChartItem> scopedCategoriesPositiveTotals = [];
|
||||
List<ChartItem> scopedCategoriesNegativeTotals = [];
|
||||
Map<int, FlSpot> scopedMonthlyTotals = {};
|
||||
Map<int, Map<String, double>> scopedCategoriesMonthlyTotals = {};
|
||||
|
||||
for(var transaction in state.transactions) {
|
||||
double subTotal = globalTotal + transaction.value;
|
||||
globalTotal = subTotal;
|
||||
globalTotal += transaction.value;
|
||||
double subTotal = globalTotal;
|
||||
|
||||
if (transaction.date.year != state.currentYear) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (state.accountsTotals.containsKey(transaction.category)) {
|
||||
continue;
|
||||
}
|
||||
scoppedTotal += transaction.value;
|
||||
|
||||
TransactionLine transactionLine = TransactionLine(transaction: transaction, subTotal: subTotal);
|
||||
|
||||
@@ -155,7 +154,6 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
a?[transaction.category] = transaction.value.abs() + (a[transaction.category] ?? 0);
|
||||
scopedCategoriesMonthlyTotals[transaction.date.month] = a!;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<ChartItem> scopedCategoriesPositiveTotalsPercents = [];
|
||||
@@ -205,6 +203,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
scopedSimplifiedCategoriesNegativeTotalsPercents.sort((a, b) => a.value.compareTo(b.value));
|
||||
|
||||
return state.copyWith(
|
||||
scoppedProfit: scoppedTotal,
|
||||
scopedCategoriesPositiveTotals: scopedCategoriesPositiveTotals,
|
||||
scopedCategoriesPositiveTotalsPercents: scopedCategoriesPositiveTotalsPercents,
|
||||
scopedCategoriesNegativeTotals: scopedCategoriesNegativeTotals,
|
||||
|
||||
@@ -29,6 +29,8 @@ final class ChartState extends Equatable {
|
||||
final List<FlSpot> scopedMonthlyTotals;
|
||||
final Map<int, Map<String, double>> scopedCategoriesMonthlyTotals;
|
||||
|
||||
final double scoppedProfit;
|
||||
|
||||
const ChartState({
|
||||
this.transactions = const [],
|
||||
this.transactionsLines = const [],
|
||||
@@ -50,6 +52,7 @@ final class ChartState extends Equatable {
|
||||
this.scopedSimplifiedCategoriesNegativeTotalsPercents = const [],
|
||||
this.scopedMonthlyTotals = const [],
|
||||
this.scopedCategoriesMonthlyTotals = const {},
|
||||
this.scoppedProfit = 0,
|
||||
});
|
||||
|
||||
ChartState copyWith({
|
||||
@@ -73,6 +76,7 @@ final class ChartState extends Equatable {
|
||||
List<ChartItem>? scopedSimplifiedCategoriesNegativeTotalsPercents,
|
||||
List<FlSpot>? scopedMonthlyTotals,
|
||||
Map<int, Map<String, double>>? scopedCategoriesMonthlyTotals,
|
||||
double? scoppedProfit,
|
||||
}) {
|
||||
return ChartState(
|
||||
transactions: transactions ?? this.transactions,
|
||||
@@ -95,6 +99,7 @@ final class ChartState extends Equatable {
|
||||
scopedSimplifiedCategoriesNegativeTotalsPercents: scopedSimplifiedCategoriesNegativeTotalsPercents ?? this.scopedSimplifiedCategoriesNegativeTotalsPercents,
|
||||
scopedMonthlyTotals: scopedMonthlyTotals ?? this.scopedMonthlyTotals,
|
||||
scopedCategoriesMonthlyTotals: scopedCategoriesMonthlyTotals ?? this.scopedCategoriesMonthlyTotals,
|
||||
scoppedProfit: scoppedProfit ?? this.scoppedProfit,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,6 +123,7 @@ final class ChartState extends Equatable {
|
||||
scopedSimplifiedCategoriesNegativeTotalsPercents,
|
||||
scopedMonthlyTotals,
|
||||
scopedCategoriesMonthlyTotals,
|
||||
scoppedProfit,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user