<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "半成品库存数据管理">
<query id = "FrmDeleteMatBcM.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,
       T.MATERIAL_NO OLD_MATERIAL_NO,
       T.MATERIAL_NAME OLD_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,
       T.REDCHONG_FLAG,
       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,
       SUM(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','判废','33','判废待审核')QCM_STAUS,
       T.GX_PLAN_NO,
       MAX(T.PRO_ORDER_NO)PRO_ORDER_NO,
       MAX(T.ORDER_NO||'/'||T.ORDER_SEQ) 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,
       MAX(T.JUDGE_TOLRESULT)JUDGE_TOLRESULT,
       (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,
       DECODE(T.SCRAP_FRIM_FLAG,'0','未申请','1','已申请','2','已审核')SCRAP_FRIM_FLAG,
       T.SCRAP_REASON,
       DECODE(T.HANGING_FLAG,'0','否','1','是')HANGING_FLAG,
    MAX(T.REASON3) REASON,
    MAX(T.BELONG_CODE_RESPONSE) BELONG_CODE_RESPONSE,
    MAX(T.BELONG_NAME_RESPONSE) BELONG_NAME_RESPONSE,
    MAX((SELECT
        MAX(D.DELVRY_EDATE) DELVRY_EDATE
        FROM
        SLM_ORDER_HEAD H
        LEFT JOIN SLM_ORDER_LINE L ON H.ORD_PK = L.ORD_PK
        AND L.VALIDFLAG = '1'
        LEFT JOIN SLM_ORDER_LINE_DELIVERY D ON L.ORD_LN_PK = D.ORD_LN_PK
        WHERE H.VALIDFLAG = '1'
        AND H.ORDER_NO = T.ORDER_NO
        AND	L.ORDER_SEQ = T.ORDER_SEQ
        GROUP BY H.ORDER_NO,L.ORDER_SEQ)) DELVRY_EDATE
 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'
 #BAL_YEAR_MONTH#
 #JUDGE_STOVE_NO#
 #BELONG_CODE#
    #PLINE_CODE#
 #GROUP#
   UNION ALL
    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,
    T.MATERIAL_NO OLD_MATERIAL_NO,
    T.MATERIAL_NAME OLD_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,
    T.REDCHONG_FLAG,
    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,
    SUM(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','判废','33','判废待审核')QCM_STAUS,
    T.GX_PLAN_NO,
    MAX(T.PRO_ORDER_NO)PRO_ORDER_NO,
    MAX(T.ORDER_NO||'/'||T.ORDER_SEQ) 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,
    MAX(T.JUDGE_TOLRESULT)JUDGE_TOLRESULT,
    (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,
    DECODE(T.SCRAP_FRIM_FLAG,'0','未申请','1','已申请','2','已审核')SCRAP_FRIM_FLAG,
    T.SCRAP_REASON,
    DECODE(T.HANGING_FLAG,'0','否','1','是')HANGING_FLAG,
    MAX(T.REASON3) REASON,
    MAX(T.BELONG_CODE_RESPONSE) BELONG_CODE_RESPONSE,
    MAX(T.BELONG_NAME_RESPONSE) BELONG_NAME_RESPONSE,
    MAX((SELECT
        MAX(D.DELVRY_EDATE) DELVRY_EDATE
        FROM
        SLM_ORDER_HEAD H
        LEFT JOIN SLM_ORDER_LINE L ON H.ORD_PK = L.ORD_PK
        AND L.VALIDFLAG = '1'
        LEFT JOIN SLM_ORDER_LINE_DELIVERY D ON L.ORD_LN_PK = D.ORD_LN_PK
        WHERE H.VALIDFLAG = '1'
        AND H.ORDER_NO = T.ORDER_NO
        AND	L.ORDER_SEQ = T.ORDER_SEQ
        GROUP BY H.ORDER_NO,L.ORDER_SEQ)) DELVRY_EDATE
    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.PLINE_CODE IN ('100101','100102')
    #BAL_YEAR_MONTH#
    #JUDGE_STOVE_NO#
    #BELONG_CODE#
    #GROUP#
 UNION ALL
 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,
       MAX(T.MATERIAL_NO) MATERIAL_NO,
       MAX(T.MATERIAL_NAME) MATERIAL_NAME,
       MAX(T.MATERIAL_NO) OLD_MATERIAL_NO,
       MAX(T.MATERIAL_NAME) OLD_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,
       T.REDCHONG_FLAG,
       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,
       SUM(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.ORDER_NO||'/'||T.ORDER_SEQ) 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,
       MAX(T.JUDGE_TOLRESULT)JUDGE_TOLRESULT,
       (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,
       DECODE(T.SCRAP_FRIM_FLAG,'0','未申请','1','已申请','2','已审核')SCRAP_FRIM_FLAG,
       T.SCRAP_REASON,
       DECODE(T.HANGING_FLAG,'0','否','1','是')HANGING_FLAG,
        MAX(T.REASON3) REASON,
    MAX(T.BELONG_CODE_RESPONSE) BELONG_CODE_RESPONSE,
    MAX(T.BELONG_NAME_RESPONSE) BELONG_NAME_RESPONSE,
    MAX((SELECT
        MAX(D.DELVRY_EDATE) DELVRY_EDATE
        FROM
        SLM_ORDER_HEAD H
        LEFT JOIN SLM_ORDER_LINE L ON H.ORD_PK = L.ORD_PK
        AND L.VALIDFLAG = '1'
        LEFT JOIN SLM_ORDER_LINE_DELIVERY D ON L.ORD_LN_PK = D.ORD_LN_PK
        WHERE H.VALIDFLAG = '1'
        AND H.ORDER_NO = T.ORDER_NO
        AND	L.ORDER_SEQ = T.ORDER_SEQ
        GROUP BY H.ORDER_NO,L.ORDER_SEQ)) DELVRY_EDATE
 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 = '801402'
 #BAL_YEAR_MONTH#
 #JUDGE_STOVE_NO#
 #BELONG_CODE#
    #PLINE_CODE#
 #GROUP#
</query>
<query id = "FrmDeleteMatBcM.doQueryScrapList" desc = "查询废品记录">
SELECT * FROM YDM_BC_SCRAPOUTLIST T WHERE 1 = 1
</query>
<query id =  "FrmDeleteMatBcM.deleteMatBcMData" desc = "删除库存垃圾数据">
<![CDATA[
DECLARE
  V_OUTSTOCK_SQE YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL;
  V_OUTSTOCK_DOC YDM_BC_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  VCOUNT         NUMBER := 1;
  V_TIME         YDM_BC_OUTLIST.CREATE_TIME%TYPE := TO_DATE('#CREATE_TIME#',
		'YYYY-MM-DD HH24:MI:SS');
		V_BATHYEAR     YDM_BC_OUTLIST.BAL_YEAR_MONTH%TYPE := TO_CHAR(SYSDATE,
		'YYYYMM');
BEGIN
  SELECT 'CQ' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0)INTO V_OUTSTOCK_DOC
    FROM YDM_BC_OUTLIST T
   WHERE T.OUTSTOCK_TYPE_CODE = '800809'
     AND T.OUTSTOCK_DOC LIKE 'CQ' || TO_CHAR(SYSDATE, 'YYMMDD') || '_____';
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*,S.STORAGE_NO,S.LOCATION_NO
                          FROM MAT_BC_M T
                          LEFT JOIN YDM_BC_BUTTRESS S
                            ON T.MAT_NO = S.MAT_NO
                         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND NVL(T.BATCH_NO, '/') = NVL('#BATCH_NO#', '/')
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND T.BELONG_CODE = '#BELONG_CODE#'
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                           AND NVL(S.STORAGE_NO, '/') =
                               NVL('#STORAGE_NO#', '/')
                           AND T.QCM_STAUS = '#QCM_STAUS#'
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    IF (MYROW.MAT_STATUS = '80150102' OR MYROW.MAT_STATUS = '80150103') THEN
      V_OUTSTOCK_SQE := V_OUTSTOCK_DOC || LPAD(VCOUNT, 4, 0);
      INSERT INTO YDM_BC_OUTLIST
        (FLAG_STOVE_NO_ZG,
         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,
         OUTSTOCK_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,
         BAL_YEAR_MONTH,
         LOAD_PLINE_CODE,
         LOAD_PLINE_NAME,
         PROCESS_CDOE,
         PROCESS_DESC)
      VALUES
        (MYROW.FLAG_STOVE_NO_ZG,
         V_OUTSTOCK_SQE,
         V_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.ACT_THEORY_WEIGHT,
         MYROW.BELONG_CODE,
         MYROW.BELONG_NAME,
         MYROW.STORAGE_NO,
         MYROW.LOCATION_NO,
         V_TIME,
         '#CREATE_NAME#',
         V_TIME,
         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,
         V_BATHYEAR,
         '',
         '人工消亡',
         MYROW.PROCESS_CDOE,
         MYROW.PROCESS_DESC);
         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;
    END IF;
    DELETE FROM YDM_BC_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
    DELETE FROM MAT_BC_M T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
       VCOUNT := VCOUNT + 1;
  END LOOP;
END;
]]>
</query>
<query id = "FrmDeleteMatBcM.adjustStorageNo" desc = "调整库存位置">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT MAT_NO
                  FROM (SELECT T.MAT_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.BELONG_CODE = '#BELONG_CODE#'
                           AND T.QCM_STAUS = '#QCM_STAUS#'
                           AND NVL(S.STORAGE_NO,'/') = NVL('#STORAGE_NO#','/')
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE YDM_BC_BUTTRESS S SET S.STORAGE_NO = '#NEW_STORAGE_NO#',S.LOCATION_NO = '#NEW_STORAGE_NO#'||'10101'
    WHERE S.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>
    <query id = "FrmDeleteMatBcM.updateFlagStoveNo" desc = "修改标识炉号">
        <![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT MAT_NO,PLINE_CODE
                  FROM (SELECT T.MAT_NO,T.PLINE_CODE
                          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.BELONG_CODE = '#BELONG_CODE#'
                           AND T.QCM_STAUS = '#QCM_STAUS#'
                           AND NVL(S.STORAGE_NO, '/') =
                               NVL('#STORAGE_NO#', '/')
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
                 UPDATE MAT_BC_M T SET T.FLAG_STOVE_NO_ZG = '#FLAG_STOVE_NO_ZG#'
                 WHERE T.MAT_NO = MYROW.MAT_NO AND T.PLINE_CODE = MYROW.PLINE_CODE;
  END LOOP;
END;

]]>
    </query>
<query id = "FrmDeleteMatBcM.getStorageNo" desc = "查询仓库">
SELECT S.STORAGE_NAME,S.STORAGE_NO FROM YDM_BS_STORAGE S WHERE S.VALIDFLAG = '1'
</query>
    <query id = "FrmDeleteMatBcM.getStorageNoGp" desc = "查询管坯仓库">
        SELECT S.STORAGE_NAME,S.STORAGE_NO FROM YDM_BS_STORAGE S WHERE S.VALIDFLAG = '1' AND S.STORAGE_TYPE_NO IN('800201','800205')
    </query>
<query id = "FrmDeleteMatBcM.doQueryWeight" desc = "查询对应支数重量">
<![CDATA[
SELECT SUM(T.ACT_WEIGHT) ACT_WEIGHT
  FROM (SELECT S.*
          FROM MAT_BC_M S
         WHERE S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND S.BATCH_NO = '#BATCH_NO#'
           AND S.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
           AND S.BELONG_CODE = '#BELONG_CODE#'
           AND S.QCM_STAUS = '00'
         ORDER BY S.MAT_NO DESC) T
 WHERE ROWNUM <= #ACT_COUNT#
 ]]>
</query>
<query id = "FrmDeleteMatBcM.setUpIntial" desc = "半成品期初建立">
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.PRODUCT_FLAG,
                       T.MAT_STATUS,
                       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,
                       T.PROCESS_CDOE,
                       T.PROCESS_DESC,
                       MAX(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD')) INSTOCK_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,
                       SUM(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.PRO_ORDER_NO) PRO_ORDER_NO,
                       S.STORAGE_NO,
                       (SELECT S1.STORAGE_NAME
                          FROM YDM_BS_STORAGE S1
                         WHERE S1.STORAGE_NO = S.STORAGE_NO) STORAGE_NAME,
                       MAX(T.JUDGE_STD_DES) JUDGE_STD_DES
                  FROM MAT_BC_M T
                  LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
                 WHERE T.BELONG_CODE = '002001001'
                   AND T.JUDGE_RESULT_CODE IS NOT NULL
                 GROUP BY T.PRODUCT_FLAG,
                          T.MAT_STATUS,
                          T.STOVE_NO,
                          T.LOT_NO,
                          T.JUDGE_STOVE_NO,
                          T.BATCH_NO,
                          T.BATCH_GROUD_NO,
                          T.BELONG_CODE,
                          T.BELONG_NAME,
                          S.STORAGE_NO,
                          T.PROCESS_CDOE,
                          T.PROCESS_DESC) LOOP
    INSERT INTO YDM_BC_INITIAL
      (JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       DIMATER,
       HEIGHT,
       LEN,
       LEN_MIN,
       LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       STORAGE_NO,
       STORAGE_NAME,
       CREATE_NAME,
       CREATE_TIME,
       BAL_YEAR_MONTH,
       GRADECODE,
       GRADENAME,
       PLINE_CODE,
       PLINE_NAME,
       INSTOCK_TIME,
       BELONG_CODE,
       BELONG_NAME,
       LOT_NO,
       STOVE_NO,
       JUDGE_STD_DES)
    VALUES
      (MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       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.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       '',
       MYROW.STORAGE_NO,
       MYROW.STORAGE_NAME,
       'admin',
       SYSDATE,
       '201805',
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       SYSDATE,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STD_DES);
  
  END LOOP;
END;
</query>
<query id = "FrmDeleteMatBcM.getProcessMaterial" desc = "获取所有物料">
    <![CDATA[
SELECT DISTINCT BASECODE ,BASENAME FROM 
(SELECT T1.OUT_MATERIAL_NO AS BASECODE, T1.OUT_MATERIAL_DESC AS BASENAME
  FROM SLM_BASE_MATERIAL_D T1
UNION ALL
SELECT T2.OUT_MATERIAL_NO AS BASECODE, T2.OUT_MATERIAL_DESC AS BASENAME
  FROM SLM_BASE_MATERIAL_E T2
UNION ALL
SELECT T3.OUT_MATERIAL_NO AS BASECODE, T3.OUT_MATERIAL_DESC AS BASENAME
  FROM SLM_BASE_MATERIAL_F T3
UNION ALL
SELECT T4.OUT_MATERIAL_NO AS BASECODE, T4.OUT_MATERIAL_DESC AS BASENAME
  FROM SLM_BASE_MATERIAL_K T4)T
  --where basename = 'WX139.70x9.17,,P110'
    ]]>
</query>
<query id = "FrmDeleteMatBcM.updateMaterial" desc = "修改物料码">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO, T.PLINE_CODE
                          FROM MAT_BC_M T LEFT JOIN YDM_BC_BUTTRESS S
                         ON T.MAT_NO = S.MAT_NO
                           WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND NVL(T.LOT_NO,'/') = NVL('#LOT_NO#','/')
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                           AND NVL(S.STORAGE_NO,'/') = NVL('#STORAGE_NO#','/')
                           AND NVL(T.MATERIAL_NO,'/') = NVL('#OLD_MATERIAL_NO#','/')
                           AND T.QCM_STAUS = '00'
                           AND T.JUDGE_RESULT_CODE IS NOT NULL
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE MAT_BC_M T
       SET T.MATERIAL_NO   = '#MATERIAL_NO#',
           T.MATERIAL_NAME = '#MATERIAL_NAME#'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
    --UPDATE YDM_BC_INLIST T
     --  SET T.MATERIAL_NO   = '#MATERIAL_NO#',
        --   T.MATERIAL_NAME = '#MATERIAL_NAME#'
     --WHERE T.MAT_NO = MYROW.MAT_NO
      -- AND T.PLINE_CODE = MYROW.PLINE_CODE;
   -- UPDATE YDM_BC_STOCKTAKINGLIST T
     --  SET T.MATERIAL_NO   = '#MATERIAL_NO#',
       --    T.MATERIAL_NAME = '#MATERIAL_NAME#'
     --WHERE T.MAT_NO = MYROW.MAT_NO
     --  AND T.PLINE_CODE = MYROW.PLINE_CODE;
  END LOOP;
  --UPDATE YDM_BC_INITIAL T
      -- SET T.MATERIAL_NO   = '#MATERIAL_NO#',
        --   T.MATERIAL_NAME = '#MATERIAL_NAME#'
    -- WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       --    AND T.BATCH_NO = '#BATCH_NO#'
         --  AND T.PLINE_CODE = '#PLINE_CODE#';
END;
]]>
</query>
<query id = "FrmDeleteMatBcM.insertOutIn" desc = "增写出入库记录">
<![CDATA[
DECLARE
V_INSTOCK_SEQ YDM_BC_INLIST.INSTOCK_SQE%TYPE :=NULL;
V_OUTSTOCK_SQE YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE :=NULL;
V_OUTCOUNT        NUMBER := 1;
V_INCOUNT   NUMBER := 1;
BEGIN
 SELECT LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_SQE, LENGTH(T.OUTSTOCK_SQE) - 3)),
                  0) + 1,
              4,
              0) OUTSTOCK_SQE
    INTO V_OUTCOUNT
    FROM YDM_BC_OUTLIST T
   WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#';
   
   SELECT LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 3)),
                  0) + 1,
              4,
              0) INSTOCK_SQE
    INTO V_INCOUNT
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#';
 FOR MYROW IN(SELECT *
                  FROM (SELECT T.*,
               S.STORAGE_NO,
               S.LOCATION_NO,
               S.LARY_NO,
               S.LOC_NO,
               S.STORAGE_TYPE_NO,
               S.STORAGE_TYPE_NAME,
               S.STORAGE_ATTR,
               S.STORAGE_ATTR_NAME
                          FROM MAT_BC_M T LEFT JOIN YDM_BC_BUTTRESS S
                         ON T.MAT_NO = S.MAT_NO
                           WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND NVL(T.LOT_NO,'/') = NVL('#LOT_NO#','/')
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                           AND NVL(S.STORAGE_NO,'/') = NVL('#STORAGE_NO#','/')
                           AND NVL(T.MATERIAL_NO,'/') = NVL('#OLD_MATERIAL_NO#','/')
                           AND T.QCM_STAUS = '00'
                           AND T.JUDGE_RESULT_CODE IS NOT NULL
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#)LOOP
                 V_OUTSTOCK_SQE := '#OUTSTOCK_DOC#' || LPAD(V_OUTCOUNT, 4, 0);
                 V_INSTOCK_SEQ := '#INSTOCK_DOC#' || LPAD(V_INCOUNT, 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,
       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,
       PROCESS_CDOE,
       PROCESS_DESC)
    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,
       '#NEW_PLINE_CODE#',
       '#NEW_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,
       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,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC);
       
       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,
       PROCESS_CDOE,
       PROCESS_DESC)
    VALUES
      (V_INSTOCK_SEQ,
       '#INSTOCK_DOC#',
       '800706',
       '改判入库',
       MYROW.MAT_NO,
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       '#MATERIAL_NO#',
       '#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,
       '#NEW_PLINE_CODE#',
       '#NEW_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,
       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,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC);
       V_OUTCOUNT := V_OUTCOUNT + 1;
       V_INCOUNT  := V_INCOUNT + 1;
 END LOOP;
