feat(approvals): Approval Flow v2 프런트엔드 전면 개편
- 환경/라우터 모듈에 approval_flow_v2 토글을 추가하고 FeatureFlags 초기화를 연결 (.env*, lib/core/**) - ApiClient 빌더·ApiRoutes 확장과 ApprovalRepositoryRemote 리팩터링으로 include·액션 시그니처를 정합화 - ApprovalFlow·ApprovalDraft 엔티티/레포/유즈케이스를 도입해 서버 초안과 단계 액션(승인·회수·재상신)을 지원 - Approval 컨트롤러·히스토리·템플릿 페이지와 공유 위젯을 재작성해 감사 로그·회수 UX·템플릿 CRUD를 반영 - Inbound/Outbound/Rental 컨트롤러·페이지에 결재 섹션을 삽입하고 대시보드 pending 카드 요약을 갱신 - SuperportDialog·FormField 등 공통 위젯을 보강하고 승인 위젯 가이드를 추가해 UI 가이드를 정리 - 결재/재고 테스트 픽스처와 단위·위젯·통합 테스트를 확장하고 flutter_test_config로 스테이징 호스트를 허용 - Approval Flow 레포트/플랜 문서를 업데이트하고 ApprovalFlow_System_Integration_and_ChangePlan.md를 추가 - 실행: flutter analyze, flutter test
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import '../../../transactions/domain/entities/stock_transaction_input.dart';
|
||||
|
||||
/// 입고 생성 요청 입력 값.
|
||||
///
|
||||
/// - 재고 트랜잭션 생성에 필요한 필드와 결재 구성을 함께 전달한다.
|
||||
class CreateInboundRequestInput {
|
||||
CreateInboundRequestInput({
|
||||
required this.transactionTypeId,
|
||||
required this.transactionStatusId,
|
||||
required this.warehouseId,
|
||||
required this.transactionDate,
|
||||
required this.createdById,
|
||||
required this.approval,
|
||||
this.note,
|
||||
this.lines = const [],
|
||||
this.customers = const [],
|
||||
});
|
||||
|
||||
final int transactionTypeId;
|
||||
final int transactionStatusId;
|
||||
final int warehouseId;
|
||||
final DateTime transactionDate;
|
||||
final int createdById;
|
||||
final String? note;
|
||||
final List<TransactionLineCreateInput> lines;
|
||||
final List<TransactionCustomerCreateInput> customers;
|
||||
final StockTransactionApprovalInput approval;
|
||||
|
||||
/// 재고 트랜잭션 생성 입력 모델로 변환한다.
|
||||
StockTransactionCreateInput toTransactionInput() {
|
||||
return StockTransactionCreateInput(
|
||||
transactionTypeId: transactionTypeId,
|
||||
transactionStatusId: transactionStatusId,
|
||||
warehouseId: warehouseId,
|
||||
transactionDate: transactionDate,
|
||||
createdById: createdById,
|
||||
note: note,
|
||||
lines: lines,
|
||||
customers: customers,
|
||||
approval: approval,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/failure.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/entities/approval_draft.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/get_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/list_approval_drafts_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/save_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/inventory/inbound/presentation/models/inbound_record.dart';
|
||||
import 'package:superport_v2/features/inventory/lookups/domain/entities/lookup_item.dart';
|
||||
import 'package:superport_v2/features/inventory/lookups/domain/repositories/inventory_lookup_repository.dart';
|
||||
@@ -20,10 +25,16 @@ class InboundController extends ChangeNotifier {
|
||||
required InventoryLookupRepository lookupRepository,
|
||||
List<String> fallbackStatusOptions = const ['작성중', '승인대기', '승인완료'],
|
||||
List<String> transactionTypeKeywords = const ['입고', 'inbound'],
|
||||
SaveApprovalDraftUseCase? saveDraftUseCase,
|
||||
GetApprovalDraftUseCase? getDraftUseCase,
|
||||
ListApprovalDraftsUseCase? listDraftsUseCase,
|
||||
}) : _transactionRepository = transactionRepository,
|
||||
_lineRepository = lineRepository,
|
||||
_customerRepository = customerRepository,
|
||||
_lookupRepository = lookupRepository,
|
||||
_saveDraftUseCase = saveDraftUseCase,
|
||||
_getDraftUseCase = getDraftUseCase,
|
||||
_listDraftsUseCase = listDraftsUseCase,
|
||||
_fallbackStatusOptions = List<String>.unmodifiable(
|
||||
fallbackStatusOptions,
|
||||
),
|
||||
@@ -37,6 +48,9 @@ class InboundController extends ChangeNotifier {
|
||||
final TransactionLineRepository _lineRepository;
|
||||
final TransactionCustomerRepository _customerRepository;
|
||||
final InventoryLookupRepository _lookupRepository;
|
||||
final SaveApprovalDraftUseCase? _saveDraftUseCase;
|
||||
final GetApprovalDraftUseCase? _getDraftUseCase;
|
||||
final ListApprovalDraftsUseCase? _listDraftsUseCase;
|
||||
final List<String> _fallbackStatusOptions;
|
||||
final List<String> _transactionTypeKeywords;
|
||||
|
||||
@@ -51,6 +65,7 @@ class InboundController extends ChangeNotifier {
|
||||
final Set<int> _processingTransactionIds = <int>{};
|
||||
List<LookupItem> _approvalStatuses = const [];
|
||||
LookupItem? _defaultApprovalStatus;
|
||||
StockTransactionApprovalInput? _approvalDraft;
|
||||
|
||||
UnmodifiableListView<String> get statusOptions =>
|
||||
UnmodifiableListView(_statusOptions);
|
||||
@@ -78,6 +93,7 @@ class InboundController extends ChangeNotifier {
|
||||
|
||||
UnmodifiableSetView<int> get processingTransactionIds =>
|
||||
UnmodifiableSetView(_processingTransactionIds);
|
||||
StockTransactionApprovalInput? get approvalDraft => _approvalDraft;
|
||||
|
||||
/// 트랜잭션 상태 목록을 서버에서 읽어온다.
|
||||
Future<void> loadStatusOptions() async {
|
||||
@@ -139,6 +155,64 @@ class InboundController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 결재 구성 초안 상태를 갱신한다.
|
||||
void updateApprovalDraft(StockTransactionApprovalInput approval) {
|
||||
_approvalDraft = approval;
|
||||
notifyListeners();
|
||||
_persistApprovalDraft(approval);
|
||||
}
|
||||
|
||||
/// 결재 구성 초안을 초기화한다.
|
||||
void clearApprovalDraft() {
|
||||
if (_approvalDraft == null) {
|
||||
return;
|
||||
}
|
||||
_approvalDraft = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadApprovalDraftFromServer({
|
||||
required int requesterId,
|
||||
int? transactionId,
|
||||
}) async {
|
||||
final listUseCase = _listDraftsUseCase;
|
||||
final getUseCase = _getDraftUseCase;
|
||||
if (listUseCase == null || getUseCase == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final result = await listUseCase.call(
|
||||
ApprovalDraftListFilter(
|
||||
requesterId: requesterId,
|
||||
transactionId: transactionId,
|
||||
pageSize: 10,
|
||||
),
|
||||
);
|
||||
if (result.items.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final sessionKey = _draftSessionKey(
|
||||
requesterId,
|
||||
transactionId: transactionId,
|
||||
);
|
||||
final summary = result.items.firstWhere(
|
||||
(item) => item.sessionKey == sessionKey,
|
||||
orElse: () => result.items.first,
|
||||
);
|
||||
final detail = await getUseCase.call(
|
||||
id: summary.id,
|
||||
requesterId: requesterId,
|
||||
);
|
||||
if (detail == null) {
|
||||
return;
|
||||
}
|
||||
_approvalDraft = _toTransactionApproval(detail);
|
||||
notifyListeners();
|
||||
} catch (error, stackTrace) {
|
||||
debugPrint('[InboundController] 초안 복구 실패: $error\n$stackTrace');
|
||||
}
|
||||
}
|
||||
|
||||
/// 필터에 맞는 입고 트랜잭션 목록을 조회한다.
|
||||
Future<void> fetchTransactions({
|
||||
required StockTransactionListFilter filter,
|
||||
@@ -179,6 +253,84 @@ class InboundController extends ChangeNotifier {
|
||||
await fetchTransactions(filter: target);
|
||||
}
|
||||
|
||||
void _persistApprovalDraft(StockTransactionApprovalInput approval) {
|
||||
final useCase = _saveDraftUseCase;
|
||||
if (useCase == null) {
|
||||
return;
|
||||
}
|
||||
if (approval.steps.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final input = _buildApprovalDraftSaveInput(approval);
|
||||
if (!input.hasSteps) {
|
||||
return;
|
||||
}
|
||||
unawaited(
|
||||
Future<void>(() async {
|
||||
try {
|
||||
await useCase.call(input);
|
||||
} catch (error, stackTrace) {
|
||||
debugPrint('[InboundController] 초안 저장 실패: $error\n$stackTrace');
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
ApprovalDraftSaveInput _buildApprovalDraftSaveInput(
|
||||
StockTransactionApprovalInput approval,
|
||||
) {
|
||||
final steps = approval.steps
|
||||
.map(
|
||||
(step) => ApprovalDraftStep(
|
||||
stepOrder: step.stepOrder,
|
||||
approverId: step.approverId,
|
||||
note: step.note,
|
||||
),
|
||||
)
|
||||
.toList(growable: false);
|
||||
return ApprovalDraftSaveInput(
|
||||
requesterId: approval.requestedById,
|
||||
transactionId: null,
|
||||
templateId: approval.templateId,
|
||||
title: approval.title,
|
||||
summary: approval.summary,
|
||||
note: approval.note,
|
||||
metadata: approval.metadata,
|
||||
sessionKey: _draftSessionKey(approval.requestedById),
|
||||
statusId: approval.approvalStatusId,
|
||||
steps: steps,
|
||||
);
|
||||
}
|
||||
|
||||
String _draftSessionKey(int requesterId, {int? transactionId}) {
|
||||
final base = 'inventory_inbound_$requesterId';
|
||||
if (transactionId == null) {
|
||||
return base;
|
||||
}
|
||||
return '${base}_$transactionId';
|
||||
}
|
||||
|
||||
StockTransactionApprovalInput _toTransactionApproval(
|
||||
ApprovalDraftDetail detail,
|
||||
) {
|
||||
final submission = detail.toSubmissionInput(defaultStatusId: null);
|
||||
return StockTransactionApprovalInput(
|
||||
requestedById: submission.requesterId,
|
||||
approvalStatusId: submission.statusId == 0 ? null : submission.statusId,
|
||||
templateId: submission.templateId,
|
||||
finalApproverId: submission.finalApproverId,
|
||||
requestedAt: submission.requestedAt,
|
||||
decidedAt: submission.decidedAt,
|
||||
cancelledAt: submission.cancelledAt,
|
||||
lastActionAt: submission.lastActionAt,
|
||||
title: submission.title,
|
||||
summary: submission.summary,
|
||||
note: submission.note,
|
||||
metadata: submission.metadata,
|
||||
steps: submission.steps,
|
||||
);
|
||||
}
|
||||
|
||||
LookupItem? _resolveDefaultApprovalStatus(List<LookupItem> items) {
|
||||
for (final item in items) {
|
||||
if (item.isDefault) {
|
||||
@@ -194,6 +346,7 @@ class InboundController extends ChangeNotifier {
|
||||
bool refreshAfter = true,
|
||||
StockTransactionListFilter? refreshFilter,
|
||||
}) {
|
||||
_approvalDraft = input.approval;
|
||||
return _executeMutation(
|
||||
() => _transactionRepository.create(input),
|
||||
refreshAfter: refreshAfter,
|
||||
|
||||
@@ -17,6 +17,13 @@ import 'package:superport_v2/widgets/components/superport_date_picker.dart';
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/partner_select_field.dart';
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/product_autocomplete_field.dart';
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/warehouse_select_field.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/controllers/approval_request_controller.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/utils/approval_form_initializer.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/widgets/approval_step_configurator.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/widgets/approval_template_picker.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/get_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/list_approval_drafts_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/save_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/core/config/environment.dart';
|
||||
import 'package:superport_v2/core/network/failure.dart';
|
||||
import 'package:superport_v2/core/permissions/permission_manager.dart';
|
||||
@@ -126,6 +133,15 @@ class _InboundPageState extends State<InboundPage> {
|
||||
lookupRepository: getIt<InventoryLookupRepository>(),
|
||||
fallbackStatusOptions: InboundTableSpec.fallbackStatusOptions,
|
||||
transactionTypeKeywords: InboundTableSpec.transactionTypeKeywords,
|
||||
saveDraftUseCase: getIt.isRegistered<SaveApprovalDraftUseCase>()
|
||||
? getIt<SaveApprovalDraftUseCase>()
|
||||
: null,
|
||||
getDraftUseCase: getIt.isRegistered<GetApprovalDraftUseCase>()
|
||||
? getIt<GetApprovalDraftUseCase>()
|
||||
: null,
|
||||
listDraftsUseCase: getIt.isRegistered<ListApprovalDraftsUseCase>()
|
||||
? getIt<ListApprovalDraftsUseCase>()
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,6 +153,10 @@ class _InboundPageState extends State<InboundPage> {
|
||||
Future.microtask(() async {
|
||||
await controller.loadStatusOptions();
|
||||
await controller.loadApprovalStatuses();
|
||||
final requester = _resolveCurrentWriter();
|
||||
if (requester != null) {
|
||||
await controller.loadApprovalDraftFromServer(requesterId: requester.id);
|
||||
}
|
||||
final hasType = await controller.resolveTransactionType();
|
||||
if (!mounted) {
|
||||
return;
|
||||
@@ -1483,6 +1503,25 @@ class _InboundPageState extends State<InboundPage> {
|
||||
return '${suggestion.name} (${suggestion.employeeNo})';
|
||||
}
|
||||
|
||||
final approvalController = ApprovalRequestController();
|
||||
final defaultRequester = () {
|
||||
final writer = writerSelection;
|
||||
if (writer == null) {
|
||||
return null;
|
||||
}
|
||||
return ApprovalRequestParticipant(
|
||||
id: writer.id,
|
||||
name: writer.name,
|
||||
employeeNo: writer.employeeNo,
|
||||
);
|
||||
}();
|
||||
ApprovalFormInitializer.populate(
|
||||
controller: approvalController,
|
||||
existingApproval: initial?.raw?.approval,
|
||||
draft: _controller?.approvalDraft,
|
||||
defaultRequester: defaultRequester,
|
||||
);
|
||||
|
||||
final writerController = TextEditingController(
|
||||
text: writerLabel(writerSelection),
|
||||
);
|
||||
@@ -1718,6 +1757,23 @@ class _InboundPageState extends State<InboundPage> {
|
||||
return;
|
||||
}
|
||||
|
||||
StockTransactionApprovalInput approvalInput;
|
||||
try {
|
||||
approvalInput = approvalController.buildTransactionApprovalInput(
|
||||
approvalStatusId: approvalStatusId,
|
||||
note: approvalNoteValue.isEmpty ? null : approvalNoteValue,
|
||||
);
|
||||
} on StateError catch (error) {
|
||||
updateSaving(false);
|
||||
SuperportToast.error(context, error.message);
|
||||
return;
|
||||
} catch (_) {
|
||||
updateSaving(false);
|
||||
SuperportToast.error(context, '결재 구성을 확인하고 다시 시도하세요.');
|
||||
return;
|
||||
}
|
||||
controller.updateApprovalDraft(approvalInput);
|
||||
|
||||
final createLines = lineDrafts
|
||||
.map(
|
||||
(draft) => TransactionLineCreateInput(
|
||||
@@ -1738,11 +1794,7 @@ class _InboundPageState extends State<InboundPage> {
|
||||
note: remarkValue,
|
||||
lines: createLines,
|
||||
customers: createCustomers,
|
||||
approval: StockTransactionApprovalInput(
|
||||
requestedById: createdById,
|
||||
approvalStatusId: approvalStatusId,
|
||||
note: approvalNoteValue.isEmpty ? null : approvalNoteValue,
|
||||
),
|
||||
approval: approvalInput,
|
||||
);
|
||||
assert(() {
|
||||
debugPrint(
|
||||
@@ -1995,6 +2047,15 @@ class _InboundPageState extends State<InboundPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (initial == null) ...[
|
||||
ApprovalTemplatePicker(controller: approvalController),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
ApprovalStepConfigurator(
|
||||
controller: approvalController,
|
||||
readOnly: initial != null,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
if (headerNotice != null)
|
||||
Padding(
|
||||
@@ -2112,6 +2173,7 @@ class _InboundPageState extends State<InboundPage> {
|
||||
final disposeApprovalNoteController = approvalNoteController;
|
||||
final disposeTransactionTypeController = transactionTypeController;
|
||||
final disposeProcessedAt = processedAt;
|
||||
final disposeApprovalController = approvalController;
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
for (final draft in disposeDrafts) {
|
||||
@@ -2123,6 +2185,7 @@ class _InboundPageState extends State<InboundPage> {
|
||||
disposeApprovalNoteController.dispose();
|
||||
disposeTransactionTypeController.dispose();
|
||||
disposeProcessedAt.dispose();
|
||||
disposeApprovalController.dispose();
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import '../../../transactions/domain/entities/stock_transaction_input.dart';
|
||||
|
||||
/// 출고 생성 요청 입력 값.
|
||||
///
|
||||
/// - 결재 구성을 포함한 재고 트랜잭션 생성 데이터를 보관한다.
|
||||
class CreateOutboundRequestInput {
|
||||
CreateOutboundRequestInput({
|
||||
required this.transactionTypeId,
|
||||
required this.transactionStatusId,
|
||||
required this.warehouseId,
|
||||
required this.transactionDate,
|
||||
required this.createdById,
|
||||
required this.approval,
|
||||
this.note,
|
||||
this.lines = const [],
|
||||
this.customers = const [],
|
||||
});
|
||||
|
||||
final int transactionTypeId;
|
||||
final int transactionStatusId;
|
||||
final int warehouseId;
|
||||
final DateTime transactionDate;
|
||||
final int createdById;
|
||||
final String? note;
|
||||
final List<TransactionLineCreateInput> lines;
|
||||
final List<TransactionCustomerCreateInput> customers;
|
||||
final StockTransactionApprovalInput approval;
|
||||
|
||||
/// 공통 재고 트랜잭션 입력 모델로 변환한다.
|
||||
StockTransactionCreateInput toTransactionInput() {
|
||||
return StockTransactionCreateInput(
|
||||
transactionTypeId: transactionTypeId,
|
||||
transactionStatusId: transactionStatusId,
|
||||
warehouseId: warehouseId,
|
||||
transactionDate: transactionDate,
|
||||
createdById: createdById,
|
||||
note: note,
|
||||
lines: lines,
|
||||
customers: customers,
|
||||
approval: approval,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/failure.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/entities/approval_draft.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/get_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/list_approval_drafts_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/save_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/inventory/lookups/domain/entities/lookup_item.dart';
|
||||
import 'package:superport_v2/features/inventory/lookups/domain/repositories/inventory_lookup_repository.dart';
|
||||
import 'package:superport_v2/features/inventory/outbound/presentation/models/outbound_record.dart';
|
||||
@@ -20,10 +25,16 @@ class OutboundController extends ChangeNotifier {
|
||||
required InventoryLookupRepository lookupRepository,
|
||||
List<String> fallbackStatusOptions = const ['작성중', '출고대기', '출고완료'],
|
||||
List<String> transactionTypeKeywords = const ['출고', 'outbound'],
|
||||
SaveApprovalDraftUseCase? saveDraftUseCase,
|
||||
GetApprovalDraftUseCase? getDraftUseCase,
|
||||
ListApprovalDraftsUseCase? listDraftsUseCase,
|
||||
}) : _transactionRepository = transactionRepository,
|
||||
_lineRepository = lineRepository,
|
||||
_customerRepository = customerRepository,
|
||||
_lookupRepository = lookupRepository,
|
||||
_saveDraftUseCase = saveDraftUseCase,
|
||||
_getDraftUseCase = getDraftUseCase,
|
||||
_listDraftsUseCase = listDraftsUseCase,
|
||||
_fallbackStatusOptions = List<String>.unmodifiable(
|
||||
fallbackStatusOptions,
|
||||
),
|
||||
@@ -37,6 +48,9 @@ class OutboundController extends ChangeNotifier {
|
||||
final TransactionLineRepository _lineRepository;
|
||||
final TransactionCustomerRepository _customerRepository;
|
||||
final InventoryLookupRepository _lookupRepository;
|
||||
final SaveApprovalDraftUseCase? _saveDraftUseCase;
|
||||
final GetApprovalDraftUseCase? _getDraftUseCase;
|
||||
final ListApprovalDraftsUseCase? _listDraftsUseCase;
|
||||
final List<String> _fallbackStatusOptions;
|
||||
final List<String> _transactionTypeKeywords;
|
||||
|
||||
@@ -49,6 +63,7 @@ class OutboundController extends ChangeNotifier {
|
||||
String? _errorMessage;
|
||||
StockTransactionListFilter? _lastFilter;
|
||||
final Set<int> _processingTransactionIds = <int>{};
|
||||
StockTransactionApprovalInput? _approvalDraft;
|
||||
|
||||
UnmodifiableListView<String> get statusOptions =>
|
||||
UnmodifiableListView(_statusOptions);
|
||||
@@ -73,6 +88,7 @@ class OutboundController extends ChangeNotifier {
|
||||
|
||||
UnmodifiableSetView<int> get processingTransactionIds =>
|
||||
UnmodifiableSetView(_processingTransactionIds);
|
||||
StockTransactionApprovalInput? get approvalDraft => _approvalDraft;
|
||||
|
||||
/// 트랜잭션 상태 값을 불러온다.
|
||||
Future<void> loadStatusOptions() async {
|
||||
@@ -119,6 +135,64 @@ class OutboundController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 결재 구성 초안 상태를 갱신한다.
|
||||
void updateApprovalDraft(StockTransactionApprovalInput approval) {
|
||||
_approvalDraft = approval;
|
||||
notifyListeners();
|
||||
_persistApprovalDraft(approval);
|
||||
}
|
||||
|
||||
/// 결재 구성 초안을 초기화한다.
|
||||
void clearApprovalDraft() {
|
||||
if (_approvalDraft == null) {
|
||||
return;
|
||||
}
|
||||
_approvalDraft = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadApprovalDraftFromServer({
|
||||
required int requesterId,
|
||||
int? transactionId,
|
||||
}) async {
|
||||
final listUseCase = _listDraftsUseCase;
|
||||
final getUseCase = _getDraftUseCase;
|
||||
if (listUseCase == null || getUseCase == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final result = await listUseCase.call(
|
||||
ApprovalDraftListFilter(
|
||||
requesterId: requesterId,
|
||||
transactionId: transactionId,
|
||||
pageSize: 10,
|
||||
),
|
||||
);
|
||||
if (result.items.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final sessionKey = _draftSessionKey(
|
||||
requesterId,
|
||||
transactionId: transactionId,
|
||||
);
|
||||
final summary = result.items.firstWhere(
|
||||
(item) => item.sessionKey == sessionKey,
|
||||
orElse: () => result.items.first,
|
||||
);
|
||||
final detail = await getUseCase.call(
|
||||
id: summary.id,
|
||||
requesterId: requesterId,
|
||||
);
|
||||
if (detail == null) {
|
||||
return;
|
||||
}
|
||||
_approvalDraft = _toTransactionApproval(detail);
|
||||
notifyListeners();
|
||||
} catch (error, stackTrace) {
|
||||
debugPrint('[OutboundController] 초안 복구 실패: $error\n$stackTrace');
|
||||
}
|
||||
}
|
||||
|
||||
/// 조건에 맞는 출고 트랜잭션 목록을 요청한다.
|
||||
Future<void> fetchTransactions({
|
||||
required StockTransactionListFilter filter,
|
||||
@@ -159,12 +233,91 @@ class OutboundController extends ChangeNotifier {
|
||||
await fetchTransactions(filter: target);
|
||||
}
|
||||
|
||||
void _persistApprovalDraft(StockTransactionApprovalInput approval) {
|
||||
final useCase = _saveDraftUseCase;
|
||||
if (useCase == null) {
|
||||
return;
|
||||
}
|
||||
if (approval.steps.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final input = _buildApprovalDraftSaveInput(approval);
|
||||
if (!input.hasSteps) {
|
||||
return;
|
||||
}
|
||||
unawaited(
|
||||
Future<void>(() async {
|
||||
try {
|
||||
await useCase.call(input);
|
||||
} catch (error, stackTrace) {
|
||||
debugPrint('[OutboundController] 초안 저장 실패: $error\n$stackTrace');
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
ApprovalDraftSaveInput _buildApprovalDraftSaveInput(
|
||||
StockTransactionApprovalInput approval,
|
||||
) {
|
||||
final steps = approval.steps
|
||||
.map(
|
||||
(step) => ApprovalDraftStep(
|
||||
stepOrder: step.stepOrder,
|
||||
approverId: step.approverId,
|
||||
note: step.note,
|
||||
),
|
||||
)
|
||||
.toList(growable: false);
|
||||
return ApprovalDraftSaveInput(
|
||||
requesterId: approval.requestedById,
|
||||
transactionId: null,
|
||||
templateId: approval.templateId,
|
||||
title: approval.title,
|
||||
summary: approval.summary,
|
||||
note: approval.note,
|
||||
metadata: approval.metadata,
|
||||
sessionKey: _draftSessionKey(approval.requestedById),
|
||||
statusId: approval.approvalStatusId,
|
||||
steps: steps,
|
||||
);
|
||||
}
|
||||
|
||||
String _draftSessionKey(int requesterId, {int? transactionId}) {
|
||||
final base = 'inventory_outbound_$requesterId';
|
||||
if (transactionId == null) {
|
||||
return base;
|
||||
}
|
||||
return '${base}_$transactionId';
|
||||
}
|
||||
|
||||
StockTransactionApprovalInput _toTransactionApproval(
|
||||
ApprovalDraftDetail detail,
|
||||
) {
|
||||
final submission = detail.toSubmissionInput(defaultStatusId: null);
|
||||
return StockTransactionApprovalInput(
|
||||
requestedById: submission.requesterId,
|
||||
approvalStatusId: submission.statusId == 0 ? null : submission.statusId,
|
||||
templateId: submission.templateId,
|
||||
finalApproverId: submission.finalApproverId,
|
||||
requestedAt: submission.requestedAt,
|
||||
decidedAt: submission.decidedAt,
|
||||
cancelledAt: submission.cancelledAt,
|
||||
lastActionAt: submission.lastActionAt,
|
||||
title: submission.title,
|
||||
summary: submission.summary,
|
||||
note: submission.note,
|
||||
metadata: submission.metadata,
|
||||
steps: submission.steps,
|
||||
);
|
||||
}
|
||||
|
||||
/// 출고 트랜잭션을 생성한다.
|
||||
Future<OutboundRecord> createTransaction(
|
||||
StockTransactionCreateInput input, {
|
||||
bool refreshAfter = true,
|
||||
StockTransactionListFilter? refreshFilter,
|
||||
}) {
|
||||
_approvalDraft = input.approval;
|
||||
return _executeMutation(
|
||||
() => _transactionRepository.create(input),
|
||||
refreshAfter: refreshAfter,
|
||||
|
||||
@@ -16,6 +16,13 @@ import 'package:superport_v2/features/inventory/shared/widgets/product_autocompl
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/employee_autocomplete_field.dart';
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/customer_multi_select_field.dart';
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/warehouse_select_field.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/controllers/approval_request_controller.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/utils/approval_form_initializer.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/widgets/approval_step_configurator.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/widgets/approval_template_picker.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/get_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/list_approval_drafts_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/save_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/core/config/environment.dart';
|
||||
import 'package:superport_v2/core/network/failure.dart';
|
||||
import 'package:superport_v2/core/common/utils/pagination_utils.dart';
|
||||
@@ -31,6 +38,7 @@ import 'package:superport_v2/features/inventory/transactions/presentation/servic
|
||||
import 'package:superport_v2/features/inventory/transactions/presentation/widgets/transaction_detail_dialog.dart';
|
||||
import 'package:superport_v2/features/masters/customer/domain/entities/customer.dart';
|
||||
import 'package:superport_v2/features/masters/customer/domain/repositories/customer_repository.dart';
|
||||
import 'package:superport_v2/features/auth/application/auth_service.dart';
|
||||
import '../../../lookups/domain/entities/lookup_item.dart';
|
||||
import '../../../lookups/domain/repositories/inventory_lookup_repository.dart';
|
||||
import '../widgets/outbound_detail_view.dart';
|
||||
@@ -133,6 +141,15 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
lookupRepository: getIt<InventoryLookupRepository>(),
|
||||
fallbackStatusOptions: OutboundTableSpec.fallbackStatusOptions,
|
||||
transactionTypeKeywords: OutboundTableSpec.transactionTypeKeywords,
|
||||
saveDraftUseCase: getIt.isRegistered<SaveApprovalDraftUseCase>()
|
||||
? getIt<SaveApprovalDraftUseCase>()
|
||||
: null,
|
||||
getDraftUseCase: getIt.isRegistered<GetApprovalDraftUseCase>()
|
||||
? getIt<GetApprovalDraftUseCase>()
|
||||
: null,
|
||||
listDraftsUseCase: getIt.isRegistered<ListApprovalDraftsUseCase>()
|
||||
? getIt<ListApprovalDraftsUseCase>()
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -143,6 +160,10 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
}
|
||||
Future.microtask(() async {
|
||||
await controller.loadStatusOptions();
|
||||
final requester = _resolveCurrentWriter();
|
||||
if (requester != null) {
|
||||
await controller.loadApprovalDraftFromServer(requesterId: requester.id);
|
||||
}
|
||||
final hasType = await controller.resolveTransactionType();
|
||||
if (!mounted) {
|
||||
return;
|
||||
@@ -213,6 +234,26 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
}
|
||||
}
|
||||
|
||||
InventoryEmployeeSuggestion? _resolveCurrentWriter() {
|
||||
final getIt = GetIt.I;
|
||||
if (!getIt.isRegistered<AuthService>()) {
|
||||
return null;
|
||||
}
|
||||
final session = getIt<AuthService>().session;
|
||||
final user = session?.user;
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
final employeeNo = (user.employeeNo ?? '').trim().isEmpty
|
||||
? user.id.toString()
|
||||
: user.employeeNo!.trim();
|
||||
return InventoryEmployeeSuggestion(
|
||||
id: user.id,
|
||||
employeeNo: employeeNo,
|
||||
name: user.name,
|
||||
);
|
||||
}
|
||||
|
||||
void _handleControllerChanged() {
|
||||
if (!mounted) {
|
||||
return;
|
||||
@@ -1556,6 +1597,25 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
return '${suggestion.name} (${suggestion.employeeNo})';
|
||||
}
|
||||
|
||||
final approvalController = ApprovalRequestController();
|
||||
final defaultRequester = () {
|
||||
final writer = writerSelection;
|
||||
if (writer == null) {
|
||||
return null;
|
||||
}
|
||||
return ApprovalRequestParticipant(
|
||||
id: writer.id,
|
||||
name: writer.name,
|
||||
employeeNo: writer.employeeNo,
|
||||
);
|
||||
}();
|
||||
ApprovalFormInitializer.populate(
|
||||
controller: approvalController,
|
||||
existingApproval: initial?.raw?.approval,
|
||||
draft: _controller?.approvalDraft,
|
||||
defaultRequester: defaultRequester,
|
||||
);
|
||||
|
||||
final writerController = TextEditingController(
|
||||
text: writerLabel(writerSelection),
|
||||
);
|
||||
@@ -1814,6 +1874,23 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
)
|
||||
.toList(growable: false);
|
||||
|
||||
StockTransactionApprovalInput approvalInput;
|
||||
try {
|
||||
approvalInput = approvalController.buildTransactionApprovalInput(
|
||||
approvalStatusId: null,
|
||||
note: approvalNoteValue.isEmpty ? null : approvalNoteValue,
|
||||
);
|
||||
} on StateError catch (error) {
|
||||
updateSaving(false);
|
||||
SuperportToast.error(context, error.message);
|
||||
return;
|
||||
} catch (_) {
|
||||
updateSaving(false);
|
||||
SuperportToast.error(context, '결재 구성을 확인하고 다시 시도하세요.');
|
||||
return;
|
||||
}
|
||||
controller.updateApprovalDraft(approvalInput);
|
||||
|
||||
final created = await controller.createTransaction(
|
||||
StockTransactionCreateInput(
|
||||
transactionTypeId: transactionTypeLookup.id,
|
||||
@@ -1824,10 +1901,7 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
note: remarkValue,
|
||||
lines: createLines,
|
||||
customers: createCustomers,
|
||||
approval: StockTransactionApprovalInput(
|
||||
requestedById: createdById,
|
||||
note: approvalNoteValue.isEmpty ? null : approvalNoteValue,
|
||||
),
|
||||
approval: approvalInput,
|
||||
),
|
||||
);
|
||||
result = created;
|
||||
@@ -2011,6 +2085,15 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
enabled: initial == null,
|
||||
onSuggestionSelected: (suggestion) {
|
||||
writerSelection = suggestion;
|
||||
approvalController.setRequester(
|
||||
suggestion == null
|
||||
? null
|
||||
: ApprovalRequestParticipant(
|
||||
id: suggestion.id,
|
||||
name: suggestion.name,
|
||||
employeeNo: suggestion.employeeNo,
|
||||
),
|
||||
);
|
||||
if (writerError != null) {
|
||||
setState(() {
|
||||
writerError = null;
|
||||
@@ -2026,6 +2109,7 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
if (currentText.isEmpty ||
|
||||
currentText != selectedLabel) {
|
||||
writerSelection = null;
|
||||
approvalController.setRequester(null);
|
||||
}
|
||||
if (writerError != null) {
|
||||
setState(() {
|
||||
@@ -2099,6 +2183,15 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (initial == null) ...[
|
||||
ApprovalTemplatePicker(controller: approvalController),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
ApprovalStepConfigurator(
|
||||
controller: approvalController,
|
||||
readOnly: initial != null,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
if (headerNotice != null)
|
||||
Padding(
|
||||
@@ -2215,6 +2308,7 @@ class _OutboundPageState extends State<OutboundPage> {
|
||||
transactionTypeController.dispose();
|
||||
approvalNoteController.dispose();
|
||||
processedAt.dispose();
|
||||
approvalController.dispose();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,7 @@ class OutboundDetailView extends StatelessWidget {
|
||||
children: [
|
||||
if (!transitionsEnabled) ...[
|
||||
ShadBadge.outline(
|
||||
child: Text(
|
||||
'재고 상태 전이가 비활성화된 상태입니다.',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
child: Text('재고 상태 전이가 비활성화된 상태입니다.', style: theme.textTheme.small),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
@@ -76,8 +73,10 @@ class OutboundDetailView extends StatelessWidget {
|
||||
for (final customer in record.customers)
|
||||
ShadBadge(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 6,
|
||||
),
|
||||
child: Text('${customer.name} · ${customer.code}'),
|
||||
),
|
||||
),
|
||||
@@ -111,9 +110,7 @@ class OutboundDetailView extends StatelessWidget {
|
||||
ShadTableCell(child: Text(item.manufacturer)),
|
||||
ShadTableCell(child: Text(item.unit)),
|
||||
ShadTableCell(child: Text('${item.quantity}')),
|
||||
ShadTableCell(
|
||||
child: Text(currencyFormatter.format(item.price)),
|
||||
),
|
||||
ShadTableCell(child: Text(currencyFormatter.format(item.price))),
|
||||
ShadTableCell(
|
||||
child: Text(item.remark.isEmpty ? '-' : item.remark),
|
||||
),
|
||||
@@ -146,13 +143,13 @@ class _DetailChip extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(label, style: theme.textTheme.small, textAlign: TextAlign.center),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
style: theme.textTheme.p,
|
||||
label,
|
||||
style: theme.textTheme.small,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(value, style: theme.textTheme.p, textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import '../../../transactions/domain/entities/stock_transaction_input.dart';
|
||||
|
||||
/// 대여 생성 요청 입력 값.
|
||||
///
|
||||
/// - 대여 반납 예정일과 결재 구성을 포함한다.
|
||||
class CreateRentalRequestInput {
|
||||
CreateRentalRequestInput({
|
||||
required this.transactionTypeId,
|
||||
required this.transactionStatusId,
|
||||
required this.warehouseId,
|
||||
required this.transactionDate,
|
||||
required this.createdById,
|
||||
required this.approval,
|
||||
this.expectedReturnDate,
|
||||
this.note,
|
||||
this.lines = const [],
|
||||
this.customers = const [],
|
||||
});
|
||||
|
||||
final int transactionTypeId;
|
||||
final int transactionStatusId;
|
||||
final int warehouseId;
|
||||
final DateTime transactionDate;
|
||||
final int createdById;
|
||||
final DateTime? expectedReturnDate;
|
||||
final String? note;
|
||||
final List<TransactionLineCreateInput> lines;
|
||||
final List<TransactionCustomerCreateInput> customers;
|
||||
final StockTransactionApprovalInput approval;
|
||||
|
||||
/// 재고 트랜잭션 입력 모델로 변환한다.
|
||||
StockTransactionCreateInput toTransactionInput() {
|
||||
return StockTransactionCreateInput(
|
||||
transactionTypeId: transactionTypeId,
|
||||
transactionStatusId: transactionStatusId,
|
||||
warehouseId: warehouseId,
|
||||
transactionDate: transactionDate,
|
||||
createdById: createdById,
|
||||
note: note,
|
||||
expectedReturnDate: expectedReturnDate,
|
||||
lines: lines,
|
||||
customers: customers,
|
||||
approval: approval,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/failure.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/entities/approval_draft.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/get_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/list_approval_drafts_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/save_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/inventory/lookups/domain/entities/lookup_item.dart';
|
||||
import 'package:superport_v2/features/inventory/lookups/domain/repositories/inventory_lookup_repository.dart';
|
||||
import 'package:superport_v2/features/inventory/rental/presentation/models/rental_record.dart';
|
||||
@@ -21,10 +26,16 @@ class RentalController extends ChangeNotifier {
|
||||
List<String> fallbackStatusOptions = const ['대여중', '반납대기', '완료'],
|
||||
List<String> rentTransactionKeywords = const ['대여', 'rent'],
|
||||
List<String> returnTransactionKeywords = const ['반납', 'return'],
|
||||
SaveApprovalDraftUseCase? saveDraftUseCase,
|
||||
GetApprovalDraftUseCase? getDraftUseCase,
|
||||
ListApprovalDraftsUseCase? listDraftsUseCase,
|
||||
}) : _transactionRepository = transactionRepository,
|
||||
_lineRepository = lineRepository,
|
||||
_customerRepository = customerRepository,
|
||||
_lookupRepository = lookupRepository,
|
||||
_saveDraftUseCase = saveDraftUseCase,
|
||||
_getDraftUseCase = getDraftUseCase,
|
||||
_listDraftsUseCase = listDraftsUseCase,
|
||||
_fallbackStatusOptions = List<String>.unmodifiable(
|
||||
fallbackStatusOptions,
|
||||
),
|
||||
@@ -41,6 +52,9 @@ class RentalController extends ChangeNotifier {
|
||||
final TransactionLineRepository _lineRepository;
|
||||
final TransactionCustomerRepository _customerRepository;
|
||||
final InventoryLookupRepository _lookupRepository;
|
||||
final SaveApprovalDraftUseCase? _saveDraftUseCase;
|
||||
final GetApprovalDraftUseCase? _getDraftUseCase;
|
||||
final ListApprovalDraftsUseCase? _listDraftsUseCase;
|
||||
final List<String> _fallbackStatusOptions;
|
||||
final List<String> _rentTransactionKeywords;
|
||||
final List<String> _returnTransactionKeywords;
|
||||
@@ -56,6 +70,7 @@ class RentalController extends ChangeNotifier {
|
||||
StockTransactionListFilter? _lastFilter;
|
||||
final Set<int> _processingTransactionIds = <int>{};
|
||||
bool _lastFilterByRentalTypes = true;
|
||||
StockTransactionApprovalInput? _approvalDraft;
|
||||
|
||||
UnmodifiableListView<String> get statusOptions =>
|
||||
UnmodifiableListView(_statusOptions);
|
||||
@@ -84,6 +99,7 @@ class RentalController extends ChangeNotifier {
|
||||
UnmodifiableSetView(_processingTransactionIds);
|
||||
|
||||
bool get lastFilterByRentalTypes => _lastFilterByRentalTypes;
|
||||
StockTransactionApprovalInput? get approvalDraft => _approvalDraft;
|
||||
|
||||
/// 트랜잭션 상태 목록을 조회한다.
|
||||
Future<void> loadStatusOptions() async {
|
||||
@@ -132,6 +148,64 @@ class RentalController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 결재 구성 초안 상태를 갱신한다.
|
||||
void updateApprovalDraft(StockTransactionApprovalInput approval) {
|
||||
_approvalDraft = approval;
|
||||
notifyListeners();
|
||||
_persistApprovalDraft(approval);
|
||||
}
|
||||
|
||||
/// 결재 구성 초안을 초기화한다.
|
||||
void clearApprovalDraft() {
|
||||
if (_approvalDraft == null) {
|
||||
return;
|
||||
}
|
||||
_approvalDraft = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadApprovalDraftFromServer({
|
||||
required int requesterId,
|
||||
int? transactionId,
|
||||
}) async {
|
||||
final listUseCase = _listDraftsUseCase;
|
||||
final getUseCase = _getDraftUseCase;
|
||||
if (listUseCase == null || getUseCase == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final result = await listUseCase.call(
|
||||
ApprovalDraftListFilter(
|
||||
requesterId: requesterId,
|
||||
transactionId: transactionId,
|
||||
pageSize: 10,
|
||||
),
|
||||
);
|
||||
if (result.items.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final sessionKey = _draftSessionKey(
|
||||
requesterId,
|
||||
transactionId: transactionId,
|
||||
);
|
||||
final summary = result.items.firstWhere(
|
||||
(item) => item.sessionKey == sessionKey,
|
||||
orElse: () => result.items.first,
|
||||
);
|
||||
final detail = await getUseCase.call(
|
||||
id: summary.id,
|
||||
requesterId: requesterId,
|
||||
);
|
||||
if (detail == null) {
|
||||
return;
|
||||
}
|
||||
_approvalDraft = _toTransactionApproval(detail);
|
||||
notifyListeners();
|
||||
} catch (error, stackTrace) {
|
||||
debugPrint('[RentalController] 초안 복구 실패: $error\n$stackTrace');
|
||||
}
|
||||
}
|
||||
|
||||
/// 필터 조건에 맞는 대여/반납 트랜잭션을 조회한다.
|
||||
Future<void> fetchTransactions({
|
||||
required StockTransactionListFilter filter,
|
||||
@@ -188,6 +262,84 @@ class RentalController extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
void _persistApprovalDraft(StockTransactionApprovalInput approval) {
|
||||
final useCase = _saveDraftUseCase;
|
||||
if (useCase == null) {
|
||||
return;
|
||||
}
|
||||
if (approval.steps.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final input = _buildApprovalDraftSaveInput(approval);
|
||||
if (!input.hasSteps) {
|
||||
return;
|
||||
}
|
||||
unawaited(
|
||||
Future<void>(() async {
|
||||
try {
|
||||
await useCase.call(input);
|
||||
} catch (error, stackTrace) {
|
||||
debugPrint('[RentalController] 초안 저장 실패: $error\n$stackTrace');
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
ApprovalDraftSaveInput _buildApprovalDraftSaveInput(
|
||||
StockTransactionApprovalInput approval,
|
||||
) {
|
||||
final steps = approval.steps
|
||||
.map(
|
||||
(step) => ApprovalDraftStep(
|
||||
stepOrder: step.stepOrder,
|
||||
approverId: step.approverId,
|
||||
note: step.note,
|
||||
),
|
||||
)
|
||||
.toList(growable: false);
|
||||
return ApprovalDraftSaveInput(
|
||||
requesterId: approval.requestedById,
|
||||
transactionId: null,
|
||||
templateId: approval.templateId,
|
||||
title: approval.title,
|
||||
summary: approval.summary,
|
||||
note: approval.note,
|
||||
metadata: approval.metadata,
|
||||
sessionKey: _draftSessionKey(approval.requestedById),
|
||||
statusId: approval.approvalStatusId,
|
||||
steps: steps,
|
||||
);
|
||||
}
|
||||
|
||||
String _draftSessionKey(int requesterId, {int? transactionId}) {
|
||||
final base = 'inventory_rental_$requesterId';
|
||||
if (transactionId == null) {
|
||||
return base;
|
||||
}
|
||||
return '${base}_$transactionId';
|
||||
}
|
||||
|
||||
StockTransactionApprovalInput _toTransactionApproval(
|
||||
ApprovalDraftDetail detail,
|
||||
) {
|
||||
final submission = detail.toSubmissionInput(defaultStatusId: null);
|
||||
return StockTransactionApprovalInput(
|
||||
requestedById: submission.requesterId,
|
||||
approvalStatusId: submission.statusId == 0 ? null : submission.statusId,
|
||||
templateId: submission.templateId,
|
||||
finalApproverId: submission.finalApproverId,
|
||||
requestedAt: submission.requestedAt,
|
||||
decidedAt: submission.decidedAt,
|
||||
cancelledAt: submission.cancelledAt,
|
||||
lastActionAt: submission.lastActionAt,
|
||||
title: submission.title,
|
||||
summary: submission.summary,
|
||||
note: submission.note,
|
||||
metadata: submission.metadata,
|
||||
steps: submission.steps,
|
||||
);
|
||||
}
|
||||
|
||||
/// 대여/반납 트랜잭션을 생성한다.
|
||||
Future<RentalRecord> createTransaction(
|
||||
StockTransactionCreateInput input, {
|
||||
@@ -195,6 +347,7 @@ class RentalController extends ChangeNotifier {
|
||||
StockTransactionListFilter? refreshFilter,
|
||||
bool? refreshFilterByRentalTypes,
|
||||
}) {
|
||||
_approvalDraft = input.approval;
|
||||
return _executeMutation(
|
||||
() => _transactionRepository.create(input),
|
||||
refreshAfter: refreshAfter,
|
||||
|
||||
@@ -17,6 +17,13 @@ import 'package:superport_v2/features/inventory/shared/widgets/product_autocompl
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/employee_autocomplete_field.dart';
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/customer_multi_select_field.dart';
|
||||
import 'package:superport_v2/features/inventory/shared/widgets/warehouse_select_field.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/controllers/approval_request_controller.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/utils/approval_form_initializer.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/widgets/approval_step_configurator.dart';
|
||||
import 'package:superport_v2/features/approvals/request/presentation/widgets/approval_template_picker.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/get_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/list_approval_drafts_use_case.dart';
|
||||
import 'package:superport_v2/features/approvals/domain/usecases/save_approval_draft_use_case.dart';
|
||||
import 'package:superport_v2/core/config/environment.dart';
|
||||
import 'package:superport_v2/core/network/failure.dart';
|
||||
import 'package:superport_v2/core/permissions/permission_manager.dart';
|
||||
@@ -29,6 +36,7 @@ import 'package:superport_v2/features/inventory/transactions/domain/entities/sto
|
||||
import 'package:superport_v2/features/inventory/transactions/domain/repositories/stock_transaction_repository.dart';
|
||||
import 'package:superport_v2/features/inventory/transactions/presentation/services/transaction_detail_sync_service.dart';
|
||||
import 'package:superport_v2/features/inventory/transactions/presentation/widgets/transaction_detail_dialog.dart';
|
||||
import 'package:superport_v2/features/auth/application/auth_service.dart';
|
||||
import '../../../lookups/domain/entities/lookup_item.dart';
|
||||
import '../../../lookups/domain/repositories/inventory_lookup_repository.dart';
|
||||
import '../widgets/rental_detail_view.dart';
|
||||
@@ -130,6 +138,15 @@ class _RentalPageState extends State<RentalPage> {
|
||||
fallbackStatusOptions: RentalTableSpec.fallbackStatusOptions,
|
||||
rentTransactionKeywords: RentalTableSpec.rentTransactionKeywords,
|
||||
returnTransactionKeywords: RentalTableSpec.returnTransactionKeywords,
|
||||
saveDraftUseCase: getIt.isRegistered<SaveApprovalDraftUseCase>()
|
||||
? getIt<SaveApprovalDraftUseCase>()
|
||||
: null,
|
||||
getDraftUseCase: getIt.isRegistered<GetApprovalDraftUseCase>()
|
||||
? getIt<GetApprovalDraftUseCase>()
|
||||
: null,
|
||||
listDraftsUseCase: getIt.isRegistered<ListApprovalDraftsUseCase>()
|
||||
? getIt<ListApprovalDraftsUseCase>()
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -140,6 +157,10 @@ class _RentalPageState extends State<RentalPage> {
|
||||
}
|
||||
Future.microtask(() async {
|
||||
await controller.loadStatusOptions();
|
||||
final requester = _resolveCurrentWriter();
|
||||
if (requester != null) {
|
||||
await controller.loadApprovalDraftFromServer(requesterId: requester.id);
|
||||
}
|
||||
final hasTypes = await controller.resolveTransactionTypes();
|
||||
if (!mounted) {
|
||||
return;
|
||||
@@ -219,6 +240,26 @@ class _RentalPageState extends State<RentalPage> {
|
||||
}
|
||||
}
|
||||
|
||||
InventoryEmployeeSuggestion? _resolveCurrentWriter() {
|
||||
final getIt = GetIt.I;
|
||||
if (!getIt.isRegistered<AuthService>()) {
|
||||
return null;
|
||||
}
|
||||
final session = getIt<AuthService>().session;
|
||||
final user = session?.user;
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
final employeeNo = (user.employeeNo ?? '').trim().isEmpty
|
||||
? user.id.toString()
|
||||
: user.employeeNo!.trim();
|
||||
return InventoryEmployeeSuggestion(
|
||||
id: user.id,
|
||||
employeeNo: employeeNo,
|
||||
name: user.name,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant RentalPage oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
@@ -1538,6 +1579,25 @@ class _RentalPageState extends State<RentalPage> {
|
||||
return '${suggestion.name} (${suggestion.employeeNo})';
|
||||
}
|
||||
|
||||
final approvalController = ApprovalRequestController();
|
||||
final defaultRequester = () {
|
||||
final writer = writerSelection;
|
||||
if (writer == null) {
|
||||
return null;
|
||||
}
|
||||
return ApprovalRequestParticipant(
|
||||
id: writer.id,
|
||||
name: writer.name,
|
||||
employeeNo: writer.employeeNo,
|
||||
);
|
||||
}();
|
||||
ApprovalFormInitializer.populate(
|
||||
controller: approvalController,
|
||||
existingApproval: initial?.raw?.approval,
|
||||
draft: _controller?.approvalDraft,
|
||||
defaultRequester: defaultRequester,
|
||||
);
|
||||
|
||||
final writerController = TextEditingController(
|
||||
text: writerLabel(writerSelection),
|
||||
);
|
||||
@@ -1792,6 +1852,23 @@ class _RentalPageState extends State<RentalPage> {
|
||||
)
|
||||
.toList(growable: false);
|
||||
|
||||
StockTransactionApprovalInput approvalInput;
|
||||
try {
|
||||
approvalInput = approvalController.buildTransactionApprovalInput(
|
||||
approvalStatusId: null,
|
||||
note: approvalNoteValue.isEmpty ? null : approvalNoteValue,
|
||||
);
|
||||
} on StateError catch (error) {
|
||||
updateSaving(false);
|
||||
SuperportToast.error(context, error.message);
|
||||
return;
|
||||
} catch (_) {
|
||||
updateSaving(false);
|
||||
SuperportToast.error(context, '결재 구성을 확인하고 다시 시도하세요.');
|
||||
return;
|
||||
}
|
||||
controller.updateApprovalDraft(approvalInput);
|
||||
|
||||
final transactionTypeId = selectedLookup.id;
|
||||
final created = await controller.createTransaction(
|
||||
StockTransactionCreateInput(
|
||||
@@ -1804,10 +1881,7 @@ class _RentalPageState extends State<RentalPage> {
|
||||
expectedReturnDate: returnDue.value,
|
||||
lines: createLines,
|
||||
customers: createCustomers,
|
||||
approval: StockTransactionApprovalInput(
|
||||
requestedById: createdById,
|
||||
note: approvalNoteValue.isEmpty ? null : approvalNoteValue,
|
||||
),
|
||||
approval: approvalInput,
|
||||
),
|
||||
);
|
||||
result = created;
|
||||
@@ -2093,6 +2167,15 @@ class _RentalPageState extends State<RentalPage> {
|
||||
enabled: initial == null,
|
||||
onSuggestionSelected: (suggestion) {
|
||||
writerSelection = suggestion;
|
||||
approvalController.setRequester(
|
||||
suggestion == null
|
||||
? null
|
||||
: ApprovalRequestParticipant(
|
||||
id: suggestion.id,
|
||||
name: suggestion.name,
|
||||
employeeNo: suggestion.employeeNo,
|
||||
),
|
||||
);
|
||||
if (writerError != null) {
|
||||
setState(() {
|
||||
writerError = null;
|
||||
@@ -2109,6 +2192,7 @@ class _RentalPageState extends State<RentalPage> {
|
||||
if (currentText.isEmpty ||
|
||||
currentText != selectedLabel) {
|
||||
writerSelection = null;
|
||||
approvalController.setRequester(null);
|
||||
}
|
||||
if (writerError != null) {
|
||||
setState(() {
|
||||
@@ -2154,6 +2238,15 @@ class _RentalPageState extends State<RentalPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (initial == null) ...[
|
||||
ApprovalTemplatePicker(controller: approvalController),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
ApprovalStepConfigurator(
|
||||
controller: approvalController,
|
||||
readOnly: initial != null,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
@@ -2274,6 +2367,7 @@ class _RentalPageState extends State<RentalPage> {
|
||||
approvalNoteController.dispose();
|
||||
processedAt.dispose();
|
||||
returnDue.dispose();
|
||||
approvalController.dispose();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,7 @@ class RentalDetailView extends StatelessWidget {
|
||||
children: [
|
||||
if (!transitionsEnabled) ...[
|
||||
ShadBadge.outline(
|
||||
child: Text(
|
||||
'재고 상태 전이가 비활성화된 상태입니다.',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
child: Text('재고 상태 전이가 비활성화된 상태입니다.', style: theme.textTheme.small),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
@@ -73,8 +70,10 @@ class RentalDetailView extends StatelessWidget {
|
||||
for (final customer in record.customers)
|
||||
ShadBadge(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 6,
|
||||
),
|
||||
child: Text('${customer.name} · ${customer.code}'),
|
||||
),
|
||||
),
|
||||
@@ -108,9 +107,7 @@ class RentalDetailView extends StatelessWidget {
|
||||
ShadTableCell(child: Text(item.manufacturer)),
|
||||
ShadTableCell(child: Text(item.unit)),
|
||||
ShadTableCell(child: Text('${item.quantity}')),
|
||||
ShadTableCell(
|
||||
child: Text(currencyFormatter.format(item.price)),
|
||||
),
|
||||
ShadTableCell(child: Text(currencyFormatter.format(item.price))),
|
||||
ShadTableCell(
|
||||
child: Text(item.remark.isEmpty ? '-' : item.remark),
|
||||
),
|
||||
@@ -143,13 +140,13 @@ class _DetailChip extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(label, style: theme.textTheme.small, textAlign: TextAlign.center),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
style: theme.textTheme.p,
|
||||
label,
|
||||
style: theme.textTheme.small,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(value, style: theme.textTheme.p, textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/common/utils/json_utils.dart';
|
||||
import 'package:superport_v2/features/approvals/data/dtos/approval_dto.dart';
|
||||
|
||||
import '../../domain/entities/stock_transaction.dart';
|
||||
|
||||
@@ -38,7 +39,7 @@ class StockTransactionDto {
|
||||
final DateTime? updatedAt;
|
||||
final List<StockTransactionLine> lines;
|
||||
final List<StockTransactionCustomer> customers;
|
||||
final StockTransactionApprovalSummary? approval;
|
||||
final ApprovalDto? approval;
|
||||
final DateTime? expectedReturnDate;
|
||||
|
||||
/// JSON 객체를 DTO로 변환한다.
|
||||
@@ -86,7 +87,7 @@ class StockTransactionDto {
|
||||
updatedAt: updatedAt,
|
||||
lines: lines,
|
||||
customers: customers,
|
||||
approval: approval,
|
||||
approval: approval?.toEntity(),
|
||||
expectedReturnDate: expectedReturnDate,
|
||||
);
|
||||
}
|
||||
@@ -328,43 +329,21 @@ StockTransactionCustomerSummary _parseCustomer(
|
||||
);
|
||||
}
|
||||
|
||||
StockTransactionApprovalSummary? _parseApproval(dynamic raw) {
|
||||
ApprovalDto? _parseApproval(dynamic raw) {
|
||||
final map = _mapOrEmpty(raw);
|
||||
if (map.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
final statusMap = _firstNonEmptyMap([map['approval_status'], map['status']]);
|
||||
return StockTransactionApprovalSummary(
|
||||
id: map['id'] as int? ?? 0,
|
||||
approvalNo:
|
||||
map['approval_no'] as String? ?? map['approvalNo'] as String? ?? '',
|
||||
status: statusMap.isEmpty
|
||||
? null
|
||||
: StockTransactionApprovalStatusSummary(
|
||||
id: statusMap['id'] as int? ?? statusMap['status_id'] as int? ?? 0,
|
||||
name:
|
||||
statusMap['name'] as String? ??
|
||||
statusMap['status_name'] as String? ??
|
||||
'-',
|
||||
isBlocking:
|
||||
statusMap['is_blocking_next'] as bool? ??
|
||||
statusMap['isBlocking'] as bool?,
|
||||
),
|
||||
);
|
||||
try {
|
||||
return ApprovalDto.fromJson(map);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> _mapOrEmpty(dynamic value) =>
|
||||
value is Map<String, dynamic> ? value : const <String, dynamic>{};
|
||||
|
||||
Map<String, dynamic> _firstNonEmptyMap(List<dynamic> candidates) {
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is Map<String, dynamic> && candidate.isNotEmpty) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return const <String, dynamic>{};
|
||||
}
|
||||
|
||||
int _readQuantity(Object? value) {
|
||||
if (value is int) {
|
||||
return value;
|
||||
|
||||
@@ -49,9 +49,6 @@ class TransactionLineRepositoryRemote implements TransactionLineRepository {
|
||||
|
||||
@override
|
||||
Future<void> restoreLine(int lineId) async {
|
||||
await _api.post<void>(
|
||||
'$_linePath/$lineId/restore',
|
||||
);
|
||||
await _api.post<void>('$_linePath/$lineId/restore');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:superport_v2/features/approvals/domain/entities/approval.dart';
|
||||
|
||||
/// 재고 트랜잭션 도메인 엔티티
|
||||
///
|
||||
/// - 입고/출고/대여 공통으로 사용되는 헤더와 라인, 고객 연결 정보를 포함한다.
|
||||
@@ -33,7 +35,7 @@ class StockTransaction {
|
||||
final DateTime? updatedAt;
|
||||
final List<StockTransactionLine> lines;
|
||||
final List<StockTransactionCustomer> customers;
|
||||
final StockTransactionApprovalSummary? approval;
|
||||
final Approval? approval;
|
||||
final DateTime? expectedReturnDate;
|
||||
|
||||
int get itemCount => lines.length;
|
||||
@@ -57,7 +59,7 @@ class StockTransaction {
|
||||
DateTime? updatedAt,
|
||||
List<StockTransactionLine>? lines,
|
||||
List<StockTransactionCustomer>? customers,
|
||||
StockTransactionApprovalSummary? approval,
|
||||
Approval? approval,
|
||||
DateTime? expectedReturnDate,
|
||||
}) {
|
||||
return StockTransaction(
|
||||
@@ -200,32 +202,6 @@ class StockTransactionUomSummary {
|
||||
final String name;
|
||||
}
|
||||
|
||||
/// 결재 요약 정보
|
||||
class StockTransactionApprovalSummary {
|
||||
StockTransactionApprovalSummary({
|
||||
required this.id,
|
||||
required this.approvalNo,
|
||||
this.status,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final String approvalNo;
|
||||
final StockTransactionApprovalStatusSummary? status;
|
||||
}
|
||||
|
||||
/// 결재 상태 요약 정보
|
||||
class StockTransactionApprovalStatusSummary {
|
||||
StockTransactionApprovalStatusSummary({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.isBlocking,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final String name;
|
||||
final bool? isBlocking;
|
||||
}
|
||||
|
||||
extension StockTransactionLineX on List<StockTransactionLine> {
|
||||
/// 라인 품목 가격 총액을 계산한다.
|
||||
double get totalAmount =>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:superport_v2/features/approvals/domain/entities/approval.dart';
|
||||
|
||||
/// 재고 트랜잭션 생성 입력 모델.
|
||||
class StockTransactionCreateInput {
|
||||
StockTransactionCreateInput({
|
||||
@@ -10,7 +12,7 @@ class StockTransactionCreateInput {
|
||||
this.expectedReturnDate,
|
||||
this.lines = const [],
|
||||
this.customers = const [],
|
||||
this.approval,
|
||||
required this.approval,
|
||||
});
|
||||
|
||||
final int transactionTypeId;
|
||||
@@ -22,7 +24,7 @@ class StockTransactionCreateInput {
|
||||
final DateTime? expectedReturnDate;
|
||||
final List<TransactionLineCreateInput> lines;
|
||||
final List<TransactionCustomerCreateInput> customers;
|
||||
final StockTransactionApprovalInput? approval;
|
||||
final StockTransactionApprovalInput approval;
|
||||
|
||||
Map<String, dynamic> toPayload() {
|
||||
final sanitizedNote = note?.trim();
|
||||
@@ -43,7 +45,7 @@ class StockTransactionCreateInput {
|
||||
'expected_return_date': _formatNaiveDate(expectedReturnDate!),
|
||||
'lines': linePayloads,
|
||||
'customers': customerPayloads,
|
||||
if (approval != null) 'approval': approval!.toJson(),
|
||||
'approval': approval.toJson(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -213,20 +215,59 @@ class StockTransactionApprovalInput {
|
||||
StockTransactionApprovalInput({
|
||||
required this.requestedById,
|
||||
this.approvalStatusId,
|
||||
this.templateId,
|
||||
this.finalApproverId,
|
||||
this.requestedAt,
|
||||
this.decidedAt,
|
||||
this.cancelledAt,
|
||||
this.lastActionAt,
|
||||
this.title,
|
||||
this.summary,
|
||||
this.note,
|
||||
this.metadata,
|
||||
this.steps = const [],
|
||||
});
|
||||
|
||||
final int requestedById;
|
||||
final int? approvalStatusId;
|
||||
final int? templateId;
|
||||
final int? finalApproverId;
|
||||
final DateTime? requestedAt;
|
||||
final DateTime? decidedAt;
|
||||
final DateTime? cancelledAt;
|
||||
final DateTime? lastActionAt;
|
||||
final String? title;
|
||||
final String? summary;
|
||||
final String? note;
|
||||
final Map<String, dynamic>? metadata;
|
||||
final List<ApprovalStepAssignmentItem> steps;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final trimmedNote = note?.trim();
|
||||
return {
|
||||
if (approvalStatusId != null) 'approval_status_id': approvalStatusId,
|
||||
final trimmedTitle = title?.trim();
|
||||
final trimmedSummary = summary?.trim();
|
||||
final payload = <String, dynamic>{
|
||||
'requested_by_id': requestedById,
|
||||
if (approvalStatusId != null) 'approval_status_id': approvalStatusId,
|
||||
if (templateId != null) 'template_id': templateId,
|
||||
if (finalApproverId != null) 'final_approver_id': finalApproverId,
|
||||
if (requestedAt != null) 'requested_at': _formatIsoUtc(requestedAt!),
|
||||
if (decidedAt != null) 'decided_at': _formatIsoUtc(decidedAt!),
|
||||
if (cancelledAt != null) 'cancelled_at': _formatIsoUtc(cancelledAt!),
|
||||
if (lastActionAt != null) 'last_action_at': _formatIsoUtc(lastActionAt!),
|
||||
if (trimmedTitle != null && trimmedTitle.isNotEmpty)
|
||||
'title': trimmedTitle,
|
||||
if (trimmedSummary != null && trimmedSummary.isNotEmpty)
|
||||
'summary': trimmedSummary,
|
||||
if (trimmedNote != null && trimmedNote.isNotEmpty) 'note': trimmedNote,
|
||||
if (metadata != null && metadata!.isNotEmpty) 'metadata': metadata,
|
||||
};
|
||||
if (steps.isNotEmpty) {
|
||||
payload['steps'] = steps
|
||||
.map((item) => _mapApprovalStep(item))
|
||||
.toList(growable: false);
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,3 +277,14 @@ String _formatNaiveDate(DateTime value) {
|
||||
final day = value.day.toString().padLeft(2, '0');
|
||||
return '$year-$month-$day';
|
||||
}
|
||||
|
||||
String _formatIsoUtc(DateTime value) => value.toUtc().toIso8601String();
|
||||
|
||||
Map<String, dynamic> _mapApprovalStep(ApprovalStepAssignmentItem item) {
|
||||
final trimmedNote = item.note?.trim();
|
||||
return {
|
||||
'step_order': item.stepOrder,
|
||||
'approver_id': item.approverId,
|
||||
if (trimmedNote != null && trimmedNote.isNotEmpty) 'note': trimmedNote,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user