<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "分切管理">
<query id = "FrmSplittingManage.doQuery" desc = "查询">
SELECT 
       DECODE(T.PRODUCT_FLAG,'801401','在制品','801402','成品','801403','商品')PRODUCT_FLAG,
       DECODE(T.MAT_STATUS,'80150101','材料产出待判','80150102','材料产出(已判定)','80150103','材料已编计划','80150104','材料待处理','80150105','材料加工','80150201','材料产出待判（未综合判定）','80150202','材料产出（已综合判定）')MAT_STATUS,
       T.STOVE_NO,
       T.LOT_NO,
       T.FLAG_STOVE_NO_ZG,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.PRO_PLAN_ID_NEXT,
       T.GX_PLAN_NO_NEXT,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       MAX(T.PRODUCCODE)PRODUCCODE,
       MAX(T.PRODUCNAME)PRODUCNAME,
       MAX(T.STEELCODE)STEELCODE,
       MAX(T.STEELNAME)STEELNAME,
       MAX(T.GRADECODE)GRADECODE,
       MAX(T.GRADENAME)GRADENAME,
       MAX(T.SPEC_CODE)SPEC_CODE,
       MAX(T.SPEC_NAME)SPEC_NAME,
       MAX(T.MODEL_CODE)MODEL_CODE,
       MAX(T.MODEL_DESC)MODEL_DESC,
       MAX(T.STD_CODE)STD_CODE,
       MAX(T.STD_NAME)STD_NAME,
       MAX(T.STD_STYLE)STD_STYLE,
       MAX(T.STD_STYLE_DESC)STD_STYLE_DESC,
       T.PRO_ORDER_ID,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       MAX(TO_CHAR(T.INSTOCK_TIME,'YYYY-MM-DD'))INSTOCK_TIME,
       MAX(TO_CHAR(T.JUDGE_RESULT_TIME,'YYYY-MM-DD'))JUDGE_RESULT_TIME,
       MAX(T.PLINE_CODE)PLINE_CODE,
       MAX(T.PLINE_NAME)PLINE_NAME,
       MAX(T.ACT_DIMATER)ACT_DIMATER,
       MAX(T.ACT_HEIGHT)ACT_HEIGHT,
       MAX(T.ACT_LEN)ACT_LEN,
       MAX(T.ACT_LEN_MIN)ACT_LEN_MIN,
       MAX(T.ACT_LEN_MAX)ACT_LEN_MAX,
       SUM(T.ACT_COUNT)ACT_COUNT,
       SUM(T.ACT_WEIGHT)ACT_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       MAX(T.BAL_YEAR_MONTH)BAL_YEAR_MONTH,
       MAX(T.TARGET)TARGET,
       DECODE(T.QCM_STAUS,'00','合格','11','待处理','22','判废')QCM_STAUS,
       T.GX_PLAN_NO,
       MAX(T.PRO_ORDER_NO)PRO_ORDER_NO,
       MAX(T.JUDGE_RESULT_CODE)SPEC_RESULT_CODE,
       MAX((SELECT S.BASENAME FROM COM_BASE_INFO S WHERE S.BASECODE = T.JUDGE_RESULT_CODE))JUDGE_RESULT_CODE,
       
       (SELECT S1.STORAGE_NAME FROM YDM_BS_STORAGE S1 WHERE S1.STORAGE_NO = S.STORAGE_NO)STORAGE_NAME,
       S.STORAGE_NO,
       MAX(T.NEXT_PROCESS_CDOE)NEXT_PROCESS_CDOE,
       MAX(T.NEXT_PROCESS_DESC)NEXT_PROCESS_DESC,
       MAX(T.CRAF_NO)CRAF_NO,
       MAX(T.JUDGE_STD_DES)JUDGE_STD_DES,
       T.JUDGE_RESULT,
       T.MEMO,
       T.MEMO AS UPDATE_MEMO,
       MAX(CASE
         WHEN T.NEXT_PROCESS_CDOE = 'E' THEN
          (SELECT T1.ORDER_NO || '/' || T1.ORDER_SEQ
             FROM PLN_ORDER_DBK_S T1
            WHERE T1.PRO_PLAN_ID = T.PRO_PLAN_ID_NEXT
              AND T1.GX_PLAN_NO = T.GX_PLAN_NO_NEXT)
         WHEN T.NEXT_PROCESS_CDOE = 'F' THEN
          (SELECT T2.ORDER_NO || '/' || T2.ORDER_SEQ
             FROM PLN_ORDER_RCL_S T2
            WHERE T2.PRO_PLAN_ID = T.PRO_PLAN_ID_NEXT
              AND T2.GX_PLAN_NO = T.GX_PLAN_NO_NEXT)
         WHEN T.NEXT_PROCESS_CDOE = 'G' THEN
          (SELECT T3.ORDER_NO || '/' || T3.ORDER_SEQ
             FROM PLN_ORDER_JGX_S T3
            WHERE T3.PRO_PLAN_ID = T.PRO_PLAN_ID_NEXT
              AND T3.GX_PLAN_NO = T.GX_PLAN_NO_NEXT)
         ELSE
          NULL
       END) ORDER_NO_NEXT,
       MAX(DECODE(T.INSTANCY_FLAG,'0','否','1','是'))INSTANCY_FLAG
 FROM MAT_BC_M T LEFT JOIN YDM_BC_BUTTRESS S
 ON T.MAT_NO = S.MAT_NO
 WHERE 1 = 1
 AND ((T.JUDGE_RESULT_CODE IN('40740701','40740709') AND T.QCM_STAUS = '00')OR(T.QCM_STAUS = '22'))
 AND T.PRODUCT_FLAG = '801401'
 AND T.PRO_PLAN_ID_NEXT IS NULL
 #BAL_YEAR_MONTH#
 #JUDGE_STOVE_NO#
 --#BELONG_CODE#
 #GROUP#

