fixed ledger account listing + quotation listing

This commit is contained in:
Stephan D
2026-01-23 02:48:10 +01:00
parent 218c4e20b3
commit 41f653775f
60 changed files with 469 additions and 283 deletions

View File

@@ -0,0 +1,106 @@
import 'package:flutter/foundation.dart';
import 'package:collection/collection.dart';
import 'package:pshared/models/payment/wallet.dart';
import 'package:pshared/provider/payment/wallets.dart';
class WalletsController with ChangeNotifier {
late WalletsProvider _wallets;
String? _orgRef;
/// UI-only: wallet refs with masked balances
final Set<String> _maskedBalanceWalletRefs = <String>{};
Set<String> _knownWalletRefs = <String>{};
String? _selectedWalletRef;
bool get isLoading => _wallets.isLoading;
Exception? get error => _wallets.error;
void update(WalletsProvider wallets) {
_wallets = wallets;
final nextOrgRef = wallets.organizationRef;
final orgChanged = nextOrgRef != _orgRef;
if (orgChanged) {
_orgRef = nextOrgRef;
_maskedBalanceWalletRefs.clear();
_knownWalletRefs = <String>{};
_selectedWalletRef = null;
}
// Remove ids that no longer exist
final ids = wallets.wallets.map((w) => w.id).toSet();
_maskedBalanceWalletRefs.removeWhere((id) => !ids.contains(id));
final newIds = ids.difference(_knownWalletRefs);
if (newIds.isNotEmpty) {
_maskedBalanceWalletRefs.addAll(newIds);
}
_knownWalletRefs = ids;
_selectedWalletRef = _resolveSelectedId(
currentRef: _selectedWalletRef,
wallets: wallets.wallets,
);
notifyListeners();
}
List<Wallet> get wallets => _wallets.wallets;
bool isBalanceMasked(String walletRef) => _maskedBalanceWalletRefs.contains(walletRef);
bool isBalanceVisible(String walletRef) => !isBalanceMasked(walletRef);
List<Wallet> get unmaskedWallets =>
wallets.where((w) => !_maskedBalanceWalletRefs.contains(w.id)).toList(growable: false);
Wallet? get selectedWallet {
final id = _selectedWalletRef;
if (id == null) return null;
return wallets.firstWhereOrNull((w) => w.id == id);
}
String? get selectedWalletRef => _selectedWalletRef;
void selectWallet(Wallet wallet) => selectWalletByRef(wallet.id);
void selectWalletByRef(String walletRef) {
if (_selectedWalletRef == walletRef) return;
_selectedWalletRef = walletRef;
notifyListeners();
}
/// Toggle wallet balance masking
void toggleBalanceMask(String walletRef) {
final existed = _maskedBalanceWalletRefs.remove(walletRef);
if (!existed) _maskedBalanceWalletRefs.add(walletRef);
notifyListeners();
}
/// Unmask balances for all wallets (bulk action)
void unmaskAllBalances() {
_maskedBalanceWalletRefs.clear();
notifyListeners();
}
String? _resolveSelectedId({
required String? currentRef,
required List<Wallet> wallets,
}) {
if (wallets.isEmpty) return null;
// Keep current selection if it still exists
if (currentRef != null && wallets.any((w) => w.id == currentRef)) {
return currentRef;
}
// Fallback to the first wallet
return wallets.first.id;
}
}