fixed ledger account listing + quotation listing
This commit is contained in:
@@ -2,7 +2,6 @@ import 'package:pshared/models/currency.dart';
|
||||
import 'package:pshared/models/payment/chain_network.dart';
|
||||
|
||||
|
||||
const String orgOwnerRef = '';
|
||||
const Currency managedCurrencyDefault = Currency.usdt;
|
||||
const Currency ledgerCurrencyDefault = Currency.rub;
|
||||
const ChainNetwork managedNetworkDefault = ChainNetwork.tronMainnet;
|
||||
|
||||
@@ -11,7 +11,6 @@ import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/wallet/chain_asset.dart';
|
||||
import 'package:pshared/provider/accounts/employees.dart';
|
||||
import 'package:pshared/provider/ledger.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
import 'package:pshared/provider/payment/wallets.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
@@ -42,7 +41,7 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
final _descriptionController = TextEditingController();
|
||||
|
||||
PaymentType _assetType = PaymentType.managedWallet;
|
||||
String _ownerRef = orgOwnerRef;
|
||||
String? _ownerRef;
|
||||
Currency _managedCurrency = managedCurrencyDefault;
|
||||
ChainNetwork _network = managedNetworkDefault;
|
||||
Currency _ledgerCurrency = ledgerCurrencyDefault;
|
||||
@@ -59,10 +58,7 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
setState(() => _assetType = value);
|
||||
}
|
||||
|
||||
void _setOwnerRef(String? value) {
|
||||
if (value == null) return;
|
||||
setState(() => _ownerRef = value);
|
||||
}
|
||||
void _setOwnerRef(String? value) => setState(() => _ownerRef = value);
|
||||
|
||||
void _setManagedCurrency(Currency? value) {
|
||||
if (value == null) return;
|
||||
@@ -87,13 +83,17 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
final name = _nameController.text.trim();
|
||||
final description = _descriptionController.text.trim();
|
||||
final employees = context.read<EmployeesProvider>().employees;
|
||||
final effectiveOwnerRef = employees.any((employee) => employee.id == _ownerRef) ? _ownerRef : orgOwnerRef;
|
||||
final isOrgWallet = effectiveOwnerRef == orgOwnerRef;
|
||||
final owner = isOrgWallet ? null : employees.firstWhereOrNull((employee) => employee.id == effectiveOwnerRef);
|
||||
final effectiveOwnerRef = employees.any((employee) => employee.id == _ownerRef)
|
||||
? _ownerRef
|
||||
: null;
|
||||
final isOrgWallet = effectiveOwnerRef == null;
|
||||
final owner = isOrgWallet
|
||||
? null
|
||||
: employees.firstWhereOrNull((employee) => employee.id == effectiveOwnerRef);
|
||||
|
||||
final errorMessage = _assetType == PaymentType.managedWallet
|
||||
? l10n.errorCreateManagedWallet
|
||||
: l10n.errorCreateLedgerAccount;
|
||||
? l10n.errorCreateManagedWallet
|
||||
: l10n.errorCreateLedgerAccount;
|
||||
|
||||
final result = await executeActionWithNotification<bool>(
|
||||
context: context,
|
||||
@@ -124,18 +124,18 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final orgName = context.select<OrganizationsProvider, String?>(
|
||||
(provider) => provider.isOrganizationSet ? provider.current.name : null,
|
||||
);
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final maxWidth = (screenWidth - 48).clamp(0.0, double.infinity);
|
||||
final dialogWidth = maxWidth >= 360.0 ? (maxWidth > 520.0 ? 520.0 : maxWidth) : maxWidth;
|
||||
final employeesProvider = context.watch<EmployeesProvider>();
|
||||
final employees = employeesProvider.employees;
|
||||
final isSaving = context.watch<WalletsProvider>().isLoading ||
|
||||
context.watch<LedgerAccountsProvider>().isLoading;
|
||||
|
||||
final ownerItems = <DropdownMenuItem<String>>[
|
||||
final ownerItems = <DropdownMenuItem<String?>>[
|
||||
DropdownMenuItem(
|
||||
value: orgOwnerRef,
|
||||
child: Text(orgName ?? l10n.companyName),
|
||||
value: null,
|
||||
child: Text(l10n.organizationOwned),
|
||||
),
|
||||
...employees.map((employee) => DropdownMenuItem(
|
||||
value: employee.id,
|
||||
@@ -143,29 +143,30 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
)),
|
||||
];
|
||||
|
||||
final resolvedOwnerRef = ownerItems.any((item) => item.value == _ownerRef)
|
||||
? _ownerRef
|
||||
: orgOwnerRef;
|
||||
final resolvedOwnerRef = ownerItems.any((item) => item.value == _ownerRef) ? _ownerRef : null;
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(l10n.actionAddNew),
|
||||
content: AddBalanceForm(
|
||||
formKey: _formKey,
|
||||
assetType: _assetType,
|
||||
isSaving: isSaving,
|
||||
ownerItems: ownerItems,
|
||||
ownerValue: resolvedOwnerRef,
|
||||
onAssetTypeChanged: _setAssetType,
|
||||
onOwnerChanged: _setOwnerRef,
|
||||
nameController: _nameController,
|
||||
descriptionController: _descriptionController,
|
||||
managedCurrency: _managedCurrency,
|
||||
network: _network,
|
||||
ledgerCurrency: _ledgerCurrency,
|
||||
onManagedCurrencyChanged: _setManagedCurrency,
|
||||
onNetworkChanged: _setNetwork,
|
||||
onLedgerCurrencyChanged: _setLedgerCurrency,
|
||||
showEmployeesLoading: employeesProvider.isLoading,
|
||||
content: SizedBox(
|
||||
width: dialogWidth,
|
||||
child: AddBalanceForm(
|
||||
formKey: _formKey,
|
||||
assetType: _assetType,
|
||||
isSaving: isSaving,
|
||||
ownerItems: ownerItems,
|
||||
ownerValue: resolvedOwnerRef,
|
||||
onAssetTypeChanged: _setAssetType,
|
||||
onOwnerChanged: _setOwnerRef,
|
||||
nameController: _nameController,
|
||||
descriptionController: _descriptionController,
|
||||
managedCurrency: _managedCurrency,
|
||||
network: _network,
|
||||
ledgerCurrency: _ledgerCurrency,
|
||||
onManagedCurrencyChanged: _setManagedCurrency,
|
||||
onNetworkChanged: _setNetwork,
|
||||
onLedgerCurrencyChanged: _setLedgerCurrency,
|
||||
showEmployeesLoading: employeesProvider.isLoading,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
DialogCancelButton(
|
||||
|
||||
@@ -17,8 +17,8 @@ class AddBalanceForm extends StatelessWidget {
|
||||
final GlobalKey<FormState> formKey;
|
||||
final PaymentType assetType;
|
||||
final bool isSaving;
|
||||
final List<DropdownMenuItem<String>> ownerItems;
|
||||
final String ownerValue;
|
||||
final List<DropdownMenuItem<String?>> ownerItems;
|
||||
final String? ownerValue;
|
||||
final ValueChanged<PaymentType?> onAssetTypeChanged;
|
||||
final ValueChanged<String?> onOwnerChanged;
|
||||
final TextEditingController nameController;
|
||||
|
||||
@@ -6,8 +6,8 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class OwnerField extends StatelessWidget {
|
||||
final String value;
|
||||
final List<DropdownMenuItem<String>> items;
|
||||
final String? value;
|
||||
final List<DropdownMenuItem<String?>> items;
|
||||
final ValueChanged<String?>? onChanged;
|
||||
|
||||
const OwnerField({
|
||||
@@ -18,9 +18,9 @@ class OwnerField extends StatelessWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => DropdownButtonFormField<String>(
|
||||
initialValue: value,
|
||||
decoration: getInputDecoration(context, AppLocalizations.of(context)!.colDataOwner, true),
|
||||
Widget build(BuildContext context) => DropdownButtonFormField<String?>(
|
||||
value: value,
|
||||
decoration: getInputDecoration(context, AppLocalizations.of(context)!.assetOwner, true),
|
||||
items: items,
|
||||
onChanged: onChanged,
|
||||
);
|
||||
|
||||
@@ -2,19 +2,19 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/wallets.dart';
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
|
||||
class BalanceAmount extends StatelessWidget {
|
||||
final Wallet wallet;
|
||||
final VoidCallback onToggleVisibility;
|
||||
final VoidCallback onToggleMask;
|
||||
|
||||
const BalanceAmount({
|
||||
super.key,
|
||||
required this.wallet,
|
||||
required this.onToggleVisibility,
|
||||
required this.onToggleMask,
|
||||
});
|
||||
|
||||
static const double _iconSpacing = 12.0;
|
||||
@@ -25,13 +25,13 @@ class BalanceAmount extends StatelessWidget {
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final currencyBalance = currencyCodeToSymbol(wallet.currency);
|
||||
final wallets = context.read<WalletsController>();
|
||||
final wallets = context.watch<WalletsController>();
|
||||
final isMasked = wallets.isBalanceMasked(wallet.id);
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Text(
|
||||
|
||||
wallets.isHidden(wallet.id) ? '•••• $currencyBalance' : '${amountToString(wallet.balance)} $currencyBalance',
|
||||
isMasked ? '•••• $currencyBalance' : '${amountToString(wallet.balance)} $currencyBalance',
|
||||
style: textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.onSurface,
|
||||
@@ -39,9 +39,9 @@ class BalanceAmount extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: _iconSpacing),
|
||||
GestureDetector(
|
||||
onTap: onToggleVisibility,
|
||||
onTap: onToggleMask,
|
||||
child: Icon(
|
||||
wallets.isHidden(wallet.id) ? Icons.visibility_off : Icons.visibility,
|
||||
isMasked ? Icons.visibility_off : Icons.visibility,
|
||||
size: _iconSize,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
@@ -49,4 +49,4 @@ class BalanceAmount extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/wallets.dart';
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/provider/ledger.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/wallets.dart';
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/models/payment/chain_network.dart';
|
||||
import 'package:pshared/utils/l10n/chain.dart';
|
||||
@@ -56,8 +56,8 @@ class WalletCard extends StatelessWidget {
|
||||
children: [
|
||||
BalanceAmount(
|
||||
wallet: wallet,
|
||||
onToggleVisibility: () {
|
||||
context.read<WalletsController>().toggleVisibility(wallet.id);
|
||||
onToggleMask: () {
|
||||
context.read<WalletsController>().toggleBalanceMask(wallet.id);
|
||||
},
|
||||
),
|
||||
WalletBalanceRefreshButton(
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/balance_mask/ledger_accounts.dart';
|
||||
import 'package:pshared/models/ledger/account.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/config.dart';
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/header.dart';
|
||||
import 'package:pweb/widgets/refresh_balance/ledger.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class LedgerAccountCard extends StatelessWidget {
|
||||
final LedgerAccount account;
|
||||
@@ -38,6 +42,20 @@ class LedgerAccountCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
String _formatMaskedBalance() {
|
||||
final currency = account.currency.trim();
|
||||
if (currency.isEmpty) return '••••';
|
||||
try {
|
||||
final symbol = currencyCodeToSymbol(currencyStringToCode(currency));
|
||||
if (symbol.trim().isEmpty) {
|
||||
return '•••• $currency';
|
||||
}
|
||||
return '•••• $symbol';
|
||||
} catch (_) {
|
||||
return '•••• $currency';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
@@ -64,12 +82,30 @@ class LedgerAccountCard extends StatelessWidget {
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
_formatBalance(),
|
||||
style: textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
Consumer<LedgerBalanceMaskController>(
|
||||
builder: (context, controller, _) {
|
||||
final isMasked = controller.isBalanceMasked(account.ledgerAccountRef);
|
||||
return Row(
|
||||
children: [
|
||||
Text(
|
||||
isMasked ? _formatMaskedBalance() : _formatBalance(),
|
||||
style: textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: () => controller.toggleBalanceMask(account.ledgerAccountRef),
|
||||
child: Icon(
|
||||
isMasked ? Icons.visibility_off : Icons.visibility,
|
||||
size: 24,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
LedgerBalanceRefreshButton(
|
||||
|
||||
Reference in New Issue
Block a user