<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "废品申请审核管理">
<query id = "FrmScrapApply.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.PRO_PLAN_ID_NEXT,
       T.GX_PLAN_NO_NEXT,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       DECODE(T1.ORDER_TYP, '120108', '双经销', '自用') IS_DEALER,
       MAX(T.PRODUCCODE)PRODUCCODE,
       MAX(T.PRODUCNAME)PRODUCNAME,
       MAX(T.STEELCODE)STEELCODE,
       MAX(T.STEELNAME)STEELNAME,
       MAX(T.GRADECODE)GRADECODE,
       MAX(T.GRADENAME)GRADENAME,
       MAX(T.SPEC_CODE)SPEC_CODE,
       MAX(T.SPEC_NAME)SPEC_NAME,
       MAX(T.MODEL_CODE)MODEL_CODE,
       MAX(T.MODEL_DESC)MODEL_DESC,
       MAX(T.STD_CODE)STD_CODE,
       MAX(T.STD_NAME)STD_NAME,
       MAX(T.STD_STYLE)STD_STYLE,
       MAX(T.STD_STYLE_DESC)STD_STYLE_DESC,
       T.PRO_ORDER_ID,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       MAX(TO_CHAR(T.INSTOCK_TIME,'YYYY-MM-DD'))INSTOCK_TIME,
       MAX(TO_CHAR(T.JUDGE_RESULT_TIME,'YYYY-MM-DD'))JUDGE_RESULT_TIME,
       MAX(T.PLINE_CODE)PLINE_CODE,
       MAX(T.PLINE_NAME)PLINE_NAME,
       MAX(T.ACT_DIMATER)ACT_DIMATER,
       MAX(T.ACT_HEIGHT)ACT_HEIGHT,
       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.JUDGE_RESULT_CODE)SPEC_RESULT_CODE,
       MAX((SELECT S.BASENAME FROM COM_BASE_INFO S WHERE S.BASECODE = T.JUDGE_RESULT_CODE))JUDGE_RESULT_CODE,
       
       (SELECT S1.STORAGE_NAME FROM YDM_BS_STORAGE S1 WHERE S1.STORAGE_NO = S.STORAGE_NO)STORAGE_NAME,
       S.STORAGE_NO,
       MAX(T.NEXT_PROCESS_CDOE)NEXT_PROCESS_CDOE,
       MAX(T.NEXT_PROCESS_DESC)NEXT_PROCESS_DESC,
       MAX(T.CRAF_NO)CRAF_NO,
       MAX(T.JUDGE_STD_DES)JUDGE_STD_DES,
       DECODE(T.SCRAP_FRIM_FLAG,'0','未申请','1','已申请','2','已审核')SCRAP_FRIM_FLAG,
       T.JUDGE_RESULT,
       T.MEMO,
       T.SCRAP_REASON,
       T.SOURE_CODE,
       T.SOURE_NAME,
       T.BAL_YEAR_MONTH_FAIL
 FROM MAT_BC_M T,YDM_BC_BUTTRESS S, SLM_ORDER_HEAD T1
 WHERE T.MAT_NO = S.MAT_NO
 AND T.QCM_STAUS = '22'
 AND T.ORD_PK = T1.ORD_PK(+)
</query>
<query id = "FrmScrapApply.doQueryApply" desc = "查询已申请信息">
 SELECT 
       T.FAIL_APPROVAL_CODE,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.PRO_ORDER_NO,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_COUNT,
       T.ACT_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       T.TARGET,
       T.SCRAP_REASON,
       T.BELONG_CODE_RESPONSE,
       T.BELONG_NAME_RESPONSE,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.FRIM_NAME,
       TO_CHAR(T.FRIM_TIME, 'YYYY-MM-DD HH24:MI:SS') FRIM_TIME,
       DECODE(T.FRIM_FLAG,'0','未审核','1','审核通过','2','审核不通过')FRIM_FLAG,
       T.BAL_YEAR_MONTH,
       T.CRAFT_NO,
       T.CRAFT_PATH,
    DECODE(T.IS_FAST,'0','否','1','是') IS_FAST,
       T.SCRAP_DESC
 FROM YDM_BC_SCRAPFRIM T
 WHERE 1 = 1
</query>
<query id = "FrmScrapApply.doQueryDepartMent" desc = "查询产线对应的部门">
SELECT T.DEPARTMENT_CODE AS DEPARTMENT_CODE_P, T.DEPARTMENT_DESC AS DEPARTMENT_DESC_P
  FROM COM_BASE_PLINE T
 WHERE T.PLINE_CODE = '#PLINE_CODE#'
