<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "成品缴库管理">
<query id = "FrmFinishAfrim.doQueryApplyJudge" desc = "查询判定数据">
SELECT 
       T.JUGDE_APPLY_CODE,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.PROCESS_CODE,
       T.PLINE_CODE,
       T.ACT_COUNT,
       T.ACT_WEIGHT,
       T.MEMO,
       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.LOT_NO,
       T.PLINE_NAME,
       T.PRO_ORDER_NO,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_LEN_MIN ||'-'||T.ACT_LEN_MAX AS LENGTH,
       T.ORD_LN_DLY_PK,
       DECODE(T.INSTOCK_FLAG,'0','未缴库','1','已缴库')INSTOCK_FLAG,
       DECODE(T.IS_ALL_SCRAP,'0','正常','6','半成品转成品','7','离线转压库','8','余材转压库')IS_ALL_SCRAP,
       T.BELONG_CODE,
       T.BELONG_NAME,
       T.ACT_LEN,
       T.BELONG_CODE_JUGDE,
       T.BELONG_NAME_JUGDE,
       T.STOVE_NO,
       T.STEEL_STANDRAD,
       T.JUGDE_APPLY_SEQUENO,
       TO_CHAR(T.JUDGE_TOLRESULT_TIME, 'YYYY-MM-DD HH24:MI:SS') JUDGE_TOLRESULT_TIME,
       T.JUDGE_TOLMEMO,
       T.CRAF_NO,
       T.JUGDE_TOLCONVICTED,
       T.MAT_GOWHERE_CODE,
       T.MAT_GOWHERE_NAME,
       T.BAL_YEAR_MONTH,
       T.JUDGE_TOLRESULT,
       T.JUDGE_TOLMAKER,
       (SELECT T1.PRODUC_DESC FROM COM_BASE_PRODUCT T1 WHERE T1.PRODUCCODE = T.PRODUCCODE)PRODUCNAME_TYPE,
        T.SUPPLY_UNIT,
        T.SUPPLY_UNIT_DESC,T.IN_STORAGE_TYPE,T.IN_STORAGE_WEIGHT,T.IN_STORAGE_CONFIRM,
        DECODE(T.IN_STORAGE_TYPE,'A','正常','B','合同超量','C','非正尺超量') IN_STORAGE_TYPE_NAME,
        to_char(T.IN_STORAGE_TIME,'YYYY-MM-DD HH24:MI:SS')IN_STORAGE_TIME,
        IN_STORAGE_FLAG,
        DECODE(T.IN_STORAGE_FLAG,'0','取消接收','1','确认接收','未接收')IN_STORAGE_FLAG_NAME,
        DECODE(T.IN_LENGTH_TYPE,'0','正尺','1','长尺','2','短尺')IN_LENGTH_TYPE,
        A.CREATE_NAME ORDER_CREATE_NAME,
        A.DELIVERY_NO DELIVERY_NO
 FROM QCM_ZG_JUGDE_APPLY T
    LEFT JOIN ( SELECT
            distinct H.create_name ,D.ORD_LN_DLY_PK,D.DELIVERY_NO
            FROM
            SLM_ORDER_HEAD H
            LEFT JOIN SLM_ORDER_LINE_DELIVERY D
            ON H.ORD_PK = D.ORD_PK AND H.VALIDFLAG = '1') A ON T.ORD_LN_DLY_PK = A.ORD_LN_DLY_PK
 WHERE T.IS_FLAG = '0'
 AND T.IS_ALL_SCRAP IN('0','6','7','8'）
 AND T.TARGET = 'A'
 AND T.JUDGE_TOLRESULT_CODE IN('40740701','40740709')
</query>
<query id = "FrmFinishAfrim.doQueryInList" desc = "缴库实绩查询">
SELECT T.INSTOCK_DOC,
       T.STOVE_NO,
       T.LOT_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       TO_CHAR(T.ACT_LEN_MIN, 'FM999990.00') AS ACT_LEN_MIN,
       TO_CHAR(T.ACT_LEN_MAX, 'FM999990.00') AS ACT_LEN_MAX,
       TO_CHAR(T.ACT_LEN_MIN, 'FM999990.00') || '-' ||
       TO_CHAR(T.ACT_LEN_MAX, 'FM999990.00') AS LEN,
       SUM(T.ACT_COUNT) AS ACT_COUNT,
       TO_CHAR(SUM(T.ACT_WEIGHT), 'FM999999990.000') AS ACT_WEIGHT,
       SUM(NVL(T.ACT_LEN, 0)) AS ACT_LEN,
       T.BELONG_CODE,
       T.BELONG_NAME,
       S.STORAGE_NAME,
       T.STORAGE_NO,
       T.MEMO,
       T.CREATE_NAME,
       MAX(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS INSTOCK_TIME,
       MAX(TO_CHAR(T.IN_TIME_F, 'YYYY-MM-DD')) AS IN_TIME_F,
       TO_CHAR(TO_DATE(T.BAL_YEAR_MONTH, 'YYYY-MM'), 'YYYY-MM') AS BAL_YEAR_MONTH,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.ORD_LN_DLY_PK,
       T.JUDGE_STD_CODE,
       T.JUDGE_STD_NAME,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.GRADECODE,
       T.GRADENAME,
       DECODE(T.PRODUCT_FLAG,
              '801401',
              '在制品',
              '801402',
              '成品',
              '801403',
              '商品') PRODUCT_FLAG,
       T.ZB_RCDID,
       D.SALE_AREA_DESC,
       D.CREATE_NAME AS ORDERCREATENAME,
       T.PIPMEMO,
       T.BATCH_GROUD_NO,
       T.PRO_ORDER_NO,
       M.BASENAME AS GROUPNAME,
       (SELECT T1.PRODUC_DESC FROM COM_BASE_PRODUCT T1 WHERE T1.PRODUCCODE = T.PRODUCCODE)PRODUCNAME_TYPE,
        T.SUPPLY_UNIT,
        T.SUPPLY_UNIT_CODE,
    T.PROCESS_CDOE,T.PROCESS_DESC,D.ORDER_TYP_DESC ORDER_TYPE,
    T.JUGDE_APPLY_CODE,
    T.INSTOCK_TYPE_CODE
  FROM YDM_ZC_INLIST T
  LEFT JOIN YDM_BS_STORAGE S ON T.STORAGE_NO = S.STORAGE_NO
  LEFT JOIN SLM_ORDER_HEAD D ON T.ORD_PK = D.ORD_PK
  LEFT JOIN (SELECT M.PLINE_CODE, G.BASENAME
               FROM COM_BASE_PLINE M, COM_BASE_INFO G
              WHERE M.GROUP_PAY = G.BASECODE) M ON M.PLINE_CODE =
                                                   T.PLINE_CODE
 WHERE (T.INSTOCK_TYPE_CODE = '800701' OR (T.INSTOCK_TYPE_CODE = '800704' and T.memo = '过磅'))
   AND T.HAND_FLAG = '0'
</query>
<query id = "FrmFinishAfrim.doQueryOrderNo" desc = "查询合同">
 SELECT 
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.PRD_CLS,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.STEELCODE,
       T.STEELNAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.LEN_NO,
       T.LEN_UNIT,
       T.LENGTHMAX,
       T.LENGTHMIN,
       TO_CHAR(T.LENGTHMIN,'FM999990.00')||'-'||TO_CHAR(T.LENGTHMAX,'FM999990.00') AS LENGTHFW,
       T.LENGTHDISC,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.ORDER_UNIT,
       T.ORDER_QTY,
       T.ORDERWEIGHT,
       T.ORDERNUM,
       T.TOTLENGTH,
       T.TOTLENGTH_UNIT,
       T.DELVRY_RANGE_TPE,
       T.DELVRY_RANGE_MIN,
       T.DELVRY_RANGE_MAX,
       DECODE(T.DELVRY_RANGE_TPE, '绝对值', T.DELVRY_RANGE_MIN, '') LOWERLIMT,
               DECODE(T.DELVRY_RANGE_TPE, '绝对值', T.DELVRY_RANGE_MAX, '') UPPERLIMIT,
               '(-' || TO_CHAR(T.DELVRY_RANGE_MIN) ||
               DECODE(T.DELVRY_RANGE_TPE, '%', '%', T.ORDER_UNIT) || ',' ||
               TO_CHAR(T.DELVRY_RANGE_MAX) ||
               DECODE(T.DELVRY_RANGE_TPE, '%', '%', T.ORDER_UNIT) || ')' DELVRY_RANGE,
       T.BUYER_ID,
       T.BUYER_NAME,
       T.ORDER_SPECIAL_DESC,
       T.ADD_ASK_NO,
       T.ORDER_ADD_DESC,
       T.ASK_TYPE_STATUS,
       DECODE(T.ORDERFROM,'100101','国内贸易部','100102','国际贸易部')ORDERFROM,
       T.FINAL_USER,
       T.FINAL_USER_DESC,
       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD HH24:MI:SS') DELVRY_EDATE,
       T.ORDERCONTACT,
       T.MONITORDEMAND,
       T.SPECSTANDARD,
       T.MEMO,
       T.PRIORITY,
       (SELECT PRIORITY_MEMO FROM PLN_SALEORD_PROC WHERE ORD_LN_DLY_PK = T.ORD_LN_DLY_PK AND ROWNUM = 1) PRIORITY_MEMO,
       DECODE(T.PORDERSTATUS,'0','待接收','1','已接收','2','已下发','3','生产中','4','生产完成','5','缴库完成')PORDERSTATUS,
       T.PSC,
       T.MSC,
       T.CODE_JG,
       T.CODE_DJ_BL,
       T.PLANWEIGHT,
       T.PAYDOWNWEIGHT,
       T.PAYDOWN_NUM,
       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.ENDGXNAME,
       T.MERGETYPE,
       T.JZ_FILE_IF_ALL,
       T.PRDCR_NO,
       T.ROLL_MONTH,
       T.ROLL_WELL_MONTH,
       T.MATERIAL_NO,
       T.MATERIAL_DESC,
       T.BL_GROUP_NUM,
       T.SHRT_LEN_RATO,
       T.SHORTEST,
       T.LONG_LEN_RATO,
       T.LONGEST,
       T.SHRT_STOVE,
       T.AVG_LEN_MIN,
       T.DIFRNC_LEN_MAX,
       T.SIGL_LEN,
       T.ENDLEN_SPECSTD,
       T.STATION_NO,
       T.STATION_NM,
       T.PRODUCE_SORT,
       T.USE_CODE,
       T.USE_DESC,
       T.WEIGHT_PER_M,
       T.TOTLENGTH_M,
       T.OUTS_BILLET_FL,
       T.OUTS_STL_PIPE_FL,
       T.PIPE_PROPERTY,
       T.LEN_TOEND_MIN,
       T.LEN_TOEND_MAX,
       T.TEMP_HTCAST,
       T.CRAFT_FILE_NO,
       T.CRAFT_FILE_MAN,
       T.LENGTH_JG,
       T.WEIGH_TYPE,
       T.TRANSIT_TYP,
       T.ACCEPT_NO,
       T.JGORD_IS_OK,
       T.JGL_REQ_IS_OK,
       T.DJBL_REQ_IS_OK,
       T.STD_STYLE_DESC,
       T.HEIGHT_ORD_MIN,
       T.HEIGHT_ORD_MAX,
       T.DELVRY_QTY,
       T.CHARGE_NUM,
       T.CHARGE_WGT,
       T.CHARGE_LEN,
       T.ELIM_NUM,
       T.ELIM_WGT,
       T.ELIM_LEN,
       T.PAYDOWN_WT_MIN,
       T.PAYDOWN_WT_MAX,
       T.CRAFT_FILE_NO_IN,
       T.CRAFT_FILE_MAN_IN,
       T.CRAFT_SEQ,
       T.IF_SALE_FREEZE,
       T.CRAFT_NO_V,
       T.IS_END_DLY,
       T.IS_BACKORD,
       T.ORDER_TYPE,
       T.OUTD_ORD_MIN,
       T.OUTD_ORD_MAX,
       T.LENGTHDISC_N,
       T.LEN_NO_N,
       NVL(T.PAYDOWNWEIGHTSHORT,'0') PAYDOWNWEIGHTSHORT,
       NVL(T.PAYDOWNWEIGHTLONG,'0') PAYDOWNWEIGHTLONG

    FROM PLN_SALEORD T
 WHERE T.ORDER_NO = ?
   AND T.ORD_LN_PK = ?
   AND T.PORDERSTATUS IN ('1','2','3','4','5')
   --AND T.ORDER_SEQ = ?
   --AND T.ORD_LN_DLY_PK = ?
</query>
<query id = "FrmFinishAfrim.getOrderWgt" desc = "查询总量">
	<![CDATA[
	SELECT SUM(NVL(T.ORDERWEIGHT, 0)) AS ORDERWEIGHT,
       SUM(NVL(T.PAYDOWNWEIGHT, 0)) AS PAYDOWNWEIGHT,
       SUM(NVL(T.ORDER_QTY, 0)) AS ORDER_QTY
  FROM PLN_SALEORD T
 WHERE T.ORDER_NO = ?
 ]]>
 </query>
 <query id = "FrmFinishAfrim.getInListDoc" desc = "查询入库单号">
 SELECT (SELECT S.MEMO FROM COM_BASE_INFO S WHERE S.BASECODE = ?) ||
       INSTOCK_DOC INSTOCK_DOC
  FROM (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 TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
           AND T.BELONG_CODE IN ('100101', '100103', '100102','100105'))
 </query>
 <query id = "FrmFinishAfrim.getOutListDoc" desc = "查询出库单号">
  SELECT 'OR' || TO_CHAR(SYSDATE, 'YYMMDD') ||
       LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) OUTSTOCK_DOC
  FROM YDM_ZC_OUTLIST T
 WHERE T.OUTSTOCK_TYPE_CODE = ?
   AND T.OUTSTOCK_DOC LIKE 'OR' || TO_CHAR(SYSDATE, 'YYMMDD')||'_____'
 </query>
 <query id = "FrmFinishAfrim.insertInList" desc = "新增库存表">
 <![CDATA[
 DECLARE
  V_INSTOCK_SEQ   YDM_ZC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_INSTOCK_DOC1 YDM_ZC_INLIST_XS.INSTOCK_DOC%TYPE := NULL;
  V_INSTOCK_SEQ1  YDM_ZC_INLIST_XS.INSTOCK_SQE%TYPE := NULL;
  V_COUNT         NUMBER := 1;
  V_COUNT1         NUMBER := 1;
  V_PAY_NUM       PROCESS_ORDER_M.PAY_NUM%TYPE := NULL;
  V_PAY_WGT       PROCESS_ORDER_M.PAY_WGT%TYPE := NULL;
  V_PAY_LEN       PROCESS_ORDER_M.PAY_LEN%TYPE := NULL;
  V_INCOUNT       NUMBER := 1;
  V_ORD_PK        YDM_ZC_INLIST.ORD_PK%TYPE := NULL;
  V_ORD_LN_PK     YDM_ZC_INLIST.ORD_LN_PK%TYPE := NULL;
  V_ORD_LN_DLY_PK YDM_ZC_INLIST.ORD_LN_DLY_PK%TYPE := NULL;
  V_ORDER_NO      YDM_ZC_INLIST.ORDER_NO%TYPE := NULL;
  V_ORDER_SEQ     YDM_ZC_INLIST.ORDER_SEQ%TYPE := NULL;
  V_DELIVERY_NO   YDM_ZC_INLIST.DELIVERY_NO%TYPE := NULL;
  V_PRODUCT_FLAG  YDM_ZC_INLIST.PRODUCT_FLAG%TYPE := NULL;
  V_MAT_STATUS    YDM_ZC_INLIST.MAT_STATUS%TYPE := NULL;
  V_IN_MOLD       YDM_ZC_INLIST.IN_MOLD%TYPE := NULL;
  V_IN_TYPE       YDM_ZC_INLIST.IN_TYPE%TYPE := NULL;
  V_STORAGE_NO    YDM_ZC_INLIST.STORAGE_NO%TYPE := NULL;
  V_ACT_WEIGHT    YDM_ZC_INLIST.ACT_WEIGHT%TYPE := NULL;
BEGIN
  V_STORAGE_NO := '#STORAGE_NO#';
  SELECT NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 4)), 0) + 1
    INTO V_COUNT
    FROM YDM_ZC_INLIST T
   WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
     AND T.INSTOCK_DOC = '#INSTOCK_DOC#';
  --获取最新INSTOCK_DOC 如：IA25052100084 
  SELECT 'IA'||TO_CHAR(SYSDATE,'YYMMDD')||LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, LENGTH(T.INSTOCK_DOC) - 4)), 0)+1,5,0) INSTOCK_DOC 
  into V_INSTOCK_DOC1
  FROM YDM_ZC_INLIST_XS T
                    WHERE 
                    TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
                    AND T.INSTOCK_TYPE_CODE  = '#INSTOCK_TYPE_CODE#'
                    AND T.BELONG_CODE IN ('100101', '100103', '100102','100105');
  --获取最新的INSTOCK_DOC        
  SELECT NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 4)), 0) + 1
    INTO V_COUNT1
    FROM YDM_ZC_INLIST_XS T
   WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
     AND T.INSTOCK_DOC = V_INSTOCK_DOC1;
  V_ORD_PK        := '#ORD_PK#';
  V_ORD_LN_PK     := '#ORD_LN_PK#';
  V_ORD_LN_DLY_PK := '#ORD_LN_DLY_PK#';
  V_ORDER_NO      := '#ORDER_NO#';
  V_ORDER_SEQ     := '#ORDER_SEQ#';
  V_DELIVERY_NO   := '#DELIVERY_NO#';
  V_PRODUCT_FLAG  := '#PRODUCT_FLAG#';
  V_MAT_STATUS    := '#MAT_STATUS#';
  V_IN_MOLD       := '#IN_MOLD#';
  V_IN_TYPE       := '802205';

  --修改申请判定表
  UPDATE QCM_ZG_JUGDE_APPLY S
     SET S.INSTOCK_FLAG = '1'
   WHERE S.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND S.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
     AND 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_JUGDE IN ('100101', '100102', '100103','100105');

  INSERT INTO YDM_INSTOCK_DOC(INSTOCK_DOC) VALUES('#INSTOCK_DOC#');

  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*,
                               S.STORAGE_NO,
                               S.LOCATION_NO,
                               S.LARY_NO,
                               (SELECT T1.STORAGE_NAME
                                  FROM YDM_BS_STORAGE T1
                                 WHERE T1.STORAGE_NO = S.STORAGE_NO) STORAGE_NAME,
                               (SELECT T2.LOCATION_NAME
                                  FROM YDM_BS_LOCATION T2
                                 WHERE T2.LOCATION_NO = S.LOCATION_NO) LOCATION_NAME
                          FROM MAT_BC_M T, YDM_BC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.PROCESS_CDOE = '#PROCESS_CDOE#'
                           AND T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                           AND T.JUGDE_APPLY_SEQUENO =
                               '#JUGDE_APPLY_SEQUENO#'
                           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 IN
                               ('100101', '100102', '100103','100105')
                           AND T.QCM_STAUS = '00'
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    IF (NVL(MYROW.PONDER_GROSS_WT, 0) = 0) THEN
      V_ACT_WEIGHT := MYROW.ACT_WEIGHT;
    ELSE
      V_ACT_WEIGHT := MYROW.PONDER_GROSS_WT;
    END IF;
    IF((#FRM_COUNT# > 0 AND V_INCOUNT > #FRM_COUNT#) OR (#FRM_COUNT# <= 0))THEN
      V_ORD_PK        := '#ORD_PK#';
      V_ORD_LN_PK     := '#ORD_LN_PK#';
      V_ORD_LN_DLY_PK := '#ORD_LN_DLY_PK#';
      V_ORDER_NO      := '#ORDER_NO#';
      V_ORDER_SEQ     := '#ORDER_SEQ#';
      V_DELIVERY_NO   := '#DELIVERY_NO#';
      V_PRODUCT_FLAG  := '801402';
      V_MAT_STATUS    := '80150202';
      V_IN_MOLD       := '801701';
      V_IN_TYPE       := '802201';
    END IF;
    IF('#IS_ALL_SCRAP#' = '离线转压库' OR '#IS_ALL_SCRAP#' = '余材转压库')THEN
    V_IN_TYPE       := '802204';
    END IF;
    IF('#IN_LENGTH_TYPE#' = '长尺')THEN
    V_IN_TYPE       := '802202';
    END IF;
    IF('#IN_LENGTH_TYPE#' = '短尺')THEN
    V_IN_TYPE       := '802203';
    END IF;
    IF(('#IN_LENGTH_TYPE#' = '短尺' OR '#IN_LENGTH_TYPE#' = '长尺') AND '#FINISHPRO_MOLD#' = '801701')THEN
    V_IN_MOLD       := '801701';
    END IF;
    V_INSTOCK_SEQ := '#INSTOCK_DOC#' || LPAD(V_COUNT, 4, 0);
    V_INSTOCK_SEQ1 := V_INSTOCK_DOC1|| LPAD(V_COUNT1, 4, 0);
    IF (V_STORAGE_NO IS NULL) THEN
      V_STORAGE_NO := MYROW.STORAGE_NO;
    END IF;
    INSERT INTO YDM_ZC_INLIST
      (MANAGEMENT_NO,
       MANAGEMENT_NAME,
       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,
       MEMO,
       CREATE_NAME,
       CREATE_TIME,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       PRODUCT_FLAG,
       MAT_STATUS,
       INSTOCK_TIME,
       ZB_RCDID,
       ACT_LEN,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       JUDGE_STD_NAME,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       BAL_YEAR_MONTH,
       IN_TIME_F,
       PIPMEMO,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       IN_MOLD,
       IN_TYPE,
       PACK_NO,
       PRO_ORDER_NO,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       JUGDE_APPLY_CODE,
       IS_DEALER,
       PROCESS_CDOE,
       PROCESS_DESC,
       IS_ALL_SCRAP)
    VALUES
      ('#MANAGEMENT_NO#',
       '#MANAGEMENT_NAME#',
       V_INSTOCK_SEQ,
       '#INSTOCK_DOC#',
       '#INSTOCK_TYPE_CODE#',
       '#INSTOCK_TYPE_NAME#',
       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,
       V_ACT_WEIGHT,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.STORAGE_NO,
       MYROW.MEMO || '#MEMO#',
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       V_ORDER_NO,
       V_ORDER_SEQ,
       V_DELIVERY_NO,
       V_ORD_PK,
       V_ORD_LN_PK,
       V_ORD_LN_DLY_PK,
       V_PRODUCT_FLAG,
       V_MAT_STATUS,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.JUGDE_TOLCONVICTED,
       MYROW.ACT_LEN,
       '#DEPARTMENT_CODE#',
       '#DEPARTMENT_DESC#',
       MYROW.JUDGE_STD_DES,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '#BAL_YEAR_MONTH#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#PIPMEMO#' ,
       '801302',
       '产线',
       '801302',
       '产线',
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       V_IN_MOLD,
       V_IN_TYPE,
       '#PACK_NO#',
       MYROW.PRO_ORDER_NO,
       '#SUPPLY_UNIT_CODE#',
       '#SUPPLY_UNIT#',
       MYROW.JUGDE_APPLY_CODE||MYROW.JUGDE_APPLY_SEQUENO,
       MYROW.IS_DEALER,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC,
       DECODE('#IS_ALL_SCRAP#','正常','0','半成品转成品','6','离线转压库','7','余材转压库','8') );
       
       INSERT INTO YDM_ZC_INLIST_XS
      (MANAGEMENT_NO,
       MANAGEMENT_NAME,
       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,
       MEMO,
       CREATE_NAME,
       CREATE_TIME,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       PRODUCT_FLAG,
       MAT_STATUS,
       INSTOCK_TIME,
       ZB_RCDID,
       ACT_LEN,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       JUDGE_STD_NAME,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       BAL_YEAR_MONTH,
       IN_TIME_F,
       PIPMEMO,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       IN_MOLD,
       IN_TYPE,
       PACK_NO,
       PRO_ORDER_NO,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       JUGDE_APPLY_CODE,
       IS_DEALER,
       PROCESS_CDOE,
       PROCESS_DESC,
       IS_ALL_SCRAP)
    VALUES
      ('#MANAGEMENT_NO#',
       '#MANAGEMENT_NAME#',
       V_INSTOCK_SEQ1,
       V_INSTOCK_DOC1,
       '#INSTOCK_TYPE_CODE#',
       '#INSTOCK_TYPE_NAME#',
       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,
       V_ACT_WEIGHT,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.STORAGE_NO,
       MYROW.MEMO || '#MEMO#',
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       V_ORDER_NO,
       V_ORDER_SEQ,
       V_DELIVERY_NO,
       V_ORD_PK,
       V_ORD_LN_PK,
       V_ORD_LN_DLY_PK,
       V_PRODUCT_FLAG,
       V_MAT_STATUS,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.JUGDE_TOLCONVICTED,
       MYROW.ACT_LEN,
       '#DEPARTMENT_CODE#',
       '#DEPARTMENT_DESC#',
       MYROW.JUDGE_STD_DES,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '#BAL_YEAR_MONTH#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#PIPMEMO#' ,
       '801302',
       '产线',
       '801302',
       '产线',
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       V_IN_MOLD,
       V_IN_TYPE,
       '#PACK_NO#',
       MYROW.PRO_ORDER_NO,
       '#SUPPLY_UNIT_CODE#',
       '#SUPPLY_UNIT#',
       MYROW.JUGDE_APPLY_CODE||MYROW.JUGDE_APPLY_SEQUENO,
       MYROW.IS_DEALER,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC,
       DECODE('#IS_ALL_SCRAP#','正常','0','半成品转成品','6','离线转压库','7','余材转压库','8') );
       

    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,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        BAL_YEAR_MONTH,
        ACT_DIMATER,
        ACT_HEIGHT,
        BELONG_CODE,
        BELONG_NAME,
        INSTOCK_TYPE_CODE,
        INSTOCK_TYPE_NAME
       )
 VALUES(
        MYROW.STORAGE_NAME,
        MYROW.MAT_NO,
        V_INSTOCK_SEQ,
        '#INSTOCK_DOC#',
        V_ORDER_NO,
        V_ORDER_SEQ,
        V_DELIVERY_NO,
        V_ORD_PK,
        V_ORD_LN_PK,
        V_ORD_LN_DLY_PK,
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = V_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,
        V_ACT_WEIGHT,
        MYROW.STORAGE_NO,
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = V_IN_MOLD),
        '#PACK_NO#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#SUPPLY_UNIT_CODE#',
       '#SUPPLY_UNIT#',
       '#BAL_YEAR_MONTH#',
        MYROW.ACT_DIMATER,
        MYROW.ACT_HEIGHT,
        MYROW.BELONG_CODE,
        MYROW.BELONG_NAME,
        '#INSTOCK_TYPE_CODE#',
        '#INSTOCK_TYPE_NAME#'
        );


      IF((#FRM_COUNT# > 0 AND V_INCOUNT > #FRM_COUNT#) OR (#FRM_COUNT# <= 0))THEN
      V_ORD_PK        := NULL;
      V_ORD_LN_PK     := NULL;
      V_ORD_LN_DLY_PK := NULL;
      V_ORDER_NO      := NULL;
      V_ORDER_SEQ     := NULL;
      V_DELIVERY_NO   := NULL;
      V_PRODUCT_FLAG  := '801402';
      V_MAT_STATUS    := '80150202';
      V_IN_MOLD       := '801701';
      V_IN_TYPE       := '802201';
    END IF;
    IF('#IS_ALL_SCRAP#' = '离线转压库' OR '#IS_ALL_SCRAP#' = '余材转压库')THEN
    V_IN_TYPE       := '802204';
    END IF;
    IF('#IN_LENGTH_TYPE#' = '长尺')THEN
    V_IN_TYPE       := '802202';
    END IF;
    IF('#IN_LENGTH_TYPE#' = '短尺')THEN
    V_IN_TYPE       := '802203';
    END IF;
    IF(('#IN_LENGTH_TYPE#' = '短尺' OR '#IN_LENGTH_TYPE#' = '长尺') AND '#FINISHPRO_MOLD#' = '801701')THEN
    V_IN_MOLD       := '801701';
    END IF;
    INSERT INTO MAT_ZC_M
      (STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       BELONG_CODE,
       BELONG_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       CREATE_NAME,
       ACT_COUNT,
       ACT_WEIGHT,
       CREATE_TIME,
       INSTOCK_TIME,
       MAT_NO,
       MEMO,
       INSTOCK_FLAG,
       PRODUCT_FLAG,
       MAT_STATUS,
       ACT_LEN,
       JUDGE_STD_NAME,
       BAL_YEAR_MONTH,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       PIPMEMO,
       JUDGE_RESULT_TIME,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       PACK_NO,
       IN_MOLD,
       IN_TYPE,
       PRO_ORDER_NO,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_MAKER,
       ZBS_FLAG,
       ZBS_ID,
       MEASURING_SEQ,
       JG_ZBS_ID,
       FLAG_STOVE_NO_ZG,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       MEMO1,
       IS_DEALER,
       IN_BC,
       IN_BZ,
       PROCESS_CDOE,
       PROCESS_DESC)
    VALUES
      (MYROW.STOVE_NO,
       MYROW.LOT_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       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,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       V_ORDER_NO,
       V_ORDER_SEQ,
       V_DELIVERY_NO,
       V_ORD_PK,
       V_ORD_LN_PK,
       V_ORD_LN_DLY_PK,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       '#CREATE_NAME#',
       MYROW.ACT_COUNT,
       --ROUND(TO_NUMBER(MYROW.PONDER_GROSS_WT), 4),
       V_ACT_WEIGHT,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.MAT_NO,
       MYROW.MEMO || '#MEMO#' ,
       '1',
       V_PRODUCT_FLAG,
       V_MAT_STATUS,
       MYROW.ACT_LEN,
       MYROW.JUDGE_STD_DES,
       '#BAL_YEAR_MONTH#',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       --'#PIPMEMO#',
       MYROW.PIPMEMO,
       TO_DATE('#JUDGE_RESULT_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '801302',
       '产线',
       '801302',
       '产线',
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       '#PACK_NO#',
       V_IN_MOLD,
       V_IN_TYPE,
       MYROW.PRO_ORDER_NO,
       MYROW.JUDGE_TOLRESULT_CODE,
       MYROW.JUDGE_TOLRESULT,
       MYROW.JUDGE_TOLMAKER,
       MYROW.ZBS_FLAG,
       MYROW.ZBS_ID,
       MYROW.MEASURING_SEQ,
       MYROW.JG_ZBS_ID,
       MYROW.FLAG_STOVE_NO_ZG,
       '#SUPPLY_UNIT_CODE#',
       '#SUPPLY_UNIT#',
       MYROW.MEMO1,
       MYROW.IS_DEALER,
       MYROW.IN_BC,
       MYROW.IN_BZ,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC);
       
       INSERT INTO MAT_ZC_M_XS
      (STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       BELONG_CODE,
       BELONG_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       CREATE_NAME,
       ACT_COUNT,
       ACT_WEIGHT,
       CREATE_TIME,
       INSTOCK_TIME,
       MAT_NO,
       MEMO,
       INSTOCK_FLAG,
       PRODUCT_FLAG,
       MAT_STATUS,
       ACT_LEN,
       JUDGE_STD_NAME,
       BAL_YEAR_MONTH,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       PIPMEMO,
       JUDGE_RESULT_TIME,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       PACK_NO,
       IN_MOLD,
       IN_TYPE,
       PRO_ORDER_NO,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_MAKER,
       ZBS_FLAG,
       ZBS_ID,
       MEASURING_SEQ,
       JG_ZBS_ID,
       FLAG_STOVE_NO_ZG,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       MEMO1,
       IS_DEALER,
       IN_BC,
       IN_BZ,
       PROCESS_CDOE,
       PROCESS_DESC)
    VALUES
      (MYROW.STOVE_NO,
       MYROW.LOT_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       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,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       V_ORDER_NO,
       V_ORDER_SEQ,
       V_DELIVERY_NO,
       V_ORD_PK,
       V_ORD_LN_PK,
       V_ORD_LN_DLY_PK,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       '#CREATE_NAME#',
       MYROW.ACT_COUNT,
       --ROUND(TO_NUMBER(MYROW.PONDER_GROSS_WT), 4),
       V_ACT_WEIGHT,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.MAT_NO,
       MYROW.MEMO || '#MEMO#' ,
       '1',
       V_PRODUCT_FLAG,
       V_MAT_STATUS,
       MYROW.ACT_LEN,
       MYROW.JUDGE_STD_DES,
       '#BAL_YEAR_MONTH#',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       --'#PIPMEMO#',
       MYROW.PIPMEMO,
       TO_DATE('#JUDGE_RESULT_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '801302',
       '产线',
       '801302',
       '产线',
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       '#PACK_NO#',
       V_IN_MOLD,
       V_IN_TYPE,
       MYROW.PRO_ORDER_NO,
       MYROW.JUDGE_TOLRESULT_CODE,
       MYROW.JUDGE_TOLRESULT,
       MYROW.JUDGE_TOLMAKER,
       MYROW.ZBS_FLAG,
       MYROW.ZBS_ID,
       MYROW.MEASURING_SEQ,
       MYROW.JG_ZBS_ID,
       MYROW.FLAG_STOVE_NO_ZG,
       '#SUPPLY_UNIT_CODE#',
       '#SUPPLY_UNIT#',
       MYROW.MEMO1,
       MYROW.IS_DEALER,
       MYROW.IN_BC,
       MYROW.IN_BZ,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC);

    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,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC)
    VALUES
      (MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       '#CREATE_NAME#',
       MYROW.MAT_NO,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#MANAGEMENT_NO#',
       '#MANAGEMENT_NAME#',
       '#DEPARTMENT_CODE#',
       '#DEPARTMENT_DESC#');
    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)
 VALUES(
        MYROW.MAT_NO,
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = V_PRODUCT_FLAG),
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = V_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,
        V_ORDER_NO,
        V_ORDER_SEQ,
        V_DELIVERY_NO,
        V_ORD_PK,
        V_ORD_LN_PK,
        V_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,
        V_ACT_WEIGHT,
        '#BELONG_CODE#',
        '#BELONG_NAME#',
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = V_IN_MOLD),
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        MYROW.STORAGE_NO,
        MYROW.LOCATION_NO,
        MYROW.STORAGE_NAME,
        MYROW.LOCATION_NAME,
        '#SUPPLY_UNIT_CODE#',
        '#SUPPLY_UNIT#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'));
    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;
    DELETE FROM YDM_BC_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
    DELETE FROM MAT_BC_M S WHERE S.MAT_NO = MYROW.MAT_NO;
    IF (V_INCOUNT <= #FRM_COUNT#) THEN
      V_PAY_NUM := TO_NUMBER(NVL(V_PAY_NUM, 0)) +
                   TO_NUMBER(NVL(MYROW.ACT_COUNT, 0));
      V_PAY_WGT := TO_NUMBER(NVL(V_PAY_WGT, 0)) +
                   TO_NUMBER(NVL(MYROW.ACT_WEIGHT, 0));
      V_PAY_LEN := TO_NUMBER(NVL(V_PAY_LEN, 0)) +
                   TO_NUMBER(NVL(MYROW.ACT_LEN, 0));
    END IF;
    V_COUNT   := V_COUNT + 1;
    V_COUNT1   := V_COUNT1 + 1;
    V_INCOUNT := V_INCOUNT + 1;

  END LOOP;
  --修改排产缴库量
  UPDATE PLN_SALEORD
     SET PAYDOWN_NUM   = TO_NUMBER(NVL(PAYDOWN_NUM, 0)) +
                         TO_NUMBER(NVL(V_PAY_NUM, 0)),
         PAYDOWNWEIGHT = TO_NUMBER(NVL(PAYDOWNWEIGHT, 0)) +
                         TO_NUMBER(NVL(V_PAY_WGT, 0))
   WHERE ORDER_NO = '#ORDER_NO#'
     AND ORDER_SEQ = '#ORDER_SEQ#'
     AND DELIVERY_NO = '#DELIVERY_NO#';
    IF('#IN_LENGTH_TYPE#' = '短尺')THEN
      UPDATE PLN_SALEORD
        SET
         PAYDOWNWEIGHTSHORT = TO_NUMBER(NVL(PAYDOWNWEIGHTSHORT, 0)) +
                         TO_NUMBER(NVL(V_PAY_WGT, 0))
        WHERE ORDER_NO = '#ORDER_NO#'
         AND ORDER_SEQ = '#ORDER_SEQ#'
         AND DELIVERY_NO = '#DELIVERY_NO#';
    END IF;
    IF('#IN_LENGTH_TYPE#' = '长尺')THEN
      UPDATE PLN_SALEORD
        SET
         PAYDOWNWEIGHTLONG = TO_NUMBER(NVL(PAYDOWNWEIGHTLONG, 0)) +
                         TO_NUMBER(NVL(V_PAY_WGT, 0))
        WHERE ORDER_NO = '#ORDER_NO#'
         AND ORDER_SEQ = '#ORDER_SEQ#'
         AND DELIVERY_NO = '#DELIVERY_NO#';
    END IF;
  --修改进程表
  UPDATE PROCESS_ORDER_M T
     SET T.PAY_NUM = TO_NUMBER(NVL(T.PAY_NUM, 0)) +
                     TO_NUMBER(NVL(V_PAY_NUM, 0)),
         T.PAY_WGT = TO_NUMBER(NVL(T.PAY_WGT, 0)) +
                     TO_NUMBER(NVL(V_PAY_WGT, 0)),
         T.PAY_LEN = TO_NUMBER(NVL(T.PAY_LEN, 0)) +
                     TO_NUMBER(NVL(V_PAY_LEN, 0))
   WHERE ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#';
   -- 修改天淮合同排产缴库量，进程表
   #UPDATE_PLNSALEORD_TH#
END;
 ]]>
 </query>
 <query id = "FrmFinishAfrim.updateBelong" desc = "转移所属权">
 <![CDATA[
 DECLARE
  V_INSTOCK_SEQ  YDM_ZC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_INCOUNT      NUMBER := 1;
  V_OUTSTOCK_SQE YDM_ZC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL;
  V_OUTCOUNT     NUMBER := 1;
BEGIN
  SELECT NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 4)), 0) + 1
    INTO V_INCOUNT
    FROM YDM_ZC_INLIST T
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#';

  SELECT NVL(MAX(SUBSTR(T.OUTSTOCK_SQE, LENGTH(T.OUTSTOCK_SQE) - 4)), 0) + 1
    INTO V_OUTCOUNT
    FROM YDM_ZC_OUTLIST T
   WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#';
  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.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.CHANGE_DOC = '#CHANGE_DOC#'
                         ORDER BY T.MAT_NO ASC
                 ) LOOP
    V_INSTOCK_SEQ  := '#INSTOCK_DOC#' || LPAD(V_INCOUNT, 4, 0);
    V_OUTSTOCK_SQE := '#OUTSTOCK_DOC#' || LPAD(V_OUTCOUNT, 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,
       MEMO,
       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,
       PIPMEMO,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       IN_MOLD,
       IN_TYPE,
       PACK_NO,
       PRO_ORDER_NO,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       IS_DEALER,
       PROCESS_CDOE,
       PROCESS_DESC)
    VALUES
      (V_INSTOCK_SEQ,
       '#INSTOCK_DOC#',
       '800712',
       '转所属权入库',
       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,
       '#SBELONG_CODE#',
       '#SBELONG_NAME#',
       MYROW.STORAGE_NO,
       MYROW.MEMO,
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.ACT_LEN,
       MYROW.JUDGE_STD_NAME,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '#BAL_YEAR_MONTH#',
       MYROW.INSTOCK_TIME,
       MYROW.PIPMEMO,
       '801302',
       '产线',
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.IN_MOLD,
       MYROW.IN_TYPE,
       MYROW.PACK_NO,
       MYROW.PRO_ORDER_NO,
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       MYROW.IS_DEALER,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC);
       
       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,
       MEMO,
       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,
       PIPMEMO,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       IN_MOLD,
       IN_TYPE,
       PACK_NO,
       PRO_ORDER_NO,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       IS_DEALER,
       PROCESS_CDOE,
       PROCESS_DESC)
    VALUES
      (V_INSTOCK_SEQ,
       '#INSTOCK_DOC#',
       '800712',
       '转所属权入库',
       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,
       '#SBELONG_CODE#',
       '#SBELONG_NAME#',
       MYROW.STORAGE_NO,
       MYROW.MEMO,
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.ACT_LEN,
       MYROW.JUDGE_STD_NAME,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '#BAL_YEAR_MONTH#',
       MYROW.INSTOCK_TIME,
       MYROW.PIPMEMO,
       '801302',
       '产线',
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.IN_MOLD,
       MYROW.IN_TYPE,
       MYROW.PACK_NO,
       MYROW.PRO_ORDER_NO,
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       MYROW.IS_DEALER,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC);
       
    INSERT INTO YDM_ZC_OUTLIST
      (OUTSTOCK_SQE,
       OUTSTOCK_DOC,
       OUTSTOCK_TYPE_CODE,
       OUTSTOCK_TYPE_NAME,
       MAT_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,
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       OUTSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       JUDGE_STD_CODE,
       BAL_YEAR_MONTH,
       FINISHPRO_MOLD,
       IN_MOLD,
       IN_TYPE,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       IS_DEALER,
       PROCESS_CDOE,
       PROCESS_DESC)
    VALUES
      (V_OUTSTOCK_SQE,
       '#OUTSTOCK_DOC#',
       '800812',
       '转所属权出库',
       MYROW.MAT_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.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.STORAGE_ATTR,
       MYROW.STORAGE_ATTR_NAME,
       MYROW.STORAGE_TYPE_NO,
       MYROW.STORAGE_TYPE_NAME,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       MYROW.JUDGE_STD_NAME,
       MYROW.JUDGE_STD_CODE,
       '#BAL_YEAR_MONTH#',
       MYROW.FINISHPRO_MOLD,
       MYROW.IN_MOLD,
       MYROW.IN_TYPE,
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       MYROW.IS_DEALER,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC);
       
       
    INSERT INTO YDM_ZC_OUTLIST_XS
      (OUTSTOCK_SQE,
       OUTSTOCK_DOC,
       OUTSTOCK_TYPE_CODE,
       OUTSTOCK_TYPE_NAME,
       MAT_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,
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       OUTSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       JUDGE_STD_CODE,
       BAL_YEAR_MONTH,
       FINISHPRO_MOLD,
       IN_MOLD,
       IN_TYPE,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       IS_DEALER,
       PROCESS_CDOE,
       PROCESS_DESC)
    VALUES
      (V_OUTSTOCK_SQE,
       '#OUTSTOCK_DOC#',
       '800812',
       '转所属权出库',
       MYROW.MAT_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.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.STORAGE_ATTR,
       MYROW.STORAGE_ATTR_NAME,
       MYROW.STORAGE_TYPE_NO,
       MYROW.STORAGE_TYPE_NAME,
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       MYROW.JUDGE_STD_NAME,
       MYROW.JUDGE_STD_CODE,
       '#BAL_YEAR_MONTH#',
       MYROW.FINISHPRO_MOLD,
       MYROW.IN_MOLD,
       MYROW.IN_TYPE,
       MYROW.SUPPLY_UNIT_CODE,
       MYROW.SUPPLY_UNIT,
       MYROW.IS_DEALER,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC);
       
    V_INCOUNT  := V_INCOUNT + 1;
    V_OUTCOUNT := V_OUTCOUNT + 1;
    UPDATE MAT_ZC_M T
       SET T.BELONG_CODE = '#SBELONG_CODE#',
           T.BELONG_NAME = '#SBELONG_NAME#',
           T.MNG_LOCK_FLAG = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO;
     
      UPDATE MAT_ZC_M_XS T
       SET T.BELONG_CODE = '#SBELONG_CODE#',
           T.BELONG_NAME = '#SBELONG_NAME#',
           T.MNG_LOCK_FLAG = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO;
     
  END LOOP;
  UPDATE YDM_ZC_CHANGEBELONG T
   SET T.FRIM_FLAG = '1', T.FRIM_NAME = '#CREATE_NAME#', T.FRIM_TIME = SYSDATE
 WHERE T.CHANGE_DOC = '#CHANGE_DOC#';
