번호 자동 부여 대응 및 API 공통 처리 보강

This commit is contained in:
JiWoong Sul
2025-10-23 14:02:31 +09:00
parent 09c31b2503
commit 7e933a2dda
55 changed files with 948 additions and 586 deletions

View File

@@ -80,6 +80,10 @@ class _RentalPageState extends State<RentalPage> {
String? _errorMessage;
Set<int> _processingTransactionIds = {};
String? _routeSelectedNumber;
String? _pendingDetailNumber;
bool _suppressNextRouteSelection = false;
late List<String> _statusOptions;
final Map<String, LookupItem> _statusLookup = {};
LookupItem? _rentTransactionType;
@@ -193,6 +197,26 @@ class _RentalPageState extends State<RentalPage> {
);
_refreshSelection();
});
final detailNumber = _pendingDetailNumber;
if (detailNumber != null) {
_pendingDetailNumber = null;
RentalRecord? matched;
for (final record in _records) {
if (record.transactionNumber == detailNumber) {
matched = record;
break;
}
}
if (matched != null) {
final target = matched;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) {
return;
}
_showDetailDialog(target);
});
}
}
}
@override
@@ -525,10 +549,7 @@ class _RentalPageState extends State<RentalPage> {
),
onRowTap: (rowIndex) {
final record = visibleRecords[rowIndex];
setState(() {
_selectedRecord = record;
});
_showDetailDialog(record);
_selectRecord(record, openDetail: true);
},
),
),
@@ -708,6 +729,24 @@ class _RentalPageState extends State<RentalPage> {
return records;
}
void _selectRecord(RentalRecord? record, {bool openDetail = false}) {
if (!mounted) return;
setState(() {
_selectedRecord = record;
});
final selectedNumber = record?.transactionNumber;
_routeSelectedNumber = selectedNumber;
_updateRoute(selected: selectedNumber);
if (openDetail && record != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) {
return;
}
_showDetailDialog(record);
});
}
}
List<String> _buildRecordRow(RentalRecord record) {
return [
record.number.split('-').last,
@@ -805,18 +844,14 @@ class _RentalPageState extends State<RentalPage> {
Future<void> _handleCreate() async {
final record = await _showRentalFormDialog();
if (record != null) {
setState(() {
_selectedRecord = record;
});
_selectRecord(record, openDetail: true);
}
}
Future<void> _handleEdit(RentalRecord record) async {
final updated = await _showRentalFormDialog(initial: record);
if (updated != null) {
setState(() {
_selectedRecord = updated;
});
_selectRecord(updated, openDetail: true);
}
}
@@ -1113,6 +1148,10 @@ class _RentalPageState extends State<RentalPage> {
(params['order'] ?? '').toLowerCase() == 'asc';
final pageSizeParam = int.tryParse(params['page_size'] ?? '');
final pageParam = int.tryParse(params['page'] ?? '');
final selectedParam = params['selected']?.trim();
final selectedNumber = selectedParam == null || selectedParam.isEmpty
? null
: selectedParam;
final warehouseId = warehouseIdParam;
final warehouseLabel = warehouseParam != null && warehouseParam.isNotEmpty
@@ -1166,6 +1205,13 @@ class _RentalPageState extends State<RentalPage> {
_sortAscending = resolvedSortAscending;
_pageSize = pageSize;
_currentPage = page;
_routeSelectedNumber = selectedNumber;
if (_suppressNextRouteSelection) {
_pendingDetailNumber = null;
} else {
_pendingDetailNumber = selectedNumber;
}
_suppressNextRouteSelection = false;
_refreshSelection();
}
@@ -1181,9 +1227,7 @@ class _RentalPageState extends State<RentalPage> {
void _goToPage(int page) {
final totalItems = _result?.total ?? _filteredRecords.length;
final totalPages = _calculateTotalPages(totalItems);
final int target = page < 1
? 1
: (page > totalPages ? totalPages : page);
final int target = page < 1 ? 1 : (page > totalPages ? totalPages : page);
if (target == _currentPage) {
return;
}
@@ -1201,6 +1245,16 @@ class _RentalPageState extends State<RentalPage> {
return;
}
final selectedNumber = _routeSelectedNumber;
if (selectedNumber != null) {
for (final record in filtered) {
if (record.transactionNumber == selectedNumber) {
_selectedRecord = record;
return;
}
}
}
final current = _selectedRecord;
if (current != null) {
RentalRecord? matched;
@@ -1222,7 +1276,7 @@ class _RentalPageState extends State<RentalPage> {
_selectedRecord = filtered.first;
}
void _updateRoute({int? page, int? pageSize}) {
void _updateRoute({int? page, int? pageSize, String? selected}) {
if (!mounted) return;
final targetPage = page ?? _currentPage;
final targetPageSize = pageSize ?? _pageSize;
@@ -1276,6 +1330,10 @@ class _RentalPageState extends State<RentalPage> {
if (targetPageSize != RentalTableSpec.pageSizeOptions.first) {
params['page_size'] = targetPageSize.toString();
}
final selectedNumber = selected ?? _selectedRecord?.transactionNumber;
if (selectedNumber != null && selectedNumber.isNotEmpty) {
params['selected'] = selectedNumber;
}
final uri = Uri(
path: widget.routeUri.path,
@@ -1289,6 +1347,7 @@ class _RentalPageState extends State<RentalPage> {
if (router == null) {
return;
}
_suppressNextRouteSelection = true;
router.go(newLocation);
}
@@ -1488,12 +1547,8 @@ class _RentalPageState extends State<RentalPage> {
final transactionTypeController = TextEditingController(
text: _transactionTypeForRental(rentalTypeValue.value),
);
final transactionNumberController = TextEditingController(
text: initial?.transactionNumber ?? '',
);
final approvalNumberController = TextEditingController(
text: initial?.raw?.approval?.approvalNo ?? '',
);
final assignedTransactionNo = initial?.transactionNumber;
final assignedApprovalNo = initial?.raw?.approval?.approvalNo;
final approvalNoteController = TextEditingController();
final drafts =
@@ -1505,8 +1560,6 @@ class _RentalPageState extends State<RentalPage> {
RentalRecord? result;
String? writerError;
String? transactionNumberError;
String? approvalNumberError;
String? customerError;
String? warehouseError;
String? statusError;
@@ -1538,10 +1591,6 @@ class _RentalPageState extends State<RentalPage> {
writerController: writerController,
writerSelection: writerSelection,
requireWriterSelection: initial == null,
transactionNumberController: transactionNumberController,
transactionNumberRequired: initial == null,
approvalNumberController: approvalNumberController,
approvalNumberRequired: initial == null,
warehouseSelection: warehouseSelection,
statusValue: statusValue.value,
selectedCustomers: customerSelection
@@ -1552,8 +1601,6 @@ class _RentalPageState extends State<RentalPage> {
);
writerError = validation.writerError;
transactionNumberError = validation.transactionNumberError;
approvalNumberError = validation.approvalNumberError;
customerError = validation.customerError;
warehouseError = validation.warehouseError;
statusError = validation.statusError;
@@ -1599,8 +1646,6 @@ class _RentalPageState extends State<RentalPage> {
final remarkText = remarkController.text.trim();
final remarkValue = remarkText.isEmpty ? null : remarkText;
final transactionNoValue = transactionNumberController.text.trim();
final approvalNoValue = approvalNumberController.text.trim();
final approvalNoteValue = approvalNoteController.text.trim();
final transactionId = initial?.id;
final initialRecord = initial;
@@ -1693,7 +1738,10 @@ class _RentalPageState extends State<RentalPage> {
if (!mounted) {
return;
}
SuperportToast.success(context, '대여 정보가 수정되었습니다.');
SuperportToast.success(
context,
'대여 정보가 수정되었습니다. (${updated.transactionNumber})',
);
navigator.pop();
return;
}
@@ -1728,7 +1776,6 @@ class _RentalPageState extends State<RentalPage> {
final transactionTypeId = selectedLookup.id;
final created = await controller.createTransaction(
StockTransactionCreateInput(
transactionNo: transactionNoValue,
transactionTypeId: transactionTypeId,
transactionStatusId: statusItem.id,
warehouseId: warehouseId,
@@ -1739,7 +1786,6 @@ class _RentalPageState extends State<RentalPage> {
lines: createLines,
customers: createCustomers,
approval: StockTransactionApprovalInput(
approvalNo: approvalNoValue,
requestedById: createdById,
note: approvalNoteValue.isEmpty ? null : approvalNoteValue,
),
@@ -1750,7 +1796,10 @@ class _RentalPageState extends State<RentalPage> {
if (!mounted) {
return;
}
SuperportToast.success(context, '대여가 등록되었습니다.');
SuperportToast.success(
context,
'대여가 등록되었습니다. (${created.transactionNumber})',
);
navigator.pop();
} catch (error) {
updateSaving(false);
@@ -1918,70 +1967,26 @@ class _RentalPageState extends State<RentalPage> {
),
SizedBox(
width: 240,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_FormFieldLabel(
label: '트랜잭션번호',
child: ShadInput(
controller: transactionNumberController,
readOnly: initial != null,
enabled: initial == null,
placeholder: const Text('예: RENT-2024-0001'),
onChanged: (_) {
if (transactionNumberError != null) {
setState(() {
transactionNumberError = null;
});
}
},
),
),
if (transactionNumberError != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
transactionNumberError!,
style: theme.textTheme.small.copyWith(
color: theme.colorScheme.destructive,
),
),
),
],
child: _FormFieldLabel(
label: '트랜잭션번호',
child: Text(
assignedTransactionNo ?? '저장 시 자동 생성',
style: assignedTransactionNo == null
? theme.textTheme.muted
: theme.textTheme.p,
),
),
),
SizedBox(
width: 240,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_FormFieldLabel(
label: '결재번호',
child: ShadInput(
controller: approvalNumberController,
readOnly: initial != null,
enabled: initial == null,
placeholder: const Text('예: APP-2024-0001'),
onChanged: (_) {
if (approvalNumberError != null) {
setState(() {
approvalNumberError = null;
});
}
},
),
),
if (approvalNumberError != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
approvalNumberError!,
style: theme.textTheme.small.copyWith(
color: theme.colorScheme.destructive,
),
),
),
],
child: _FormFieldLabel(
label: '결재번호',
child: Text(
assignedApprovalNo ?? '저장 시 자동 생성',
style: assignedApprovalNo == null
? theme.textTheme.muted
: theme.textTheme.p,
),
),
),
SizedBox(
@@ -2247,8 +2252,6 @@ class _RentalPageState extends State<RentalPage> {
writerController.dispose();
remarkController.dispose();
transactionTypeController.dispose();
transactionNumberController.dispose();
approvalNumberController.dispose();
approvalNoteController.dispose();
processedAt.dispose();
returnDue.dispose();
@@ -2523,10 +2526,6 @@ _RentalFormValidation _validateRentalForm({
required TextEditingController writerController,
required InventoryEmployeeSuggestion? writerSelection,
required bool requireWriterSelection,
required TextEditingController transactionNumberController,
required bool transactionNumberRequired,
required TextEditingController approvalNumberController,
required bool approvalNumberRequired,
required InventoryWarehouseOption? warehouseSelection,
required String statusValue,
required List<InventoryCustomerOption> selectedCustomers,
@@ -2535,8 +2534,6 @@ _RentalFormValidation _validateRentalForm({
}) {
var isValid = true;
String? writerError;
String? transactionNumberError;
String? approvalNumberError;
String? customerError;
String? warehouseError;
String? statusError;
@@ -2553,18 +2550,6 @@ _RentalFormValidation _validateRentalForm({
isValid = false;
}
final transactionNumber = transactionNumberController.text.trim();
if (transactionNumberRequired && transactionNumber.isEmpty) {
transactionNumberError = '거래번호를 입력하세요.';
isValid = false;
}
final approvalNumber = approvalNumberController.text.trim();
if (approvalNumberRequired && approvalNumber.isEmpty) {
approvalNumberError = '결재번호를 입력하세요.';
isValid = false;
}
if (warehouseSelection == null) {
warehouseError = '창고를 선택하세요.';
isValid = false;
@@ -2628,8 +2613,6 @@ _RentalFormValidation _validateRentalForm({
return _RentalFormValidation(
isValid: isValid,
writerError: writerError,
transactionNumberError: transactionNumberError,
approvalNumberError: approvalNumberError,
customerError: customerError,
warehouseError: warehouseError,
statusError: statusError,
@@ -2641,8 +2624,6 @@ class _RentalFormValidation {
const _RentalFormValidation({
required this.isValid,
this.writerError,
this.transactionNumberError,
this.approvalNumberError,
this.customerError,
this.warehouseError,
this.statusError,
@@ -2651,8 +2632,6 @@ class _RentalFormValidation {
final bool isValid;
final String? writerError;
final String? transactionNumberError;
final String? approvalNumberError;
final String? customerError;
final String? warehouseError;
final String? statusError;