END;
]]>
</query>
<query id = "FrmDeleteMatBcM.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 = "FrmDeleteMatBcM.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 = "FrmDeleteMatBcM.updateMemo" desc = "修改备注">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO, T.PLINE_CODE
                          FROM MAT_BC_M T
                          LEFT JOIN YDM_BC_BUTTRESS S
                            ON T.MAT_NO = S.MAT_NO
                         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 = '#QCM_STAUS#'
                           AND NVL(T.JUDGE_RESULT_CODE, '/') =
                               NVL('#SPEC_RESULT_CODE#', '/')
                           AND NVL(T.MEMO, '/') = NVL('#MEMO#', '/')
                           AND NVL(S.STORAGE_NO,'/') = NVL('#STORAGE_NO#','/')
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE MAT_BC_M T
       SET T.MEMO = '#UPDATE_MEMO#'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
  END LOOP;
END;
]]>
</query>
<query id = "FrmDeleteMatBcM.scrapOut" desc = "废品倒运出库">
<![CDATA[
DECLARE
  V_TL_SEQ YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL;
  V_TLCOUNT 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 = '#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 NVL(T.BATCH_NO,'/') = NVL('#BATCH_NO#','/')
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND T.QCM_STAUS = '22'
                           AND T.BELONG_CODE = '#BELONG_CODE#'
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                           AND T.SCRAP_FRIM_FLAG = '2'
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #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 := '#OUTSTOCK_DOC#' || LPAD(V_TLCOUNT,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,
        HAND_FLAG,
        CREATE_NAME,
        CREATE_TIME,
        PRODUCT_FLAG,
        MAT_STATUS,
        JUDGE_STD_NAME,
        BAL_YEAR_MONTH,
        LOAD_PLINE_CODE,
        LOAD_PLINE_NAME,
        MEMO,
        BELONG_CODE_RESPONSE,
        BELONG_NAME_RESPONSE,
        TAR_STORAGE_NO,
        TAR_REC_FLAG
        )
 VALUES( 
        V_TL_SEQ,
        '#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'),
        '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.BELONG_CODE_RESPONSE,
        MYROW.BELONG_NAME_RESPONSE,
        '#LOAD_PLINE_CODE#',
        '1');
        
        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;
  END LOOP;