END;
 ]]>
 <query id = "FrmFinishAfrim.updateChange" desc = "审批不通过">
 DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM MAT_ZC_M T
                 WHERE T.CHANGE_DOC = '#CHANGE_DOC#'
                   AND T.MNG_LOCK_FLAG = '1') LOOP
    UPDATE MAT_ZC_M T
       SET T.MNG_LOCK_FLAG = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  UPDATE YDM_ZC_CHANGEBELONG T
     SET T.FRIM_FLAG = '2',
         T.FRIM_NAME = '#FRIM_NAME#',
         T.FRIM_TIME = SYSDATE
   WHERE T.CHANGE_DOC = '#CHANGE_DOC#';
END;
 </query>
 </query>
 <query id = "FrmFinishAfrim.canceDoFrim" desc = "撤销缴库">
     <![CDATA[
     DECLARE
     V_PAY_NUM     PROCESS_ORDER_M.PAY_NUM%TYPE := NULL;
     V_PAY_WGT     PROCESS_ORDER_M.PAY_WGT%TYPE := NULL;
     V_PAY_LEN     PROCESS_ORDER_M.PAY_LEN%TYPE := NULL;
     V_STORAGE_NO  YDM_ZC_INLIST.STORAGE_NO%TYPE := NULL;
     V_LOCATION_NO YDM_ZC_BUTTRESS.LOCATION_NO%TYPE := NULL;
     V_LARY_NO     YDM_ZC_BUTTRESS.LARY_NO%TYPE := NULL;
     V_IN_MOLD     YDM_ZC_INLIST.IN_MOLD%TYPE := NULL;
     V_IN_TYPE     YDM_ZC_INLIST.IN_MOLD%TYPE := NULL;
     V_TDLK        NUMBER := 0;
     V_OCOUNT   NUMBER := 1;
     V_RESUME_SEQ MAT_ZC_TRACK.RESUME_SEQ%TYPE := NULL; --履历单号
     BEGIN
     SELECT SUM(T.ACT_LEN), SUM(T.ACT_COUNT), SUM(T.ACT_WEIGHT)
     INTO V_PAY_LEN, V_PAY_NUM, V_PAY_WGT
     FROM YDM_ZC_INLIST T
     WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#' AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.PRODUCT_FLAG = '801403';

     FOR MYROW IN (SELECT T.*
     FROM YDM_ZC_INLIST T
     WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     ORDER BY T.MAT_NO DESC) LOOP
     SELECT T.STORAGE_NO, T.LOCATION_NO, T.LARY_NO
     INTO V_STORAGE_NO, V_LOCATION_NO, V_LARY_NO
     FROM YDM_ZC_BUTTRESS T
     WHERE T.MAT_NO = MYROW.MAT_NO;
     INSERT INTO MAT_BC_M
     SELECT *
     FROM MAT_BC_BACKUP S
     WHERE S.MAT_NO = MYROW.MAT_NO
     AND S.PLINE_CODE = MYROW.PLINE_CODE
     AND S.PRODUCT_FLAG = '801402';
     INSERT INTO YDM_BC_BUTTRESS
     (JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     STORAGE_NO,
     LOCATION_NO,
     LARY_NO,
     CREATE_NAME,
     MAT_NO,
     CREATE_TIME,
     MANAGEMENT_NO,
     MANAGEMENT_NAME,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC)
     VALUES
     (MYROW.JUDGE_STOVE_NO,
     MYROW.BATCH_NO,
     MYROW.BATCH_GROUD_NO,
     V_STORAGE_NO,
     V_LOCATION_NO,
     V_LARY_NO,
     MYROW.CREATE_NAME,
     MYROW.MAT_NO,
     MYROW.CREATE_TIME,
     '',
     '',
     '',
     '');
     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(
     '',
     MYROW.MAT_NO,
     MYROW.INSTOCK_SQE,
     MYROW.INSTOCK_DOC,
     MYROW.ORDER_NO,
     MYROW.ORDER_SEQ,
     MYROW.DELIVERY_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,
     MYROW.INSTOCK_TIME,
     TO_DATE('#CREATE_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.DELIVERY_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),
     MYROW.INSTOCK_TIME,
     MYROW.STORAGE_NO,
     MYROW.LOCATION_NO,
     '',
     '',
     MYROW.SUPPLY_UNIT_CODE,
     MYROW.SUPPLY_UNIT,
     TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),'2');

     --脱单利库
     SELECT
     NVL(QZLK,0) + NVL(LK,0) - NVL(TD,0) INTO V_TDLK
     FROM
     ( SELECT COUNT( 1 ) C, EVENT_ID FROM CRM_MAT_ZC_TRACK T WHERE JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       and BATCH_NO = MYROW.BATCH_NO
       and BATCH_GROUD_NO = MYROW.BATCH_GROUD_NO
        GROUP BY EVENT_ID ) T
     PIVOT ( SUM( NVL( C, 0 ) ) FOR EVENT_ID IN ( '900101' AS TD, '900102' AS LK, '900103' AS QZLK ));
     IF(V_TDLK > 0)THEN
         --生成履历序号
         SELECT
         LPAD(NVL(MAX(SUBSTR(T.RESUME_SEQ, 15)), 0) + 1, 10, 0) RESUME_SEQ
         INTO V_OCOUNT
         FROM MAT_ZC_TRACK T
         WHERE TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD');
         V_RESUME_SEQ := TO_CHAR(SYSDATE,'YYYYMMDDHH24MISS') || LPAD(V_OCOUNT, 10, 0);
         INSERT INTO MAT_ZC_TRACK(
         RESUME_SEQ,
         EVENT_ID,
         EVENT_DESC,
         FORM_NAME,
         CALL_FUNC_CODING,
         KEYVALUE_1,
         KEYVALUE_1_DESC,
         KEYVALUE_2,
         KEYVALUE_2_DESC2,
         KEYVALUE_3,
         KEYVALUE_3_DESC3,
         KEYVALUE_4,
         KEYVALUE_4_DESC4,
         KEYVALUE_5,
         KEYVALUE_5_DESC5,
         KEYVALUE_6,
         KEYVALUE_6_DESC6,
         KEYVALUE_7,
         KEYVALUE_7_DESC7,
         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,
         STD_CODE,
         STD_NAME,
         STD_STYLE,
         STD_STYLE_DESC,
         SPEC_CODE,
         SPEC_NAME,
         MODEL_CODE,
         MODEL_DESC,
         ACT_LEN,
         ACT_LEN_MIN,
         ACT_LEN_MAX,
         ACT_COUNT,
         ACT_WEIGHT,
         ACT_THEORY_WEIGHT,
         PRO_ORDER_NO,
         PRO_ORDER_ID,
         PRO_ORDER_NO1,
         PRO_ORDER_ID1,
         ORD_PK,
         ORD_LN_PK,
         ORD_LN_DLY_PK,
         ORDER_NO,
         ORDER_SEQ,
         ORDER_SEQ_NO,
         OLD_ORD_PK,
         OLD_ORD_LN_PK,
         OLD_ORD_LN_DLY_PK,
         OLD_ORDER_NO,
         OLD_ORDER_SEQ,
         OLD_ORDER_SEQ_NO,
         BELONG_CODE,
         BELONG_NAME,
         MEMO,
         CREATE_NAME,
         CREATE_TIME,
         IN_MOLD,
         SUPPLY_UNIT_CODE,
         SUPPLY_UNIT)
         VALUES(
         V_RESUME_SEQ,
         '900101',
         '脱单',
         'Core.StlMes.Client.YdmPipeManage.FrmFinishAfrim',
         'monomer',
         'ArrayList<MatZcMEntity> paramList',
         '物料主表关键字(group)实体类集合',
         'String monomerExplain',
         '脱单说明',
         'String isRolling',
         '是否补轧',
         'String userName',
         '操作人',
         'String deptId',
         '操作人部门ID',
         '',
         '',
         '',
         '',
         MYROW.MAT_NO,
         MYROW.PRODUCT_FLAG,
         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.STD_CODE,
         MYROW.STD_NAME,
         MYROW.STD_STYLE,
         MYROW.STD_STYLE_DESC,
         MYROW.SPEC_CODE,
         MYROW.SPEC_NAME,
         MYROW.MODEL_CODE,
         MYROW.MODEL_DESC,
         MYROW.ACT_LEN,
         MYROW.ACT_LEN_MIN,
         MYROW.ACT_LEN_MAX,
         MYROW.ACT_COUNT,
         MYROW.ACT_WEIGHT,
         MYROW.ACT_THEORY_WEIGHT,
         MYROW.PRO_ORDER_NO,
         '',
         '',
         '',
         (SELECT ORD_PK FROM MAT_ZC_M S WHERE S.MAT_NO = MYROW.MAT_NO AND ROWNUM =1) ,
         (SELECT ORD_LN_PK FROM MAT_ZC_M S WHERE S.MAT_NO = MYROW.MAT_NO AND ROWNUM =1) ,
         (SELECT ORD_LN_DLY_PK FROM MAT_ZC_M S WHERE S.MAT_NO = MYROW.MAT_NO AND ROWNUM =1) ,
         (SELECT ORDER_NO FROM MAT_ZC_M S WHERE S.MAT_NO = MYROW.MAT_NO AND ROWNUM =1) ,
         (SELECT ORDER_SEQ FROM MAT_ZC_M S WHERE S.MAT_NO = MYROW.MAT_NO AND ROWNUM =1) ,
         (SELECT ORDER_SEQ_NO FROM MAT_ZC_M S WHERE S.MAT_NO = MYROW.MAT_NO AND ROWNUM =1) ,
         '',
         '',
         '',
         '',
         '',
         '',
         MYROW.BELONG_CODE,
         MYROW.BELONG_NAME,
         '撤销缴库，系统写入',
         'SYSTEM',
         TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
         MYROW.IN_MOLD,
         MYROW.SUPPLY_UNIT_CODE,
         MYROW.SUPPLY_UNIT);
         V_OCOUNT := V_OCOUNT + 1;
     END IF;

     DELETE FROM MAT_ZC_M S WHERE S.MAT_NO = MYROW.MAT_NO;
     DELETE FROM MAT_ZC_M_XS S WHERE S.MAT_NO = MYROW.MAT_NO;
     DELETE FROM YDM_ZC_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
     DELETE FROM YDM_ZC_INLIST_XS S
     WHERE S.MAT_NO = MYROW.MAT_NO
     AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND S.INSTOCK_TYPE_CODE = '#INSTOCK_TYPE_CODE#';
     DELETE FROM MAT_BC_BACKUP S
     WHERE S.MAT_NO = MYROW.MAT_NO
     AND S.PLINE_CODE = MYROW.PLINE_CODE;
     V_IN_MOLD := MYROW.IN_MOLD;
     V_IN_TYPE := MYROW.IN_TYPE;
     END LOOP;
     --修改排产缴库量
     UPDATE PLN_SALEORD
     SET PAYDOWN_NUM   = TO_NUMBER(NVL(PAYDOWN_NUM, 0)) -
     TO_NUMBER(NVL(V_PAY_NUM, 0)),
     PAYDOWNWEIGHT = TO_NUMBER(NVL(PAYDOWNWEIGHT, 0)) -
     TO_NUMBER(NVL(V_PAY_WGT, 0))
     WHERE ORDER_NO = '#ORDER_NO#'
     AND ORDER_SEQ = '#ORDER_SEQ#'
     AND DELIVERY_NO = '#DELIVERY_NO#';
     IF(V_IN_MOLD = '801707' OR V_IN_TYPE = '802203')THEN -- 短尺
         UPDATE PLN_SALEORD
         SET
         PAYDOWNWEIGHTSHORT =TO_NUMBER(NVL(PAYDOWNWEIGHTSHORT, 0)) -
            TO_NUMBER(NVL(V_PAY_WGT, 0))
         WHERE ORDER_NO = '#ORDER_NO#'
         AND ORDER_SEQ = '#ORDER_SEQ#'
         AND DELIVERY_NO = '#DELIVERY_NO#';
     END IF;
     IF(V_IN_MOLD = '801706' OR V_IN_TYPE = '802203')THEN -- 长尺
         UPDATE PLN_SALEORD
         SET
         PAYDOWNWEIGHTLONG = TO_NUMBER(NVL(PAYDOWNWEIGHTLONG, 0)) -
            TO_NUMBER(NVL(V_PAY_WGT, 0))
         WHERE ORDER_NO = '#ORDER_NO#'
         AND ORDER_SEQ = '#ORDER_SEQ#'
         AND DELIVERY_NO = '#DELIVERY_NO#';
     END IF;
     --修改进程表
     UPDATE PROCESS_ORDER_M T
     SET T.PAY_NUM = TO_NUMBER(NVL(T.PAY_NUM, 0)) -
     TO_NUMBER(NVL(V_PAY_NUM, 0)),
     T.PAY_WGT = TO_NUMBER(NVL(T.PAY_WGT, 0)) -
     TO_NUMBER(NVL(V_PAY_WGT, 0)),
     T.PAY_LEN = TO_NUMBER(NVL(T.PAY_LEN, 0)) -
     TO_NUMBER(NVL(V_PAY_LEN, 0))
     WHERE ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#';
     --修改天淮合同排产，进程信息
     #UPDATE_PLNSALEORD_TH#
     --修改申请判定表
     UPDATE QCM_ZG_JUGDE_APPLY S
     SET S.INSTOCK_FLAG = '0'
     WHERE S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND S.BATCH_NO = '#BATCH_NO#'
     AND S.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
     AND S.PRODUCCODE = '#PRODUCCODE#'
     AND S.MODEL_CODE = '#MODEL_CODE#'
     AND S.JUGDE_TOLCONVICTED = '#ZB_RCDID#'
     AND S.TARGET = 'A'
     AND S.BELONG_CODE_JUGDE IN ('100101', '100102', '100103','100105');
     DELETE FROM YDM_ZC_INLIST S WHERE S.INSTOCK_DOC = '#INSTOCK_DOC#' AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
     DELETE FROM YDM_INSTOCK_DOC S WHERE S.INSTOCK_DOC = '#INSTOCK_DOC#';
     END;
     ]]>
 </query>
 <query id = "FrmFinishAfrim.updateCarryOverDate" desc = "调整结转年月">
 DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM YDM_ZC_INLIST S
                 WHERE S.INSTOCK_DOC = '#INSTOCK_DOC#'
                   AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND S.BATCH_NO = '#BATCH_NO#'
                   AND S.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND S.PRODUCT_FLAG = '#PRODUCT_FLAG#'
                   AND S.STORAGE_NO = '#STORAGE_NO#'
                 ORDER BY S.MAT_NO DESC) LOOP
    UPDATE YDM_ZC_INLIST T
       SET T.BAL_YEAR_MONTH = '#BAL_YEAR_MONTH#',
           T.INSTOCK_TIME   = TO_DATE('#INSTOCK_TIME#', 'YYYY-MM-DD HH24:MI:SS')
     WHERE T.INSTOCK_SQE = MYROW.INSTOCK_SQE;
  END LOOP;
