<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "库里剔废">
<query id = "FrmStorageScrap.queryMat" desc = "查询库存信息">
<![CDATA[
select T.MAT_NO,
       T.PRODUCT_FLAG,
       T.MAT_STATUS,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       DECODE(T.SAMPLE_FLAG, '1', '样管', '') SAMPLE_FLAG,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.INPUT_MATERIAL_NAME,
       T.INPUT_MATERIAL_NO,
       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.PRO_ORDER_ID,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.ORDER_SEQ_NO,
       T.CRAF_NO,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       T.NEXT_PROCESS_CDOE,
       T.NEXT_PROCESS_DESC,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.MAT_ORIGIN_CODE,
       T.MAT_ORIGIN_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.ACT_THEORY_WEIGHT,
       T.MEASURE_FLAG,
       T.BELONG_CODE,
       T.BELONG_NAME,
       T.PACK_FLAG,
       T.MAT_GOWHERE_CODE,
       T.MAT_GOWHERE_NAME,
       T.MAT_RETURN_FLAG,
       T.LOCK_FLAG,
       T.MNG_LOCK_FLAG,
       T.JUGDE_APPLY_FLAG,
       T.JUGDE_APPLY_CODE,
       TO_CHAR(T.JUGDE_APPLY_TIME, 'YYYY-MM-DD HH24:MI:SS') JUGDE_APPLY_TIME,
       T.FACE_RESULT_CODE,
       TO_CHAR(T.FACE_RESULT_TIME, 'YYYY-MM-DD HH24:MI:SS') FACE_RESULT_TIME,
       T.FACE_MAKER,
       T.SPEC_RESULT_CODE,
       TO_CHAR(T.SPEC_RESULT_TIME, 'YYYY-MM-DD HH24:MI:SS') SPEC_RESULT_TIME,
       T.SPEC_MAKER,
       T.CHEM_RESULT_CODE,
       TO_CHAR(T.CHEM_RESULT_TIME, 'YYYY-MM-DD HH24:MI:SS') CHEM_RESULT_TIME,
       T.CHEM_MAKER,
       T.PHY_RESULT_CODE,
       TO_CHAR(T.PHY_RESULT_TIME, 'YYYY-MM-DD HH24:MI:SS') PHY_RESULT_TIME,
       T.PHY_MAKER,
       T.DETECT_RESULT_CODE,
       T.WPRESSURE_RESULT_CODE,
       T.JUDGE_RESULT_CODE,
       T.JUDGE_RESULT,
       TO_CHAR(T.JUDGE_RESULT_TIME, 'YYYY-MM-DD HH24:MI:SS') JUDGE_RESULT_TIME,
       T.JUDGE_MAKER,
       T.INSTOCK_FLAG,
       TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS') INSTOCK_TIME,
       T.BAR_CODE,
       T.MEMO,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       T.BAL_YEAR_MONTH,
       T.JUDGE_STD_NAME,
       T.PIPMEMO,
       T.SOURE_CODE,
       T.SOURE_NAME,
       T.PONDER_NO,
       T.PONDER_GROSS_WT,
       T.JUDGE_ID,
       T.LOCK_LIKU,
       DECODE(T.QCM_STAUS,
              '00',
              '合格',
              '11',
              '待处理',
              '22',
              '判废',
              '10',
              '处理合格',
              '12',
              '处理判废') QCM_STAUS,
       T.OUTSTOCK_DOC,
       T.HEAT_PLAN_NO,
       T.ZG_STOVE_SQE,
       T.GX_PLAN_NO,
       T.ZG_MAT_NO,
       T.TARGET,
       T.PROCESS_STATUS,
       T.JUGDE_CONVICTED,
       T.FIXTYPE_CODE,
       T.QUALITY_GROUP_ZG,
       T.FLAG_STOVE_NO_ZG,
       T.DETECT_RESULT_CODE1,
       T.TESTING_GRADE,
       T.TESTING_TYPE,
       T.TESTING_GRADE1,
       T.TESTING_TYPE1,
       T.JUDGE_STOVE_NO_UP,
       T.CRAFT_SEQ,
       T.PRO_PLAN_ID_NEXT,
       T.GX_PLAN_NO_NEXT,
       T.HANGING_FLAG,
       T.CUT_NUM,
       T.JUDGE_TOLRESULT_CODE,
       T.JUDGE_TOLRESULT,
       TO_CHAR(T.JUDGE_TOLRESULT_TIME, 'YYYY-MM-DD HH24:MI:SS') JUDGE_TOLRESULT_TIME,
       T.JUDGE_TOLMAKER,
       T.INSTANCY_FLAG,
       T.JUGDE_TOLCONVICTED,
       T.JUDGE_STD_DES,
       T.MNG_LOCK_REMARK,
       T.LOCK_REMARK,
       T.JUGDE_APPLY_SEQUENO,
       T.HEAT_PLAN_NO_NEXT,
       T.CODE_JG_BL,
       T.CIC,
       T.SCRAP_REASON,
       T.BELONG_CODE_RESPONSE,
       T.BELONG_NAME_RESPONSE,
       T.ZBS_FLAG,
       T.SCRAP_TYPE,
       T.ZBS_ID,
       T.HEAT_PLAN_NO_OLD,
       T.MEASURING_SEQ,
       T.SCRAP_FLAG,
       T.LIKU_PROCESS_CODE,
       T.JG_ZBS_ID,
       T.FAIL_APPROVAL_CODE,
       T.OFFLINE_DOC,
       T.SUBCONTRACT_NO,
       T.SCRAP_FRIM_FLAG,
       T.ZZB_FLAG,
       T.BAL_YEAR_MONTH_FAIL,
       T.SUBCONTRACT_NO_SEQ,
       T.SCRAP_NAME,
       TO_CHAR(T.SCRAP_TIME, 'YYYY-MM-DD HH24:MI:SS') SCRAP_TIME,
       T1.STORAGE_NO,
       T2.STORAGE_NAME
  from MAT_BC_M T, YDM_BC_BUTTRESS T1, YDM_BS_STORAGE T2
 WHERE T.MAT_NO = T1.MAT_NO
   AND T1.STORAGE_NO = T2.STORAGE_NO
   AND T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_CDOE = ?
   AND T.JUGDE_APPLY_CODE IS NULL
      --AND T.JUDGE_RESULT IS NULL
   AND (T.QCM_STAUS = '00' OR T.SCRAP_NAME IS NOT NULL)
   ORDER BY T.MAT_NO
       ]]>