</query>
<query id = "FrmSplittingManage.doQueryCount" desc = "查询余材信息">
SELECT COUNT(1) ACOUNT
  FROM MAT_BC_M T, YDM_BC_BUTTRESS S
 WHERE T.MAT_NO = S.MAT_NO
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
   AND T.PRO_PLAN_ID_NEXT IS NULL
   AND T.QCM_STAUS = '00'
   AND T.JUDGE_RESULT_CODE IN('40740701','40740709')
</query>
<query id = "FrmSplittingManage.doQueryWgt" desc = "查询单支重量">
SELECT T.ACT_WEIGHT,T.ACT_LEN
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
   AND T.ACT_LEN = '#ACT_LEN#'
   AND T.PRO_PLAN_ID_NEXT IS NULL
   AND T.QCM_STAUS = '00'
   AND T.JUDGE_RESULT_CODE IN('40740701','40740709')
   AND ROWNUM = 1
</query>
<query id = "FrmSplittingManage.insertMatBcSpilit" desc = "分切写库存表">
DECLARE
  V_PLINE_CODE MAT_BC_M.PLINE_CODE%TYPE := NULL;
  V_PLINE_NAME MAT_BC_M.PLINE_NAME%TYPE := NULL;
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM MAT_BC_BACKUP T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.QCM_STAUS = '00'
                   AND T.BELONG_CODE = '002001001'
                   AND ROWNUM = 1) LOOP
    IF (MYROW.PLINE_CODE = '100101' OR MYROW.PLINE_CODE = '100102' OR
       MYROW.PLINE_CODE = '100103') THEN
      IF (MYROW.PROCESS_CDOE = 'D') THEN
        V_PLINE_CODE := 'C008';
        V_PLINE_NAME := '250机组';
      ELSIF (MYROW.PROCESS_CDOE = 'F') THEN
        V_PLINE_CODE := 'C022';
        V_PLINE_NAME := '热处理01#（管加工1号热）';
      END IF;
    ELSE
      V_PLINE_CODE := MYROW.PLINE_CODE;
      V_PLINE_NAME := MYROW.PLINE_NAME;
    END IF;
    INSERT INTO MAT_BC_M
      (MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       SAMPLE_FLAG,
       MATERIAL_NO,
       MATERIAL_NAME,
       INPUT_MATERIAL_NAME,
       INPUT_MATERIAL_NO,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       CRAF_NO,
       PROCESS_CDOE,
       PROCESS_DESC,
       PLINE_CODE,
       PLINE_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       MAT_GOWHERE_CODE,
       MAT_GOWHERE_NAME,
       JUGDE_APPLY_CODE,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_RESULT_TIME,
       JUDGE_MAKER,
       INSTOCK_FLAG,
       INSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       BAL_YEAR_MONTH,
       JUDGE_STD_NAME,
       SOURE_CODE,
       SOURE_NAME,
       QCM_STAUS,
       HEAT_PLAN_NO,
       GX_PLAN_NO,
       TARGET,
       PROCESS_STATUS,
       JUGDE_CONVICTED,
       FLAG_STOVE_NO_ZG,
       TESTING_GRADE,
       TESTING_TYPE,
       TESTING_GRADE1,
       TESTING_TYPE1,
       JUDGE_STOVE_NO_UP,
       CRAFT_SEQ,
       CUT_NUM,
       INSTANCY_FLAG,
       JUDGE_STD_DES,
       JUGDE_APPLY_SEQUENO,
       CODE_JG_BL,
       CIC,
       HEAT_PLAN_NO_OLD)
    VALUES
      ('#MAT_NO#',
       MYROW.PRODUCT_FLAG,
       '80150102',
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.SAMPLE_FLAG,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.INPUT_MATERIAL_NAME,
       MYROW.INPUT_MATERIAL_NO,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.PRO_ORDER_NO,
       MYROW.PRO_ORDER_ID,
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.CRAF_NO,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       '#ACT_LEN#',
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       '#ACT_COUNT#',
       '#ACT_WEIGHT#',
       '#ACT_WEIGHT#',
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       MYROW.MAT_GOWHERE_CODE,
       MYROW.MAT_GOWHERE_NAME,
       MYROW.JUGDE_APPLY_CODE,
       MYROW.JUDGE_RESULT_CODE,
       MYROW.JUDGE_RESULT,
       MYROW.JUDGE_RESULT_TIME,
       MYROW.JUDGE_MAKER,
       MYROW.INSTOCK_FLAG,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       '#BAL_YEAR_MONTH#',
       MYROW.JUDGE_STD_NAME,
       MYROW.SOURE_CODE,
       MYROW.SOURE_NAME,
       MYROW.QCM_STAUS,
       MYROW.HEAT_PLAN_NO,
       MYROW.GX_PLAN_NO,
       MYROW.TARGET,
       MYROW.PROCESS_STATUS,
       MYROW.JUGDE_CONVICTED,
       MYROW.FLAG_STOVE_NO_ZG,
       MYROW.TESTING_GRADE,
       MYROW.TESTING_TYPE,
       MYROW.TESTING_GRADE1,
       MYROW.TESTING_TYPE1,
       MYROW.JUDGE_STOVE_NO_UP,
       MYROW.CRAFT_SEQ,
       MYROW.CUT_NUM,
       MYROW.INSTANCY_FLAG,
       MYROW.JUDGE_STD_DES,
       MYROW.JUGDE_APPLY_SEQUENO,
       MYROW.CODE_JG_BL,
       MYROW.CIC,
       MYROW.HEAT_PLAN_NO_OLD);
    INSERT INTO YDM_BC_BUTTRESS
      (MAT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       CREATE_NAME,
       CREATE_TIME)
    VALUES
      ('#MAT_NO#',
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       '#STORAGE_NO#',
       '#STORAGE_NO#' || '10101',
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO YDM_BC_INLIST
      (INSTOCK_SQE,
       INSTOCK_DOC,
       INSTOCK_TYPE_CODE,
       INSTOCK_TYPE_NAME,
       MAT_NO,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       GRADECODE,
       GRADENAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       PRO_ORDER_NO,
       PLINE_CODE,
       PLINE_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       INSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       IN_TIME_F,
       BAL_YEAR_MONTH,
       QCM_STAUS,
       CUT_FLAG)
    VALUES
      ('#INSTOCK_SQE#',
       '#INSTOCK_DOC#',
       '800706',
       '改判入库',
       '#MAT_NO#',
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.PRO_ORDER_NO,
       V_PLINE_CODE,
       V_PLINE_NAME,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       '#ACT_LEN#',
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       '#ACT_COUNT#',
       '#ACT_WEIGHT#',
       '#ACT_WEIGHT#',
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       MYROW.JUDGE_STD_DES,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#BAL_YEAR_MONTH#',
       MYROW.QCM_STAUS,
       '1');
  END LOOP;
END;
</query>
<query id = "FrmSplittingManage.insertOut" desc = "产权出库">
<![CDATA[
DECLARE
  V_OUTSTOCK_SQE YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL;
  V_COUNT        NUMBER := 1;
  V_PLINE_CODE   MAT_BC_M.PLINE_CODE%TYPE := NULL;
  V_PLINE_NAME   MAT_BC_M.PLINE_NAME%TYPE := NULL;
BEGIN
  SELECT LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_SQE, LENGTH(T.OUTSTOCK_SQE) - 3)),
                  0) + 1,
              4,
              0) OUTSTOCK_SQE
    INTO V_COUNT
    FROM YDM_BC_OUTLIST T
   WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#';

  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*,
                               S.STORAGE_NO,
                               S.LOCATION_NO,
                               S.LARY_NO,
                               S.LOC_NO,
                               S.STORAGE_ATTR,
                               S.STORAGE_ATTR_NAME,
                               S.STORAGE_TYPE_NO,
                               S.STORAGE_TYPE_NAME,
                               S.MANAGEMENT_NO,
                               S.MANAGEMENT_NAME,
                               S.DEPARTMENT_CODE,
                               S.DEPARTMENT_DESC
                          FROM MAT_BC_M T, YDM_BC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                              --AND T.ACT_LEN = '#ACT_LEN#'
                           AND T.QCM_STAUS = '00'
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    IF (MYROW.PLINE_CODE = '100101' OR MYROW.PLINE_CODE = '100102' OR
       MYROW.PLINE_CODE = '100103') THEN
      IF (MYROW.PROCESS_CDOE = 'D') THEN
        V_PLINE_CODE := 'C008';
        V_PLINE_NAME := '250机组';
      ELSIF (MYROW.PROCESS_CDOE = 'E') THEN
        V_PLINE_CODE := 'C018';
        V_PLINE_NAME := '720旋扩';
      ELSIF (MYROW.PROCESS_CDOE = 'F') THEN
        V_PLINE_CODE := 'C022';
        V_PLINE_NAME := '热处理01#（管加工1号热）';
      END IF;
    ELSE
      V_PLINE_CODE := MYROW.PLINE_CODE;
      V_PLINE_NAME := MYROW.PLINE_NAME;
    END IF;
    V_OUTSTOCK_SQE := '#OUTSTOCK_DOC#' || LPAD(V_COUNT, 4, 0);
    INSERT INTO YDM_BC_OUTLIST
      (OUTSTOCK_SQE,
       OUTSTOCK_DOC,
       OUTSTOCK_TYPE_CODE,
       OUTSTOCK_TYPE_NAME,
       MAT_NO,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       GRADECODE,
       GRADENAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       PRO_ORDER_NO,
       PLINE_CODE,
       PLINE_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       LOC_NO,
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       INSTOCK_TIME,
       OUTSTOCK_TIME,
       MEMO,
       CREATE_NAME,
       CREATE_TIME,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       BAL_YEAR_MONTH,
       QCM_STAUS,
       CUT_FLAG)
    VALUES
      (V_OUTSTOCK_SQE,
       '#OUTSTOCK_DOC#',
       '800808',
       '改判出库',
       MYROW.MAT_NO,
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.PRO_ORDER_NO,
       V_PLINE_CODE,
       V_PLINE_NAME,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.LOC_NO,
       MYROW.STORAGE_ATTR,
       MYROW.STORAGE_ATTR_NAME,
       MYROW.STORAGE_TYPE_NO,
       MYROW.STORAGE_TYPE_NAME,
       MYROW.MANAGEMENT_NO,
       MYROW.MANAGEMENT_NAME,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.MEMO,
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       MYROW.JUDGE_STD_NAME,
       '#BAL_YEAR_MONTH#',
       MYROW.QCM_STAUS,
       '1');
    INSERT INTO MAT_BC_BACKUP
      SELECT *
        FROM MAT_BC_M T
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.PLINE_CODE = MYROW.PLINE_CODE;
    DELETE FROM MAT_BC_M T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
    DELETE FROM YDM_BC_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
    V_COUNT := V_COUNT + 1;
  END LOOP;