END;
 </query>
 <query id = "FrmFinishAfrim.selectBcMatCount" desc = "查询半成品表成品支数">
     SELECT NVL(SUM(T.ACT_COUNT),0)ACT_COUNT
     FROM YDM_BC_OUTLIST T
     WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#'
     AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
     AND T.PLINE_CODE = '#PLINE_CODE#'
     AND T.TAR_REC_FLAG = '0'
     AND T.OUTSTOCK_TYPE_CODE = '800803'
     AND T.QCM_STAUS = '00'
     AND T.VALIDFLAG = '1'
 </query>

<query id = "FrmFinishAfrim.selectBcMatCount1" desc = "查询半成品表成品支数">
    <![CDATA[
        SELECT count(1) ACT_COUNT
        FROM (SELECT T.*,
        S.STORAGE_NO,
        S.LOCATION_NO,
        S.LARY_NO,
        (SELECT T1.STORAGE_NAME
        FROM YDM_BS_STORAGE T1
        WHERE T1.STORAGE_NO = S.STORAGE_NO) STORAGE_NAME,
        (SELECT T2.LOCATION_NAME
        FROM YDM_BS_LOCATION T2
        WHERE T2.LOCATION_NO = S.LOCATION_NO) LOCATION_NAME
        FROM MAT_BC_M T, YDM_BC_BUTTRESS S
        WHERE T.MAT_NO = S.MAT_NO
        AND T.PROCESS_CDOE = '#PROCESS_CODE#'
        AND T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
        AND T.JUGDE_APPLY_SEQUENO =
        '#JUGDE_APPLY_SEQUENO#'
        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 IN
        ('100101', '100102', '100103','100105')
        AND T.QCM_STAUS = '00'
        ORDER BY T.MAT_NO DESC)
        WHERE ROWNUM <= #ACT_COUNT#
    ]]>
