<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "红冲接收管理">
<query id = "FrmFrimRedChong.doQueryPline" desc = "获取所有产线">
SELECT T.PLINE_NAME, T.PLINE_CODE
  FROM COM_BASE_PLINE T
 WHERE T.PROCESS_CODE IN ('D', 'E', 'F', 'G')
    AND T.SUPPLY_UNIT_CODE = ?
 ORDER BY T.PLINE_CODE ASC
</query>
<query id = "FrmFrimRedChong.insertMatBcSeq" desc = "审核通过">
       DECLARE
  V_INSTOCK_SEQ       YDM_ZC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_INSTOCK_SEQ_CX    YDM_BC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_COUNT             NUMBER := 1;
  V_COUNTCX           NUMBER := 1;
  V_PROCESS_CDOE      MAT_BC_M.PROCESS_CDOE%TYPE := NULL;
  V_PROCESS_DESC      MAT_BC_M.PROCESS_DESC%TYPE := NULL;
  V_JUDGE_RESULT_CODE MAT_ZC_M.JUDGE_RESULT_CODE%TYPE := NULL;
  V_JUDGE_RESULT      MAT_ZC_M.JUDGE_RESULT%TYPE := NULL;
  V_BELONG_CODE       MAT_ZC_M.BELONG_CODE%TYPE := NULL;
  V_BELONG_NAME       MAT_ZC_M.BELONG_NAME%TYPE := NULL;
