feat: добавить утилиты для тегов и тестовых транзакций
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import '../models/tag.dart';
|
||||
|
||||
/// Утилиты для работы с тегами
|
||||
class TagUtils {
|
||||
/// Возвращает список предопределенных тегов
|
||||
static List<Tag> getDefaultTags() {
|
||||
return [
|
||||
Tag(
|
||||
id: 'tag_important',
|
||||
name: 'Важное',
|
||||
),
|
||||
Tag(
|
||||
id: 'tag_work',
|
||||
name: 'Работа',
|
||||
),
|
||||
Tag(
|
||||
id: 'tag_family',
|
||||
name: 'Семья',
|
||||
),
|
||||
Tag(
|
||||
id: 'tag_friends',
|
||||
name: 'Друзья',
|
||||
),
|
||||
Tag(
|
||||
id: 'tag_holiday',
|
||||
name: 'Отпуск',
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import '../models/transaction_record.dart';
|
||||
import '../models/category.dart';
|
||||
import '../models/tag.dart';
|
||||
import 'category_utils.dart';
|
||||
import 'tag_utils.dart';
|
||||
|
||||
/// Утилиты для работы с тестовыми транзакциями
|
||||
class TransactionUtils {
|
||||
/// Возвращает список тестовых транзакций
|
||||
static List<TransactionRecord> getSampleTransactions() {
|
||||
final categories = CategoryUtils.getDefaultCategories();
|
||||
final tags = TagUtils.getDefaultTags();
|
||||
|
||||
return [
|
||||
// Доходы
|
||||
TransactionRecord(
|
||||
category: categories.firstWhere((c) => c.id == 'income_salary'),
|
||||
tag: tags.firstWhere((t) => t.id == 'tag_work'),
|
||||
amount: 100000,
|
||||
dateTime: DateTime.now().subtract(const Duration(days: 5)),
|
||||
vendor: 'ООО "Рога и копыта"',
|
||||
currency: 'RUB',
|
||||
),
|
||||
TransactionRecord(
|
||||
category: categories.firstWhere((c) => c.id == 'income_freelance'),
|
||||
tag: tags.firstWhere((t) => t.id == 'tag_work'),
|
||||
amount: 25000,
|
||||
dateTime: DateTime.now().subtract(const Duration(days: 2)),
|
||||
vendor: 'Фриланс проект',
|
||||
currency: 'RUB',
|
||||
),
|
||||
|
||||
// Расходы
|
||||
TransactionRecord(
|
||||
category: categories.firstWhere((c) => c.id == 'expense_food'),
|
||||
tag: tags.firstWhere((t) => t.id == 'tag_family'),
|
||||
amount: -3500,
|
||||
dateTime: DateTime.now().subtract(const Duration(days: 1)),
|
||||
vendor: 'Пятерочка',
|
||||
currency: 'RUB',
|
||||
),
|
||||
TransactionRecord(
|
||||
category: categories.firstWhere((c) => c.id == 'expense_transport'),
|
||||
amount: -500,
|
||||
dateTime: DateTime.now().subtract(const Duration(hours: 12)),
|
||||
vendor: 'Яндекс Такси',
|
||||
currency: 'RUB',
|
||||
),
|
||||
TransactionRecord(
|
||||
category: categories.firstWhere((c) => c.id == 'expense_entertainment'),
|
||||
tag: tags.firstWhere((t) => t.id == 'tag_friends'),
|
||||
amount: -2000,
|
||||
dateTime: DateTime.now().subtract(const Duration(hours: 6)),
|
||||
vendor: 'Кинотеатр',
|
||||
currency: 'RUB',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// Возвращает только доходы
|
||||
static List<TransactionRecord> getIncomeTransactions() {
|
||||
return getSampleTransactions().where((t) => t.isIncome).toList();
|
||||
}
|
||||
|
||||
/// Возвращает только расходы
|
||||
static List<TransactionRecord> getExpenseTransactions() {
|
||||
return getSampleTransactions().where((t) => !t.isIncome).toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user