</query>
 <query id = "FrmFinishAfrim.selectNowInial" desc = "查询是否有期初数据">
	SELECT COUNT(1) FROM YDM_ZC_INITIAL T WHERE T.BAL_YEAR_MONTH = ?
	</query>
	<query id = "FrmFinishAfrim.SelectMatNo" desc = "查询所有物料号">
        <![CDATA[
	SELECT T.MAT_NO
  FROM MAT_ZC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.PRODUCNAME = ?
   AND T.STEELNAME = ?
   AND T.SPEC_NAME =?
   AND T.MODEL_DESC = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.PRODUCT_FLAG = ?
   AND NVL(T.IN_MOLD,'/') = NVL(?,'/')
   AND NVL(T.FINISHPRO_MOLD,'/') = NVL(?,'/')
   AND T.MAT_STATUS IN('80150301', '80150202', '80150204', '80150205')
        AND ROWNUM <= ?
        ]]>
	</query>

    <query id = "FrmFinishAfrim.SelectMatNo1" desc = "查询所有物料信息">
        <![CDATA[
	SELECT t.*
      FROM MAT_ZC_M T
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.BATCH_NO = ?
       AND T.PRODUCNAME = ?
       AND T.STEELNAME = ?
       AND T.SPEC_NAME =?
       AND T.MODEL_DESC = ?
       AND T.BATCH_GROUD_NO = ?
       AND T.PRODUCT_FLAG = ?
       AND NVL(T.IN_MOLD,'/') = NVL(?,'/')
       AND NVL(T.FINISHPRO_MOLD,'/') = NVL(?,'/')
       AND T.MAT_STATUS IN('80150301', '80150202', '80150204', '80150205')
        ]]>
    </query>

    <query id = "FrmFinishAfrim.SelectMatNo2" desc = "查询所有物料信息">
        <![CDATA[
	SELECT t.*
      FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T2
     WHERE
       T.MAT_NO = T2.MAT_NO
       AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND T.BATCH_NO = '#BATCH_NO#'
       AND T.PRODUCNAME = '#PRODUCNAME#'
       AND T.STEELNAME = '#STEELNAME#'
       AND T.SPEC_NAME = '#SPEC_NAME#'
       AND T.MODEL_DESC = '#MODEL_DESC#'
       AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
       AND T.PRODUCT_FLAG = '#PRODUCT_FLAG#'
       AND T2.STORAGE_NO = '#STORAGE_NO#'
       AND T2.LOCATION_NO = '#LOCATION_NO#'
       AND NVL(T.MEMO,'/') = NVL('#MEMO#','/')
       AND T.MAT_STATUS IN('80150301', '80150202', '80150204', '80150205')
        ]]>
    </query>
	<query id = "FrmFinishAfrim.updatePipMemo" desc = "修改入库备注">
	UPDATE MAT_ZC_M T SET T.PIPMEMO = ? WHERE T.MAT_NO = ?
	</query>
	<query id = "FrmFinishAfrim.updateStoreNo" desc = "修改入库仓库位置">
	UPDATE YDM_ZC_INLIST T SET T.STORAGE_NO = ? WHERE T.MAT_NO = ?
	</query>
	<query id = "FrmFinishAfrim.updateButessStoreNo" desc = "修改位置表库存地点">
	UPDATE YDM_ZC_BUTTRESS T SET T.STORAGE_NO = ?,T.LOCATION_NO = ? WHERE T.MAT_NO = ?
	</query>
	<query id = "FrmFinishAfrim.updateFinishedProduct" desc = "修改成品区分">
	DECLARE