BEGIN

  SELECT S2.PROCESS_CODE,
         S2.PROCESS_DESC,
         S2.DEPARTMENT_CODE,
         S2.DEPARTMENT_DESC
    INTO V_PROCESS_CDOE, V_PROCESS_DESC, V_BELONG_CODE, V_BELONG_NAME
    FROM COM_BASE_PLINE S2
   WHERE S2.PLINE_CODE = '#FRIM_PLINE_CODE#';
  SELECT LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 3)), 0) + 1,
              4,
              0) INSTOCK_SQE
    INTO V_COUNT
    FROM YDM_ZC_INLIST T
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC_R#';

  SELECT LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 3)), 0) + 1,
              4,
              0) INSTOCK_SQE
    INTO V_COUNTCX
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC_CX#';
  FOR MYROW IN (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
                  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
                 WHERE T.MAT_NO = S.MAT_NO
                   AND T.INSTOCK_DOC = '#INSTOCK_DOC#'
                 ORDER BY T.MAT_NO ASC) LOOP
    IF (MYROW.JUDGE_RESULT_CODE IS NULL) THEN
      V_JUDGE_RESULT_CODE := '40740701';
      V_JUDGE_RESULT      := '合格';
    ELSE
      V_JUDGE_RESULT_CODE := MYROW.JUDGE_RESULT_CODE;
      V_JUDGE_RESULT      := MYROW.JUDGE_RESULT;
    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,
       MATERIAL_NO,
       MATERIAL_NAME,
       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,
       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,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_RESULT_TIME,
       JUDGE_MAKER,
       INSTOCK_FLAG,
       INSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       BAL_YEAR_MONTH,
       JUDGE_STD_NAME,
       QCM_STAUS,
       TARGET,
       PROCESS_STATUS,
       FLAG_STOVE_NO_ZG,
       JUDGE_STD_DES,
       ZBS_FLAG,
       ZBS_ID,
       MEMO,
       MEASURING_SEQ,
       IS_DEALER,
       REDCHONG_FLAG)
    VALUES
      (MYROW.MAT_NO || '1',
       '801401',
       '80150102',
       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.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.CRAF_NO,
       V_PROCESS_CDOE,
       V_PROCESS_DESC,
      '#FRIM_PLINE_CODE#',
      '#FRIM_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,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       V_JUDGE_RESULT_CODE,
       V_JUDGE_RESULT,
       MYROW.JUDGE_RESULT_TIME,
       MYROW.JUDGE_MAKER,
       '1',
       MYROW.INSTOCK_TIME,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME,
       MYROW.BAL_YEAR_MONTH,
       MYROW.JUDGE_STD_NAME,
       '00',
       'B',
       MYROW.PROCESS_STATUS,
       MYROW.FLAG_STOVE_NO_ZG,
       MYROW.JUDGE_STD_NAME,
       MYROW.ZBS_FLAG,
       MYROW.ZBS_ID,
       MYROW.MEMO,
       MYROW.MEASURING_SEQ,
       MYROW.IS_DEALER,
       '1');
    INSERT INTO YDM_BC_BUTTRESS
      (MAT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       CREATE_NAME,
       CREATE_TIME, PLINE_CODE)
    VALUES
      (MYROW.MAT_NO || '1',
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME, '#FRIM_PLINE_CODE#');
    V_INSTOCK_SEQ_CX := '#INSTOCK_DOC_CX#' || LPAD(V_COUNT, 4, 0);
    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,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       IN_TIME_F,
       BAL_YEAR_MONTH,
       QCM_STAUS,
       SOURE_CODE,
       SOURE_NAME,
       PROCESS_CDOE,
       PROCESS_DESC)
    VALUES
      (V_INSTOCK_SEQ_CX,
       '#INSTOCK_DOC_CX#',
       '800704',
       '红冲入库',
       MYROW.MAT_NO || '1',
       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,
       '#FRIM_PLINE_CODE#',
       '#FRIM_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,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#FRIM_NAME#',
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '801401',
       '80150102',
       MYROW.JUDGE_STD_NAME,
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#BAL_YEAR_MONTH#',
       MYROW.QCM_STAUS,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       V_PROCESS_CDOE,
       V_PROCESS_DESC);
    V_INSTOCK_SEQ := '#INSTOCK_DOC_R#' || LPAD(V_COUNT, 4, 0);
    INSERT INTO YDM_ZC_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,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       STORAGE_NO,
       CREATE_NAME,
       CREATE_TIME,
       PRODUCT_FLAG,
       MAT_STATUS,
       INSTOCK_TIME,
       ACT_LEN,
       JUDGE_STD_NAME,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       BAL_YEAR_MONTH,
       IN_TIME_F,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       IN_MOLD,
       IN_TYPE,
       PRO_ORDER_NO,
       IS_DEALER,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       PROCESS_CDOE,
       PROCESS_DESC,
       JUGDE_APPLY_CODE)
    VALUES
      (V_INSTOCK_SEQ,
       '#INSTOCK_DOC_R#',
       '800704',
       '产出红冲',
       MYROW.MAT_NO,
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       '-' || MYROW.ACT_COUNT,
       '-' || MYROW.ACT_WEIGHT,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       MYROW.STORAGE_NO,
       '#FRIM_NAME#',
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       CASE WHEN MYROW.ACT_LEN IS NULL THEN '0' ELSE '-' || MYROW.ACT_LEN END,
       MYROW.JUDGE_STD_NAME,
       'C071',
       '制造管理部',
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '#BAL_YEAR_MONTH#',
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '801302',
       '产线',
       'C071',
       '制造管理部',
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.IN_MOLD,
       MYROW.IN_TYPE,
       MYROW.PRO_ORDER_NO,
       MYROW.IS_DEALER,
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC,
       '#INSTOCK_DOC#');
       
       INSERT INTO YDM_ZC_INLIST_XS
      (INSTOCK_SQE,
       INSTOCK_DOC,
       INSTOCK_TYPE_CODE,
       INSTOCK_TYPE_NAME,
       MAT_NO,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       STORAGE_NO,
       CREATE_NAME,
       CREATE_TIME,
       PRODUCT_FLAG,
       MAT_STATUS,
       INSTOCK_TIME,
       ACT_LEN,
       JUDGE_STD_NAME,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       BAL_YEAR_MONTH,
       IN_TIME_F,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       IN_MOLD,
       IN_TYPE,
       PRO_ORDER_NO,
       IS_DEALER,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       PROCESS_CDOE,
       PROCESS_DESC,
       JUGDE_APPLY_CODE)
    VALUES
      (V_INSTOCK_SEQ,
       '#INSTOCK_DOC_R#',
       '800704',
       '产出红冲',
       MYROW.MAT_NO,
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       '-' || MYROW.ACT_COUNT,
       '-' || MYROW.ACT_WEIGHT,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       MYROW.STORAGE_NO,
       '#FRIM_NAME#',
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       CASE WHEN MYROW.ACT_LEN IS NULL THEN '0' ELSE '-' || MYROW.ACT_LEN END,
       MYROW.JUDGE_STD_NAME,
       'C071',
       '制造管理部',
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '#BAL_YEAR_MONTH#',
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '801302',
       '产线',
       'C071',
       '制造管理部',
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.IN_MOLD,
       MYROW.IN_TYPE,
       MYROW.PRO_ORDER_NO,
       MYROW.IS_DEALER,
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC,
       '#INSTOCK_DOC#');
  
    INSERT INTO CRM_ZC_INLIST
      (STORAGE_NAME,
       MAT_NO,
       INSTOCK_SQE,
       INSTOCK_DOC,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       PRODUCT_FLAG,
       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,
       PLINE_CODE,
       PLINE_NAME,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       STORAGE_NO,
       IN_MOLD,
       PACK_NO,
       INSTOCK_TIME,
       CREATE_TIME,
       DATA_STATUS,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       BAL_YEAR_MONTH,
       ACT_DIMATER,
       ACT_HEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       INSTOCK_TYPE_CODE,
       INSTOCK_TYPE_NAME)
    VALUES
      ((SELECT G.STORAGE_NAME
         FROM YDM_BS_STORAGE G
        WHERE G.STORAGE_NO = MYROW.STORAGE_NO),
       MYROW.MAT_NO,
       V_INSTOCK_SEQ,
       '#INSTOCK_DOC_R#',
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.PRODUCT_FLAG),
       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.PLINE_CODE,
       MYROW.PLINE_NAME,
       '-' || MYROW.ACT_LEN,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       '-' || MYROW.ACT_COUNT,
       '-' || MYROW.ACT_WEIGHT,
       MYROW.STORAGE_NO,
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.IN_MOLD),
       MYROW.PACK_NO,
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '0',
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       '#BAL_YEAR_MONTH#',
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       '800704',
       '产出红冲');
  
    INSERT INTO CRM_MAT_ZC
      (MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       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,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       PLINE_CODE,
       PLINE_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       IN_MOLD,
       INSTOCK_TIME,
       STORAGE_NO,
       LOCATION_NO,
       STORAGE_NAME,
       LOCATION_NAME,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       CREATE_TIME,
       DATA_STATUS)
    VALUES
      (MYROW.MAT_NO,
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.PRODUCT_FLAG),
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.MAT_STATUS),
       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.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.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       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,
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.IN_MOLD),
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       (SELECT G.STORAGE_NAME
          FROM YDM_BS_STORAGE G
         WHERE G.STORAGE_NO = MYROW.STORAGE_NO),
       (SELECT G1.LOCATION_NAME
          FROM YDM_BS_LOCATION G1
         WHERE G1.LOCATION_NO = MYROW.LOCATION_NO),
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '2');
  
    DELETE FROM MAT_ZC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM MAT_ZC_M_XS T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM YDM_ZC_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
    V_COUNTCX := V_COUNTCX + 1;
    V_COUNT   := V_COUNT + 1;
  END LOOP;
  UPDATE YDM_ZC_REDCHONG T
     SET T.FRIM_FLAG       = '1',
         T.FRIM_NAME       = '#FRIM_NAME#',
         T.FRIM_TIME       = TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
         T.BAL_YEAR_MONTH  = '#BAL_YEAR_MONTH#',
         T.FRIM_PLINE_CODE = '#FRIM_PLINE_CODE#',
         T.FRIM_PLINE_NAME = '#FRIM_PLINE_NAME#',
         T.FRIM_MEMO       = '#FRIM_MEMO#'
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#';
END;
</query>
<query id = "FrmFrimRedChong.doFrimNot" desc = "审核不通过">
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM MAT_ZC_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.INSTOCK_DOC = '#INSTOCK_DOC#'
                   AND T.PRODUCT_FLAG = '801402') LOOP
    UPDATE MAT_ZC_M T
       SET T.MNG_LOCK_FLAG   = '0',
           T.MNG_LOCK_REMARK = ''
     WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  UPDATE YDM_ZC_REDCHONG T
     SET T.FRIM_FLAG = '2', T.FRIM_MEMO = '#FRIM_MEMO#',T.FRIM_NAME = '#FRIM_NAME#',T.FRIM_TIME = SYSDATE
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#';
END;
</query>
<query id = "FrmFrimRedChong.selectMatBcCount" desc = "查询库存支数">
SELECT NVL(SUM(T.ACT_COUNT), '0') ACT_COUNT
  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 NVL(T.MATERIAL_NO, '/') = NVL('#MATERIAL_NO#', '/')
   AND NVL(T.PRODUCCODE, '/') = NVL('#PRODUCCODE#', '/')
   AND T.QCM_STAUS = '00'
   AND T.MAT_STATUS = '80150102'
   AND T.REDCHONG_FLAG = '1'
   --AND T.PLINE_CODE IN ('100101', '100102')
