-- CONTRACT_MGMT 테이블에 수주 관련 컬럼 추가
-- 기존 컬럼 활용:
--   - 수주상태: contract_result (기존 컬럼 사용)
--   - 환종: contract_currency (기존 컬럼 사용)
--   - 환율: exchange_rate (기존 컬럼 사용)
--   - 발주번호: po_no (기존 컬럼 사용)

-- 수주 관련 신규 컬럼들
ALTER TABLE public.contract_mgmt ADD COLUMN IF NOT EXISTS order_date VARCHAR(50);
ALTER TABLE public.contract_mgmt ADD COLUMN IF NOT EXISTS order_unit_price NUMERIC(15,2);
ALTER TABLE public.contract_mgmt ADD COLUMN IF NOT EXISTS order_supply_price NUMERIC(15,2);
ALTER TABLE public.contract_mgmt ADD COLUMN IF NOT EXISTS order_vat NUMERIC(15,2);
ALTER TABLE public.contract_mgmt ADD COLUMN IF NOT EXISTS order_total_amount NUMERIC(15,2);

-- 컬럼 코멘트 추가
COMMENT ON COLUMN public.contract_mgmt.contract_result IS '영업진행상태 / 수주상태';
COMMENT ON COLUMN public.contract_mgmt.po_no IS '발주번호';
COMMENT ON COLUMN public.contract_mgmt.order_date IS '발주일';
COMMENT ON COLUMN public.contract_mgmt.order_unit_price IS '수주 단가';
COMMENT ON COLUMN public.contract_mgmt.order_supply_price IS '수주 공급가액';
COMMENT ON COLUMN public.contract_mgmt.order_vat IS '수주 부가세';
COMMENT ON COLUMN public.contract_mgmt.order_total_amount IS '수주 총액';
COMMENT ON COLUMN public.contract_mgmt.contract_currency IS '견적/수주 환종';
COMMENT ON COLUMN public.contract_mgmt.exchange_rate IS '견적/수주 환율';

-- 인덱스 추가 (선택사항)
CREATE INDEX IF NOT EXISTS idx_contract_result ON public.contract_mgmt(contract_result);
CREATE INDEX IF NOT EXISTS idx_contract_order_date ON public.contract_mgmt(order_date);

-- 조회 예시
-- SELECT objid, contract_no, contract_result, po_no, order_date, order_total_amount, contract_currency, exchange_rate
-- FROM public.contract_mgmt 
-- WHERE contract_result IS NOT NULL;