</query>
<query id = "FrmScrapApply.doQueryApplyCount" desc = "查询未申请支数">
SELECT SUM(T.ACT_COUNT) ACOUNT
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(T.SCRAP_REASON,'/') = NVL('#SCRAP_REASON#','/')
   AND T.QCM_STAUS = '22'
   AND T.SCRAP_FRIM_FLAG = '0'
   AND T.PLINE_CODE = '#PLINE_CODE#'
</query>
<query id = "FrmScrapApply.doQueryApplyWgt" desc = "查询重量">
<![CDATA[
SELECT SUM(ACT_WEIGHT) AWGT
  FROM (SELECT T.ACT_WEIGHT
          FROM MAT_BC_M T
         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND NVL(T.SCRAP_REASON, '/') = NVL('#SCRAP_REASON#', '/')
           AND T.QCM_STAUS = '22'
           AND T.SCRAP_FRIM_FLAG = '0'
           AND T.PLINE_CODE = '#PLINE_CODE#'
         ORDER BY T.MAT_NO DESC)
 WHERE ROWNUM <= #ACT_COUNT#
 ]]>
</query>
<query id = "FrmScrapApply.getApplyCode" desc = "生成申请单号">
SELECT ? || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.FAIL_APPROVAL_CODE, 11)), 0) + 1, 5, 0) FAIL_APPROVAL_CODE
    FROM YDM_BC_SCRAPFRIM T
   WHERE T.FAIL_APPROVAL_CODE LIKE ? || TO_CHAR(SYSDATE, 'YYMMDD') || '_____'
</query>

<query id = "FrmScrapApply.getApplyCode2" desc = "生成申请单号">
SELECT '#PLINE_CODE#' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.FAIL_APPROVAL_CODE, 11)), 0) + 1, 5, 0) FAIL_APPROVAL_CODE
    FROM YDM_BC_SCRAPFRIM T
   WHERE T.FAIL_APPROVAL_CODE LIKE '#PLINE_CODE#' || TO_CHAR(SYSDATE, 'YYMMDD') || '_____'
</query>

<query id = "FrmScrapApply.applyFrim" desc = "申请审核">
<![CDATA[
DECLARE
  V_FAIL_APPROVAL_CODE YDM_BC_SCRAPFRIM.FAIL_APPROVAL_CODE%TYPE := NULL;
BEGIN
  SELECT '#PLINE_CODE#' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.FAIL_APPROVAL_CODE, 11)), 0) + 1, 5, 0)
    INTO V_FAIL_APPROVAL_CODE
    FROM YDM_BC_SCRAPFRIM T
   WHERE T.FAIL_APPROVAL_CODE LIKE
         '#PLINE_CODE#' || TO_CHAR(SYSDATE, 'YYMMDD') || '_____';
  INSERT INTO YDM_BC_SCRAPFRIM
    (FAIL_APPROVAL_CODE,
     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,
     PROCESS_CDOE,
     PROCESS_DESC,
     PLINE_CODE,
     PLINE_NAME,
     ACT_DIMATER,
     ACT_HEIGHT,
     ACT_LEN,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     ACT_COUNT,
     ACT_WEIGHT,
     BELONG_CODE,
     BELONG_NAME,
     TARGET,
     SCRAP_REASON,
     CREATE_NAME,
     CREATE_TIME,
     BAL_YEAR_MONTH,
     CRAFT_NO,
     CRAFT_PATH,
     BELONG_CODE_RESPONSE,
     BELONG_NAME_RESPONSE,
     IS_FAST,
     SCRAP_DESC,
     SOURE_CODE,
     SOURE_NAME)
  VALUES
    (V_FAIL_APPROVAL_CODE,
     '#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#',
     '#PROCESS_CDOE#',
     '#PROCESS_DESC#',
     '#PLINE_CODE#',
     '#PLINE_NAME#',
     '#ACT_DIMATER#',
     '#ACT_HEIGHT#',
     '#ACT_LEN#',
     '#ACT_LEN_MIN#',
     '#ACT_LEN_MAX#',
     '#ACT_COUNT#',
     '#ACT_WEIGHT#',
     '#BELONG_CODE#',
     '#BELONG_NAME#',
     '#TARGET#',
     '#SCRAP_REASON#',
     '#CREATE_NAME#',
     SYSDATE,
     '#BAL_YEAR_MONTH#',
     '#CRAFT_NO#',
     '#CRAFT_PATH#',
     '#BELONG_CODE_RESPONSE#',
     '#BELONG_NAME_RESPONSE#',
     '#IS_FAST#',
     '#SCRAP_DESC#',
     '#SOURE_CODE#',
     '#SOURE_NAME#');
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*
                          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.QCM_STAUS = '22'
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                           AND T.SCRAP_FRIM_FLAG = '0'
                           AND NVL(T.SCRAP_REASON, '/') =
                               NVL('#SCRAP_REASON#', '/')
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE MAT_BC_M T
       SET T.FAIL_APPROVAL_CODE = V_FAIL_APPROVAL_CODE,
           T.SCRAP_FRIM_FLAG    = '1'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
  END LOOP;
