36c7ad8b43
Deploy Client / build-client-web (push) Successful in 38s
Deploy Client / build-windows (push) Successful in 1m52s
Deploy Client / build-macos (push) Successful in 1m55s
Deploy Client / build-android (push) Successful in 1m0s
Deploy Client / build-ios (push) Successful in 2m47s
Deploy Client / release-deploy-client (push) Successful in 1m21s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
116 lines
2.9 KiB
Dart
116 lines
2.9 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../core/api/api_client.dart';
|
|
import '../core/auth/auth_state.dart';
|
|
import '../core/config/app_constants.dart';
|
|
import '../core/models/page_result.dart';
|
|
import '../models/stock_out.dart';
|
|
import '../repositories/stock_out_repository.dart';
|
|
import 'connectivity_provider.dart';
|
|
import 'inventory_provider.dart';
|
|
|
|
final stockOutRepositoryProvider = Provider<StockOutRepository>((ref) {
|
|
return StockOutRepository(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final stockOutListProvider =
|
|
AsyncNotifierProvider<StockOutListNotifier, PageResult<StockOutOrder>>(
|
|
StockOutListNotifier.new,
|
|
);
|
|
|
|
class StockOutListNotifier extends AsyncNotifier<PageResult<StockOutOrder>> {
|
|
int _page = 1;
|
|
int _pageSize = AppConstants.defaultPageSize;
|
|
String _status = '';
|
|
String? _startDate;
|
|
String? _endDate;
|
|
PageResult<StockOutOrder>? _cache;
|
|
|
|
@override
|
|
Future<PageResult<StockOutOrder>> build() async {
|
|
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
|
ref.watch(networkRecoveryCountProvider);
|
|
try {
|
|
final result = await _fetch();
|
|
_cache = result;
|
|
return result;
|
|
} catch (_) {
|
|
if (_cache != null) return _cache!;
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<PageResult<StockOutOrder>> _fetch() {
|
|
return ref.read(stockOutRepositoryProvider).list(
|
|
status: _status.isEmpty ? null : _status,
|
|
startDate: _startDate,
|
|
endDate: _endDate,
|
|
page: _page,
|
|
pageSize: _pageSize,
|
|
);
|
|
}
|
|
|
|
void setPage(int page) {
|
|
_page = page;
|
|
reload();
|
|
}
|
|
|
|
void setPageSize(int pageSize) {
|
|
_pageSize = pageSize;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void setStatus(String status) {
|
|
_status = status;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void setDateRange(String? startDate, String? endDate) {
|
|
_startDate = startDate;
|
|
_endDate = endDate;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void reload() {
|
|
state = const AsyncValue.loading();
|
|
_fetch().then((result) {
|
|
_cache = result;
|
|
state = AsyncValue.data(result);
|
|
}, onError: (e, st) {
|
|
if (_cache != null) {
|
|
state = AsyncValue.data(_cache!);
|
|
} else {
|
|
state = AsyncValue.error(e, st);
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> createOrder(Map<String, dynamic> data) async {
|
|
await ref.read(stockOutRepositoryProvider).create(data);
|
|
reload();
|
|
}
|
|
|
|
Future<void> deleteOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).delete(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> submitOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).submit(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> approveOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).approve(id);
|
|
reload();
|
|
ref.invalidate(inventoryListProvider);
|
|
}
|
|
|
|
Future<void> rejectOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).reject(id);
|
|
reload();
|
|
}
|
|
}
|