86 lines
2.6 KiB
TypeScript
86 lines
2.6 KiB
TypeScript
import type { ElaprAplnRow } from "../model/elapr-apln-row-types";
|
|
|
|
const ATRZ_RECEIVER_CD = "ATRZ01";
|
|
const ATRZ_FINAL_CD = "ATRZ99";
|
|
|
|
export function getVisibleRows(rows: ElaprAplnRow[]): ElaprAplnRow[] {
|
|
return rows.filter((row) => !row.isDeleted);
|
|
}
|
|
|
|
/** 접수자·최종승인자 위치·중복 검증 (최종 저장 시점) */
|
|
export function validateAtrzOrder(rows: ElaprAplnRow[]): string | null {
|
|
const visibleRows = getVisibleRows(rows);
|
|
|
|
const receiverCount = visibleRows.filter((row) => row.atrzSeComCd === ATRZ_RECEIVER_CD).length;
|
|
if (receiverCount === 0) {
|
|
return "접수자는 반드시 등록해야 합니다.";
|
|
}
|
|
if (receiverCount > 1) {
|
|
return "접수자는 한 명만 등록할 수 있습니다.";
|
|
}
|
|
|
|
const finalCount = visibleRows.filter((row) => row.atrzSeComCd === ATRZ_FINAL_CD).length;
|
|
if (finalCount === 0) {
|
|
return "최종승인자는 반드시 등록해야 합니다.";
|
|
}
|
|
if (finalCount > 1) {
|
|
return "최종승인자는 한 명만 등록할 수 있습니다.";
|
|
}
|
|
|
|
if (receiverCount === 1 && visibleRows[0]?.atrzSeComCd !== ATRZ_RECEIVER_CD) {
|
|
return "접수자는 결재선 첫 번째에 배치해야 합니다.";
|
|
}
|
|
|
|
if (finalCount === 1) {
|
|
const lastRow = visibleRows[visibleRows.length - 1];
|
|
if (lastRow?.atrzSeComCd !== ATRZ_FINAL_CD) {
|
|
return "최종승인자는 결재선 마지막에 배치해야 합니다.";
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function validateAplnRow(row: ElaprAplnRow): string | null {
|
|
if (!row.atrzSeComCd?.trim()) {
|
|
return "결재구분을 선택해 주세요.";
|
|
}
|
|
if (!row.aprvrUuid?.trim()) {
|
|
return "결재자를 선택해 주세요.";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function validateAllRowsForSave(
|
|
rows: ElaprAplnRow[],
|
|
isEditingLocked: boolean,
|
|
): string | null {
|
|
if (isEditingLocked) {
|
|
return "편집 중인 행을 먼저 저장하거나 취소해 주세요.";
|
|
}
|
|
|
|
const visibleRows = getVisibleRows(rows);
|
|
if (visibleRows.length === 0) {
|
|
return "저장할 결재선이 없습니다.";
|
|
}
|
|
|
|
for (const row of visibleRows) {
|
|
const fieldError = validateAplnRow(row);
|
|
if (fieldError) return fieldError;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function validateUniqueSeqNo(rows: ElaprAplnRow[]): string | null {
|
|
const seqSet = new Set<number>();
|
|
for (const row of getVisibleRows(rows)) {
|
|
if (row.atrzSeqNo == null) continue;
|
|
if (seqSet.has(row.atrzSeqNo)) {
|
|
return "동일 서식 내 결재순서번호가 중복됩니다.";
|
|
}
|
|
seqSet.add(row.atrzSeqNo);
|
|
}
|
|
return null;
|
|
}
|