Compare commits
No commits in common. "8e6b574023d53faa3c93dbbf376ddd3c48cd5f57" and "ab9b3e0bf940954af3bc8b3e15e5bb890f9fda8e" have entirely different histories.
8e6b574023
...
ab9b3e0bf9
33
lib/db.dart
33
lib/db.dart
@ -24,9 +24,8 @@ class DatabaseHelper {
|
|||||||
String path = join(documentsDirectory.path, "com_hyperling_expense.db");
|
String path = join(documentsDirectory.path, "com_hyperling_expense.db");
|
||||||
return await openDatabase(
|
return await openDatabase(
|
||||||
path,
|
path,
|
||||||
version: 2,
|
version: 1,
|
||||||
onCreate: _onCreate,
|
onCreate: _onCreate,
|
||||||
onUpgrade: _onUpgrade,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,29 +41,6 @@ class DatabaseHelper {
|
|||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _onUpgrade(Database db, int previousVersion, int newVersion) async {
|
|
||||||
// Added in DB version 2.
|
|
||||||
if (previousVersion < 2 && newVersion >= 2) {
|
|
||||||
await db.execute("""
|
|
||||||
CREATE TABLE income
|
|
||||||
( id INTEGER PRIMARY KEY
|
|
||||||
, name TEXT NOT NULL UNIQUE
|
|
||||||
, revenue DOUBLE NOT NULL
|
|
||||||
, frequency TEXT NOT NULL
|
|
||||||
, description TEXT
|
|
||||||
)
|
|
||||||
""");
|
|
||||||
await db.execute("""
|
|
||||||
CREATE TABLE asset
|
|
||||||
( id INTEGER PRIMARY KEY
|
|
||||||
, name TEXT NOT NULL UNIQUE
|
|
||||||
, amount DOUBLE NOT NULL
|
|
||||||
, description TEXT
|
|
||||||
)
|
|
||||||
""");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Expense Section
|
/// Expense Section
|
||||||
///
|
///
|
||||||
Future<List<Expense>> getExpenses() async {
|
Future<List<Expense>> getExpenses() async {
|
||||||
@ -105,11 +81,8 @@ class DatabaseHelper {
|
|||||||
|
|
||||||
Future<bool> checkExpenseNameExists(String name) async {
|
Future<bool> checkExpenseNameExists(String name) async {
|
||||||
Database db = await instance.db;
|
Database db = await instance.db;
|
||||||
var expenses = await db.query(
|
var expenses = await db.query("expense",
|
||||||
"expense",
|
where: "name = ?", whereArgs: [name],);
|
||||||
where: "name = ?",
|
|
||||||
whereArgs: [name],
|
|
||||||
);
|
|
||||||
return expenses.isNotEmpty;
|
return expenses.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
import '/models/tracked_type.dart';
|
|
||||||
|
|
||||||
class Asset extends TrackedType {
|
|
||||||
static String amountText = "Amount";
|
|
||||||
|
|
||||||
Asset({
|
|
||||||
super.id,
|
|
||||||
required super.name,
|
|
||||||
required super.amount,
|
|
||||||
required super.description,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory Asset.fromMap(Map<String, dynamic> json) => Asset(
|
|
||||||
id: json['id'],
|
|
||||||
name: json['name'],
|
|
||||||
amount: json['amount'],
|
|
||||||
description: json['description'],
|
|
||||||
);
|
|
||||||
}
|
|
@ -21,15 +21,4 @@ class Expense extends RecurringTrackedType {
|
|||||||
.first,
|
.first,
|
||||||
description: json['description'],
|
description: json['description'],
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
|
||||||
Map<String, dynamic> toMap() {
|
|
||||||
return {
|
|
||||||
'id': id,
|
|
||||||
'name': name,
|
|
||||||
'cost': amount,
|
|
||||||
'frequency': frequency.title,
|
|
||||||
'description': description,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import '/models/recurring_tracked_type.dart';
|
|
||||||
import '/models/frequency.dart';
|
|
||||||
|
|
||||||
class Income extends RecurringTrackedType {
|
|
||||||
static String amountText = "Revenue";
|
|
||||||
|
|
||||||
Income({
|
|
||||||
super.id,
|
|
||||||
required super.name,
|
|
||||||
required super.amount,
|
|
||||||
required super.frequency,
|
|
||||||
required super.description,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory Income.fromMap(Map<String, dynamic> json) => Income(
|
|
||||||
id: json['id'],
|
|
||||||
name: json['name'],
|
|
||||||
amount: json['revenue'],
|
|
||||||
frequency: Frequency.values
|
|
||||||
.where((freq) => freq.title == json['frequency'])
|
|
||||||
.first,
|
|
||||||
description: json['description'],
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Map<String, dynamic> toMap() {
|
|
||||||
return {
|
|
||||||
'id': id,
|
|
||||||
'name': name,
|
|
||||||
'revenue': amount,
|
|
||||||
'frequency': frequency.title,
|
|
||||||
'description': description,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -289,15 +289,15 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
|||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return "${Expense.amountText} must be provided.";
|
return "${Expense.amountText} must be provided.";
|
||||||
}
|
}
|
||||||
if (double.tryParse(value) == null) {
|
|
||||||
return "${Expense.amountText} must be a valid number.";
|
|
||||||
}
|
|
||||||
if (double.parse(value) < 0) {
|
if (double.parse(value) < 0) {
|
||||||
return "Please use the Income page rather than having negative expenses.";
|
return "Please use the Income page rather than having negative expenses.";
|
||||||
}
|
}
|
||||||
if (double.parse(value) < 0.01) {
|
if (double.parse(value) < 0.01) {
|
||||||
return "${Expense.amountText} must be one hundreth (0.01) or higher.";
|
return "${Expense.amountText} must be one hundreth (0.01) or higher.";
|
||||||
}
|
}
|
||||||
|
if (double.tryParse(value) == null) {
|
||||||
|
return "${Expense.amountText} must be a valid number.";
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
onSaved: (value) {
|
onSaved: (value) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user