BEGIN
  FOR MYROW IN (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 = ?
                   AND T.BATCH_NO = ?
                   AND T.BATCH_GROUD_NO = ?
                   AND T.PRODUCT_FLAG = ?
                   AND NVL(T.PIPMEMO, '/') = NVL(?, '/')
                   AND NVL(T.IN_MOLD,'/') = NVL(?,'/')
                 ORDER BY T.MAT_NO ASC) LOOP
    UPDATE MAT_ZC_M T
       SET T.FINISHPRO_MOLD = ?
     WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
	</query>
	<query id="FrmFinishAfrim.QUERYMAT" desc="库存查询">
		<![CDATA[
      SELECT T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       T1.LEN_NO,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.GRADECODE,
       T1.GRADENAME,
      sum(T1.ACT_COUNT)
            UNIT,
            to_char(sum(T1.Act_Weight),'FM999999990.000')
           WEIGHT,
       sum(nvl(T1.ACT_LEN,0)) as ACT_LEN,
       T1.LEN_DESC,
       T1.LEN_UNIT,
       to_char(T1.ACT_LEN_MIN,'FM999990.00') AS ACT_LEN_MIN,
       to_char(T1.ACT_LEN_MAX,'FM999990.00') AS ACT_LEN_MAX,
       to_char(T1.ACT_LEN_MIN,'FM999990.00')||'-'||to_char(T1.ACT_LEN_MAX,'FM999990.00') as LEN,
       T1.CREATE_NAME,
       max(TO_CHAR(T1.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       max(to_char(T1.INSTOCK_TIME,'YYYY-MM-DD')) INSTOCK_TIME,
       T2.STORAGE_NO,
       S.STORAGE_NAME,
       T1.MEMO,
       T1.PIPMEMO,
       T1.JUDGE_STD_CODE,
       T1.JUDGE_STD_NAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       T1.OLD_ORDER_NO,
       T1.MAT_STATUS,
       --T1.BAL_YEAR_MONTH,
       to_char(to_date(T1.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       DECODE(T1.PRODUCT_FLAG,'801401','在制品','801402','成品','801403','商品')PRODUCT_FLAG,
       T1.FINISHPRO_MOLD,
       T1.IN_MOLD,
       T1.IN_TYPE,
       T1.SUPPLY_UNIT,
       T1.SUPPLY_UNIT_CODE
  FROM MAT_ZC_M T1, YDM_ZC_BUTTRESS T2
 LEFT JOIN ydm_bs_storage S ON S.STORAGE_NO=T2.STORAGE_NO
 WHERE T1.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
   AND T1.BATCH_NO = T2.BATCH_NO
    AND T1.MAT_NO=T2.MAT_NO
  
		]]>
	</query>
 <query id = "FrmFinishAfrim.getRealTimeStore" desc = "获取实时期末库存">
	DECLARE
BEGIN
  FOR MYROW IN (SELECT JUDGE_STOVE_NO,
                       BATCH_NO,
                       BATCH_GROUD_NO,
                       SUM(ACT_WEIGHT)ACT_WEIGHT FROM
               (SELECT F.JUDGE_STOVE_NO,
                       F.BATCH_NO,
                       F.BATCH_GROUD_NO,
                       SUM(F.ACT_COUNT) ACT_COUNT,
                       SUM(F.ACT_WEIGHT) ACT_WEIGHT
                  FROM MAT_ZC_M F, YDM_ZC_BUTTRESS G
                 WHERE F.MAT_NO = G.MAT_NO
                 AND F.PRODUCT_FLAG = '801402'
                 AND F.SUPPLY_UNIT_CODE = '#CUSTOM#'
                 #CONDITIONS#
                 GROUP BY F.JUDGE_STOVE_NO, F.BATCH_NO, F.BATCH_GROUD_NO
                 UNION ALL
                 SELECT F.JUDGE_STOVE_NO,
                       F.BATCH_NO,
                       F.BATCH_GROUD_NO,
                       SUM(F.ACT_COUNT) ACT_COUNT,
                       SUM(F.ACT_WEIGHT) ACT_WEIGHT
                  FROM MAT_ZC_M F, YDM_ZC_BUTTRESS G
                 WHERE F.MAT_NO = G.MAT_NO
                 AND F.PRODUCT_FLAG = '801403'
                 AND F.SUPPLY_UNIT_CODE = '#CUSTOM#'
                 #CONDITIONS#
                 GROUP BY F.JUDGE_STOVE_NO, F.BATCH_NO, F.BATCH_GROUD_NO)
                 GROUP BY JUDGE_STOVE_NO,BATCH_NO,BATCH_GROUD_NO) LOOP
                 UPDATE YDM_ZC_INITIAL T
   SET T.ACT_WEIGHT_S = MYROW.ACT_WEIGHT
 WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
   AND T.BATCH_NO = MYROW.BATCH_NO
   AND T.BATCH_GROUD_NO = MYROW.BATCH_GROUD_NO
   AND T.BAL_YEAR_MONTH = TO_CHAR(SYSDATE, 'YYYYMM');
  END LOOP;
  DELETE FROM MAT_ZC_INITIAL T1 WHERE T1.BAL_YEAR_MONTH = ? #CONDITIONS1#; 
  FOR MYROW1 IN (select T1.ORDER_NO || '/' || T1.ORDER_SEQ AS SORDER,
       T1.OLD_ORDER_NO || '/' || T1.OLD_ORDER_SEQ AS OLDORDER,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.STEELCODE,
       T1.SPEC_CODE,
       T1.MODEL_CODE,
       T1.STD_CODE,
       T1.GRADECODE,
       T1.STEELNAME,
       T1.SPEC_NAME,
       T1.MODEL_DESC,
       T1.STD_NAME,
       T1.JUDGE_STD_NAME,
       T1.GRADENAME,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.ACT_LEN_MIN,
       T1.ACT_LEN_MAX,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       d.SALE_AREA_DESC,
       d.CREATE_NAME AS ORDERCREATENAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       S.STORAGE_NAME,
       d.CUSTOMER_NM,
       g.RECEIV_NM,
       T1.PRODUCT_FLAG,
       T1.MAT_STATUS,
       T1.MEMO,
       T1.PIPMEMO,
       to_char(T1.INSTOCK_TIME, 'YYYY-MM-DD') as INSTOCK_TIME,
       DECODE(g.TRANSIT_TYP,
              '110501',
              '汽运',
              '110502',
              '铁运',
              '110503',
              '船运',
              '110504',
              '航运') TRANSIT_TYP,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T1.IN_MOLD AND ROWNUM = 1) IN_MOLD,
       DECODE(t1.FINISHPRO_MOLD,
              '801801',
              '合同变更',
              '801802',
              '超交货期',
              '801803',
              '超载甩量',
              '801804',
              '成品备库',
              '801805',
              '质量异议待处理') FINISHPRO_MOLD,
       sum(T1.ACT_COUNT) as ACT_COUNT,
       sum(T1.ACT_WEIGHT) as ACT_WEIGHT,
       sum(T1.ACT_LEN) as ACT_LEN,
     T1.SUPPLY_UNIT_CODE,
     T1.SUPPLY_UNIT
  FROM MAT_ZC_M                T1,
       YDM_ZC_BUTTRESS         T2,
       ydm_bs_storage          S,
       SLM_ORDER_HEAD          D,
       slm_order_line_delivery G
 WHERE T1.MAT_NO = T2.MAT_NO
   AND T2.STORAGE_NO = S.STORAGE_NO(+)
   AND T1.Ord_Pk = d.ord_pk(+)
   AND T1.Ord_Ln_Dly_Pk = g.ord_ln_dly_pk(+)
   and T1.product_flag = '801403'
     AND T1.SUPPLY_UNIT_CODE = '#CUSTOM#'
   #CONDITIONS1#
 group by T1.ORDER_NO || '/' || T1.ORDER_SEQ,
          T1.OLD_ORDER_NO || '/' || T1.OLD_ORDER_SEQ,
          T1.ORDER_NO,
          T1.ORDER_SEQ,
          T1.ORDER_SEQ_NO,
          T1.JUDGE_STOVE_NO,
          T1.BATCH_NO,
          T1.BATCH_GROUD_NO,
          T1.PRODUCCODE,
          T1.PRODUCNAME,
          T1.STD_STYLE,
          T1.STD_STYLE_DESC,
          T1.STEELCODE,
          T1.SPEC_CODE,
          T1.MODEL_CODE,
          T1.STD_CODE,
          T1.GRADECODE,
          T1.STEELNAME,
          T1.SPEC_NAME,
          T1.MODEL_DESC,
          T1.STD_NAME,
          T1.JUDGE_STD_NAME,
          T1.GRADENAME,
          T1.ACT_DIMATER,
          T1.ACT_HEIGHT,
          T1.ACT_LEN_MIN,
          T1.ACT_LEN_MAX,
          T1.BELONG_CODE,
          T1.BELONG_NAME,
          d.SALE_AREA_DESC,
          d.CREATE_NAME,
          T1.PLINE_CODE,
          T1.PLINE_NAME,
          S.STORAGE_NAME,
          d.CUSTOMER_NM,
          g.RECEIV_NM,
          T1.PRODUCT_FLAG,
          T1.MAT_STATUS,
          T1.MEMO,
          T1.PIPMEMO,
          to_char(T1.INSTOCK_TIME, 'YYYY-MM-DD'),
          g.TRANSIT_TYP,
          t1.IN_MOLD,
          t1.FINISHPRO_MOLD,
     T1.SUPPLY_UNIT_CODE,
     T1.SUPPLY_UNIT
union all
select T1.ORDER_NO || '/' || T1.ORDER_SEQ AS SORDER,
       T1.OLD_ORDER_NO || '/' || T1.OLD_ORDER_SEQ AS OLDORDER,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.STEELCODE,
       T1.SPEC_CODE,
       T1.MODEL_CODE,
       T1.STD_CODE,
       T1.GRADECODE,
       T1.STEELNAME,
       T1.SPEC_NAME,
       T1.MODEL_DESC,
       T1.STD_NAME,
       T1.JUDGE_STD_NAME,
       T1.GRADENAME,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.ACT_LEN_MIN,
       T1.ACT_LEN_MAX,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       d.SALE_AREA_DESC,
       d.CREATE_NAME AS ORDERCREATENAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       S.STORAGE_NAME,
       d.CUSTOMER_NM,
       g.RECEIV_NM,
       T1.PRODUCT_FLAG,
       T1.MAT_STATUS,
       T1.MEMO,
       T1.PIPMEMO,
       to_char(T1.INSTOCK_TIME, 'YYYY-MM-DD') as INSTOCK_TIME,
       DECODE(g.TRANSIT_TYP,
              '110501',
              '汽运',
              '110502',
              '铁运',
              '110503',
              '船运',
              '110504',
              '航运') TRANSIT_TYP,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T1.IN_MOLD AND ROWNUM = 1) IN_MOLD,
       DECODE(t1.FINISHPRO_MOLD,
              '801801',
              '合同变更',
              '801802',
              '超交货期',
              '801803',
              '超载甩量',
              '801804',
              '成品备库',
              '801805',
              '质量异议待处理') FINISHPRO_MOLD,
       sum(T1.ACT_COUNT) as ACT_COUNT,
       sum(T1.ACT_WEIGHT) as ACT_WEIGHT,
       sum(T1.ACT_LEN) as ACT_LEN,
     T1.SUPPLY_UNIT_CODE,
     T1.SUPPLY_UNIT
  FROM MAT_ZC_M T1,
       YDM_ZC_BUTTRESS T2,
       ydm_bs_storage S,
       (select e.SALE_AREA_DESC, e.CREATE_NAME, e.CUSTOMER_NM, e.order_no
          from SLM_ORDER_HEAD e
         where e.validflag = '1') d,
       slm_order_line_delivery g
 WHERE t1.mat_no = t2.mat_no
   and t2.STORAGE_NO = S.STORAGE_NO(+)
   and substr(T1.OLD_ORDER_NO,
              1,
              decode(instr(T1.OLD_ORDER_NO, '/'),
                     0,
                     length(T1.OLD_ORDER_NO),
                     instr(T1.OLD_ORDER_NO, '/') - 1)) = d.order_no(+)
   and T1.Ord_Ln_Dly_Pk = g.ord_ln_dly_pk(+)
   and T1.product_flag = '801402'
     AND T1.SUPPLY_UNIT_CODE = '#CUSTOM#'
   #CONDITIONS1#
 group by T1.ORDER_NO || '/' || T1.ORDER_SEQ,
          T1.OLD_ORDER_NO || '/' || T1.OLD_ORDER_SEQ,
          T1.ORDER_NO,
          T1.ORDER_SEQ,
          T1.ORDER_SEQ_NO,
          T1.JUDGE_STOVE_NO,
          T1.BATCH_NO,
          T1.BATCH_GROUD_NO,
          T1.PRODUCCODE,
          T1.PRODUCNAME,
          T1.STD_STYLE,
          T1.STD_STYLE_DESC,
          T1.STEELCODE,
          T1.SPEC_CODE,
          T1.MODEL_CODE,
          T1.STD_CODE,
          T1.GRADECODE,
          T1.STEELNAME,
          T1.SPEC_NAME,
          T1.MODEL_DESC,
          T1.STD_NAME,
          T1.JUDGE_STD_NAME,
          T1.GRADENAME,
          T1.ACT_DIMATER,
          T1.ACT_HEIGHT,
          T1.ACT_LEN_MIN,
          T1.ACT_LEN_MAX,
          T1.BELONG_CODE,
          T1.BELONG_NAME,
          d.SALE_AREA_DESC,
          d.CREATE_NAME,
          T1.PLINE_CODE,
          T1.PLINE_NAME,
          S.STORAGE_NAME,
          d.CUSTOMER_NM,
          g.RECEIV_NM,
          T1.PRODUCT_FLAG,
          T1.MAT_STATUS,
          T1.MEMO,
          T1.PIPMEMO,
          to_char(T1.INSTOCK_TIME, 'YYYY-MM-DD'),
          g.TRANSIT_TYP,
          t1.IN_MOLD,
          t1.FINISHPRO_MOLD,
     T1.SUPPLY_UNIT_CODE,
     T1.SUPPLY_UNIT
)LOOP
   INSERT INTO MAT_ZC_INITIAL(
        SORDER,
        OLDORDER,
        ORDER_NO,
        ORDER_SEQ,
        ORDER_SEQ_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        PRODUCCODE,
        PRODUCNAME,
        STD_STYLE,
        STD_STYLE_DESC,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        STD_CODE,
        STD_NAME,
        JUDGE_STD_NAME,
        GRADECODE,
        GRADENAME,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_COUNT,
        ACT_WEIGHT,
        BELONG_CODE,
        BELONG_NAME,
        SALE_AREA_DESC,
        ORDERCREATENAME,
        PLINE_CODE,
        PLINE_NAME,
        STORAGE_NAME,
        CUSTOMER_NM,
        RECEIV_NM,
        PRODUCT_FLAG,
        MAT_STATUS,
        MEMO,
        PIPMEMO,
        TRANSIT_TYP,
        ACT_LEN,
        FINISHPRO_MOLD,
        IN_MOLD,
        INSTOCK_TIME,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
     BAL_YEAR_MONTH)
 VALUES( 
        MYROW1.SORDER,
        MYROW1.OLDORDER,
        MYROW1.ORDER_NO,
        MYROW1.ORDER_SEQ,
        MYROW1.ORDER_SEQ_NO,
        MYROW1.JUDGE_STOVE_NO,
        MYROW1.BATCH_NO,
        MYROW1.BATCH_GROUD_NO,
        MYROW1.PRODUCCODE,
        MYROW1.PRODUCNAME,
        MYROW1.STD_STYLE,
        MYROW1.STD_STYLE_DESC,
        MYROW1.STEELCODE,
        MYROW1.STEELNAME,
        MYROW1.SPEC_CODE,
        MYROW1.SPEC_NAME,
        MYROW1.MODEL_CODE,
        MYROW1.MODEL_DESC,
        MYROW1.STD_CODE,
        MYROW1.STD_NAME,
        MYROW1.JUDGE_STD_NAME,
        MYROW1.GRADECODE,
        MYROW1.GRADENAME,
        MYROW1.ACT_DIMATER,
        MYROW1.ACT_HEIGHT,
        MYROW1.ACT_LEN_MIN,
        MYROW1.ACT_LEN_MAX,
        MYROW1.ACT_COUNT,
        MYROW1.ACT_WEIGHT,
        MYROW1.BELONG_CODE,
        MYROW1.BELONG_NAME,
        MYROW1.SALE_AREA_DESC,
        MYROW1.ORDERCREATENAME,
        MYROW1.PLINE_CODE,
        MYROW1.PLINE_NAME,
        MYROW1.STORAGE_NAME,
        MYROW1.CUSTOMER_NM,
        MYROW1.RECEIV_NM,
        MYROW1.PRODUCT_FLAG,
        MYROW1.MAT_STATUS,
        MYROW1.MEMO,
        MYROW1.PIPMEMO,
        MYROW1.TRANSIT_TYP,
        MYROW1.ACT_LEN,
        MYROW1.FINISHPRO_MOLD,
        MYROW1.IN_MOLD,
        TO_DATE(MYROW1.INSTOCK_TIME,'YYYY-MM-DD'),
        MYROW1.SUPPLY_UNIT_CODE,
     MYROW1.SUPPLY_UNIT,
     '#BAL_YEAR_MONTH#');
  END LOOP;
END;
	</query>
	<query id = "FrmFinishAfrim.doQueryChangeData" desc = "查询转移单">
	SELECT T.CHANGE_DOC,
       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.STD_CODE,
       T.STD_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_LEN,
       T.ACT_COUNT,
       T.ACT_WEIGHT,
       T.ACT_THEORY_WEIGHT,
       T.BELONG_CODE_BEFOR,
       T.BELONG_NAME_BEFOR,
       T.STORAGE_NO,
       T.PRODUCT_FLAG,
       T.MAT_STATUS,
       T.BAL_YEAR_MONTH,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       DECODE(T.FRIM_FLAG,'0','未审批','1','审批通过','2','审批不通过')FRIM_FLAG,
       T.FRIM_NAME,
       TO_CHAR(T.FRIM_TIME, 'YYYY-MM-DD HH24:MI:SS') FRIM_TIME,
       T.CHANGE_MEMO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.BELONG_CODE,
       T.BELONG_NAME
  FROM YDM_ZC_CHANGEBELONG T
 WHERE 1 = 1
	</query>
	<query id = "FrmFinishAfrim.selectBelongFlag" desc = "查询审核标识">
	SELECT T.FRIM_FLAG FROM YDM_ZC_CHANGEBELONG T WHERE T.CHANGE_DOC = '#CHANGE_DOC#'
	</query>
	<query id = "FrmFinishAfrim.insertChangeBelong" desc = "生成转移单数据">
	<![CDATA[
	DECLARE
  V_CHANGE_DOC YDM_ZC_CHANGEBELONG.CHANGE_DOC%TYPE := NULL;
  V_WGT MAT_ZC_M.ACT_WEIGHT%TYPE := NULL;
  V_LEN MAT_ZC_M.ACT_LEN%TYPE := NULL;
  V_COUNT NUMBER:=0;
BEGIN
  SELECT TO_CHAR(SYSDATE, 'YYYYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.CHANGE_DOC, 9)), 0) + 1, 4, 0) CHANGE_DOC
    INTO V_CHANGE_DOC
    FROM YDM_ZC_CHANGEBELONG T
   WHERE T.CHANGE_DOC LIKE TO_CHAR(SYSDATE, 'YYYYMMDD') || '____';
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*,S.STORAGE_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.LOCK_FLAG = '0'
                           AND T.MNG_LOCK_FLAG = '0'
                           AND T.BELONG_CODE = '#BELONG_CODE_BEFOR#'
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
               V_COUNT := V_COUNT + 1;  
    UPDATE MAT_ZC_M T
       SET T.MNG_LOCK_FLAG = '1', T.CHANGE_DOC = V_CHANGE_DOC
     WHERE T.MAT_NO = MYROW.MAT_NO;
     V_WGT := TO_NUMBER(NVL(V_WGT,'0')) + TO_NUMBER(NVL(MYROW.ACT_WEIGHT,'0'));
     V_LEN := TO_NUMBER(NVL(V_LEN,'0')) + TO_NUMBER(NVL(MYROW.ACT_LEN,'0'));
     IF(V_COUNT = '#ACT_COUNT#')THEN
     INSERT INTO YDM_ZC_CHANGEBELONG(
        CHANGE_DOC,
        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,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_LEN,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_THEORY_WEIGHT,
        BELONG_CODE_BEFOR,
        BELONG_NAME_BEFOR,
        STORAGE_NO,
        PRODUCT_FLAG,
        MAT_STATUS,
        BAL_YEAR_MONTH,
        CREATE_NAME,
        CREATE_TIME,
        PLINE_CODE,
        PLINE_NAME,
        BELONG_CODE,
        BELONG_NAME)
 VALUES( 
        V_CHANGE_DOC,
        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.ACT_DIMATER,
        MYROW.ACT_HEIGHT,
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        V_LEN,
        '#ACT_COUNT#',
        V_WGT,
        V_WGT,
        MYROW.BELONG_CODE,
        MYROW.BELONG_NAME,
        MYROW.STORAGE_NO,
        MYROW.PRODUCT_FLAG,
        MYROW.MAT_STATUS,
        '#BAL_YEAR_MONTH#',
        '#CREATE_NAME#',
        SYSDATE,
        MYROW.PLINE_CODE,
        MYROW.PLINE_NAME,
        '#BELONG_CODE#',
        '#BELONG_NAME#');
     END IF;
  END LOOP; 
END;
	]]>
	</query>
	<query id = "FrmFinishAfrim.QueryMatNoM1" desc = "查询材料号">
	SELECT ? || ? ||
       LPAD(NVL(MAX(SUBSTR(T2.MAT_NO, LENGTH(T2.MAT_NO) - 3)), 0) + 1, 4, 0) MAT_NO
  FROM (SELECT MAX(T.MAT_NO)MAT_NO
          FROM MAT_ZC_M T
         WHERE T.JUDGE_STOVE_NO = ?
           AND T.BATCH_NO = ?
        UNION ALL
        SELECT MAX(T1.MAT_NO)MAT_NO
          FROM YDM_ZC_INLIST T1
         WHERE T1.JUDGE_STOVE_NO = ?
           AND T1.BATCH_NO = ?
         UNION ALL
         SELECT MAX(T3.MAT_NO)MAT_NO
         FROM MAT_ZC_BACKUP T3
         WHERE T3.JUDGE_STOVE_NO = ?
         AND T3.BATCH_NO = ?) T2
	</query>
	<query id = "FrmFinishAfrim.getInListDoc1" desc = "生成入库流水">
	SELECT ?||LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 4)), 0)+1,5,0)INSTOCK_SQE FROM YDM_ZC_INLIST T
    WHERE T.INSTOCK_DOC = ?
	</query>
	<query id = "FrmFinishAfrim.insertInListJG" desc = "商品接箍缴库">
        DECLARE
        V_ZBS_ID            COUPLING_MAT_M.ZBS_ID%TYPE := NULL;
        V_ZBS_FLAG          COUPLING_MAT_M.ZBS_FLAG%TYPE := NULL;
        V_BELONG_CODE_JUDGE QCM_ZG_JUGDE_APPLY.BELONG_NAME_JUGDE%TYPE := NULL;
        BEGIN
        --去向
        SELECT T.BELONG_NAME_JUGDE
        INTO V_BELONG_CODE_JUDGE
        FROM QCM_ZG_JUGDE_APPLY T
        WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
        AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
        AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
        FOR MYROW IN (SELECT T.*
        FROM QCM_ZG_JUGDE_APPLY T
        WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
        AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
        AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
        AND T.BATCH_NO = '#BATCH_NO#'
        AND T.PROCESS_CODE = 'H') LOOP
        INSERT INTO YDM_ZC_INLIST
        (MANAGEMENT_NO,
        MANAGEMENT_NAME,
        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,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        PRODUCT_FLAG,
        MAT_STATUS,
        INSTOCK_TIME,
        ZB_RCDID,
        ACT_LEN,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        JUDGE_STD_NAME,
        PLINE_CODE,
        PLINE_NAME,
        GRADECODE,
        GRADENAME,
        BAL_YEAR_MONTH,
        IN_TIME_F,
        PIPMEMO,
        MAT_ORIGIN_CODE,
        MAT_ORIGIN_NAME,
        SOURE_CODE,
        SOURE_NAME,
        MATERIAL_NO,
        MATERIAL_NAME,
        IN_MOLD,
        IN_TYPE,
        PACK_NO,
        PRO_ORDER_NO,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        JUGDE_APPLY_CODE,
        IS_DEALER,
        PROCESS_CDOE,
        PROCESS_DESC,
        IS_ALL_SCRAP)
        VALUES
        ('#MANAGEMENT_NO#',
        '#MANAGEMENT_NAME#',
        '#INSTOCK_SQE#',
        '#INSTOCK_DOC#',
        '#INSTOCK_TYPE_CODE#',
        '#INSTOCK_TYPE_NAME#',
        '#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,
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        MYROW.BELONG_CODE_JUGDE,
        MYROW.BELONG_NAME_JUGDE,
        '#STORAGE_NO#',
        '#MEMO#',
        '#CREATE_NAME#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#ORDER_NO#',
        '#ORDER_SEQ#',
        '#DELIVERY_NO#',
        '#ORD_PK#',
        '#ORD_LN_PK#',
        '#ORD_LN_DLY_PK#',
        '#PRODUCT_FLAG#',
        '#MAT_STATUS#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        MYROW.JUGDE_TOLCONVICTED,
        '#ACT_LEN#',
        '#DEPARTMENT_CODE#',
        '#DEPARTMENT_DESC#',
        MYROW.STEEL_STANDRAD,
        MYROW.PLINE_CODE,
        MYROW.PLINE_NAME,
        MYROW.GRADECODE,
        MYROW.GRADENAME,
        '#BAL_YEAR_MONTH#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#PIPMEMO#',
        '801302',
        '产线',
        '801302',
        '产线',
        MYROW.MATERIAL_NO,
        MYROW.MATERIAL_NAME,
        '#IN_MOLD#',
        '#IN_TYPE#',
        '#PACK_NO#',
        MYROW.PRO_ORDER_NO,
        '#SUPPLY_UNIT_CODE#',
        '#SUPPLY_UNIT#',
        MYROW.JUGDE_APPLY_CODE||MYROW.JUGDE_APPLY_SEQUENO,
        '0','H','接箍加工',
        MYROW.IS_ALL_SCRAP);
        
        INSERT INTO YDM_ZC_INLIST_XS
        (MANAGEMENT_NO,
        MANAGEMENT_NAME,
        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,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        PRODUCT_FLAG,
        MAT_STATUS,
        INSTOCK_TIME,
        ZB_RCDID,
        ACT_LEN,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        JUDGE_STD_NAME,
        PLINE_CODE,
        PLINE_NAME,
        GRADECODE,
        GRADENAME,
        BAL_YEAR_MONTH,
        IN_TIME_F,
        PIPMEMO,
        MAT_ORIGIN_CODE,
        MAT_ORIGIN_NAME,
        SOURE_CODE,
        SOURE_NAME,
        MATERIAL_NO,
        MATERIAL_NAME,
        IN_MOLD,
        IN_TYPE,
        PACK_NO,
        PRO_ORDER_NO,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        JUGDE_APPLY_CODE,
        IS_DEALER,
        PROCESS_CDOE,
        PROCESS_DESC,
        IS_ALL_SCRAP)
        VALUES
        ('#MANAGEMENT_NO#',
        '#MANAGEMENT_NAME#',
        '#INSTOCK_SQE#',
        '#INSTOCK_DOC#',
        '#INSTOCK_TYPE_CODE#',
        '#INSTOCK_TYPE_NAME#',
        '#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,
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        MYROW.BELONG_CODE_JUGDE,
        MYROW.BELONG_NAME_JUGDE,
        '#STORAGE_NO#',
        '#MEMO#',
        '#CREATE_NAME#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#ORDER_NO#',
        '#ORDER_SEQ#',
        '#DELIVERY_NO#',
        '#ORD_PK#',
        '#ORD_LN_PK#',
        '#ORD_LN_DLY_PK#',
        '#PRODUCT_FLAG#',
        '#MAT_STATUS#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        MYROW.JUGDE_TOLCONVICTED,
        '#ACT_LEN#',
        '#DEPARTMENT_CODE#',
        '#DEPARTMENT_DESC#',
        MYROW.STEEL_STANDRAD,
        MYROW.PLINE_CODE,
        MYROW.PLINE_NAME,
        MYROW.GRADECODE,
        MYROW.GRADENAME,
        '#BAL_YEAR_MONTH#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#PIPMEMO#',
        '801302',
        '产线',
        '801302',
        '产线',
        MYROW.MATERIAL_NO,
        MYROW.MATERIAL_NAME,
        '#IN_MOLD#',
        '#IN_TYPE#',
        '#PACK_NO#',
        MYROW.PRO_ORDER_NO,
        '#SUPPLY_UNIT_CODE#',
        '#SUPPLY_UNIT#',
        MYROW.JUGDE_APPLY_CODE||MYROW.JUGDE_APPLY_SEQUENO,
        '0','H','接箍加工',
        MYROW.IS_ALL_SCRAP);
        
        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,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        BAL_YEAR_MONTH,
        ACT_DIMATER,
        ACT_HEIGHT,
        BELONG_CODE,
        BELONG_NAME,
        INSTOCK_TYPE_CODE,
        INSTOCK_TYPE_NAME
        )
        VALUES(
        (SELECT F.STORAGE_NAME FROM YDM_BS_STORAGE F WHERE F.STORAGE_NO = '#STORAGE_NO#'),
        '#MAT_NO#',
        '#INSTOCK_SQE#',
        '#INSTOCK_DOC#',
        '#ORDER_NO#',
        '#ORDER_SEQ#',
        '#DELIVERY_NO#',
        '#ORD_PK#',
        '#ORD_LN_PK#',
        '#ORD_LN_DLY_PK#',
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = '#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,
        '#ACT_LEN#',
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        '#STORAGE_NO#',
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = '#IN_MOLD#'),
        '#PACK_NO#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#SUPPLY_UNIT_CODE#',
        '#SUPPLY_UNIT#',
        '#BAL_YEAR_MONTH#',
        MYROW.ACT_DIMATER,
        MYROW.ACT_HEIGHT,
        MYROW.BELONG_CODE_JUGDE,
        MYROW.BELONG_NAME_JUGDE,
        '#INSTOCK_TYPE_CODE#',
        '#INSTOCK_TYPE_NAME#'
        );
        INSERT INTO MAT_ZC_M
        (STOVE_NO,
        LOT_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        PRODUCCODE,
        PRODUCNAME,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        STD_CODE,
        STD_NAME,
        BELONG_CODE,
        BELONG_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        ORDER_NO,
        ORDER_SEQ,
        ORDER_SEQ_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        CREATE_NAME,
        ACT_COUNT,
        ACT_WEIGHT,
        CREATE_TIME,
        INSTOCK_TIME,
        MAT_NO,
        MEMO,
        INSTOCK_FLAG,
        PRODUCT_FLAG,
        MAT_STATUS,
        ACT_LEN,
        JUDGE_STD_NAME,
        BAL_YEAR_MONTH,
        PLINE_CODE,
        PLINE_NAME,
        GRADECODE,
        GRADENAME,
        PIPMEMO,
        JUDGE_RESULT_TIME,
        MAT_ORIGIN_CODE,
        MAT_ORIGIN_NAME,
        SOURE_CODE,
        SOURE_NAME,
        MATERIAL_NO,
        MATERIAL_NAME,
        PACK_NO,
        IN_MOLD,
        IN_TYPE,
        PRO_ORDER_NO,
        JUDGE_RESULT_CODE,
        JUDGE_RESULT,
        JUDGE_MAKER,
        ZBS_FLAG,
        ZBS_ID,
        JG_ZBS_ID,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        IS_DEALER,
        PROCESS_CDOE,
        PROCESS_DESC)
        VALUES
        (MYROW.STOVE_NO,
        MYROW.LOT_NO,
        MYROW.JUDGE_STOVE_NO,
        MYROW.BATCH_NO,
        MYROW.BATCH_GROUD_NO,
        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.BELONG_CODE_JUGDE,
        MYROW.BELONG_NAME_JUGDE,
        MYROW.STD_STYLE,
        MYROW.STD_STYLE_DESC,
        '#ORDER_NO#',
        '#ORDER_SEQ#',
        '#DELIVERY_NO#',
        '#ORD_PK#',
        '#ORD_LN_PK#',
        '#ORD_LN_DLY_PK#',
        MYROW.ACT_DIMATER,
        MYROW.ACT_HEIGHT,
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        '#CREATE_NAME#',
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#MAT_NO#',
        '#MEMO#',
        '1',
        '#PRODUCT_FLAG#',
        '#MAT_STATUS#',
        '#ACT_LEN#',
        MYROW.STEEL_STANDRAD,
        '#BAL_YEAR_MONTH#',
        MYROW.PLINE_CODE,
        MYROW.PLINE_NAME,
        MYROW.GRADECODE,
        MYROW.GRADENAME,
        '#PIPMEMO#',
        TO_DATE('#JUDGE_RESULT_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '801302',
        '产线',
        '801302',
        '产线',
        MYROW.MATERIAL_NO,
        MYROW.MATERIAL_NAME,
        '#PACK_NO#',
        '#IN_MOLD#',
        '#IN_TYPE#',
        MYROW.PRO_ORDER_NO,
        MYROW.JUDGE_TOLRESULT_CODE,
        MYROW.JUDGE_TOLRESULT,
        MYROW.JUDGE_TOLMAKER,
        '#ZBS_FLAG#',
        '#ZBS_ID#',
        '',
        '#SUPPLY_UNIT_CODE#',
        '#SUPPLY_UNIT#','0','H','接箍加工');

INSERT INTO MAT_ZC_M_XS
        (STOVE_NO,
        LOT_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        PRODUCCODE,
        PRODUCNAME,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        STD_CODE,
        STD_NAME,
        BELONG_CODE,
        BELONG_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        ORDER_NO,
        ORDER_SEQ,
        ORDER_SEQ_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        CREATE_NAME,
        ACT_COUNT,
        ACT_WEIGHT,
        CREATE_TIME,
        INSTOCK_TIME,
        MAT_NO,
        MEMO,
        INSTOCK_FLAG,
        PRODUCT_FLAG,
        MAT_STATUS,
        ACT_LEN,
        JUDGE_STD_NAME,
        BAL_YEAR_MONTH,
        PLINE_CODE,
        PLINE_NAME,
        GRADECODE,
        GRADENAME,
        PIPMEMO,
        JUDGE_RESULT_TIME,
        MAT_ORIGIN_CODE,
        MAT_ORIGIN_NAME,
        SOURE_CODE,
        SOURE_NAME,
        MATERIAL_NO,
        MATERIAL_NAME,
        PACK_NO,
        IN_MOLD,
        IN_TYPE,
        PRO_ORDER_NO,
        JUDGE_RESULT_CODE,
        JUDGE_RESULT,
        JUDGE_MAKER,
        ZBS_FLAG,
        ZBS_ID,
        JG_ZBS_ID,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        IS_DEALER,
        PROCESS_CDOE,
        PROCESS_DESC)
        VALUES
        (MYROW.STOVE_NO,
        MYROW.LOT_NO,
        MYROW.JUDGE_STOVE_NO,
        MYROW.BATCH_NO,
        MYROW.BATCH_GROUD_NO,
        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.BELONG_CODE_JUGDE,
        MYROW.BELONG_NAME_JUGDE,
        MYROW.STD_STYLE,
        MYROW.STD_STYLE_DESC,
        '#ORDER_NO#',
        '#ORDER_SEQ#',
        '#DELIVERY_NO#',
        '#ORD_PK#',
        '#ORD_LN_PK#',
        '#ORD_LN_DLY_PK#',
        MYROW.ACT_DIMATER,
        MYROW.ACT_HEIGHT,
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        '#CREATE_NAME#',
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#MAT_NO#',
        '#MEMO#',
        '1',
        '#PRODUCT_FLAG#',
        '#MAT_STATUS#',
        '#ACT_LEN#',
        MYROW.STEEL_STANDRAD,
        '#BAL_YEAR_MONTH#',
        MYROW.PLINE_CODE,
        MYROW.PLINE_NAME,
        MYROW.GRADECODE,
        MYROW.GRADENAME,
        '#PIPMEMO#',
        TO_DATE('#JUDGE_RESULT_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '801302',
        '产线',
        '801302',
        '产线',
        MYROW.MATERIAL_NO,
        MYROW.MATERIAL_NAME,
        '#PACK_NO#',
        '#IN_MOLD#',
        '#IN_TYPE#',
        MYROW.PRO_ORDER_NO,
        MYROW.JUDGE_TOLRESULT_CODE,
        MYROW.JUDGE_TOLRESULT,
        MYROW.JUDGE_TOLMAKER,
        '#ZBS_FLAG#',
        '#ZBS_ID#',
        '',
        '#SUPPLY_UNIT_CODE#',
        '#SUPPLY_UNIT#','0','H','接箍加工');
        
        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,
        MANAGEMENT_NO,
        MANAGEMENT_NAME,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC)
        VALUES
        (MYROW.JUDGE_STOVE_NO,
        MYROW.BATCH_NO,
        MYROW.BATCH_GROUD_NO,
        '#STORAGE_NO#',
        '#LOCATION_NO#',
        '1',
        '#CREATE_NAME#',
        '#MAT_NO#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#MANAGEMENT_NO#',
        '#MANAGEMENT_NAME#',
        '#DEPARTMENT_CODE#',
        '#DEPARTMENT_DESC#');
        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
        )
        VALUES(
        '#MAT_NO#',
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = '#PRODUCT_FLAG#'),
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = '#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,
        '#ORDER_NO#',
        '#ORDER_SEQ#',
        '#DELIVERY_NO#',
        '#ORD_PK#',
        '#ORD_LN_PK#',
        '#ORD_LN_DLY_PK#',
        MYROW.PLINE_CODE,
        MYROW.PLINE_NAME,
        MYROW.ACT_DIMATER,
        MYROW.ACT_HEIGHT,
        '#ACT_LEN#',
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        MYROW.BELONG_CODE_JUGDE,
        MYROW.BELONG_NAME_JUGDE,
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = '#IN_MOLD#'),
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#STORAGE_NO#',
        '#LOCATION_NO#',
        (SELECT F.STORAGE_NAME FROM YDM_BS_STORAGE F WHERE F.STORAGE_NO = '#STORAGE_NO#'),
        (SELECT F.LOCATION_NAME FROM YDM_BS_LOCATION F WHERE F.LOCATION_NO = '#LOCATION_NO#'),
        '#SUPPLY_UNIT_CODE#',
        '#SUPPLY_UNIT#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'));
        END LOOP;
        END;
    </query>
	<query id = "FrmFinishAfrim.deleteJg" desc = "商品接箍缴库2">
	DECLARE
	 V_DEAL_ORDE         COUPLING_MAT_DEAL.DEAL_ORDE%TYPE := NULL;
	  V_BELONG_CODE_JUDGE QCM_ZG_JUGDE_APPLY.BELONG_NAME_JUGDE%TYPE := NULL;
        V_ACOUNT            QCM_ZG_JUGDE_APPLY.ACT_COUNT%TYPE := NULL;
        V_INCOUNT      NUMBER := 1;