</query>
<query id = "FrmFrimRedChong.selectFmisZcCount" desc = "查询库存支数">
select SUM(F.ACT_COUNT) ACT_COUNT
  from FMIS_ZC_INLIST F
 WHERE F.SYNC_FLAG = '0'
   AND F.INSTOCK_DOC IN
       (SELECT T1.INSTOCK_DOC
          FROM MAT_BC_M T, YDM_ZC_INLIST T1
         WHERE T.MAT_NO = T1.MAT_NO || '1'
         AND T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND T.BATCH_NO = '#BATCH_NO#'
           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
           AND NVL(T.MATERIAL_NO, '/') = NVL('#MATERIAL_NO#', '/')
           AND NVL(T.PRODUCCODE, '/') = NVL('#PRODUCCODE#', '/')
           AND T1.INSTOCK_TYPE_CODE = '800704'
           AND T.QCM_STAUS = '00'
           AND T.PRODUCT_FLAG = '801401'
           AND T.MAT_STATUS = '80150102')
</query>
<query id = "FrmFrimRedChong.selectMatZcCount" desc = "查询库存支数">
SELECT NVL(SUM(T.ACT_COUNT),'0')ACT_COUNT
  FROM MAT_ZC_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.INSTOCK_DOC = '#INSTOCK_DOC#'
   AND T.PRODUCT_FLAG = '801402'
