feat(WEB): 회계 DevFill 개선 - 유형 검증 제거, 매입 결재선/참조 자동설정

- 입금/출금: depositType/withdrawalType 'unset' 검증 제거 (미설정 상태로 등록 가능)
- 매입(지출결의서):
  - 문서번호 자동 생성 (DEV-YYYYMMDD-HHMM-XXX)
  - 결재선: localStorage에서 현재 사용자 이름 매칭, 없으면 랜덤 선택
  - 참조: 경리/회계/재무 부서 직원 중 랜덤 1명 선택
This commit is contained in:
2026-01-22 20:38:03 +09:00
parent 0a133f7890
commit 0dd00d17f3
4 changed files with 154 additions and 13 deletions

View File

@@ -19,7 +19,9 @@ import {
updateApproval,
updateAndSubmitApproval,
deleteApproval,
getEmployees,
} from './actions';
import { useAuth } from '@/contexts/AuthContext';
import { Button } from '@/components/ui/button';
import { BasicInfoSection } from './BasicInfoSection';
import { ApprovalLineSection } from './ApprovalLineSection';
@@ -82,6 +84,7 @@ export function DocumentCreate() {
const router = useRouter();
const searchParams = useSearchParams();
const [isPending, startTransition] = useTransition();
const { currentUser } = useAuth();
// 수정 모드 / 복제 모드 상태
const documentId = searchParams.get('id');
@@ -121,21 +124,57 @@ export function DocumentCreate() {
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
// ===== DevFill: 자동 입력 기능 =====
useDevFill('purchaseApproval', useCallback(() => {
useDevFill('purchaseApproval', useCallback(async () => {
if (!isEditMode && !isCopyMode) {
const mockData = generatePurchaseApprovalData();
// 직원 목록 가져오기
const employees = await getEmployees();
// localStorage에서 실제 로그인 사용자 이름 가져오기 (우측 상단 표시와 동일한 소스)
const userDataStr = localStorage.getItem("user");
const currentUserName = userDataStr ? JSON.parse(userDataStr).name : currentUser?.name;
// 현재 사용자 이름으로 결재선에 추가할 직원 찾기
const approver = currentUserName
? employees.find(e => e.name === currentUserName)
: null;
// 경리/회계/재무 부서 직원 중 랜덤 1명 참조 추가
const accountingDepts = ['경리', '회계', '재무'];
const accountingStaff = employees.filter(e =>
accountingDepts.some(dept => e.department?.includes(dept))
);
const randomReference = accountingStaff.length > 0
? accountingStaff[Math.floor(Math.random() * accountingStaff.length)]
: null;
setBasicInfo(prev => ({
...prev,
...mockData.basicInfo,
draftDate: prev.draftDate || mockData.basicInfo.draftDate,
}));
// 결재선: 현재 사용자가 직원 목록에 있으면 설정, 없으면 랜덤 1명
if (approver) {
setApprovalLine([approver]);
} else if (employees.length > 0) {
const randomApprover = employees[Math.floor(Math.random() * employees.length)];
setApprovalLine([randomApprover]);
}
// 참조: 경리/회계/재무 직원이 있으면 설정
if (randomReference) {
setReferences([randomReference]);
}
setProposalData(prev => ({
...prev,
...mockData.proposalData,
}));
toast.success('지출결의서 데이터가 자동 입력되었습니다.');
}
}, [isEditMode, isCopyMode]));
}, [isEditMode, isCopyMode, currentUser?.name]));
// 수정 모드: 문서 로드
useEffect(() => {