BEGIN
 
  --去向
  SELECT T.BELONG_NAME_JUGDE INTO V_BELONG_CODE_JUDGE
    FROM QCM_ZG_JUGDE_APPLY T
   WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
        AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';

 --生成出库单号
  SELECT NVL(MAX(SUBSTR(T.DEAL_ORDE, 11)), 0) + 1
    INTO V_INCOUNT
    FROM COUPLING_MAT_DEAL T
   WHERE T.DEAL_TYPE_CODE = '800805'
     AND T.DEAL_ORDE LIKE 'OH' || TO_CHAR(SYSDATE, 'YYYYMMDD') || '___';
  --写接箍出库表、删接箍库存、位置、合同信息表
    FOR MYROW1 IN (SELECT T.*,
                          S.STORAGE_NO,
                          S.LOCATION_NO,
                          S.STORAGE_ATTR,
                          S.STORAGE_ATTR_NAME,
                          S.STORAGE_TYPE_NO,
                          S.STORAGE_TYPE_NAME,
                          S.PRODUCT_FLAG,
                          S.MAT_STATUS,
                          S.CUST_ALPHA_NO,
                          S.ORDER_SPECIAL_DESC,
                          S.ALPHA_CODE,
                          S.KEP_NO,
                          S.MAT_NO_XH,
                          D.ORDER_NO AS ORDER_NO1,
                          D.ORDER_SEQ AS ORDER_SEQ1,
                          D.ORDER_SEQ_NO AS ORDER_SEQ_NO1,
                          D.ORD_PK,
                          D.ORD_LN_PK,
                          D.ORD_LN_DLY_PK AS ORD_LN_DLY_PK1,
                          D.CRAFT_SEQ_ORD,
                          D.CRAFT_FILE_NO_ORD,
                          D.JG_ORDERNO
                     FROM COUPLING_MAT_M        T,
                          COUPLING_MAT_BUTTRESS S,
                          PLN_ZY_JG_MIDDLE      D
                    WHERE T.MAT_NO = S.MAT_NO
                      AND S.MAT_NO = D.MAT_NO(+)
                      AND S.MAT_NO_XH = D.MAT_NO_XH(+)
                      AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                      AND T.BATCH_NO = '#BATCH_NO#'
                      AND T.DETER_NO = '#JUGDE_APPLY_CODE#'
                      AND T.DETER_NO_SEQ = '#JUGDE_APPLY_SEQUENO#'
                      AND T.QCM_STAUS = '00') LOOP
        V_DEAL_ORDE := 'OH' || TO_CHAR(SYSDATE, 'YYYYMMDD')|| LPAD(V_INCOUNT,3,0);
        INSERT INTO COUPLING_MAT_DEAL
        (DEAL_ORDE,
         DEAL_TYPE_CODE,
         DEAL_TYPE_NAME,
         SOURCE_CODE,
         SOURCE_NAME,
         KEP_NO,
         MAT_NO,
         RESULT_NO,
         WO_ID,
         PLINE_CODE,
         PLINE_NAME,
         MAT_ORIGIN_CODE,
         MAT_ORIGIN_NAME,
         SOURE_CODE,
         SOURE_NAME,
         JUDGE_STOVE_NO,
         BATCH_NO,
         BL_WL_ID,
         BL_WL_DESC,
         MIN_D,
         MIN_H,
         CODE_JG,
         GRADECODE,
         GRADENAME,
         STEELCODE,
         STEELNAME,
         MODEL_CODE,
         MODEL_DESC,
         OUTDIAMETER,
         WALLTHICK,
         SPEC_JG,
         SPEC_JG_DESC,
         STYLE_JG,
         DIAMETER,
         CHECK_J_VAL,
         AIMLENGTH,
         SINGLEWEIGHT,
         MONITORDEMAND,
         IF_MONITOR_JG,
         PRDCR_NO,
         PRODUCER,
         DEAL_NUM,
         DEAL_WT,
         BAL_YEAR_MONTH,
         F_IN_TIME,
         DEAL_TIME,
         STORAGE_NO,
         LOCATION_NO,
         STORAGE_ATTR,
         STORAGE_ATTR_NAME,
         STORAGE_TYPE_NO,
         STORAGE_TYPE_NAME,
         HAND_FLAG,
         DEMAND_COPPER,
         DEMAND_DETECTION,
         DEMAND_BLAST,
         DEMAND_BONDERIZING,
         CUST_ALPHA_NO,
         ORDER_SPECIAL_DESC,
         ALPHA_CODE,
         DETER_NO,
         DETER_RESULTS,
         COL_OPERATOR,
         MEMO,
         CREATE_NAME,
         CREATE_TIME,
         PRODUCT_FLAG,
         MAT_STATUS,
         DETER_STATUS,
         CODE_JG_BL,
         CRAFT_FILE_NO,
         CRAFT_SEQ,
         BELONG_CODE,
         BELONG_NAME,
         COAT_TYPE,
         MAT_NO_XH,
         QCM_STAUS,
         OUT_FLAG,
         JG_ORDERNO,
         ORDER_NO,
         ORDER_SEQ,
         DELIVERY_NO,
         ORD_PK,
         ORD_LN_PK,
         ORD_LN_DLY_PK,
         CRAFT_SEQ_ORD,
         CRAFT_FILE_NO_ORD,
         STOVE_NO,
         FLAG_STOVE_NO,
         GOWHERE_NAME)
      VALUES
        (V_DEAL_ORDE,
         '800805',
         '销售出库',
         '#MANAGEMENT_NO#',
         '#MANAGEMENT_NAME#',
         MYROW1.KEP_NO,
         MYROW1.MAT_NO,
         MYROW1.RESULT_NO,
         MYROW1.WO_ID,
         MYROW1.PLINE_CODE,
         MYROW1.PLINE_NAME,
         MYROW1.MAT_ORIGIN_CODE,
         MYROW1.MAT_ORIGIN_NAME,
         MYROW1.SOURE_CODE,
         MYROW1.SOURE_NAME,
         MYROW1.JUDGE_STOVE_NO,
         MYROW1.BATCH_NO,
         MYROW1.BL_WL_ID,
         MYROW1.BL_WL_DESC,
         MYROW1.MIN_D,
         MYROW1.MIN_H,
         MYROW1.CODE_JG,
         MYROW1.GRADECODE,
         MYROW1.GRADENAME,
         MYROW1.STEELCODE,
         MYROW1.STEELNAME,
         MYROW1.MODEL_CODE,
         MYROW1.MODEL_DESC,
         MYROW1.OUTDIAMETER,
         MYROW1.WALLTHICK,
         MYROW1.SPEC_JG,
         MYROW1.SPEC_JG_DESC,
         MYROW1.STYLE_JG,
         MYROW1.DIAMETER,
         MYROW1.CHECK_J_VAL,
         MYROW1.AIMLENGTH,
         MYROW1.SINGLEWEIGHT,
         MYROW1.MONITORDEMAND,
         MYROW1.IF_MONITOR_JG,
         MYROW1.PRDCR_NO,
         MYROW1.PRODUCER,
         MYROW1.PRO_NUM,
         MYROW1.PRO_WT,
         '#BAL_YEAR_MONTH#',
         MYROW1.F_IN_TIME,
         TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
         MYROW1.STORAGE_NO,
         MYROW1.LOCATION_NO,
         MYROW1.STORAGE_ATTR,
         MYROW1.STORAGE_ATTR_NAME,
         MYROW1.STORAGE_TYPE_NO,
         MYROW1.STORAGE_TYPE_NAME,
         '0',
         MYROW1.DEMAND_COPPER,
         MYROW1.DEMAND_DETECTION,
         MYROW1.DEMAND_BLAST,
         MYROW1.DEMAND_BONDERIZING,
         MYROW1.CUST_ALPHA_NO,
         MYROW1.ORDER_SPECIAL_DESC,
         MYROW1.ALPHA_CODE,
         MYROW1.DETER_NO,
         MYROW1.DETER_RESULTS,
         '#CREATE_NAME#', --人
         MYROW1.MEMO,
         '#CREATE_NAME#',
         TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
         MYROW1.PRODUCT_FLAG,
         MYROW1.MAT_STATUS,
         MYROW1.DETER_STATUS,
         MYROW1.CODE_JG_BL,
         MYROW1.CRAFT_FILE_NO,
         MYROW1.CRAFT_SEQ,
         MYROW1.BELONG_CODE,
         MYROW1.BELONG_NAME,
         MYROW1.COAT_TYPE,
         MYROW1.MAT_NO_XH,
         MYROW1.QCM_STAUS,
         '0',
         MYROW1.JG_ORDERNO,
         MYROW1.ORDER_NO1,
         MYROW1.ORDER_SEQ1,
         MYROW1.ORDER_SEQ_NO1,
         MYROW1.ORD_PK,
         MYROW1.ORD_LN_PK,
         MYROW1.ORD_LN_DLY_PK1,
         MYROW1.CRAFT_SEQ_ORD,
         MYROW1.CRAFT_FILE_NO_ORD,
         MYROW1.STOVE_NO,
         MYROW1.FLAG_STOVE_NO,
         V_BELONG_CODE_JUDGE);
        V_INCOUNT  := V_INCOUNT + 1;
        SELECT COUNT(1)
        INTO V_ACOUNT
        FROM COUPLING_MAT_BACKUP T
        WHERE T.MAT_NO = MYROW1.MAT_NO;
        IF (V_ACOUNT > 0) THEN
        UPDATE COUPLING_MAT_BACKUP T
        SET T.PRO_NUM = TO_NUMBER(T.PRO_NUM) + TO_NUMBER(MYROW1.PRO_NUM),
        T.PRO_WT  = TO_NUMBER(T.PRO_WT) + TO_NUMBER(MYROW1.PRO_WT)
        WHERE T.MAT_NO = MYROW1.MAT_NO;
        ELSE
        INSERT INTO COUPLING_MAT_BACKUP
        SELECT *
        FROM COUPLING_MAT_M T
        WHERE T.MAT_NO = MYROW1.MAT_NO
        AND T.DETER_NO = MYROW1.DETER_NO
        AND T.QCM_STAUS = '00';
        END IF;
      DELETE FROM COUPLING_MAT_M T WHERE T.MAT_NO = MYROW1.MAT_NO;
      DELETE FROM COUPLING_MAT_BUTTRESS T WHERE T.MAT_NO = MYROW1.MAT_NO AND T.MAT_NO_XH = MYROW1.MAT_NO_XH;
      DELETE FROM PLN_ZY_JG_MIDDLE T
       WHERE T.MAT_NO = MYROW1.MAT_NO
         AND T.MAT_NO_XH = MYROW1.MAT_NO_XH;
      
    END LOOP;
 
 UPDATE QCM_ZG_JUGDE_APPLY S
     SET S.INSTOCK_FLAG = '1'
   WHERE S.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND S.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
     AND 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_JUGDE IN ('100101', '100102', '100103','100105');
     --修改排产缴库量
  UPDATE PLN_SALEORD
     SET PAYDOWN_NUM   = TO_NUMBER(NVL(PAYDOWN_NUM,0)) + TO_NUMBER(NVL('#PAY_NUM#',0)),
         PAYDOWNWEIGHT = TO_NUMBER(NVL(PAYDOWNWEIGHT,0)) + TO_NUMBER(NVL('#PAY_WGT#',0))
   WHERE ORDER_NO = '#ORDER_NO#'
     AND ORDER_SEQ = '#ORDER_SEQ#'
     AND DELIVERY_NO = '#DELIVERY_NO#';
  --修改进程表
  UPDATE PROCESS_ORDER_M T
     SET T.PAY_NUM = TO_NUMBER(NVL(T.PAY_NUM, 0)) + TO_NUMBER(NVL('#PAY_NUM#',0)),
         T.PAY_WGT = TO_NUMBER(NVL(T.PAY_WGT, 0)) + TO_NUMBER(NVL('#PAY_WGT#',0)),
         T.PAY_LEN = TO_NUMBER(NVL(T.PAY_LEN, 0)) + TO_NUMBER(NVL('#PAY_LEN#',0))
   WHERE ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#';