END;
]]>
</query>
<query id  = "FrmSplittingManage.doQueryMatNo" desc = "生成材料号">
SELECT ? || ? ||
       LPAD(NVL(MAX(SUBSTR(T2.MAT_NO, LENGTH(T2.MAT_NO) - 3)), 0) + 1, 4, 0) MAT_NO
  FROM (SELECT MAX(T.MAT_NO) MAT_NO
          FROM MAT_BC_M T
         WHERE T.MAT_NO LIKE ? || ? || '____'
        UNION ALL
        SELECT MAX(T3.MAT_NO) MAT_NO
          FROM MAT_BC_BACKUP T3
         WHERE T3.MAT_NO LIKE ? || ? || '____') T2
</query>
<query id = "FrmSplittingManage.doQueryInDoc" desc = "生成入库单号">
SELECT 'IP' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 9)), 0) + 1, 5, 0) INSTOCK_DOC
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_TYPE_CODE = '800706'
     AND T.INSTOCK_DOC LIKE 'IP' || TO_CHAR(SYSDATE, 'YYMMDD') || '_____'
</query>
<query id = "FrmSplittingManage.doQueryOutDoc" desc = "生成出库单号">
SELECT 'OP' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) OUTSTOCK_DOC
    FROM YDM_BC_OUTLIST T
   WHERE T.OUTSTOCK_TYPE_CODE = '800808'
     AND T.OUTSTOCK_DOC LIKE 'OP' || TO_CHAR(SYSDATE, 'YYMMDD') || '_____'
