Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

255 fail querry collection new #290

Merged
merged 7 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import 'package:cashcompass_hook/src/accounts/active_account/active_account.dart';
import 'package:cashcompass_hook/src/accounts/category/category.dart';
import 'package:cashcompass_hook/src/chart_of_accounts.dart/data.dart';
import 'package:cashcompass_hook/src/data_storage/accout_manager.dart';
import 'package:cashcompass_hook/src/transactions/transactions/transaction.dart';

class CategoryAndTransactions {
final Category category;
final List<Transaction> soll, haben;
CategoryAndTransactions(
{required this.category, required this.haben, required this.soll});
}

class ChartOfAccounts {
final Accountmanager _accountmanager;
Expand All @@ -13,6 +22,58 @@ class ChartOfAccounts {
.toList();
}

List<CategoryAndTransactions> getCategoriesAndTransaktions() {
var cates = _accountmanager.getAllCategories();
var ret = <CategoryAndTransactions>[];
for (Category i in cates) {
ret.add(
CategoryAndTransactions(category: i, haben: i.habenT, soll: i.sollT));
}
return ret;
}

Map<Category, Iterable<Expense>> getExpencesPerCategory(Category? category) {
Map<Category, Iterable<Expense>> ret = {};
Iterable<Category> categories = _accountmanager
.getAllCategories()
.where((cate) => category == null ? true : cate == category);

for (var category in categories) {
var e = category.sollT.map((elem) => Expense(elem, category));
if (e.isNotEmpty) {
ret[category] = e;
}
}
return ret;
}

Map<Category, Iterable<Income>> getIncomePerCategory(Category? category) {
Map<Category, Iterable<Income>> ret = {};
Iterable<Category> categories = _accountmanager
.getAllCategories()
.where((cate) => category == null ? true : cate == category);

for (var category in categories) {
var e = category.sollT.map((elem) => Income(elem, category));
if (e.isNotEmpty) {
ret[category] = e;
}
}
return ret;
}

List<TransactionInfo> getAllTransactionsRealtedToCategories() {
List<TransactionInfo> ret = [];
ret.addAll(_accountmanager.getAllCategories().expand((cate) => cate.habenT
.map((transaction) =>
TransactionInfo(TransactionTypes.expense, transaction, cate))));

ret.addAll(_accountmanager.getAllCategories().expand((cate) => cate.sollT
.map((transaction) =>
TransactionInfo(TransactionTypes.income, transaction, cate))));
return ret;
}

List<ActiveAccount> getActiveAccounts(
{bool Function(ActiveAccount)? matcher}) {
return _accountmanager
Expand Down
34 changes: 34 additions & 0 deletions client/cashcompass_hook/lib/src/chart_of_accounts.dart/data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:cashcompass_hook/src/accounts/category/category.dart';
import 'package:cashcompass_hook/src/transactions/transactions/transaction.dart';

class Income {
final Transaction transaction;
final Category category;
Income(this.transaction, this.category);
String get icon => category.iconString;
DateTime get timestamp => transaction.timestamp;
}

class Expense {
final Transaction transaction;
final Category category;
Expense(this.transaction, this.category);
String get icon => category.iconString;
DateTime get timestamp => transaction.timestamp;
}

enum TransactionTypes {
expense,
income;
}

class TransactionInfo {
final TransactionTypes transactionType;
final Transaction transcation;
final Category category;
TransactionInfo(this.transactionType, this.transcation, this.category);
double get amount => transcation.amount;
String get label => transcation.label;
String get walletName => category.name;
String get icon => category.iconString;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class SyncController implements DataAdapter {

@override
Future<InitialPullData> getInitialPull(Accountmanager accountmanager) async {
var remote =
_remoteStorage.getInitialPull(accountmanager).timeout(const Duration(seconds: 5));
var remote = _remoteStorage
.getInitialPull(accountmanager)
.timeout(const Duration(seconds: 5));
var local = _localStorage.getInitialPull(accountmanager);
InitialPullData? localData, remoteData;
try {
Expand Down