-- 수주상태(CONTRACT_RESULT)에 코드 추가
-- 기존 코드 그룹: 0000963
-- 기존 코드: 0000964(수주), 0000968(수주(FCST))

-- 진행중 상태 추가
INSERT INTO COMM_CODE (OBJID, PARENT_CODE_ID, CODE_ID, CODE_NAME, CODE_VALUE, CODE_SORT_ORDER, CODE_USE_YN, CODE_DEPTH)
SELECT NEXTVAL('SEQ_OBJID'), '0000963', '0000965', '진행중', 'progress', 1, 'Y', 2
WHERE NOT EXISTS (SELECT 1 FROM COMM_CODE WHERE CODE_ID = '0000965');

-- Drop 상태 추가
INSERT INTO COMM_CODE (OBJID, PARENT_CODE_ID, CODE_ID, CODE_NAME, CODE_VALUE, CODE_SORT_ORDER, CODE_USE_YN, CODE_DEPTH)
SELECT NEXTVAL('SEQ_OBJID'), '0000963', '0000969', 'Drop', 'drop', 4, 'Y', 2
WHERE NOT EXISTS (SELECT 1 FROM COMM_CODE WHERE CODE_ID = '0000969');

-- Hold 상태 추가
INSERT INTO COMM_CODE (OBJID, PARENT_CODE_ID, CODE_ID, CODE_NAME, CODE_VALUE, CODE_SORT_ORDER, CODE_USE_YN, CODE_DEPTH)
SELECT NEXTVAL('SEQ_OBJID'), '0000963', '0000970', 'Hold', 'hold', 5, 'Y', 2
WHERE NOT EXISTS (SELECT 1 FROM COMM_CODE WHERE CODE_ID = '0000970');

-- Cancel 상태 추가
INSERT INTO COMM_CODE (OBJID, PARENT_CODE_ID, CODE_ID, CODE_NAME, CODE_VALUE, CODE_SORT_ORDER, CODE_USE_YN, CODE_DEPTH)
SELECT NEXTVAL('SEQ_OBJID'), '0000963', '0000971', 'Cancel', 'cancel', 6, 'Y', 2
WHERE NOT EXISTS (SELECT 1 FROM COMM_CODE WHERE CODE_ID = '0000971');

-- 기존 코드 정렬 순서 업데이트 (필요시)
UPDATE COMM_CODE SET CODE_SORT_ORDER = 2 WHERE CODE_ID = '0000968'; -- 수주(FCST)
UPDATE COMM_CODE SET CODE_SORT_ORDER = 3 WHERE CODE_ID = '0000964'; -- 수주

-- 결과 확인
SELECT CODE_ID, CODE_NAME, CODE_VALUE, CODE_SORT_ORDER 
FROM COMM_CODE 
WHERE PARENT_CODE_ID = '0000963' 
ORDER BY CODE_SORT_ORDER;
