58 lines
1.5 KiB
Dart
58 lines
1.5 KiB
Dart
// Local
|
|
import '/models/expense.dart';
|
|
import '/models/income.dart';
|
|
import '/models/asset.dart';
|
|
import '/db.dart';
|
|
|
|
/// TODO:
|
|
/// - Test the JSON data to ensure it's formed properly.
|
|
/// - Enable the functions for income and assets once they are implemented.
|
|
/// - Create a method (factory?) to load JSON data and delete/insert the data.
|
|
|
|
class DatabaseBackup {
|
|
List<Expense> expenseTable = [];
|
|
List<Income> incomeTable = [];
|
|
List<Asset> assetTable = [];
|
|
|
|
void loadTables() async {
|
|
expenseTable = await DatabaseHelper.instance.getExpenses();
|
|
//incomeTable = await DatabaseHelper.instance.getIncomes();
|
|
//assetTable = await DatabaseHelper.instance.getAssets();
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
loadTables(); // TODO: Do we somehow need to wait for this to finish?
|
|
return {
|
|
'expense_table': [
|
|
for (Expense e in expenseTable)
|
|
{
|
|
'id': e.id,
|
|
'name': e.name,
|
|
'cost': e.amount,
|
|
'frequency': e.frequency!.title,
|
|
'description': e.description,
|
|
},
|
|
],
|
|
'income_table': [
|
|
for (Income i in incomeTable)
|
|
{
|
|
'id': i.id,
|
|
'name': i.name,
|
|
'revenue': i.amount,
|
|
'frequency': i.frequency!.title,
|
|
'description': i.description,
|
|
},
|
|
],
|
|
'asset_table': [
|
|
for (Asset a in assetTable)
|
|
{
|
|
'id': a.id,
|
|
'name': a.name,
|
|
'amount': a.amount,
|
|
'description': a.description,
|
|
},
|
|
],
|
|
};
|
|
}
|
|
}
|