Skip to content

Commit

Permalink
som update
Browse files Browse the repository at this point in the history
  • Loading branch information
Somsomza committed Dec 26, 2023
1 parent 80de341 commit e240e54
Show file tree
Hide file tree
Showing 10 changed files with 787 additions and 787 deletions.
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
#org.gradle.java.home = /Library/Java/JavaVirtualMachines/jdk-18.0.2.1.jdk/Contents/Home
org.gradle.java.home = C:/Program Files/Java/jdk-18.0.2.1

43 changes: 21 additions & 22 deletions lib/backend/category.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/widgets.dart';
import 'package:graphic/graphic.dart';
import 'wyrm/database.dart';
import 'package:smartspend/backend/payments.dart';

Expand Down Expand Up @@ -34,11 +33,13 @@ class Category {

static List<DateTime> getWeekDates() {
final List<DateTime> res = [];
DateTime mostRecentWeekday(DateTime date, int weekday) => //code from stackoverflow, thanks Irn
DateTime(date.year, date.month, date.day - (date.weekday - weekday) % 7);
DateTime mostRecentWeekday(
DateTime date, int weekday) => //code from stackoverflow, thanks Irn
DateTime(
date.year, date.month, date.day - (date.weekday - weekday) % 7);
DateTime monday = mostRecentWeekday(DateTime.now(), 1);
res.add(monday);
for(int i = 1; i < 7; i++){
for (int i = 1; i < 7; i++) {
res.add(monday.add(Duration(days: i)));
}
return res;
Expand All @@ -47,18 +48,20 @@ class Category {
Future<Map<String, num>> getWeekSpending() async {
final Map<String, num> res = {};
final List<DateTime> thisWeekDates = getWeekDates();
List<List<Payment>> paymentsPerDay = await database.getPaymentsByDate(thisWeekDates, categoryID);
List<List<Payment>> paymentsPerDay =
await database.getPaymentsByDate(thisWeekDates, categoryID);

for(int i = 0; i < paymentsPerDay.length; i++){
for (int i = 0; i < paymentsPerDay.length; i++) {
String date;
try {
date = DateTime.parse(paymentsPerDay[i].first.paymentDate).day.toString();
date =
DateTime.parse(paymentsPerDay[i].first.paymentDate).day.toString();
} catch (e) {
date = thisWeekDates[i].day.toString();
}

num amountSpent = 0;
for(int j = 0; j < paymentsPerDay[i].length; j++){
for (int j = 0; j < paymentsPerDay[i].length; j++) {
amountSpent += paymentsPerDay[i][j].paymentAmount;
}
res[date] = amountSpent;
Expand All @@ -70,24 +73,20 @@ class Category {
currentSpending += amount;

Payment expense = Payment(
paymentID: DateTime.now().millisecondsSinceEpoch.toInt(),
categoryID: categoryID,
paymentDate: date,
paymentAmount: amount,
paymentID: DateTime.now().millisecondsSinceEpoch.toInt(),
categoryID: categoryID,
paymentDate: date,
paymentAmount: amount,
);

await database.insertToTable(
expense,
'payment'
);
await database.insertToTable(expense, 'payment');

await database.updateEntryInTable(
'category',
'categoryID',
categoryID,
this,
'category',
'categoryID',
categoryID,
this,
);

}

@override
Expand All @@ -97,4 +96,4 @@ class Category {
"Category Name: $categoryName, Spending Limit: $spendingLimit, "
"Current Spending: $currentSpending}";
}
}
}
38 changes: 18 additions & 20 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:smartspend/backend/category.dart';
void main() async {
Wyrm database = Wyrm();
User client = await initClient(database);
List<Category> categories = await initCategories(database, client);
//List<Category> categories = await initCategories(database, client);
goFullscreen();
runApp(MyApp(client: client));
}
Expand All @@ -20,20 +20,18 @@ void goFullscreen() async {
);
while (true) {
await SystemChrome.setSystemUIChangeCallback(
(systemOverlaysAreVisible) async {
await Future.delayed(Duration(seconds: 5));
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersive,
overlays: [SystemUiOverlay.top],
);
}
);
(systemOverlaysAreVisible) async {
await Future.delayed(Duration(seconds: 5));
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersive,
overlays: [SystemUiOverlay.top],
);
});
}
}


class MyApp extends StatelessWidget {
User client;
final User client;

MyApp({super.key, required this.client});

Expand All @@ -59,20 +57,20 @@ Future<User> initClient(Wyrm database) async {
client = (await database.users()).first;
} catch (e) {
client = User(
userID: 1,
name: "",
passcode: "",
birthDate: "",
newUser: 0,
monthlyIncome: 30000);
userID: 1,
name: "",
passcode: "",
birthDate: "",
newUser: 0,
monthlyIncome: 30000);
database.insertToTable(client, 'user');
}
return client;
}

Future<List<Category>> initCategories(Wyrm database, User client) async {
List<Category> categories = await database.categories();
if (categories.length < 4){
if (categories.length < 4) {
categories = [
Category(
userID: client.userID,
Expand Down Expand Up @@ -107,9 +105,9 @@ Future<List<Category>> initCategories(Wyrm database, User client) async {
currentSpending: 0,
)
];
for (int i = 0; i < categories.length; i++){
for (int i = 0; i < categories.length; i++) {
await database.insertToTable(categories[i], 'category');
}
}
return categories;
}
}
Loading

0 comments on commit e240e54

Please sign in to comment.