</query>
<query id = "FrmRedChong.selectInStockDoc" desc = "生成入库单号">
SELECT ? || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 9)), 0) + 1, 5, 0) INSTOCK_DOC
    FROM YDM_ZC_INLIST T
   WHERE T.INSTOCK_TYPE_CODE = ?
     AND T.INSTOCK_DOC LIKE ? || TO_CHAR(SYSDATE, 'YYMMDD') || '_____'
</query>
<query id = "FrmRedChong.selectInStockDocCx" desc = "生成入库单号">
SELECT ? || 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 = ?
     AND T.INSTOCK_DOC LIKE ? || TO_CHAR(SYSDATE, 'YYMMDD') || '_____'
</query>
<query id = "FrmFrimRedChong.selectSumMatZc" desc = "查询总量">
SELECT NVL(SUM(T.ACT_COUNT),0)ACT_COUNT,
       NVL(SUM(T.ACT_WEIGHT),0) ACT_WEIGHT,
       NVL(SUM(T.ACT_LEN),0) ACT_LEN
  FROM MAT_ZC_M T, YDM_ZC_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.PRODUCT_FLAG = '801402'
</query>
<query id = "FrmFrimRedChong.selectMatZcRed" desc = "查询红冲材料号">
<![CDATA[
SELECT T.MAT_NO
          FROM MAT_ZC_M T, YDM_ZC_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.INSTOCK_DOC = '#INSTOCK_DOC#'
           AND T.PRODUCT_FLAG = '801402'
         ORDER BY T.MAT_NO ASC
 ]]>
