solyanka iz fix for payout page design, ledger wallet now clickable
This commit is contained in:
@@ -3,18 +3,24 @@ import 'dart:collection';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/operation.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/models/payment/source_type.dart';
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
import 'package:pshared/provider/payment/payments.dart';
|
||||
|
||||
import 'package:pweb/models/state/load_more_state.dart';
|
||||
import 'package:pweb/utils/report/operations/operations.dart';
|
||||
import 'package:pweb/utils/report/payment_mapper.dart';
|
||||
import 'package:pweb/utils/report/source_filter.dart';
|
||||
|
||||
|
||||
class ReportOperationsController extends ChangeNotifier {
|
||||
PaymentsProvider? _payments;
|
||||
PaymentSourceType? _sourceType;
|
||||
Set<String> _sourceRefs = const <String>{};
|
||||
DateTimeRange? _selectedRange;
|
||||
final Set<OperationStatus> _selectedStatuses = {};
|
||||
List<Payment> _paymentItems = const [];
|
||||
List<OperationItem> _operations = const [];
|
||||
List<OperationItem> _filtered = const [];
|
||||
|
||||
@@ -36,10 +42,20 @@ class ReportOperationsController extends ChangeNotifier {
|
||||
return LoadMoreState.hidden;
|
||||
}
|
||||
|
||||
void update(PaymentsProvider provider) {
|
||||
void update(
|
||||
PaymentsProvider provider, {
|
||||
PaymentSourceType? sourceType,
|
||||
String? sourceRef,
|
||||
List<String>? sourceRefs,
|
||||
}) {
|
||||
if (!identical(_payments, provider)) {
|
||||
_payments = provider;
|
||||
}
|
||||
_sourceType = sourceType;
|
||||
final effectiveSourceRefs =
|
||||
sourceRefs ??
|
||||
(sourceRef == null ? const <String>[] : <String>[sourceRef]);
|
||||
_sourceRefs = _normalizeRefs(effectiveSourceRefs);
|
||||
_rebuildOperations();
|
||||
}
|
||||
|
||||
@@ -74,13 +90,16 @@ class ReportOperationsController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void _rebuildOperations() {
|
||||
final items = _payments?.payments ?? const [];
|
||||
_operations = items.map(mapPaymentToOperation).toList();
|
||||
_paymentItems = _payments?.payments ?? const [];
|
||||
_operations = _paymentItems
|
||||
.where(_matchesCurrentSource)
|
||||
.map(mapPaymentToOperation)
|
||||
.toList();
|
||||
_rebuildFiltered(notify: true);
|
||||
}
|
||||
|
||||
void _rebuildFiltered({bool notify = true}) {
|
||||
_filtered = _applyFilters(_operations);
|
||||
_filtered = _applyFilters(sortOperations(_operations));
|
||||
if (notify) {
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -88,13 +107,14 @@ class ReportOperationsController extends ChangeNotifier {
|
||||
|
||||
List<OperationItem> _applyFilters(List<OperationItem> operations) {
|
||||
if (_selectedRange == null && _selectedStatuses.isEmpty) {
|
||||
return sortOperations(operations);
|
||||
return operations;
|
||||
}
|
||||
|
||||
final filtered = operations.where((op) {
|
||||
final statusMatch =
|
||||
_selectedStatuses.isEmpty || _selectedStatuses.contains(op.status);
|
||||
final dateMatch = _selectedRange == null ||
|
||||
final dateMatch =
|
||||
_selectedRange == null ||
|
||||
isUnknownDate(op.date) ||
|
||||
(op.date.isAfter(
|
||||
_selectedRange!.start.subtract(const Duration(seconds: 1)),
|
||||
@@ -105,7 +125,30 @@ class ReportOperationsController extends ChangeNotifier {
|
||||
return statusMatch && dateMatch;
|
||||
}).toList();
|
||||
|
||||
return sortOperations(filtered);
|
||||
return filtered;
|
||||
}
|
||||
|
||||
bool _matchesCurrentSource(Payment payment) {
|
||||
final sourceType = _sourceType;
|
||||
if (sourceType == null || _sourceRefs.isEmpty) return true;
|
||||
for (final sourceRef in _sourceRefs) {
|
||||
if (paymentMatchesSource(
|
||||
payment,
|
||||
sourceType: sourceType,
|
||||
sourceRef: sourceRef,
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<String> _normalizeRefs(List<String> refs) {
|
||||
final normalized = refs
|
||||
.map((value) => value.trim())
|
||||
.where((value) => value.isNotEmpty)
|
||||
.toSet();
|
||||
return normalized;
|
||||
}
|
||||
|
||||
bool _isSameRange(DateTimeRange? left, DateTimeRange? right) {
|
||||
|
||||
@@ -71,16 +71,24 @@ class WalletTransactionsController extends ChangeNotifier {
|
||||
|
||||
void _rebuildFiltered({bool notify = true}) {
|
||||
final source = _provider?.transactions ?? const <WalletTransaction>[];
|
||||
final activeWalletId = _provider?.walletId;
|
||||
_filteredTransactions = source.where((tx) {
|
||||
final walletMatch =
|
||||
activeWalletId == null || tx.walletId == activeWalletId;
|
||||
final statusMatch =
|
||||
_selectedStatuses.isEmpty || _selectedStatuses.contains(tx.status);
|
||||
final typeMatch =
|
||||
_selectedTypes.isEmpty || _selectedTypes.contains(tx.type);
|
||||
final dateMatch = _dateRange == null ||
|
||||
(tx.date.isAfter(_dateRange!.start.subtract(const Duration(seconds: 1))) &&
|
||||
tx.date.isBefore(_dateRange!.end.add(const Duration(seconds: 1))));
|
||||
final dateMatch =
|
||||
_dateRange == null ||
|
||||
(tx.date.isAfter(
|
||||
_dateRange!.start.subtract(const Duration(seconds: 1)),
|
||||
) &&
|
||||
tx.date.isBefore(
|
||||
_dateRange!.end.add(const Duration(seconds: 1)),
|
||||
));
|
||||
|
||||
return statusMatch && typeMatch && dateMatch;
|
||||
return walletMatch && statusMatch && typeMatch && dateMatch;
|
||||
}).toList();
|
||||
|
||||
if (notify) notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user