END;

]]>
</query>

<query id = "FrmScrapApply.addApplyFrim" desc = "插入管材废品申请审核表">
<![CDATA[
DECLARE
  V_FAIL_APPROVAL_CODE YDM_BC_SCRAPFRIM.FAIL_APPROVAL_CODE%TYPE := NULL;
BEGIN
  INSERT INTO YDM_BC_SCRAPFRIM
    (FAIL_APPROVAL_CODE,
     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,
     PROCESS_CDOE,
     PROCESS_DESC,
     PLINE_CODE,
     PLINE_NAME,
     ACT_DIMATER,
     ACT_HEIGHT,
     ACT_LEN,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     ACT_COUNT,
     ACT_WEIGHT,
     BELONG_CODE,
     BELONG_NAME,
     TARGET,
     SCRAP_REASON,
     CREATE_NAME,
     CREATE_TIME,
     BAL_YEAR_MONTH,
     CRAFT_NO,
     CRAFT_PATH,
     BELONG_CODE_RESPONSE,
     BELONG_NAME_RESPONSE,
     IS_FAST,
     SCRAP_DESC,
     SCRAP_TYPE,
     FRIM_FLAG,
     FRIM_NAME,
     FRIM_TIME,
     SOURE_CODE,
     SOURE_NAME)
  VALUES
    ('#FAIL_APPROVAL_CODE#',
     '#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#',
     '#PROCESS_CDOE#',
     '#PROCESS_DESC#',
     '#PLINE_CODE#',
     '#PLINE_NAME#',
     '#ACT_DIMATER#',
     '#ACT_HEIGHT#',
     '#ACT_LEN#',
     '#ACT_LEN_MIN#',
     '#ACT_LEN_MAX#',
     '#ACT_COUNT#',
     '#ACT_WEIGHT#',
     '#BELONG_CODE#',
     '#BELONG_NAME#',
     '#TARGET#',
     '#SCRAP_REASON#',
     '#CREATE_NAME#',
     SYSDATE,
     '#BAL_YEAR_MONTH#',
     '#CRAFT_NO#',
     '#CRAFT_PATH#',
     (SELECT C.DEPARTMENT_CODE
        FROM COM_BASE_PLINE C
       WHERE C.PLINE_CODE = '#BELONG_CODE_RESPONSE#'),
     (SELECT C.DEPARTMENT_DESC
        FROM COM_BASE_PLINE C
       WHERE C.PLINE_CODE = '#BELONG_CODE_RESPONSE#'),
     '#IS_FAST#',
     '#SCRAP_DESC#',
     '1',
     '#FRIM_FLAG#',
     '#FRIM_NAME#',
     SYSDATE,
     '#SOURE_CODE#',
     '#SOURE_NAME#');
END;

]]>
</query>
<query id = "FrmScrapApply.getFrimFlag" desc = "查询状态">
SELECT T.FRIM_FLAG FROM YDM_BC_SCRAPFRIM T WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#'
</query>
<query id = "FrmScrapApply.cancelApplyFrim" desc = "撤销申请">
DECLARE
BEGIN
  UPDATE MAT_BC_M T
     SET T.SCRAP_FRIM_FLAG = '0', T.FAIL_APPROVAL_CODE = ''
   WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#'
     AND T.PLINE_CODE = '#PLINE_CODE#';
  DELETE FROM YDM_BC_SCRAPFRIM T
   WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#';
END;
</query>
<query id = "FrmScrapApply.doQueryMatCount" desc = "查询库存">
SELECT SUM(T.ACT_COUNT) ACOUNT
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.QCM_STAUS = '22'
   AND NVL(T.SCRAP_REASON,'/') = NVL('#SCRAP_REASON#','/')
   AND T.SCRAP_FRIM_FLAG = '#SCRAP_FRIM_FLAG#'