END;
	</query>
	<query id = "FrmFinishAfrim.canceDoFrimJG" desc = "撤销商品接箍缴库">
        DECLARE
        V_JUGDE_APPLY_CODE QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_CODE%TYPE := NULL;
        V_PAY_NUM          PROCESS_ORDER_M.PAY_NUM%TYPE := NULL;
        V_PAY_WGT          PROCESS_ORDER_M.PAY_WGT%TYPE := NULL;
        V_PAY_LEN          PROCESS_ORDER_M.PAY_LEN%TYPE := NULL;
        BEGIN

        SELECT SUM(T.ACT_LEN), SUM(T.ACT_COUNT), SUM(T.ACT_WEIGHT)
        INTO V_PAY_LEN, V_PAY_NUM, V_PAY_WGT
        FROM YDM_ZC_INLIST T
        WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#'
        AND T.PRODUCT_FLAG = '801403';
        FOR MYROW IN (SELECT t.*, J.PRODUCCODE_JG, J.PRODUCCODE_JG_DESC,J.STD_STYLE,J.STD_STYLE_DESC,J.STD_CODE,J.STD_NAME
        FROM COUPLING_MAT_DEAL T, com_msc_jg J
        WHERE T.CODE_JG = J.CODE_JG
        and T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
        AND T.BATCH_NO = '#BATCH_NO#'
        AND T.DEAL_TYPE_CODE = '800805') LOOP
        INSERT INTO COUPLING_MAT_BUTTRESS
        (MAT_NO,
        MAT_NO_XH,
        PRODUCT_FLAG,
        MAT_STATUS,
        PRO_PLAN_ID,
        JG_GROUP_ID,
        MACH_NO,
        MACH_NM,
        MAT_ORIGIN_CODE,
        MAT_ORIGIN_NAME,
        SOURE_CODE,
        SOURE_NAME,
        PIECES,
        WEIGHT,
        CUST_ALPHA_NO,
        ORDER_SPECIAL_DESC,
        ALPHA_CODE,
        OFFLINE_LOG,
        LOCK_LIKU,
        DEAL_ORDE,
        KEP_NO,
        STORAGE_NO,
        LOCATION_NO,
        STORAGE_ATTR,
        STORAGE_ATTR_NAME,
        STORAGE_TYPE_NO,
        STORAGE_TYPE_NAME,
        MANAGEMENT_NO,
        MANAGEMENT_NAME,
        CREATE_NAME,
        CREATE_TIME)
        VALUES
        (MYROW.Mat_No,
        MYROW.Mat_No_Xh,
        MYROW.Product_Flag,
        MYROW.Mat_Status,
        MYROW.Pro_Plan_Id,
        MYROW.Jg_Group_Id,
        MYROW.Mach_No,
        MYROW.Mach_Nm,
        MYROW.Mat_Origin_Code,
        MYROW.MAT_ORIGIN_NAME,
        MYROW.Soure_Code,
        MYROW.Soure_Name,
        MYROW.DEAL_NUM,
        MYROW.DEAL_WT,
        MYROW.CUST_ALPHA_NO,
        MYROW.ORDER_SPECIAL_DESC,
        MYROW.ALPHA_CODE,
        '0',
        '0',
        MYROW.DEAL_ORDE,
        MYROW.KEP_NO,
        MYROW.STORAGE_NO,
        MYROW.LOCATION_NO,
        MYROW.STORAGE_ATTR,
        MYROW.STORAGE_ATTR_NAME,
        MYROW.STORAGE_TYPE_NO,
        MYROW.STORAGE_TYPE_NAME,
        MYROW.SOURCE_CODE,
        MYROW.SOURCE_NAME,
        MYROW.CREATE_NAME,
        MYROW.F_IN_TIME);
        INSERT INTO PLN_ZY_JG_MIDDLE
        (WO_ID,
        JG_ORDERNO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        PLINE_CODE,
        PLINE_NAME,
        DEMAND_COPPER,
        DEMAND_DETECTION,
        DEMAND_BLAST,
        DEMAND_BONDERIZING,
        PLAN_NUM,
        PLAN_WT,
        STOVE_NO,
        FLAG_STOVE_NO,
        STEELCODE,
        STEELNAME,
        GRADECODE,
        GRADENAME,
        SPEC_JG_DESC,
        SPEC_JG,
        STYLE_JG,
        STD_CODE,
        STD_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        PRODUCCODE_JG,
        PRODUCCODE_JG_DESC,
        CODE_JG,
        MODEL_CODE,
        MODEL_DESC,
        IF_MONITOR_JG,
        PRDCR_NO,
        STATUS,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        ORDER_NO,
        ORDER_SEQ,
        ORDER_SEQ_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        MAT_NO,
        CRAFT_SEQ_ORD,
        CRAFT_FILE_NO_ORD,
        MAT_NO_XH)
        VALUES
        (MYROW.WO_ID,
        MYROW.JG_ORDERNO,
        MYROW.JUDGE_STOVE_NO,
        MYROW.BATCH_NO,
        MYROW.PLINE_CODE,
        MYROW.PLINE_NAME,
        MYROW.DEMAND_COPPER,
        MYROW.DEMAND_DETECTION,
        MYROW.DEMAND_BLAST,
        MYROW.DEMAND_BONDERIZING,
        MYROW.DEAL_NUM,
        MYROW.DEAL_WT,
        MYROW.STOVE_NO,
        MYROW.FLAG_STOVE_NO,
        MYROW.STEELCODE,
        MYROW.STEELNAME,
        MYROW.GRADECODE,
        MYROW.GRADENAME,
        MYROW.SPEC_JG_DESC,
        MYROW.SPEC_JG,
        MYROW.STYLE_JG,
        MYROW.STD_CODE,
        MYROW.STD_NAME,
        MYROW.STD_STYLE,
        MYROW.STD_STYLE_DESC,
        MYROW.PRODUCCODE_JG,
        MYROW.PRODUCCODE_JG_DESC,
        MYROW.CODE_JG,
        MYROW.MODEL_CODE,
        MYROW.MODEL_DESC,
        MYROW.IF_MONITOR_JG,
        MYROW.PRDCR_NO,
        '0',
        MYROW.MEMO,
        MYROW.CREATE_NAME,
        MYROW.F_IN_TIME,
        MYROW.ORDER_NO,
        MYROW. ORDER_SEQ,
        MYROW.DELIVERY_NO,
        MYROW.ORD_PK,
        MYROW. ORD_LN_PK,
        MYROW.ORD_LN_DLY_PK,
        MYROW.MAT_NO,
        MYROW.CRAFT_SEQ_ORD,
        MYROW.CRAFT_FILE_NO_ORD,
        MYROW.MAT_NO_XH);
        SELECT T.JUGDE_APPLY_CODE
        INTO V_JUGDE_APPLY_CODE
        FROM QCM_ZG_JUGDE_APPLY T
        WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
        AND T.BATCH_NO = '#BATCH_NO#'
        AND T.JUGDE_APPLY_CODE||T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_CODE#'
        AND T.TARGET = 'A'
        AND T.IS_ALL_SCRAP IN ('0','6'）
        AND T.IS_FLAG = '0';
        INSERT INTO COUPLING_MAT_M
        SELECT *
        FROM COUPLING_MAT_BACKUP T
        WHERE T.DETER_NO = V_JUGDE_APPLY_CODE;
        DELETE FROM COUPLING_MAT_BACKUP T
        WHERE T.DETER_NO = V_JUGDE_APPLY_CODE;
        DELETE FROM COUPLING_MAT_DEAL T WHERE T.DEAL_ORDE = MYROW.DEAL_ORDE;
        END LOOP;
        FOR MYROW1 IN (SELECT T.*
        FROM YDM_ZC_INLIST T
        WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#'
        ORDER BY T.MAT_NO DESC) LOOP
        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(
        '',
        MYROW1.MAT_NO,
        MYROW1.INSTOCK_SQE,
        MYROW1.INSTOCK_DOC,
        MYROW1.ORDER_NO,
        MYROW1.ORDER_SEQ,
        MYROW1.DELIVERY_NO,
        MYROW1.ORD_PK,
        MYROW1.ORD_LN_PK,
        MYROW1.ORD_LN_DLY_PK,
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = MYROW1.PRODUCT_FLAG),
        MYROW1.JUDGE_STOVE_NO,
        MYROW1.BATCH_NO,
        MYROW1.BATCH_GROUD_NO,
        MYROW1.MATERIAL_NO,
        MYROW1.MATERIAL_NAME,
        MYROW1.PRODUCCODE,
        MYROW1.PRODUCNAME,
        MYROW1.STD_CODE,
        MYROW1.STD_NAME,
        MYROW1.GRADECODE,
        MYROW1.GRADENAME,
        MYROW1.STEELCODE,
        MYROW1.STEELNAME,
        MYROW1.STD_STYLE,
        MYROW1.STD_STYLE_DESC,
        MYROW1.SPEC_CODE,
        MYROW1.SPEC_NAME,
        MYROW1.MODEL_CODE,
        MYROW1.MODEL_DESC,
        MYROW1.PLINE_CODE,
        MYROW1.PLINE_NAME,
        MYROW1.ACT_LEN,
        MYROW1.ACT_LEN_MIN,
        MYROW1.ACT_LEN_MAX,
        MYROW1.ACT_COUNT,
        MYROW1.ACT_WEIGHT,
        MYROW1.STORAGE_NO,
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = MYROW1.IN_MOLD),
        MYROW1.PACK_NO,
        MYROW1.INSTOCK_TIME,
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '2',
        MYROW1.SUPPLY_UNIT_CODE,
        MYROW1.SUPPLY_UNIT,
        MYROW1.BAL_YEAR_MONTH,
        MYROW1.ACT_DIMATER,
        MYROW1.ACT_HEIGHT,
        MYROW1.BELONG_CODE,
        MYROW1.BELONG_NAME,
        MYROW1.INSTOCK_TYPE_CODE,
        MYROW1.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(
        MYROW1.MAT_NO,
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = MYROW1.PRODUCT_FLAG),
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = MYROW1.MAT_STATUS),
        MYROW1.LOT_NO,
        MYROW1.STOVE_NO,
        MYROW1.JUDGE_STOVE_NO,
        MYROW1.BATCH_NO,
        MYROW1.BATCH_GROUD_NO,
        MYROW1.MATERIAL_NO,
        MYROW1.MATERIAL_NAME,
        MYROW1.PRODUCCODE,
        MYROW1.PRODUCNAME,
        MYROW1.STEELCODE,
        MYROW1.STEELNAME,
        MYROW1.GRADECODE,
        MYROW1.GRADENAME,
        MYROW1.SPEC_CODE,
        MYROW1.SPEC_NAME,
        MYROW1.MODEL_CODE,
        MYROW1.MODEL_DESC,
        MYROW1.STD_CODE,
        MYROW1.STD_NAME,
        MYROW1.STD_STYLE,
        MYROW1.STD_STYLE_DESC,
        MYROW1.PRO_ORDER_NO,
        MYROW1.ORDER_NO,
        MYROW1.ORDER_SEQ,
        MYROW1.DELIVERY_NO,
        MYROW1.ORD_PK,
        MYROW1.ORD_LN_PK,
        MYROW1.ORD_LN_DLY_PK,
        MYROW1.PLINE_CODE,
        MYROW1.PLINE_NAME,
        MYROW1.ACT_DIMATER,
        MYROW1.ACT_HEIGHT,
        MYROW1.ACT_LEN,
        MYROW1.ACT_LEN_MIN,
        MYROW1.ACT_LEN_MAX,
        MYROW1.ACT_COUNT,
        MYROW1.ACT_WEIGHT,
        MYROW1.BELONG_CODE,
        MYROW1.BELONG_NAME,
        (SELECT F.BASENAME FROM COM_BASE_INFO F WHERE F.BASECODE = MYROW1.IN_MOLD),
        MYROW1.INSTOCK_TIME,
        MYROW1.STORAGE_NO,
        MYROW1.LOCATION_NO,
        '',
        '',
        MYROW1.SUPPLY_UNIT_CODE,
        MYROW1.SUPPLY_UNIT,
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),'2');
        DELETE FROM MAT_ZC_M T WHERE T.MAT_NO = MYROW1.MAT_NO;
        DELETE FROM YDM_ZC_BUTTRESS S WHERE S.MAT_NO = MYROW1.MAT_NO;
        DELETE FROM YDM_ZC_INLIST T WHERE T.INSTOCK_DOC = MYROW1.INSTOCK_DOC;
        END LOOP;
        --修改排产缴库量
        UPDATE PLN_SALEORD
        SET PAYDOWN_NUM   = TO_NUMBER(NVL(PAYDOWN_NUM, 0)) -
        TO_NUMBER(NVL(V_PAY_NUM, 0)),
        PAYDOWNWEIGHT = TO_NUMBER(NVL(PAYDOWNWEIGHT, 0)) -
        TO_NUMBER(NVL(V_PAY_WGT, 0))
        WHERE ORDER_NO = '#ORDER_NO#'
        AND ORDER_SEQ = '#ORDER_SEQ#'
        AND DELIVERY_NO = '#DELIVERY_NO#';
        --修改进程表
        UPDATE PROCESS_ORDER_M T
        SET T.PAY_NUM = TO_NUMBER(NVL(T.PAY_NUM, 0)) -
        TO_NUMBER(NVL(V_PAY_NUM, 0)),
        T.PAY_WGT = TO_NUMBER(NVL(T.PAY_WGT, 0)) -
        TO_NUMBER(NVL(V_PAY_WGT, 0)),
        T.PAY_LEN = TO_NUMBER(NVL(T.PAY_LEN, 0)) -
        TO_NUMBER(NVL(V_PAY_LEN, 0))
        WHERE ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#';
        --修改申请判定表
        UPDATE QCM_ZG_JUGDE_APPLY S
        SET S.INSTOCK_FLAG = '0'
        WHERE S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
        AND S.BATCH_NO = '#BATCH_NO#'
        AND S.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
        AND S.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
        AND S.TARGET = 'A'
        AND S.BELONG_CODE_JUGDE IN ('100101', '100102', '100103','100105');
        END;
	</query>
    <query id = "FrmFinishAfrim.selectMatCount" desc = "查询总支数">

        SELECT NVL(SUM(T1.ACT_COUNT),0)ACOUNT
        FROM YDM_ZC_INLIST T, MAT_ZC_M T1
        WHERE T.MAT_NO = T1.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 = '#PRODUCT_FLAG#'
    </query>
    <query id = "FrmFinishAfrim.selectMatBill" desc = "查询已编提单数">
        SELECT NVL(SUM(T1.ACT_COUNT),0)ACOUNT
        FROM YDM_ZC_INLIST T, MAT_ZC_M T1
        WHERE T.MAT_NO = T1.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 = '#PRODUCT_FLAG#'
        AND T.ZB_RCDID = '#ZB_RCDID#'
        AND T1.MAT_STATUS = '80150302'
    </query>
    <query id = "FrmFinishAfrim.selectButtress" desc = "查询接箍位置">
        SELECT S.STORAGE_NO, S.LOCATION_NO
        FROM COUPLING_MAT_M T, COUPLING_MAT_BUTTRESS S
        WHERE T.MAT_NO = S.MAT_NO
        AND T.DETER_NO = '#JUGDE_APPLY_CODE#'
        AND T.DETER_NO_SEQ = '#JUGDE_APPLY_SEQUENO#'
        AND ROWNUM = 1
    </query>
    <query id = "FrmFinishAfrim.selectJgZbs" desc = "查询接箍质保书ID">
        SELECT T.ZBS_ID,T.ZBS_FLAG FROM COUPLING_MAT_M T WHERE T.DETER_NO = ?
        AND ROWNUM = 1
    </query>
    <query id = "FrmFinishAfrim.selectSyncFlagZcIn" desc = "查询财务系统同步信息">
        SELECT T.* FROM FMIS_ZC_INLIST T WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#' AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
    </query>
    <query id = "FrmFinishAfrim.deleteFmisZcIn" desc = "删除财务系统同步信息">
        DELETE FROM FMIS_ZC_INLIST T WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#' AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
    </query>

    <query id = "FrmFinishAfrim.updateMatZcMOrder" desc = "修改材料表合同">
        UPDATE MAT_ZC_M T1
        SET T1.ORDER_NO          = '#ORDER_NO#',
        T1.ORDER_SEQ         = '#ORDER_SEQ#',
        T1.ORDER_SEQ_NO      = '#ORDER_SEQ_NO#',
        T1.ORD_PK            = '#ORD_PK#',
        T1.ORD_LN_PK         = '#ORD_LN_PK#',
        T1.ORD_LN_DLY_PK     = '#ORD_LN_DLY_PK#',
        T1.OLD_ORDER_NO      = T1.ORDER_NO,
        T1.OLD_ORDER_SEQ     = T1.ORDER_SEQ,
        T1.OLD_ORDER_SEQ_NO  = T1.ORDER_SEQ_NO,
        T1.OLD_ORD_PK        = T1.ORD_PK,
        T1.OLD_ORD_LN_PK     = T1.ORD_LN_PK,
        T1.OLD_ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK,
        T1.OLD_MATERIAL_NO   = T1.MATERIAL_NO,
        T1.OLD_MATERIAL_NAME = T1.MATERIAL_NAME
        WHERE
        T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
        AND T1.BATCH_NO = '#BATCH_NO#'
        AND T1.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
        AND NVL(T1.JUDGE_RESULT_CODE,'/')=NVL('#JUDGE_RESULT_CODE#','/')
    </query>

    <query id = "FrmFinishAfrim.getCustmOrderNoByOrderNo" desc = "根据合同号查询客户合同信息">
        SELECT
        t.ORDER_NO,L.ORDER_SEQ,D.DELIVERY_NO,T.ORD_PK,L.ORD_LN_PK,D.ORD_LN_DLY_PK,T.SALE_ORG as BELONG_CODE,T.SALE_ORG_DESC as BELONG_NAME
        FROM
        SLM_ORDER_HEAD T
        LEFT JOIN SLM_ORDER_LINE L ON T.ORD_PK = L.ORD_PK
        LEFT JOIN SLM_ORDER_LINE_DELIVERY D ON D.ORD_LN_PK = L.ORD_LN_PK
        WHERE
        T.ORDER_NO = ( SELECT CUSTM_ORDER_NO FROM SLM_ORDER_HEAD WHERE ORDER_NO = {0} and VALIDFLAG = '1' ) and t.VALIDFLAG = '1'
        AND L.ORDER_SEQ = {1} and l.VALIDFLAG = '1'
        AND D.DELIVERY_NO = {2} and d.VALIDFLAG = '1'
    </query>

    <query id = "FrmFinishAfrim.getOrderNoByCustmOrderNo" desc = "根据客户合同号查询合同信息">
        SELECT
        t.ORDER_NO,L.ORDER_SEQ,D.DELIVERY_NO,T.ORD_PK,L.ORD_LN_PK,D.ORD_LN_DLY_PK
        FROM
        SLM_ORDER_HEAD T
        LEFT JOIN SLM_ORDER_LINE L ON T.ORD_PK = L.ORD_PK
        LEFT JOIN SLM_ORDER_LINE_DELIVERY D ON D.ORD_LN_PK = L.ORD_LN_PK
        WHERE
        T.ORDER_NO = ( SELECT ORDER_NO FROM SLM_ORDER_HEAD WHERE CUSTM_ORDER_NO = {0} and VALIDFLAG = '1' ) and t.VALIDFLAG = '1'
        AND L.ORDER_SEQ = {1} and L.VALIDFLAG = '1'
        AND D.DELIVERY_NO = {2} and D.VALIDFLAG = '1'
    </query>

    <query id = "FrmFinishAfrim.updatePlnSaleord" desc = "修改排产缴库量">
        --修改排产缴库量
        UPDATE PLN_SALEORD
        SET PAYDOWN_NUM   = TO_NUMBER(NVL(PAYDOWN_NUM, 0)) -
        TO_NUMBER(NVL(V_PAY_NUM, 0)),
        PAYDOWNWEIGHT = TO_NUMBER(NVL(PAYDOWNWEIGHT, 0)) -
        TO_NUMBER(NVL(V_PAY_WGT, 0))
        WHERE ORDER_NO = '#ORDER_NO#'
        AND ORDER_SEQ = '#ORDER_SEQ#'
        AND DELIVERY_NO = '#DELIVERY_NO#';
        --修改进程表
        UPDATE PROCESS_ORDER_M T
        SET T.PAY_NUM = TO_NUMBER(NVL(T.PAY_NUM, 0)) -
        TO_NUMBER(NVL(V_PAY_NUM, 0)),
        T.PAY_WGT = TO_NUMBER(NVL(T.PAY_WGT, 0)) -
        TO_NUMBER(NVL(V_PAY_WGT, 0)),
        T.PAY_LEN = TO_NUMBER(NVL(T.PAY_LEN, 0)) -
        TO_NUMBER(NVL(V_PAY_LEN, 0))
        WHERE ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#';
    </query>

    <query id = "FrmFinishAfrim.updatePlnSaleord1" desc = "修改排产缴库量">
        --修改排产缴库量
        UPDATE PLN_SALEORD
        SET PAYDOWN_NUM   = TO_NUMBER(NVL(PAYDOWN_NUM, 0)) +
        TO_NUMBER(NVL(V_PAY_NUM, 0)),
        PAYDOWNWEIGHT = TO_NUMBER(NVL(PAYDOWNWEIGHT, 0)) +
        TO_NUMBER(NVL(V_PAY_WGT, 0))
        WHERE ORDER_NO = '#ORDER_NO#'
        AND ORDER_SEQ = '#ORDER_SEQ#'
        AND DELIVERY_NO = '#DELIVERY_NO#';
        --修改进程表
        UPDATE PROCESS_ORDER_M T
        SET T.PAY_NUM = TO_NUMBER(NVL(T.PAY_NUM, 0)) +
        TO_NUMBER(NVL(V_PAY_NUM, 0)),
        T.PAY_WGT = TO_NUMBER(NVL(T.PAY_WGT, 0)) +
        TO_NUMBER(NVL(V_PAY_WGT, 0)),
        T.PAY_LEN = TO_NUMBER(NVL(T.PAY_LEN, 0)) +
        TO_NUMBER(NVL(V_PAY_LEN, 0))
        WHERE ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#';
    </query>

    <query id = "FrmFinishAfrim.updateInStorageFlag" desc = "修改确认状态">
        UPDATE QCM_ZG_JUGDE_APPLY SET
            IN_STORAGE_CONFIRM = '#IN_STORAGE_CONFIRM#',
            IN_STORAGE_TIME = to_date('#IN_STORAGE_TIME#','YYYY-MM-DD HH24:MI:SS'),
            IN_STORAGE_FLAG = '#IN_STORAGE_FLAG#'
        WHERE
            JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
            AND JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
            AND BATCH_NO = '#BATCH_NO#'
            AND BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
            AND JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
            AND TARGET = 'A'

    </query>
    
    <!-- tzh 24.11.12 add 新增查询料架信息 -->
    <query id = "FrmFinishAfrim.QueryByLocation" desc = "查询料架信息">
	<![CDATA[
						SELECT COUNT(1) COUNT_L
                          FROM MAT_BC_M T, YDM_BC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                           AND T.JUGDE_APPLY_SEQUENO =
                               '#JUGDE_APPLY_SEQUENO#'
                           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 IN
                               ('100101', '100102', '100103','100105')
                           AND T.QCM_STAUS = '00' AND S.LOCATION_NO is null
                         ORDER BY T.MAT_NO DESC
 ]]>
 </query>
</queryMap>