END;
]]>
</query>
<query id = "FrmDeleteMatBcM.scrapAcount" desc = "查询废品审核支数">
SELECT NVL(SUM(T.ACT_COUNT), 0) 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 NVL(T.BATCH_NO, '/') = NVL('#BATCH_NO#', '/')
   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
   AND T.QCM_STAUS = '22'
   AND T.BELONG_CODE = '#BELONG_CODE#'
   AND T.PLINE_CODE = '#PLINE_CODE#'
   AND T.SCRAP_FRIM_FLAG = '2'

</query>
<query id = "FrmDeleteMatBcM.insertYdmBcScrap" desc = "插入废品表">
 INSERT INTO YDM_BC_SCRAPOUTLIST(
        OUTSTOCK_DOC,
        OUTSTOCK_TYPE_CODE,
        OUTSTOCK_TYPE_NAME,
        FLAG_STOVE_NO,
        ACT_COUNT,
        ACT_WEIGHT,
        CRATE_NAME,
        CRATE_TIME)
 VALUES( 
        '#OUTSTOCK_DOC#',
        '#OUTSTOCK_TYPE_CODE#',
        '#OUTSTOCK_TYPE_NAME#',
        '#FLAG_STOVE_NO#',
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        '#CRATE_NAME#',
        TO_DATE('#CRATE_TIME#','YYYY-MM-DD HH24:MI:SS'))
