<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "手工上料">
<query id = "FrmLoadMatData.doQueryMatM" desc = "查询库存信息">
SELECT T1.*,
       (CASE
         WHEN T1.NEXT_PROCESS_CDOE = 'E' THEN
          (SELECT S1.PLINE_CODE
             FROM PLN_ORDER_DBK_S S1
            WHERE S1.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
              AND S1.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
         WHEN T1.NEXT_PROCESS_CDOE = 'F' THEN
          (SELECT S2.PLINE_CODE
             FROM PLN_ORDER_RCL_S S2
            WHERE S2.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
              AND S2.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
         WHEN T1.NEXT_PROCESS_CDOE = 'G' THEN
          (SELECT S3.PLINE_CODE
             FROM PLN_ORDER_JGX_S S3
            WHERE S3.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
              AND S3.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
          WHEN T1.NEXT_PROCESS_CDOE = 'H' THEN
          (SELECT S4.PLINE_CODE
             FROM PLN_GX_JG_PROP_S S4
            WHERE S4.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
              AND S4.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
       END) PLINE_CODE_NEXT,
       (CASE
         WHEN T1.NEXT_PROCESS_CDOE = 'E' THEN
          (SELECT S1.PLINE_NAME
             FROM PLN_ORDER_DBK_S S1
            WHERE S1.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
              AND S1.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
         WHEN T1.NEXT_PROCESS_CDOE = 'F' THEN
          (SELECT S2.PLINE_NAME
             FROM PLN_ORDER_RCL_S S2
            WHERE S2.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
              AND S2.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
         WHEN T1.NEXT_PROCESS_CDOE = 'G' THEN
          (SELECT S3.PLINE_NAME
             FROM PLN_ORDER_JGX_S S3
            WHERE S3.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
              AND S3.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
              WHEN T1.NEXT_PROCESS_CDOE = 'H' THEN
          (SELECT S4.PLINE_NAME
             FROM PLN_GX_JG_PROP_S S4
            WHERE S4.PRO_PLAN_ID = T1.PRO_PLAN_ID_NEXT
              AND S4.GX_PLAN_NO = T1.GX_PLAN_NO_NEXT)
       END) PLINE_NAME_NEXT
  FROM (SELECT DECODE(T.PRODUCT_FLAG,
                      '801401',
                      '在制品',
                      '801402',
                      '成品',
                      '801403',
                      '商品') PRODUCT_FLAG,
               T.STOVE_NO,
               T.LOT_NO,
               T.JUDGE_STOVE_NO,
               T.BATCH_NO,
               T.BATCH_GROUD_NO,
               MAX(T.MATERIAL_NO) MATERIAL_NO,
               MAX(T.MATERIAL_NAME) 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,
               MAX(TO_CHAR(T.INSTOCK_TIME,'YYYY-MM-DD'))INSTOCK_TIME,
               T.PRO_ORDER_ID,
               T.PROCESS_CDOE,
               T.PROCESS_DESC,
               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_COUNT) LOAD_ACT_COUNT,
               SUM(T.ACT_WEIGHT) ACT_WEIGHT,
               SUM(T.PONDER_GROSS_WT) PONDER_GROSS_WT,
               T.BELONG_CODE,
               T.BELONG_NAME,
               MAX(T.BAL_YEAR_MONTH) BAL_YEAR_MONTH,
               MAX(T.TARGET) TARGET,
               MAX(T.QCM_STAUS) QCM_STAUS,
               T.GX_PLAN_NO,
               MAX(T.PRO_ORDER_NO) PRO_ORDER_NO,
               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,
               T.PRO_PLAN_ID_NEXT,
               T.GX_PLAN_NO_NEXT,
               T.MEMO,
               MAX(T.CRAF_NO)CRAF_NO,
               MAX(T.JUDGE_STD_DES)JUDGE_STD_DES,
               MAX(TO_CHAR(T.JUDGE_RESULT_TIME,'YYYY-MM-DD HH:MM:SS'))JUDGE_RESULT_TIME
          FROM MAT_BC_M T
          LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
         WHERE 1 = 1
           AND T.PRODUCT_FLAG = '801401'
           AND T.QCM_STAUS = '00'
           AND (T.JUDGE_RESULT_CODE IS NOT NULL OR (T.JUDGE_RESULT_CODE IS NULL AND T.INSTANCY_FLAG = '1'))
           #JUDGE_STOVE_NO#
         GROUP BY T.PRODUCT_FLAG,
                  T.LOT_NO,
                  T.JUDGE_STOVE_NO,
                  T.BATCH_NO,
                  T.BATCH_GROUD_NO,
                  T.STOVE_NO,
                  T.PRO_ORDER_ID,
                  T.QCM_STAUS,
                  T.PRO_ORDER_NO,
                  S.STORAGE_NO,
                  T.PRO_PLAN_ID_NEXT,
                  T.GX_PLAN_NO_NEXT,
                  T.PROCESS_CDOE,
                  T.PROCESS_DESC,
                  T.PLINE_CODE,
                  T.PLINE_NAME,
                  T.BELONG_CODE,
                  T.BELONG_NAME,
                  T.GX_PLAN_NO,
                  T.MEMO) T1
</query>
<query id = "FrmLoadMatData.doQueryOutList" desc = "查询出库记录">
SELECT 
       T.OUTSTOCK_DOC,
       MAX(T.OUTSTOCK_TYPE_CODE)OUTSTOCK_TYPE_CODE,
       MAX(T.OUTSTOCK_TYPE_NAME)OUTSTOCK_TYPE_NAME,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MEMO,
       MAX(T.MATERIAL_NO)MATERIAL_NO,
       MAX(T.MATERIAL_NAME)MATERIAL_NAME,
       MAX(T.PRODUCCODE)PRODUCCODE,
       MAX(T.PRODUCNAME)PRODUCNAME,
       MAX(T.STD_CODE)STD_CODE,
       MAX(T.STD_NAME)STD_NAME,
       MAX(T.GRADECODE)GRADECODE,
       MAX(T.GRADENAME)GRADENAME,
       MAX(T.STEELCODE)STEELCODE,
       MAX(T.STEELNAME)STEELNAME,
       MAX(T.STD_STYLE)STD_STYLE,
       MAX(T.STD_STYLE_DESC)STD_STYLE_DESC,
       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.PRO_ORDER_NO)PRO_ORDER_NO,
       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,
       MAX(T.BELONG_CODE)BELONG_CODE,
       MAX(T.BELONG_NAME)BELONG_NAME,
       MAX((SELECT S.STORAGE_NAME FROM YDM_BS_STORAGE S WHERE S.STORAGE_NO = T.STORAGE_NO))STORAGE_NO,
       MAX(T.LOCATION_NO)LOCATION_NO,
       MAX(T.LARY_NO)LARY_NO,
       MAX(T.LOC_NO)LOC_NO,
       MAX(TO_CHAR(T.OUTSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) OUTSTOCK_TIME,
       MAX(T.CREATE_NAME)CREATE_NAME,
       MAX(TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       MAX(T.BAL_YEAR_MONTH)BAL_YEAR_MONTH,
       MAX(T.LOAD_PLINE_CODE)LOAD_PLINE_CODE,
       MAX(T.LOAD_PLINE_NAME)LOAD_PLINE_NAME
 FROM YDM_BC_OUTLIST T
 WHERE T.OUTSTOCK_TYPE_CODE IN('800801','800804')
</query>
<query id = "FrmLoadMatData.getOutListDoc" desc = "查询出库单号">
SELECT (SELECT S.MEMO
          FROM COM_BASE_INFO S
         WHERE S.BASECODE = ?) || OUTSTOCK_DOC OUTSTOCK_DOC
  FROM (SELECT 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 = ?
           AND T.OUTSTOCK_DOC LIKE (SELECT S.MEMO FROM COM_BASE_INFO S WHERE S.BASECODE = ?) || TO_CHAR(SYSDATE, 'YYMMDD') || '_____')
</query>
<query id = "FrmLoadMatData.loadMatBcMData" desc = "上料出库">
<![CDATA[
DECLARE
  V_TL_SEQ YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL;
  V_CQ_SEQ YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL;
  V_TLCOUNT NUMBER := 1;
  V_CQCOUNT NUMBER := 1;
  V_PLINE_CODE YDM_BC_OUTLIST.PLINE_CODE%TYPE := NULL;
  V_PLINE_NAME YDM_BC_OUTLIST.PLINE_NAME%TYPE := NULL;
BEGIN
  SELECT NVL(MAX(SUBSTR(T.OUTSTOCK_SQE, LENGTH(T.OUTSTOCK_SQE) - 3)), 0) + 1
    INTO V_TLCOUNT
    FROM YDM_BC_OUTLIST T
   WHERE T.OUTSTOCK_DOC = '#TL_OUTSTOCK_DOC#';

  SELECT NVL(MAX(SUBSTR(T.OUTSTOCK_SQE, LENGTH(T.OUTSTOCK_SQE) - 3)), 0) + 1
    INTO V_CQCOUNT
    FROM YDM_BC_OUTLIST T
   WHERE T.OUTSTOCK_DOC = '#CQ_OUTSTOCK_DOC#';
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*,
                               S.STORAGE_NO,
                               S.LOCATION_NO,
                               S.LARY_NO,
                               S.LOC_NO
                          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.QCM_STAUS = '00'
                           AND T.BELONG_CODE = '#BELONG_CODE#'
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                           AND S.STORAGE_NO = '#STORAGE_NO#'
                           AND (T.JUDGE_RESULT_CODE IN('40740701','40740706','40740702','40740709') OR (T.JUDGE_RESULT_CODE IS NULL AND T.INSTANCY_FLAG = '1'))
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #LOAD_ACT_COUNT#) LOOP
    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;
    V_TL_SEQ := '#TL_OUTSTOCK_DOC#' || LPAD(V_TLCOUNT,4,0);
    V_CQ_SEQ := '#CQ_OUTSTOCK_DOC#' || LPAD(V_CQCOUNT,4,0);
    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;
    --投料出库
     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,
        BELONG_CODE,
        BELONG_NAME,
        STORAGE_NO,
        LOCATION_NO,
        LARY_NO,
        LOC_NO,
        INSTOCK_TIME,
        OUTSTOCK_TIME,
        OUT_BC,
        OUT_BZ,
        HAND_FLAG,
        CREATE_NAME,
        CREATE_TIME,
        PRODUCT_FLAG,
        MAT_STATUS,
        JUDGE_STD_NAME,
        BAL_YEAR_MONTH,
        LOAD_PLINE_CODE,
        LOAD_PLINE_NAME,
        MEMO,
        PROCESS_CDOE,
        PROCESS_DESC)
 VALUES( 
        V_TL_SEQ,
        '#TL_OUTSTOCK_DOC#',
        '#OUTSTOCK_TYPE_CODE#',
        '#OUTSTOCK_TYPE_NAME#',
        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.BELONG_CODE,
        MYROW.BELONG_NAME,
        MYROW.STORAGE_NO,
        MYROW.LOCATION_NO,
        MYROW.LARY_NO,
        MYROW.LOC_NO,
        MYROW.INSTOCK_TIME,
        TO_DATE('#OUTSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#PRO_BC#',
        '#PRO_BZ#',
        '1',
        '#CREATE_NAME#',
        TO_DATE('#OUTSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        MYROW.PRODUCT_FLAG,
        MYROW.MAT_STATUS,
        MYROW.JUDGE_STD_DES,
        '#BAL_YEAR_MONTH#',
        '#LOAD_PLINE_CODE#',
        '#LOAD_PLINE_NAME#',
        MYROW.MEMO,
        MYROW.PROCESS_CDOE,
        MYROW.PROCESS_DESC);
        -- 产权出库
     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,
        BELONG_CODE,
        BELONG_NAME,
        STORAGE_NO,
        LOCATION_NO,
        LARY_NO,
        LOC_NO,
        INSTOCK_TIME,
        OUTSTOCK_TIME,
        OUT_BC,
        OUT_BZ,
        HAND_FLAG,
        CREATE_NAME,
        CREATE_TIME,
        PRODUCT_FLAG,
        MAT_STATUS,
        JUDGE_STD_NAME,
        BAL_YEAR_MONTH,
        LOAD_PLINE_CODE,
        LOAD_PLINE_NAME,
        MEMO,
        PROCESS_CDOE,
        PROCESS_DESC)
 VALUES( 
        V_CQ_SEQ,
        '#CQ_OUTSTOCK_DOC#',
        '800809',
        '产权出库',
        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.BELONG_CODE,
        MYROW.BELONG_NAME,
        MYROW.STORAGE_NO,
        MYROW.LOCATION_NO,
        MYROW.LARY_NO,
        MYROW.LOC_NO,
        MYROW.INSTOCK_TIME,
        TO_DATE('#OUTSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#PRO_BC#',
        '#PRO_BZ#',
        '1',
        '#CREATE_NAME#',
        TO_DATE('#OUTSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        MYROW.PRODUCT_FLAG,
        MYROW.MAT_STATUS,
        MYROW.JUDGE_STD_DES,
        '#BAL_YEAR_MONTH#',
        '#LOAD_PLINE_CODE#',
        '#LOAD_PLINE_NAME#',
        MYROW.MEMO,
        MYROW.PROCESS_CDOE,
        MYROW.PROCESS_DESC);
        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_TLCOUNT := V_TLCOUNT + 1;
        V_CQCOUNT := V_CQCOUNT + 1;
  END LOOP;
END;
]]>
</query>
<!-- 产权出库
     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,
        BELONG_CODE,
        BELONG_NAME,
        STORAGE_NO,
        LOCATION_NO,
        LARY_NO,
        LOC_NO,
        INSTOCK_TIME,
        OUTSTOCK_TIME,
        OUT_BC,
        OUT_BZ,
        HAND_FLAG,
        CREATE_NAME,
        CREATE_TIME,
        PRODUCT_FLAG,
        MAT_STATUS,
        JUDGE_STD_NAME,
        BAL_YEAR_MONTH,
        LOAD_PLINE_CODE,
        LOAD_PLINE_NAME,
        MEMO)
 VALUES( 
        V_CQ_SEQ,
        '#CQ_OUTSTOCK_DOC#',
        '800809',
        '产权出库',
        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,
        MYROW.PLINE_CODE,
        MYROW.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.BELONG_CODE,
        MYROW.BELONG_NAME,
        MYROW.STORAGE_NO,
        MYROW.LOCATION_NO,
        MYROW.LARY_NO,
        MYROW.LOC_NO,
        MYROW.INSTOCK_TIME,
        TO_DATE('#OUTSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#PRO_BC#',
        '#PRO_BZ#',
        '1',
        '#CREATE_NAME#',
        TO_DATE('#OUTSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        MYROW.PRODUCT_FLAG,
        MYROW.MAT_STATUS,
        MYROW.JUDGE_STD_DES,
        '#BAL_YEAR_MONTH#',
        '#LOAD_PLINE_CODE#',
        '#LOAD_PLINE_NAME#',
        MYROW.MEMO); -->
<query id = "FrmLoadMatData.cancelLoadData" desc = "撤销上料">
DECLARE
  V_CREATE_NAME MAT_BC_M.CREATE_NAME%TYPE := NULL;
  V_CREATE_TIME MAT_BC_M.CREATE_TIME%TYPE := NULL;
    V_COUNT       MAT_BC_M.ACT_COUNT%TYPE := NULL;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM YDM_BC_OUTLIST T
                 WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#'
                 ORDER BY T.MAT_NO ASC) LOOP
    SELECT NVL(SUM(S.ACT_COUNT), 0)
    INTO V_COUNT
    FROM MAT_BC_BACKUP S
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.PLINE_CODE = MYROW.PLINE_CODE;
    IF (V_COUNT = 0) THEN
    SELECT S.CREATE_NAME, S.CREATE_TIME
    INTO V_CREATE_NAME, V_CREATE_TIME
    FROM MAT_BC_BACKUP S
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.PLINE_CODE IN ('100101', '100102', '100103');

    INSERT INTO MAT_BC_M
    SELECT *
    FROM MAT_BC_BACKUP S
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.PLINE_CODE IN ('100101', '100102', '100103');
    ELSE
    SELECT S.CREATE_NAME, S.CREATE_TIME
    INTO V_CREATE_NAME, V_CREATE_TIME
    FROM MAT_BC_BACKUP S
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.PLINE_CODE = MYROW.PLINE_CODE;

    INSERT INTO MAT_BC_M
    SELECT *
    FROM MAT_BC_BACKUP S
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.PLINE_CODE = MYROW.PLINE_CODE;
    END IF;
  

    INSERT INTO YDM_BC_BUTTRESS
      (MAT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       LOC_NO,
       CREATE_NAME,
       CREATE_TIME)
    VALUES
      (MYROW.MAT_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.LOC_NO,
       V_CREATE_NAME,
       V_CREATE_TIME);
       IF('#OUTSTOCK_TYPE_CODE#' = '800804')THEN
       DELETE FROM YDM_BC_OUTLIST S
     WHERE S.MAT_NO = MYROW.MAT_NO
       AND S.PLINE_CODE = MYROW.PLINE_CODE
       AND S.OUTSTOCK_TYPE_CODE IN ('800804', '800809');
       ELSE
       DELETE FROM YDM_BC_OUTLIST S
     WHERE S.MAT_NO = MYROW.MAT_NO
       AND S.PLINE_CODE = MYROW.PLINE_CODE
       AND S.OUTSTOCK_TYPE_CODE IN ('800801', '800809');
       END IF;

    IF (V_COUNT = 0) THEN
    DELETE FROM MAT_BC_BACKUP S
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.PLINE_CODE IN ('100101', '100102', '100103');
    ELSE
    DELETE FROM MAT_BC_BACKUP S
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.PLINE_CODE = MYROW.PLINE_CODE;
    END IF;
  END LOOP;
END;
</query>
<query id = "FrmLoadMatData.doQueryPline" desc = "加载查询产线">
SELECT S.PLINE_NAME, S.PLINE_CODE
  FROM COM_BASE_PLINE S
 WHERE S.PROCESS_CODE IN ('F', 'G','H')
 ORDER BY S.PLINE_NAME ASC
</query>
<query id = "FrmLoadMatData.SelectOutBathYear" desc = "查询出库记录年月">
SELECT NVL(COUNT(1),0)ACOUNT FROM YDM_BC_INITIAL T WHERE T.BAL_YEAR_MONTH = '#BAL_YEAR_MONTH#'
</query>
<query id = "FrmLoadMatData.loadMatBcMDataCrush" desc = "回废出库">
<![CDATA[
DECLARE
  V_TL_SEQ YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL;
  V_CQ_SEQ YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL;
  V_TLCOUNT NUMBER := 1;
  V_CQCOUNT NUMBER := 1;
BEGIN
  SELECT NVL(MAX(SUBSTR(T.OUTSTOCK_SQE, LENGTH(T.OUTSTOCK_SQE) - 3)), 0) + 1
    INTO V_TLCOUNT
    FROM YDM_BC_OUTLIST T
   WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
     AND T.OUTSTOCK_DOC = '#TL_OUTSTOCK_DOC#';

  SELECT NVL(MAX(SUBSTR(T.OUTSTOCK_SQE, LENGTH(T.OUTSTOCK_SQE) - 3)), 0) + 1
    INTO V_CQCOUNT
    FROM YDM_BC_OUTLIST T
   WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
     AND T.OUTSTOCK_DOC = '#CQ_OUTSTOCK_DOC#';
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*,
                               S.STORAGE_NO,
                               S.LOCATION_NO,
                               S.LARY_NO,
                               S.LOC_NO
                          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.QCM_STAUS = '00'
                           AND T.BELONG_CODE = '#BELONG_CODE#'
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                           AND (T.JUDGE_RESULT_CODE IN('40740701','40740706','40740702') OR (T.JUDGE_RESULT_CODE IS NULL AND T.INSTANCY_FLAG = '1'))
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #LOAD_ACT_COUNT#) LOOP
    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;
    V_TL_SEQ := '#TL_OUTSTOCK_DOC#' || LPAD(V_TLCOUNT,4,0);
    V_CQ_SEQ := '#CQ_OUTSTOCK_DOC#' || LPAD(V_CQCOUNT,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,
        BELONG_CODE,
        BELONG_NAME,
        STORAGE_NO,
        LOCATION_NO,
        LARY_NO,
        LOC_NO,
        INSTOCK_TIME,
        OUTSTOCK_TIME,
        OUT_BC,
        OUT_BZ,
        HAND_FLAG,
        CREATE_NAME,
        CREATE_TIME,
        PRODUCT_FLAG,
        MAT_STATUS,
        JUDGE_STD_NAME,
        BAL_YEAR_MONTH,
        LOAD_PLINE_CODE,
        LOAD_PLINE_NAME,
        MEMO,
        PROCESS_CDOE,
        PROCESS_DESC)
 VALUES( 
        V_TL_SEQ,
        '#TL_OUTSTOCK_DOC#',
        '#OUTSTOCK_TYPE_CODE#',
        '#OUTSTOCK_TYPE_NAME#',
        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,
        MYROW.PLINE_CODE,
        MYROW.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.BELONG_CODE,
        MYROW.BELONG_NAME,
        MYROW.STORAGE_NO,
        MYROW.LOCATION_NO,
        MYROW.LARY_NO,
        MYROW.LOC_NO,
        MYROW.INSTOCK_TIME,
        TO_DATE('#OUTSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#PRO_BC#',
        '#PRO_BZ#',
        '1',
        '#CREATE_NAME#',
        TO_DATE('#OUTSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        MYROW.PRODUCT_FLAG,
        MYROW.MAT_STATUS,
        MYROW.JUDGE_STD_DES,
        '#BAL_YEAR_MONTH#',
        '#LOAD_PLINE_CODE#',
        '#LOAD_PLINE_NAME#',
        MYROW.MEMO,
        MYROW.PROCESS_CDOE,
        MYROW.PROCESS_DESC);
        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_TLCOUNT := V_TLCOUNT + 1;
        V_CQCOUNT := V_CQCOUNT + 1;
  END LOOP;
END;
]]>
</query>
<query id = "FrmLoadMatData.selectQcmFlag" desc = "查询是否已确认">
SELECT NVL(COUNT(1),0)ACOUNT
  FROM QCM_ZG_JUGDE_APPLY 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.INSTOCK_FLAG = '0'
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
   AND T.PROCESS_CODE IN('D','E')
</query>
</queryMap>