</query>
<query id = "FrmScrapApply.frimScarp" desc = "审核">
<![CDATA[
DECLARE
  V_PROCESS_CODE MAT_BC_M.PROCESS_CDOE%TYPE := NULL;
BEGIN
  SELECT T.PROCESS_CODE
    INTO V_PROCESS_CODE
    FROM COM_BASE_PLINE T
   WHERE T.PLINE_CODE = '#PLINE_CODE#';
  FOR MYROW IN (SELECT *
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.QCM_STAUS = '22'
                   AND NVL(T.SCRAP_REASON, '/') = NVL('#SCRAP_REASON#', '/')
                   AND T.SCRAP_FRIM_FLAG = '0'
                   AND ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE MAT_BC_M T
       SET T.SCRAP_FRIM_FLAG      = '#SCRAP_FRIM_FLAG#',
           T.FAIL_APPROVAL_CODE   = '#FAIL_APPROVAL_CODE#',
           T.BAL_YEAR_MONTH_FAIL  = '#BAL_YEAR_MONTH#',
           T.BELONG_CODE_RESPONSE = '#BELONG_CODE_RESPONSE#',
           T.BELONG_NAME_RESPONSE = '#BELONG_NAME_RESPONSE#',
           T.JUDGE_RESULT_CODE    = '40740705',
           T.JUDGE_RESULT         = '废品',
           T.SCRAP_NAME           = '#SCRAP_NAME#',
           T.SCRAP_TIME           = TO_DATE('#SCRAP_TIME#',
                                            'YYYY-MM-DD HH24:MI:SS')
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
    IF (V_PROCESS_CODE = 'F') THEN
      UPDATE PORT_HTT_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK       = '1',
             T.BAL_YEAR_MONTH_FAIL = '#BAL_YEAR_MONTH#'
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    ELSIF (V_PROCESS_CODE = 'G') THEN
      UPDATE PORT_MCH_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK       = '1',
             T.BAL_YEAR_MONTH_FAIL = '#BAL_YEAR_MONTH#'
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    ELSIF (V_PROCESS_CODE = 'E') THEN
      UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK       = '1',
             T.BAL_YEAR_MONTH_FAIL = '#BAL_YEAR_MONTH#'
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    END IF;
  END LOOP;
END;

]]>
</query>
<query id = "FrmScrapApply.cancelFrimScrap" desc = "撤销审核">
<![CDATA[
DECLARE
  V_PROCESS_CODE MAT_BC_M.PROCESS_CDOE%TYPE := NULL;
BEGIN
  SELECT T.PROCESS_CODE
    INTO V_PROCESS_CODE
    FROM COM_BASE_PLINE T
   WHERE T.PLINE_CODE = '#PLINE_CODE#';
  FOR MYROW IN (SELECT *
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.QCM_STAUS = '22'
                   AND NVL(T.SCRAP_REASON, '/') = NVL('#SCRAP_REASON#', '/')
                   AND T.SCRAP_FRIM_FLAG = '2'
                   AND (T.FAIL_APPROVAL_CODE IS NULL OR
                       T.FAIL_APPROVAL_CODE IN
                       (SELECT S.FAIL_APPROVAL_CODE
                           FROM YDM_BC_SCRAPFRIM S
                          WHERE S.SCRAP_TYPE = '1'))
                   AND ROWNUM <= #ACT_COUNT#) LOOP
                   
    IF (MYROW.FAIL_APPROVAL_CODE IS NOT NULL) THEN
      DELETE FROM YDM_BC_SCRAPFRIM S
       WHERE S.FAIL_APPROVAL_CODE = MYROW.FAIL_APPROVAL_CODE;
    END IF;
    
    UPDATE MAT_BC_M T
       SET T.SCRAP_FRIM_FLAG     = '#SCRAP_FRIM_FLAG#',
           T.FAIL_APPROVAL_CODE  = '',
           T.BAL_YEAR_MONTH_FAIL = '',
           T.SCRAP_NAME          = '',
           T.SCRAP_TIME          = ''
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
    IF (V_PROCESS_CODE = 'F') THEN
      UPDATE PORT_HTT_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK = '0', T.BAL_YEAR_MONTH_FAIL = ''
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    ELSIF (V_PROCESS_CODE = 'G') THEN
      UPDATE PORT_MCH_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK = '0', T.BAL_YEAR_MONTH_FAIL = ''
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    ELSIF (V_PROCESS_CODE = 'E') THEN
      UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK = '0', T.BAL_YEAR_MONTH_FAIL = ''
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    END IF;
  END LOOP;
END;

]]>
</query>
<query id = "FrmScrapApply.doQueryCraftPath" desc = "查询工艺文件路径">
SELECT T.CRAFT_PATH FROM CRAFT_ORD_DESIGN T WHERE T.CRAFT_NO = '#CRAF_NO#'
</query>
</queryMap>