</query>
<query id = "FrmFrimRedChong.selectMatZcStorage" desc = "修改剩余库存信息">
        SELECT T.MAT_NO
          FROM MAT_ZC_M T, YDM_ZC_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.PRODUCT_FLAG = '801402'
           AND T.INSTOCK_DOC IS NULL
         ORDER BY T.MAT_NO ASC
</query>
<query id = "FrmFrimRedChong.updateMatZcWgt" desc = "修改库存信息">

UPDATE MAT_ZC_M T
   SET T.ACT_WEIGHT  = '#ACT_WEIGHT#',
       T.ACT_LEN     = '#ACT_LEN#',
       T.INSTOCK_DOC = '#INSTOCK_DOC#',
       T.MNG_LOCK_FLAG = '1',
       T.MNG_LOCK_REMARK = '红冲'
 WHERE T.MAT_NO = '#MAT_NO#'
</query>
<query id = "FrmFrimRedChong.updateMatZcWgtStorage" desc = "修改库存剩余信息">
UPDATE MAT_ZC_M T
   SET T.ACT_WEIGHT  = '#ACT_WEIGHT#',
       T.ACT_LEN     = '#ACT_LEN#'
 WHERE T.MAT_NO = '#MAT_NO#'
</query>
<query id = "FrmFrimRedChong.cancelFrim" desc = "撤销审核">
DECLARE
V_INSTOCK_SEQ       YDM_ZC_INLIST.INSTOCK_SQE%TYPE := NULL;
V_COUNT             NUMBER := 1;
BEGIN
  FOR MYROW IN (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,
                       T1.INSTOCK_DOC,
                       T1.SUPPLY_UNIT_CODE,
                       T1.SUPPLY_UNIT,
                       T1.PACK_NO,
                       T1.IN_MOLD,
                       T1.INSTOCK_TYPE_CODE,
                       T1.INSTOCK_TYPE_NAME,
                       T1.PROCESS_CDOE AS PROCESS_CDOE_ZC
                  FROM MAT_BC_M T, YDM_BC_BUTTRESS S, YDM_ZC_INLIST T1
                 WHERE T.MAT_NO = S.MAT_NO
                   AND T.MAT_NO = T1.MAT_NO || '1'
                   AND S.MAT_NO = T1.MAT_NO || '1'
                   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND NVL(T.MATERIAL_NO, '/') = NVL('#MATERIAL_NO#', '/')
                   AND NVL(T.PRODUCCODE, '/') = NVL('#PRODUCCODE#', '/')
                   AND T1.INSTOCK_TYPE_CODE = '800704'
                   AND T1.JUGDE_APPLY_CODE= '#INSTOCK_DOC#' --红冲单号
                   AND T.QCM_STAUS = '00'
                   AND T.PRODUCT_FLAG = '801401'
                   AND T.MAT_STATUS = '80150102') LOOP
    INSERT INTO MAT_ZC_M
      (STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       STEELCODE,
       STEELNAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       PRO_ORDER_NO,
       BELONG_CODE,
       BELONG_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_LEN,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       CREATE_NAME,
       CREATE_TIME,
       INSTOCK_TIME,
       MAT_NO,
       MEMO,
       JUGDE_APPLY_FLAG,
       INSTOCK_FLAG,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       BAL_YEAR_MONTH,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_RESULT_TIME,
       JUDGE_MAKER,
       MNG_LOCK_FLAG,
       MNG_LOCK_REMARK,
       INSTOCK_DOC,
       ZBS_FLAG,
       ZBS_ID,
       MEASURING_SEQ,
       PROCESS_CDOE,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT)
    VALUES
      (MYROW.STOVE_NO,
       MYROW.LOT_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.PRO_ORDER_NO,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_LEN,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME,
       MYROW.INSTOCK_TIME,
       SUBSTR(MYROW.MAT_NO, 0, LENGTH(MYROW.MAT_NO) - 1),
       MYROW.MEMO,
       '1',
       '1',
       '801402',
       '80150202',
       MYROW.JUDGE_STD_DES,
       MYROW.BAL_YEAR_MONTH,
       '#PLINE_CODE#',
       '#PLINE_NAME#',
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.JUDGE_TOLRESULT_CODE,
       MYROW.JUDGE_TOLRESULT,
       MYROW.JUDGE_TOLRESULT_TIME,
       MYROW.JUDGE_TOLMAKER,
       '1',
       '红冲',
       '#INSTOCK_DOC#',
       MYROW.ZBS_FLAG,
       MYROW.ZBS_ID,
       MYROW.MEASURING_SEQ,
       MYROW.PROCESS_CDOE_ZC,
       '#SUPPLY_UNIT_CODE#',
       '#SUPPLY_UNIT#');
       
       INSERT INTO MAT_ZC_M_XS
      (STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       STEELCODE,
       STEELNAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       PRO_ORDER_NO,
       BELONG_CODE,
       BELONG_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_LEN,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       CREATE_NAME,
       CREATE_TIME,
       INSTOCK_TIME,
       MAT_NO,
       MEMO,
       JUGDE_APPLY_FLAG,
       INSTOCK_FLAG,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       BAL_YEAR_MONTH,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_RESULT_TIME,
       JUDGE_MAKER,
       MNG_LOCK_FLAG,
       MNG_LOCK_REMARK,
       INSTOCK_DOC,
       ZBS_FLAG,
       ZBS_ID,
       MEASURING_SEQ,
       PROCESS_CDOE,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT)
    VALUES
      (MYROW.STOVE_NO,
       MYROW.LOT_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.PRO_ORDER_NO,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_LEN,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME,
       MYROW.INSTOCK_TIME,
       SUBSTR(MYROW.MAT_NO, 0, LENGTH(MYROW.MAT_NO) - 1),
       MYROW.MEMO,
       '1',
       '1',
       '801402',
       '80150202',
       MYROW.JUDGE_STD_DES,
       MYROW.BAL_YEAR_MONTH,
       '#PLINE_CODE#',
       '#PLINE_NAME#',
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.JUDGE_TOLRESULT_CODE,
       MYROW.JUDGE_TOLRESULT,
       MYROW.JUDGE_TOLRESULT_TIME,
       MYROW.JUDGE_TOLMAKER,
       '1',
       '红冲',
       '#INSTOCK_DOC#',
       MYROW.ZBS_FLAG,
       MYROW.ZBS_ID,
       MYROW.MEASURING_SEQ,
       MYROW.PROCESS_CDOE_ZC,
       '#SUPPLY_UNIT_CODE#',
       '#SUPPLY_UNIT#');
       
    INSERT INTO YDM_ZC_BUTTRESS
      (JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       CREATE_NAME,
       MAT_NO,
       CREATE_TIME)
    VALUES
      (MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.CREATE_NAME,
       SUBSTR(MYROW.MAT_NO, 0, LENGTH(MYROW.MAT_NO) - 1),
       MYROW.CREATE_TIME);
  
    --CRM
    V_INSTOCK_SEQ := '#INSTOCK_DOC#' || LPAD(V_COUNT, 4, 0);
    INSERT INTO CRM_ZC_INLIST
      (STORAGE_NAME,
       MAT_NO,
       INSTOCK_SQE,
       INSTOCK_DOC,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       PRODUCT_FLAG,
       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,
       PLINE_CODE,
       PLINE_NAME,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       STORAGE_NO,
       IN_MOLD,
       PACK_NO,
       INSTOCK_TIME,
       CREATE_TIME,
       DATA_STATUS,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       BAL_YEAR_MONTH,
       ACT_DIMATER,
       ACT_HEIGHT,
       BELONG_CODE,
       BELONG_NAME,
        INSTOCK_TYPE_CODE,
        INSTOCK_TYPE_NAME)
    VALUES
      ((SELECT G.STORAGE_NAME
         FROM YDM_BS_STORAGE G
        WHERE G.STORAGE_NO = MYROW.STORAGE_NO),
       MYROW.MAT_NO,
       V_INSTOCK_SEQ,
       '#INSTOCK_DOC_R#',
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.PRODUCT_FLAG),
       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.PLINE_CODE,
       MYROW.PLINE_NAME,
       '-' || MYROW.ACT_LEN,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       '-' || MYROW.ACT_COUNT,
       '-' || MYROW.ACT_WEIGHT,
       MYROW.STORAGE_NO,
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.IN_MOLD),
       MYROW.PACK_NO,
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '2',
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       MYROW.BAL_YEAR_MONTH,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
        MYROW.INSTOCK_TYPE_CODE,
        MYROW.INSTOCK_TYPE_NAME);
  
    INSERT INTO CRM_MAT_ZC
      (MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       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,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       PLINE_CODE,
       PLINE_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       IN_MOLD,
       INSTOCK_TIME,
       STORAGE_NO,
       LOCATION_NO,
       STORAGE_NAME,
       LOCATION_NAME,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       CREATE_TIME,
       DATA_STATUS)
    VALUES
      (MYROW.MAT_NO,
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.PRODUCT_FLAG),
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.MAT_STATUS),
       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.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.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       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,
       (SELECT F.BASENAME
          FROM COM_BASE_INFO F
         WHERE F.BASECODE = MYROW.IN_MOLD),
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       (SELECT G.STORAGE_NAME
          FROM YDM_BS_STORAGE G
         WHERE G.STORAGE_NO = MYROW.STORAGE_NO),
       (SELECT G1.LOCATION_NAME
          FROM YDM_BS_LOCATION G1
         WHERE G1.LOCATION_NO = MYROW.LOCATION_NO),
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       TO_DATE('#FRIM_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '0');
  
    DELETE FROM YDM_BC_INLIST T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.INSTOCK_TYPE_CODE = '800704'
       AND T.PLINE_CODE = '#FRIM_PLINE_CODE#';
    DELETE FROM YDM_ZC_INLIST T
     WHERE T.MAT_NO = SUBSTR(MYROW.MAT_NO, 0, LENGTH(MYROW.MAT_NO) - 1)
       AND T.INSTOCK_TYPE_CODE = '800704'
       AND T.PLINE_CODE = '#PLINE_CODE#';
        DELETE FROM YDM_ZC_INLIST_XS T
     WHERE T.MAT_NO = SUBSTR(MYROW.MAT_NO, 0, LENGTH(MYROW.MAT_NO) - 1)
       AND T.INSTOCK_TYPE_CODE = '800704'
       AND T.PLINE_CODE = '#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;
    
     --FMIS
  DELETE FROM FMIS_ZC_INLIST T
   WHERE T.INSTOCK_DOC = MYROW.INSTOCK_DOC
     AND T.SYNC_FLAG = '0';
    
    V_COUNT   := V_COUNT + 1;
  END LOOP;
 
  UPDATE YDM_ZC_REDCHONG T
     SET T.FRIM_FLAG       = '0',
         T.FRIM_NAME       = '',
         T.FRIM_TIME       = '',
         T.FRIM_PLINE_CODE = '',
         T.FRIM_PLINE_NAME = '',
         T.FRIM_MEMO       = ''
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#';
END;
</query>
<query id = "FrmFrimRedChong.cancelFrimNot" desc = "撤销审核不通过">
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM MAT_ZC_M T
                 WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#'
                 ORDER BY T.MAT_NO ASC) LOOP
    UPDATE MAT_ZC_M T
       SET T.MNG_LOCK_FLAG = '0', T.MNG_LOCK_REMARK = '红冲'
     WHERE T.MAT_NO = MYROW.MAT_NO;
     
     UPDATE MAT_ZC_M_XS T
       SET T.MNG_LOCK_FLAG = '0', T.MNG_LOCK_REMARK = '红冲'
     WHERE T.MAT_NO = MYROW.MAT_NO;
     
  END LOOP;
  UPDATE YDM_ZC_REDCHONG T
     SET T.FRIM_FLAG = '0',
         T.FRIM_MEMO = '',
         T.FRIM_NAME = '',
         T.FRIM_TIME = ''
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#';
END;
</query>
</queryMap>