</query>
<query id = "FrmDeleteMatBcM.doQueryScrapOutList" 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,
       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,
       SUM(T.ACT_THEORY_WEIGHT)ACT_THEORY_WEIGHT,
       MAX(T.BELONG_CODE)BELONG_CODE,
       MAX(T.BELONG_NAME)BELONG_NAME,
       T.STORAGE_NO,
       (SELECT T1.STORAGE_NAME FROM YDM_BS_STORAGE T1 WHERE T1.STORAGE_NO = T.STORAGE_NO)STORAGE_NAME,
       T.TAR_STORAGE_NO,
       (SELECT T2.STORAGE_NAME FROM YDM_BS_STORAGE T2 WHERE T2.STORAGE_NO = T.TAR_STORAGE_NO)TAR_STORAGE_NAME,
       MAX(TO_CHAR(T.OUTSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) OUTSTOCK_TIME,
       MAX(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       MAX(T.JUDGE_STD_NAME)JUDGE_STD_NAME,
       T.LOAD_PLINE_CODE,
       T.LOAD_PLINE_NAME,
       T.BELONG_CODE_RESPONSE,
       T.BELONG_NAME_RESPONSE
 FROM YDM_BC_OUTLIST T
 WHERE T.OUTSTOCK_DOC = ?
 GROUP BY T.OUTSTOCK_DOC,T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.LOAD_PLINE_CODE,
       T.LOAD_PLINE_NAME,
       T.BELONG_CODE_RESPONSE,
       T.BELONG_NAME_RESPONSE,
       T.STORAGE_NO,
       T.TAR_STORAGE_NO     
</query>
<query id = "FrmDeleteMatBcM.doQueryDepartM" desc = "加载部门">
SELECT *
  FROM (SELECT T.DEPARTMENT_DESC AS DEPARTMENT_DESC_P,
               T.DEPARTMENT_CODE AS DEPARTMENT_CODE_P
          FROM COM_BASE_PLINE T
         WHERE T.VALIDFLAG = '1'
         GROUP BY T.DEPARTMENT_CODE, T.DEPARTMENT_DESC
        
        UNION ALL
        
        SELECT '待定' DEPARTMENT_DESC_P, '0' DEPARTMENT_CODE_P
          FROM DUAL
    UNION ALL

    SELECT '供方责任' DEPARTMENT_DESC_P, '1' DEPARTMENT_CODE_P
    FROM DUAL
    
    UNION ALL
    SELECT '新品/试验品/难干品种' DEPARTMENT_DESC_P, '2' DEPARTMENT_CODE_P
    FROM DUAL
    
    UNION ALL
    SELECT '生产物流部' DEPARTMENT_DESC_P, '3' DEPARTMENT_CODE_P
    FROM DUAL
    )
 ORDER BY DEPARTMENT_CODE_P ASC
</query>
<query id = "FrmDeleteMatBcM.updatePorssWgt" desc= "回报过磅量">
UPDATE YDM_BC_SCRAPOUTLIST T SET T.PONDER_GROSS_WT = '#PONDER_GROSS_WT#' WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#'
</query>
<query id = "FrmDeleteMatBcM.belongResponse" desc = "修改责任单位">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM YDM_BC_OUTLIST T
                         WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#'
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE YDM_BC_OUTLIST T
       SET T.BELONG_CODE_RESPONSE = '#BELONG_CODE_RESPONSE#',
           T.BELONG_NAME_RESPONSE = '#BELONG_NAME_RESPONSE#'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.OUTSTOCK_DOC = MYROW.OUTSTOCK_DOC;
  END LOOP;
END;
]]>
</query>
<query id = "FrmDeleteMatBcM.cancelScrapOut" desc = "撤销废品出库">
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM YDM_BC_OUTLIST T
                 WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#'
                 ORDER BY T.MAT_NO ASC) LOOP
    INSERT INTO MAT_BC_M
      SELECT *
        FROM MAT_BC_BACKUP T
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.PLINE_CODE = MYROW.PLINE_CODE;
    INSERT INTO YDM_BC_BUTTRESS
      (MAT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       CREATE_NAME,
       CREATE_TIME)
    VALUES
      (MYROW.MAT_NO,
       MYROW.Judge_Stove_No,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.STORAGE_NO,
       MYROW.STORAGE_NO || '10101',
       '#CRATE_NAME#',
       MYROW.INSTOCK_TIME);
    DELETE FROM MAT_BC_BACKUP T WHERE T.MAT_NO = MYROW.MAT_NO
    AND T.PLINE_CODE = MYROW.PLINE_CODE;
    DELETE FROM YDM_BC_OUTLIST T
     WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#'
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  DELETE FROM YDM_BC_SCRAPOUTLIST T
   WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#';
