Skip to content

Commit

Permalink
v1.0.19 - Month leads to transactions (#19)
Browse files Browse the repository at this point in the history
* v1.0.19 - Month leads to transactions

* v1.0.19 - Fix DB Import bug

* v1.0.19 - Update Entry Service

* v1.0.19 - Make month clickable

* v1.0.19 - Update App Bar
  • Loading branch information
Donnie committed Jan 21, 2024
1 parent cfac3b3 commit c0fc9e7
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 138 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<a href="https://flutter.dev/" style="text-decoration:none" area-label="flutter">
<img src="https://img.shields.io/badge/Platform-Flutter%203.16.5-blue">
</a>
<a href="https://github.com/Donnie/Finease/releases/tag/v1.0.18" style="text-decoration:none" area-label="flutter">
<img src="https://img.shields.io/badge/Version-1.0.18-orange">
<a href="https://github.com/Donnie/Finease/releases/tag/v1.0.19" style="text-decoration:none" area-label="flutter">
<img src="https://img.shields.io/badge/Version-1.0.19-orange">
</a>
<a href="https://github.com/Donnie/Finease/actions/workflows/android_release.yml" style="text-decoration:none" area-label="flutter">
<img src="https://github.com/Donnie/Finease/actions/workflows/android_release.yml/badge.svg">
Expand Down
42 changes: 35 additions & 7 deletions lib/db/entries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,39 @@ class EntryService {
return null;
}

Future<List<Entry>> getAllEntries() async {
Future<List<Entry>> getAllEntries({
DateTime? startDate,
DateTime? endDate,
}) async {
final dbClient = await _databaseHelper.db;

// Fetch all entries and all accounts in separate calls
final List<Map<String, dynamic>> entriesData =
await dbClient.query('Entries');
final List<Account> allAccounts = await AccountService().getAllAccounts(true);
String whereClause = '';
List<dynamic> whereArguments = [];

// If startDate is provided, add it to the where clause
if (startDate != null) {
whereClause += 'date >= ?';
whereArguments.add(startDate.toIso8601String());
}

// If endDate is provided, add it to the where clause
if (endDate != null) {
if (whereClause.isNotEmpty) {
whereClause += ' AND ';
}
whereClause += 'date <= ?';
whereArguments.add(endDate.toIso8601String());
}

// Fetch all entries according to the provided start and end dates
final List<Map<String, dynamic>> entriesData = await dbClient.query(
'Entries',
where: whereClause.isEmpty ? null : whereClause,
whereArgs: whereArguments.isEmpty ? null : whereArguments,
);

final List<Account> allAccounts =
await AccountService().getAllAccounts(true);

// Create a map for quick account lookup by ID
var accountsMap = {for (var account in allAccounts) account.id: account};
Expand Down Expand Up @@ -105,7 +131,8 @@ class EntryService {
);
}

Future adjustFirstBalance(int toAccountId, int fromAccountId, double balance) async {
Future adjustFirstBalance(
int toAccountId, int fromAccountId, double balance) async {
if (balance == 0) {
return;
}
Expand All @@ -121,7 +148,8 @@ class EntryService {
await dbClient.insert('Entries', entry.toJson());
}

Future adjustFirstForexBalance(int toAccountId, int fromAccountId, double balance) async {
Future adjustFirstForexBalance(
int toAccountId, int fromAccountId, double balance) async {
if (balance == 0) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/export.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export "home/frame/destinations.dart";
export "home/frame/main.dart";
export "home/frame/mobile.dart";
export "home/frame/tablet.dart";
export "home/months/main.dart";
export "home/months/month_card.dart";
export 'home/months/screen/main.dart';
export 'home/months/screen/month_card.dart';
export 'home/summary/main.dart';
export 'home/summary/widgets.dart';
export "intro/intro_big.dart";
Expand Down
11 changes: 10 additions & 1 deletion lib/pages/home/entries/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

class EntriesPage extends StatefulWidget {
final DateTime? startDate;
final DateTime? endDate;
final int? accountID;
const EntriesPage({
super.key,
this.accountID,
this.startDate,
this.endDate,
});

@override
Expand All @@ -25,7 +31,10 @@ class EntriesPageState extends State<EntriesPage> {
}

Future<void> loadEntries() async {
List<Entry> entriesList = await _entryService.getAllEntries();
List<Entry> entriesList = await _entryService.getAllEntries(
startDate: widget.startDate,
endDate: widget.endDate,
);
entriesList.sort((a, b) => (b.date!.compareTo(a.date!)));

List<Entry> mergedEntries = [];
Expand Down
121 changes: 0 additions & 121 deletions lib/pages/home/months/month_card.dart

This file was deleted.

File renamed without changes.
138 changes: 138 additions & 0 deletions lib/pages/home/months/screen/month_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import 'package:finease/db/months.dart';
import 'package:finease/parts/card.dart';
import 'package:finease/routes/routes_name.dart';
import 'package:flutter/material.dart';
import 'package:finease/core/export.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';

DateFormat formatter = DateFormat('MMMM yyyy');

class MonthCards extends StatelessWidget {
final List<Month> months;

const MonthCards({
super.key,
required this.months,
});

@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: months.length,
itemBuilder: (context, index) => MonthCard(
month: months[index],
),
);
}
}

class MonthCard extends StatelessWidget {
const MonthCard({
super.key,
required this.month,
});

final Month month;

@override
Widget build(BuildContext context) {
DateTime startDate = month.date!;
DateTime endDate = DateTime(month.date!.year, month.date!.month + 1, 1)
.subtract(const Duration(seconds: 1));

return InkWell(
onTap: () {
context.pushNamed(
RoutesName.transactionsByDate.name,
extra: {
'startDate': startDate.toIso8601String(),
'endDate': endDate.toIso8601String(),
},
);
},
child: AppCard(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
formatter.format(month.date!),
style: context.titleSmall,
)
],
),
const Divider(),
Row(
children: [
Expanded(
child: MonthWidget(
title: "Net Worth",
content: month.networth!.toStringAsFixed(2),
),
),
const SizedBox(width: 8),
Expanded(
child: MonthWidget(
title: "Effect",
content: month.effect!.toStringAsFixed(2),
),
),
],
),
const SizedBox(height: 6),
Row(
children: [
Expanded(
child: MonthWidget(
title: "Income",
content: month.income!.toStringAsFixed(2),
),
),
const SizedBox(width: 8),
Expanded(
child: MonthWidget(
title: "Expense",
content: month.expense!.toStringAsFixed(2),
),
),
],
),
],
),
),
),
);
}
}

class MonthWidget extends StatelessWidget {
const MonthWidget({
super.key,
required this.title,
required this.content,
});

final String content;
final String title;

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title),
Text(
content,
style: context.titleLarge,
),
],
);
}
}
2 changes: 0 additions & 2 deletions lib/pages/settings/import_db.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:io';
import 'package:finease/core/export.dart';
import 'package:finease/db/db.dart';
import 'package:finease/db/settings.dart';
Expand Down Expand Up @@ -32,7 +31,6 @@ class ImportDatabaseWidgetState extends State<ImportDatabaseWidget> {

bool importSuccessful = await _importDatabase(filePath);
if (importSuccessful) {
await File(filePath).delete();
// ignore: use_build_context_synchronously
context.pop();
widget.onImport();
Expand Down
Loading

0 comments on commit c0fc9e7

Please sign in to comment.