fix tx listing
This commit is contained in:
@@ -322,26 +322,30 @@ class TxMetaController extends ChangeNotifier {
|
||||
BankTransaction prototype,
|
||||
List<BankTransaction> all, {
|
||||
String? pattern,
|
||||
SimilarMatchCriteria? criteria,
|
||||
}) {
|
||||
final needle = (pattern ?? prototype.merchantKey).trim();
|
||||
if (needle.isEmpty) return 1;
|
||||
var count = 0;
|
||||
for (final tx in all) {
|
||||
if (descriptionMatchesPattern(tx.description, needle)) count++;
|
||||
}
|
||||
return count == 0 ? 1 : count;
|
||||
return similarTo(
|
||||
prototype,
|
||||
all,
|
||||
pattern: pattern,
|
||||
criteria: criteria,
|
||||
).length;
|
||||
}
|
||||
|
||||
List<BankTransaction> similarTo(
|
||||
BankTransaction prototype,
|
||||
List<BankTransaction> all, {
|
||||
String? pattern,
|
||||
SimilarMatchCriteria? criteria,
|
||||
}) {
|
||||
final needle = (pattern ?? prototype.merchantKey).trim();
|
||||
if (needle.isEmpty) return [prototype];
|
||||
final query = criteria ??
|
||||
SimilarMatchCriteria(
|
||||
pattern: (pattern ?? prototype.merchantKey).trim(),
|
||||
);
|
||||
if (query.pattern.trim().isEmpty) return [prototype];
|
||||
final matches = [
|
||||
for (final tx in all)
|
||||
if (descriptionMatchesPattern(tx.description, needle)) tx,
|
||||
if (txMatchesSimilarCriteria(tx, query)) tx,
|
||||
];
|
||||
return matches.isEmpty ? [prototype] : matches;
|
||||
}
|
||||
@@ -432,6 +436,46 @@ class TxMetaController extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
/// Replace labels on every transaction in [txs] (per-id overrides).
|
||||
Future<void> setLabelsForMany(
|
||||
List<BankTransaction> txs,
|
||||
List<String> labelIds,
|
||||
) async {
|
||||
if (txs.isEmpty) return;
|
||||
|
||||
final expanded = expandWithAncestors([
|
||||
for (final id in labelIds)
|
||||
if (id.isNotEmpty && id != kUncategorizedFilterId) id,
|
||||
]);
|
||||
final unique = <String>[];
|
||||
for (final id in expanded) {
|
||||
if (!unique.contains(id)) unique.add(id);
|
||||
}
|
||||
|
||||
final nextById = Map<String, TxMeta>.of(_byId);
|
||||
for (final tx in txs) {
|
||||
final stored = nextById[tx.id];
|
||||
final current = stored ?? metaFor(tx);
|
||||
nextById[tx.id] = unique.isEmpty
|
||||
? current.copyWith(clearLabels: true)
|
||||
: current.copyWith(labelIds: unique);
|
||||
}
|
||||
_byId = nextById;
|
||||
_schedulePersist();
|
||||
}
|
||||
|
||||
/// Label ids shared by every transaction in [txs].
|
||||
Set<String> commonLabelIds(List<BankTransaction> txs) {
|
||||
if (txs.isEmpty) return {};
|
||||
Set<String>? common;
|
||||
for (final tx in txs) {
|
||||
final ids = metaFor(tx).labelIds.toSet();
|
||||
common = common == null ? ids : common.intersection(ids);
|
||||
if (common.isEmpty) break;
|
||||
}
|
||||
return common ?? {};
|
||||
}
|
||||
|
||||
Future<TxLabel> createLabel(String name, {String? parentId}) async {
|
||||
final trimmed = name.trim();
|
||||
if (trimmed.isEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user