END;
</query>
<query id = "FrmDeleteMatBcM.cancelScrapJudgeNo" desc = "按炉撤销废品">
DECLARE
V_ACOUNT NUMBER:=0;
V_WGT NUMBER:=0;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM YDM_BC_OUTLIST T
                 WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#'
                 AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                 AND T.BATCH_NO = '#BATCH_NO#'
                 AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                 ORDER BY T.MAT_NO ASC) LOOP
    INSERT INTO MAT_BC_M
      SELECT *
        FROM MAT_BC_BACKUP T
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.PLINE_CODE = MYROW.PLINE_CODE;
    INSERT INTO YDM_BC_BUTTRESS
      (MAT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       CREATE_NAME,
       CREATE_TIME)
    VALUES
      (MYROW.MAT_NO,
       MYROW.Judge_Stove_No,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.STORAGE_NO,
       MYROW.STORAGE_NO || '10101',
       '#CREATE_NAME#',
       MYROW.INSTOCK_TIME);
    DELETE FROM MAT_BC_BACKUP T WHERE T.MAT_NO = MYROW.MAT_NO
    AND T.PLINE_CODE = MYROW.PLINE_CODE;
    DELETE FROM YDM_BC_OUTLIST T
     WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#'
       AND T.MAT_NO = MYROW.MAT_NO;
       V_ACOUNT := V_ACOUNT + 1;
       V_WGT := V_WGT + TO_NUMBER(MYROW.ACT_WEIGHT);
  END LOOP;
  UPDATE YDM_BC_SCRAPOUTLIST T SET T.ACT_COUNT = TO_NUMBER(T.ACT_COUNT)-V_ACOUNT,
  T.ACT_WEIGHT = TO_NUMBER(T.ACT_WEIGHT)-V_WGT
  WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#';