</query>
<query id = "FrmSplittingManage.doQueryPline" desc = "获取产线">
SELECT T.PLINE_NAME, T.PLINE_CODE
  FROM COM_BASE_PLINE T
 WHERE T.PROCESS_CODE IN ('D', 'E', 'F', 'G')
 ORDER BY T.PLINE_CODE ASC
</query>
<query id = "FrmSplittingManage.selectProcess" desc = "查询工序代码">
SELECT T.PROCESS_CODE, T.PROCESS_DESC,T.DEPARTMENT_CODE,T.DEPARTMENT_DESC
  FROM COM_BASE_PLINE T
 WHERE T.PLINE_CODE = '#NEW_PLINE_CODE#'

</query>
<query id = "FrmSplittingManage.scrapToOk" desc = "不合转合">
<![CDATA[
UPDATE MAT_BC_M T
   SET T.PLINE_CODE   = '#NEW_PLINE_CODE#',
       T.PLINE_NAME   = '#NEW_PLINE_NAME#',
       T.BELONG_CODE  = '#BELONG_CODE#',
       T.BELONG_NAME  = '#BELONG_NAME#',
       T.PROCESS_CDOE = '#PROCESS_CDOE#',
       T.PROCESS_DESC = '#PROCESS_DESC#',
       T.JUDGE_RESULT_CODE = '',
       T.JUDGE_RESULT = '',
       T.QCM_STAUS    = '00',
       T.SCRAP_FLAG = '1'
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
   AND T.PLINE_CODE = '#PLINE_CODE#'
   AND T.QCM_STAUS = '22'
   AND ROWNUM <= #ACT_COUNT#
   ]]>
</query>
</queryMap>