-- ============================================================
-- 운영판 wace 211.115.91.141:11133 production_plan 1:1 추출
-- 추출일: 2026-05-13
-- 추출 명령: psql ... -c "\d production_plan"
--
-- 용도: 생산관리>M-BOM 관리 PR-A2 의 getProjectMgmtDetail.TOTAL_PROD_QTY 서브쿼리 의존
--   COALESCE((SELECT NULLIF(PP.TOTAL_PROD_QTY,'')::numeric
--             FROM PRODUCTION_PLAN PP
--             WHERE PP.PROJECT_OBJID = PM.OBJID
--               AND UPPER(PP.STATUS) = 'ACTIVE' LIMIT 1),
--            COALESCE(NULLIF(PM.QUANTITY,'')::numeric, 0)) AS TOTAL_PROD_QTY
-- ============================================================

CREATE TABLE IF NOT EXISTS public.production_plan (
    objid            character varying(50)  NOT NULL,
    project_objid    character varying(50),
    product_code     character varying(50),
    category_code    character varying(50),
    production_type  character varying(50),
    customer_objid   character varying(50),
    req_del_date     character varying(20),
    part_no          character varying(100),
    part_name        character varying(200),
    serial_no        character varying(500),
    order_qty        character varying(20) DEFAULT '0',
    extra_prod_qty   character varying(20) DEFAULT '0',
    total_prod_qty   character varying(20) DEFAULT '0',
    customer_request character varying(500),
    status           character varying(20) DEFAULT 'active',
    regdate          timestamp without time zone DEFAULT now(),
    writer           character varying(50),
    moddate          timestamp without time zone,
    modifier         character varying(50),
    CONSTRAINT production_plan_pkey PRIMARY KEY (objid)
);

CREATE INDEX IF NOT EXISTS idx_production_plan_customer ON public.production_plan USING btree (customer_objid);
CREATE INDEX IF NOT EXISTS idx_production_plan_project  ON public.production_plan USING btree (project_objid);
CREATE INDEX IF NOT EXISTS idx_production_plan_regdate  ON public.production_plan USING btree (regdate);
CREATE INDEX IF NOT EXISTS idx_production_plan_status   ON public.production_plan USING btree (status);