END;
</query>
<query id = "FrmDeleteMatBcM.takeBill" desc = "置余材">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*,S.STORAGE_NO
                          FROM MAT_BC_M T
                          LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
                         WHERE 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 = '#PRO_PLAN_ID_NEXT#'
                           AND T.GX_PLAN_NO_NEXT = '#GX_PLAN_NO_NEXT#'
                           AND S.STORAGE_NO = '#STORAGE_NO#'
                           AND T.QCM_STAUS = '00'
                           AND T.BELONG_CODE IN('002001001','002023005')
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= '#ACT_COUNT#') LOOP
                 IF(MYROW.INSTANCY_FLAG = '1')THEN
                 UPDATE MAT_BC_M T
       SET T.MAT_STATUS        = '80150101',
           T.NEXT_PROCESS_CDOE = '',
           T.NEXT_PROCESS_DESC = '',
           T.PRO_PLAN_ID_NEXT  = '',
           T.GX_PLAN_NO_NEXT   = '',
           T.HANGING_FLAG      = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
                 ELSE
                 UPDATE MAT_BC_M T
       SET T.MAT_STATUS        = '80150102',
           T.NEXT_PROCESS_CDOE = '',
           T.NEXT_PROCESS_DESC = '',
           T.PRO_PLAN_ID_NEXT  = '',
           T.GX_PLAN_NO_NEXT   = '',
           T.HANGING_FLAG      = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
                 END IF;
    
  END LOOP;