</query>

<query id = "FrmStorageScrap.selectByMatNo" desc = "根据材料号查询库存信息">
<![CDATA[
select COUNT(1) ACOUNT
  from MAT_BC_M T
 WHERE T.MAT_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_CDOE = ?
   AND T.QCM_STAUS = ?
   AND T.JUGDE_APPLY_CODE IS NULL
   AND (T.QCM_STAUS = '00' OR T.SCRAP_NAME IS NOT NULL)
       ]]>
</query>

<query id = "FrmStorageScrap.selectByMatNo2" desc = "根据材料号查询库存信息">
<![CDATA[
select T.*
  from MAT_BC_M T
 WHERE T.MAT_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_CDOE = ?
   AND T.JUGDE_APPLY_CODE IS NULL
   AND (T.QCM_STAUS = '00' OR T.SCRAP_NAME IS NOT NULL)
       ]]>
</query>

<query id = "FrmStorageScrap.scrape" desc = "库里剔废">
<![CDATA[
DECLARE
  V_MAT_NO         MAT_BC_M.MAT_NO%type := ?;
  V_JUDGE_STOVE_NO MAT_BC_M.JUDGE_STOVE_NO%type := ?;
  V_PROCESS_CDOE   MAT_BC_M.PROCESS_CDOE%type := ?;
  V_SCRAP_NAME     MAT_BC_M.SCRAP_NAME%type := ?;
  V_SCRAP_REASON   MAT_BC_M.SCRAP_REASON%type := ?;
BEGIN
  update MAT_BC_M t
     set t.qcm_staus         = '22',
         T.JUDGE_RESULT_CODE = '40740705',
         T.JUDGE_RESULT      = '废品',
         T.SCRAP_REASON      = V_SCRAP_REASON,
         T.PRO_PLAN_ID_NEXT  = '',
         T.GX_PLAN_NO_NEXT   = '',
         T.SCRAP_NAME        = V_SCRAP_NAME,
         T.SCRAP_TIME        = SYSDATE
   where t. mat_no = V_MAT_NO
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PROCESS_CDOE = V_PROCESS_CDOE;

  update YDM_BC_INLIST t
     set t.QCM_STAUS = '22'
   where t.judge_stove_no = V_JUDGE_STOVE_NO
     and t.instock_type_code = '800701'
     and t.mat_no = V_MAT_NO;

  IF (V_PROCESS_CDOE = 'E') THEN
    UPDATE PORT_VRP_BATCH_SAMPLE_RESULT S
       SET S.MAT_STATUS = '10'
     WHERE S.MAT_NO = V_MAT_NO
       AND S.MAT_STATUS = '00'
       AND S.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
  ELSIF (V_PROCESS_CDOE = 'F') THEN
    UPDATE PORT_HTT_BATCH_SAMPLE_RESULT S
       SET S.MAT_STATUS = '10'
     WHERE S.MAT_NO = V_MAT_NO
       AND S.MAT_STATUS = '00'
       AND S.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
  ELSIF (V_PROCESS_CDOE = 'G') THEN
    UPDATE PORT_MCH_BATCH_SAMPLE_RESULT S
       SET S.MAT_STATUS = '10'
     WHERE S.MAT_NO = V_MAT_NO
       AND S.MAT_STATUS = '00'
       AND S.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
  END IF;
END;
       ]]>
