Compare commits
No commits in common. "8e6b574023d53faa3c93dbbf376ddd3c48cd5f57" and "ab9b3e0bf940954af3bc8b3e15e5bb890f9fda8e" have entirely different histories.
8e6b574023
...
ab9b3e0bf9
37
lib/db.dart
37
lib/db.dart
@ -24,45 +24,21 @@ class DatabaseHelper {
|
||||
String path = join(documentsDirectory.path, "com_hyperling_expense.db");
|
||||
return await openDatabase(
|
||||
path,
|
||||
version: 2,
|
||||
version: 1,
|
||||
onCreate: _onCreate,
|
||||
onUpgrade: _onUpgrade,
|
||||
);
|
||||
}
|
||||
|
||||
Future _onCreate(Database db, int version) async {
|
||||
await db.execute("""
|
||||
CREATE TABLE expense
|
||||
( id INTEGER PRIMARY KEY
|
||||
, name TEXT NOT NULL UNIQUE
|
||||
, cost DOUBLE NOT NULL
|
||||
, frequency TEXT NOT NULL
|
||||
, description TEXT
|
||||
)
|
||||
""");
|
||||
}
|
||||
|
||||
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
|
||||
CREATE TABLE expense
|
||||
( id INTEGER PRIMARY KEY
|
||||
, name TEXT NOT NULL UNIQUE
|
||||
, revenue DOUBLE NOT NULL
|
||||
, cost 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
|
||||
@ -105,11 +81,8 @@ class DatabaseHelper {
|
||||
|
||||
Future<bool> checkExpenseNameExists(String name) async {
|
||||
Database db = await instance.db;
|
||||
var expenses = await db.query(
|
||||
"expense",
|
||||
where: "name = ?",
|
||||
whereArgs: [name],
|
||||
);
|
||||
var expenses = await db.query("expense",
|
||||
where: "name = ?", whereArgs: [name],);
|
||||
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,
|
||||
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) {
|
||||
return "${Expense.amountText} must be provided.";
|
||||
}
|
||||
if (double.tryParse(value) == null) {
|
||||
return "${Expense.amountText} must be a valid number.";
|
||||
}
|
||||
if (double.parse(value) < 0) {
|
||||
return "Please use the Income page rather than having negative expenses.";
|
||||
}
|
||||
if (double.parse(value) < 0.01) {
|
||||
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;
|
||||
},
|
||||
onSaved: (value) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user