END;
]]>
</query>

<query id = "FrmDeleteMatBcM.QuerytakeBill" desc = "查询置余材">
<![CDATA[
SELECT NVL(SUM(T.ACT_COUNT),0) ACT_COUNT
  FROM MAT_BC_M T
  LEFT JOIN YDM_BC_BUTTRESS S
    ON T.MAT_NO = S.MAT_NO
 WHERE 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 = '#PRO_PLAN_ID_NEXT#'
   AND T.GX_PLAN_NO_NEXT = '#GX_PLAN_NO_NEXT#'
   AND S.STORAGE_NO = '#STORAGE_NO#'
   AND T.QCM_STAUS = '00'
   AND T.BELONG_CODE IN ('002001001', '002023005')
]]>
</query>

<query id = "FrmDeleteMatBcM.updateReason" desc = "离线原因">
        <![CDATA[
DECLARE V_DATA_COUNT INTEGER;
BEGIN
		FOR MYROW IN (
		SELECT
			*
		FROM
			(
			SELECT
				T.MAT_NO,
				T.PLINE_CODE
			FROM
				MAT_BC_M T
				LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
			WHERE
				T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
				AND T.BATCH_NO = '#BATCH_NO#'
				AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
				AND NVL( T.LOT_NO, '/' ) = NVL( '#LOT_NO#', '/' )
				AND T.PLINE_CODE = '#PLINE_CODE#'
				AND NVL( S.STORAGE_NO, '/' ) = NVL( '#STORAGE_NO#', '/' )
				AND T.QCM_STAUS = '11'
				AND T.MEMO = '#MEMO#'
				AND T.JUDGE_RESULT_CODE IS NULL
			ORDER BY
				T.MAT_NO DESC
			)
		WHERE
			ROWNUM <= '#ACT_COUNT#'
		)
		LOOP
		V_DATA_COUNT := 0;
-- 库存表
	UPDATE MAT_BC_M T
	SET T.REASON1 = '#REASON1#',
	T.REASON2 = '#REASON2#',
	T.REASON3 = '#REASON3#'
	WHERE
		T.MAT_NO = MYROW.MAT_NO
		AND T.PLINE_CODE = MYROW.PLINE_CODE;
-- 备份表
	SELECT
		COUNT( 1 ) INTO V_DATA_COUNT
	FROM
		MAT_BC_M_BACK_UP T
	WHERE
		T.MAT_NO = MYROW.MAT_NO
		AND T.PLINE_CODE = MYROW.PLINE_CODE;
	IF V_DATA_COUNT = 0 THEN
			INSERT INTO MAT_BC_M_BACK_UP SELECT
			*
		FROM
			MAT_BC_M T
		WHERE
			T.MAT_NO = MYROW.MAT_NO
			AND T.PLINE_CODE = MYROW.PLINE_CODE;
	ELSE
		UPDATE MAT_BC_M_BACK_UP T
		SET T.REASON1 = '#REASON1#',
		T.REASON2 = '#REASON2#',
		T.REASON3 = '#REASON3#'
		WHERE
			T.MAT_NO = MYROW.MAT_NO
			AND T.PLINE_CODE = MYROW.PLINE_CODE
			AND T.QCM_STAUS = '11';
	END IF;

END LOOP;
END;
]]>
    </query>

    <query id = "FrmDeleteMatBcM.updateBelongCodeResponse" desc = "责任单位">
        <![CDATA[
DECLARE V_DATA_COUNT INTEGER;
BEGIN
		FOR MYROW IN (
		SELECT
			*
		FROM
			(
			SELECT
				T.MAT_NO,
				T.PLINE_CODE
			FROM
				MAT_BC_M T
				LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
			WHERE
				T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
				AND T.BATCH_NO = '#BATCH_NO#'
				AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
				AND T.FLAG_STOVE_NO_ZG = '#FLAG_STOVE_NO_ZG#'
				AND NVL( T.LOT_NO, '/' ) = NVL( '#LOT_NO#', '/' )
				AND T.PLINE_CODE = '#PLINE_CODE#'
				AND NVL( S.STORAGE_NO, '/' ) = NVL( '#STORAGE_NO#', '/' )
				AND T.QCM_STAUS = '11'
				AND T.MEMO = '#MEMO#'
				AND T.JUDGE_RESULT_CODE IS NULL
			ORDER BY
				T.MAT_NO DESC
			)
		WHERE
			ROWNUM <= '#ACT_COUNT#'
		)
		LOOP
		V_DATA_COUNT := 0;
-- 库存表
	UPDATE MAT_BC_M T
	SET T.BELONG_CODE_RESPONSE = '#BELONG_CODE_RESPONSE#',
        t.BELONG_NAME_RESPONSE = '#BELONG_NAME_RESPONSE#'
	WHERE
		T.MAT_NO = MYROW.MAT_NO
		AND T.PLINE_CODE = MYROW.PLINE_CODE;
-- 备份表
	SELECT
		COUNT( 1 ) INTO V_DATA_COUNT
	FROM
		MAT_BC_M_BACK_UP T
	WHERE
		T.MAT_NO = MYROW.MAT_NO
		AND T.PLINE_CODE = MYROW.PLINE_CODE;
	IF V_DATA_COUNT = 0 THEN
			INSERT INTO MAT_BC_M_BACK_UP SELECT
			*
		FROM
			MAT_BC_M T
		WHERE
			T.MAT_NO = MYROW.MAT_NO
			AND T.PLINE_CODE = MYROW.PLINE_CODE;
	ELSE
		UPDATE MAT_BC_M_BACK_UP T
		SET T.BELONG_CODE_RESPONSE = '#BELONG_CODE_RESPONSE#',
        t.BELONG_NAME_RESPONSE = '#BELONG_NAME_RESPONSE#'
		WHERE
			T.MAT_NO = MYROW.MAT_NO
			AND T.PLINE_CODE = MYROW.PLINE_CODE
			AND T.QCM_STAUS = '11';
	END IF;

END LOOP;
END;
]]>
    </query>

    <query id = "FrmDeleteMatBcM.queryReason" desc = "查询离线原因">
        <![CDATA[
        SELECT
            A.BASECODE REASON_CODE1,
            A.BASENAME REASON_NAME1,
            B.BASECODE REASON_CODE2,
            B.BASENAME REASON_NAME2,
            C.BASECODE REASON_CODE3,
            A.BASENAME||'/'|| B.BASENAME ||'/'||C.BASENAME REASON_NAME3
        FROM
            COM_BASE_INFO A
            LEFT JOIN COM_BASE_INFO B ON A.BASECODE = B.SORTCODE
            LEFT JOIN COM_BASE_INFO C ON B.BASECODE = C.SORTCODE
        WHERE
            A.SORTCODE = '4113' AND C.VALIDFLAG = '1'
        ORDER BY c.BASECODE
        ]]>
    </query>

    <query id = "FrmDeleteMatBcM.queryPline" desc = "查询产线">
        <![CDATA[
        SELECT
            PLINE_CODE,
            PLINE_NAME
        FROM
            COM_BASE_PLINE A
        WHERE
            A.VALIDFLAG = '1'
        ORDER BY PLINE_NAME
        ]]>
    </query>


    <query id = "FrmDeleteMatBcM.doQueryBelong" desc = "查询半成品所属权">
        <![CDATA[
        SELECT
            BELONG_CODE,
            BELONG_NAME
        FROM
            MAT_BC_M
        GROUP BY
            BELONG_CODE,
            BELONG_NAME
        ORDER BY
            BELONG_CODE
        ]]>
    </query>
</queryMap>
