Compare commits

...

2 commits

Author SHA1 Message Date
Matyáš Caras
e40f0491fc
fix: actually make recurring entries work correctly 2024-01-08 23:22:35 +01:00
Matyáš Caras
b72e811339
fix: differentiate expense/income with color 2024-01-08 21:53:51 +01:00
3 changed files with 83 additions and 21 deletions

View file

@ -6,6 +6,7 @@
- Added pie chart for expense/income data per category
- Added recurring entries
- Fixed wrong default sorting
- Differentiate expense and income on home view
# 1.0.0-alpha+2
- Fixed localization issues
- Added graphs for expenses and income per month/year

View file

@ -1,6 +1,7 @@
import 'package:currency_picker/currency_picker.dart';
import 'package:intl/intl.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:logger/logger.dart';
import 'package:prasule/api/category.dart';
import 'package:prasule/api/recurring_entry.dart';
import 'package:prasule/api/wallet_entry.dart';
@ -56,9 +57,11 @@ class Wallet {
/// Getter for the next unused unique number ID in the wallet's **entry** list
int get nextId {
var id = 1;
logger.d("Making ID after ${entries.length} entries");
while (entries.where((element) => element.id == id).isNotEmpty) {
id++; // create unique ID
}
logger.d("New ID: $id\nLast entry ID: ${entries.lastOrNull?.id}");
return id;
}
@ -91,33 +94,57 @@ class Wallet {
while (n.isAfter(
m,
)) {
logger.i("Adding recurring entry ${ent.data.name}");
logger
..i("Adding recurring entry ${ent.data.name}")
..d("Current entry count: ${entries.length}");
recurringEntries[recurringEntries.indexOf(ent)].lastRunDate =
m; // update date on recurring entry
logger.i(recurringEntries[recurringEntries.indexOf(ent)].lastRunDate);
final addedEntry = (recurringEntries[recurringEntries.indexOf(ent)]
as WalletSingleEntry)
..date = DateTime.now()
..id = nextId; // copy entry with today's date and unique ID
entries.add(
addedEntry,
); // add it to entries
var id = 1;
logger.d("Making ID after ${entries.length} entries");
while (entries.where((element) => element.id == id).isNotEmpty) {
id++; // create unique ID
}
logger.d("New ID: $id\nLast entry ID: ${entries.lastOrNull?.id}");
final addedEntry = WalletSingleEntry(
data: recurringEntries[recurringEntries.indexOf(ent)].data,
type: recurringEntries[recurringEntries.indexOf(ent)].type,
date: m,
category: recurringEntries[recurringEntries.indexOf(ent)].category,
id: id,
);
entries.add(addedEntry);
m = DateTime(
(ent.recurType == RecurType.year)
? ent.lastRunDate.year + ent.repeatAfter
: ent.lastRunDate.year,
? recurringEntries[recurringEntries.indexOf(ent)]
.lastRunDate
.year +
ent.repeatAfter
: recurringEntries[recurringEntries.indexOf(ent)]
.lastRunDate
.year,
(ent.recurType == RecurType.month)
? ent.lastRunDate.month + ent.repeatAfter
: ent.lastRunDate.month,
? recurringEntries[recurringEntries.indexOf(ent)]
.lastRunDate
.month +
ent.repeatAfter
: recurringEntries[recurringEntries.indexOf(ent)]
.lastRunDate
.month,
(ent.recurType == RecurType.day)
? ent.lastRunDate.day + ent.repeatAfter
: ent.lastRunDate.day,
); // add tne variable again to check if we aren't missing any entries
? recurringEntries[recurringEntries.indexOf(ent)]
.lastRunDate
.day +
ent.repeatAfter
: recurringEntries[recurringEntries.indexOf(ent)].lastRunDate.day,
); // add the variable again to check if we aren't missing any entries
logger.i(
"Last recurred date is now on ${DateFormat.yMMMMd().format(m)} (${n.isAfter(m)})");
}
WalletManager.saveWallet(this); // save wallet
}
}

View file

@ -3,6 +3,7 @@
import 'dart:async';
import 'dart:math';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
@ -146,7 +147,8 @@ class _HomeViewState extends State<HomeView> {
}
logger.d(
"Created ${selectedWallet!.recurringEntries.length} recurring entries");
"Created ${selectedWallet!.recurringEntries.length} recurring entries",
);
// save and reload
WalletManager.saveWallet(selectedWallet!).then((value) {
@ -372,6 +374,7 @@ class _HomeViewState extends State<HomeView> {
selectedWallet?.entries.removeWhere(
(e) => e.id == element.id,
);
WalletManager.saveWallet(
selectedWallet!,
);
@ -408,10 +411,41 @@ class _HomeViewState extends State<HomeView> {
),
),
title: Text(element.data.name),
subtitle: Text(
NumberFormat.currency(
subtitle: RichText(
text: TextSpan(
children: [
TextSpan(
text: NumberFormat.currency(
symbol: selectedWallet!.currency.symbol,
).format(element.data.amount),
style: TextStyle(
color: (element.type == EntryType.income)
? (MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.green.shade300
: Colors.green.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)
: (MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.red.shade300
: Colors.red.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
),
),
),
TextSpan(
text:
" | ${DateFormat.MMMd(locale).format(element.date)}",
),
],
),
),
),
),