</query>

<query id = "FrmStorageScrap.scrapeBack" desc = "撤销剔废">
<![CDATA[
DECLARE
  V_MAT_NO         MAT_BC_M.MAT_NO%type := ?;
  V_JUDGE_STOVE_NO MAT_BC_M.JUDGE_STOVE_NO%type := ?;
  V_PROCESS_CDOE   MAT_BC_M.PROCESS_CDOE%type := ?;
BEGIN
  update MAT_BC_M t
     set t.qcm_staus         = '00',
         T.JUDGE_RESULT_CODE = '',
         T.JUDGE_RESULT      = '',
         T.SCRAP_REASON      = '',
         T.SCRAP_NAME        = '',
         T.SCRAP_TIME        = ''
   where t. mat_no = V_MAT_NO
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PROCESS_CDOE = V_PROCESS_CDOE;

  update YDM_BC_INLIST t
     set t.QCM_STAUS = '00'
   where t.judge_stove_no = V_JUDGE_STOVE_NO
     and t.instock_type_code = '800701'
     and t.mat_no = V_MAT_NO;

  IF (V_PROCESS_CDOE = 'E') THEN
    UPDATE PORT_VRP_BATCH_SAMPLE_RESULT S
       SET S.MAT_STATUS = '00'
     WHERE S.MAT_NO = V_MAT_NO
       AND S.MAT_STATUS = '10'
       AND S.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
  ELSIF (V_PROCESS_CDOE = 'F') THEN
    UPDATE PORT_HTT_BATCH_SAMPLE_RESULT S
       SET S.MAT_STATUS = '00'
     WHERE S.MAT_NO = V_MAT_NO
       AND S.MAT_STATUS = '10'
       AND S.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
  ELSIF (V_PROCESS_CDOE = 'G') THEN
    UPDATE PORT_MCH_BATCH_SAMPLE_RESULT S
       SET S.MAT_STATUS = '00'
     WHERE S.MAT_NO = V_MAT_NO
       AND S.MAT_STATUS = '10'
       AND S.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
  END IF;

END;
       ]]>
</query>
</queryMap>
