<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="利库">
	<query id="FrmPlanMaterialJgx.updatePlnZgM" desc="修改热处理虚拟炉计划">
		<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT SUM(T.PLAN_INDOUBLE_NUM) V_NUM,
                       SUM(T.PLAN_INDOUBLE_WT) V_WT,
                       T.OUTNUM_CUT V_OUTCUT,
                       NVL(C.BURNOUT_RATE, 0) / 100 V_BURNOUT_RATE
                  FROM PLN_ZY_JGX_C T, COM_BASE_PLINE C
                 WHERE T.PLINE_CODE = C.PLINE_CODE
                   AND T.HEAT_PLAN_NO = ?
                 GROUP BY C.BURNOUT_RATE, T.OUTNUM_CUT) LOOP
    UPDATE PLN_ZY_JGX_M T
       SET T.PLN_INSINGLE_NUM  = MYROW.V_NUM,
           T.PLN_INSINGLE_WT   = MYROW.V_WT,
           T.PLN_OUTSINGLE_NUM = MYROW.V_NUM * MYROW.V_OUTCUT,
           T.PLN_OUTSINGLE_W   = MYROW.V_WT - MYROW.V_WT * MYROW.V_BURNOUT_RATE
     WHERE T.HEAT_PLAN_NO = ?;
  END LOOP;
END;
		]]>
	</query>
	<query id="FrmPlanMaterialJgx.queryCic" desc="获取炼钢CIC">
		<![CDATA[
SELECT DISTINCT C.CIC, D.GRADECODE
  FROM PLN_ORDER_JGX_S           T,
       PLN_SALEORD              T1,
       CRAFT_ORD_DESIGN         M,
       CRAFT_ORD_DESIGN_STD_CIC C,
       COM_MSC_STD_CIC          D
 WHERE T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
   AND M.ORD_LN_PK = T1.ORD_LN_PK
   AND M.CRAFT_SEQ = T.CRAFT_SEQ
   AND C.DESGIN_KEY = M.DESGIN_KEY
   AND C.MSC_PLINE = T.INDEX_SEQ
   AND C.PROCESS_CODE IN ('A')
   AND C.CIC = D.CIC
   AND D.GRADENAME = ?
   AND T.PRO_PLAN_ID =?
   AND T.GX_PLAN_NO = ?
		]]>
	</query>
	<query id="FrmPlanMaterialJgx.queryMaterial" desc="查询库存管坯物料">
            <![CDATA[
SELECT T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.STOVE_NO,
       T.PRO_ORDER_ID || '/' || T.GX_PLAN_NO ON_PRO_ORDER_ID,
       T.HEAT_PLAN_NO,
       CASE
         WHEN T.PRO_PLAN_ID_NEXT IS NULL THEN
          ''
         ELSE
          T.PRO_PLAN_ID_NEXT || '/' || T.GX_PLAN_NO_NEXT
       END UND_PRO_ORDER_ID,
       T.PRODUCNAME,
       T.GRADENAME,
       T.STEELNAME,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.STD_NAME,
       T.STD_STYLE_DESC,
       T.NEXT_PROCESS_CDOE,
       T.PLINE_NAME,
       T.PLINE_CODE,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       SUM(T.ACT_LEN) ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       SUM(T.ACT_COUNT) ACT_COUNT,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT,
       SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT,
       (SELECT I.BASENAME
          FROM COM_BASE_INFO I
         WHERE I.BASECODE = T.PRODUCT_FLAG) PRODUCT_FLAG,
       (SELECT I.BASENAME
          FROM COM_BASE_INFO I
         WHERE I.BASECODE = T.MAT_STATUS) MAT_STATUS,
       SUM(T.ACT_COUNT) TAKE_COUNT,
       SUM(T.ACT_WEIGHT) TAKE_WEIGHT,
       T.BELONG_NAME,
       T.ORDER_NO || '/' || T.ORDER_SEQ order_Seq_No,
       T.CRAF_NO,
       T.PRO_ORDER_NO,t.cic,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO,
       S.STORAGE_NO,
       (SELECT T1.STORAGE_NAME FROM YDM_BS_STORAGE T1 WHERE T1.STORAGE_NO = S.STORAGE_NO)STORAGE_NAME
  FROM MAT_BC_M T LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
 WHERE T.PRODUCT_FLAG = '801401'
   AND (T.MAT_STATUS ='80150102' AND T.INSTOCK_FLAG='1' AND T.JUDGE_RESULT_CODE IN ('40740701','40740709') OR T.MAT_STATUS ='80150101'AND T.INSTANCY_FLAG='1')
   AND T.QCM_STAUS = '00' 
   --AND T.LOCK_FLAG='0' AND T.MNG_LOCK_FLAG='0'
      AND INSTR((CASE
                   WHEN (SELECT P.PRODUC_TYPE
                  FROM PLN_ORDER_JGX_S S, PLN_SALEORD S1, COM_BASE_PRODUCT P
                 WHERE S1.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
                   AND P.PRODUCCODE = S1.PRODUCCODE
                   AND S.PRO_PLAN_ID =?
                   AND S.GX_PLAN_NO = ?) != 'E' AND (SELECT P.PRODUC_TYPE
                  FROM PLN_ORDER_JGX_S S, PLN_SALEORD S1, COM_BASE_PRODUCT P
                 WHERE S1.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
                   AND P.PRODUCCODE = S1.PRODUCCODE
                   AND S.PRO_PLAN_ID = ?
                   AND S.GX_PLAN_NO = ?) != 'C' THEN
                    ?
                   ELSE
                    T.MATERIAL_NO
                 END),
                 T.MATERIAL_NO) > 0

              ]]>
	</query>
	<query id="FrmPlanMaterialJgx.queryMaterial1" desc="查询库存管坯物料">
            <![CDATA[
SELECT T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.STOVE_NO,
       T.PRO_ORDER_ID || '/' || T.GX_PLAN_NO ON_PRO_ORDER_ID,
       T.HEAT_PLAN_NO,
       CASE
         WHEN T.PRO_PLAN_ID_NEXT IS NULL THEN
          ''
         ELSE
          T.PRO_PLAN_ID_NEXT || '/' || T.GX_PLAN_NO_NEXT
       END UND_PRO_ORDER_ID,
       T.PRODUCNAME,
       T.GRADENAME,
       T.STEELNAME,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.STD_NAME,
       T.STD_STYLE_DESC,
       T.NEXT_PROCESS_CDOE,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       SUM(T.ACT_COUNT) ACT_COUNT,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT,
       SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT,
       (SELECT I.BASENAME
          FROM COM_BASE_INFO I
         WHERE I.BASECODE = T.PRODUCT_FLAG) PRODUCT_FLAG,
       (SELECT I.BASENAME
          FROM COM_BASE_INFO I
         WHERE I.BASECODE = T.MAT_STATUS) MAT_STATUS,
       SUM(T.ACT_COUNT) TAKE_COUNT,
       SUM(T.ACT_WEIGHT) TAKE_WEIGHT,
       T.BELONG_NAME,
       T.ORDER_NO || '/' || T.ORDER_SEQ order_Seq_No,
       T.CRAF_NO,
       T.PRO_ORDER_NO,t.cic,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO,
       S.STORAGE_NO,
       (SELECT T1.STORAGE_NAME FROM YDM_BS_STORAGE T1 WHERE T1.STORAGE_NO = S.STORAGE_NO)STORAGE_NAME
  FROM MAT_BC_M T LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
 WHERE T.PRODUCT_FLAG = '801401'
   AND (T.MAT_STATUS ='80150102' AND T.INSTOCK_FLAG='1' AND T.JUDGE_RESULT_CODE IN ('40740701','40740709') OR T.MAT_STATUS ='80150101'AND T.INSTANCY_FLAG='1')
   AND T.QCM_STAUS = '00' 
   --AND T.LOCK_FLAG='0' AND T.MNG_LOCK_FLAG='0'
      AND INSTR((CASE
                   WHEN (SELECT P.PRODUC_TYPE
                  FROM PLN_ORDER_JGX_S S, PLN_SALEORD S1, COM_BASE_PRODUCT P
                 WHERE S1.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
                   AND P.PRODUCCODE = S1.PRODUCCODE
                   AND S.PRO_PLAN_ID =?
                   AND S.GX_PLAN_NO = ?) != 'E' AND (SELECT P.PRODUC_TYPE
                  FROM PLN_ORDER_JGX_S S, PLN_SALEORD S1, COM_BASE_PRODUCT P
                 WHERE S1.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
                   AND P.PRODUCCODE = S1.PRODUCCODE
                   AND S.PRO_PLAN_ID = ?
                   AND S.GX_PLAN_NO = ?) != 'C' THEN
                    ?
                   ELSE
                    T.MATERIAL_NO
                 END),
                 T.MATERIAL_NO) > 0

              ]]>
	</query>
	<query id = "FrmPlanMaterialJgx.doQueryApplyCode" desc = "生成申请判定单号">
	<![CDATA[
	SELECT ? || '801401' || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.JUGDE_APPLY_CODE, 19,5)), 0) + 1, 5, 0) JUGDE_APPLY_CODE
    FROM QCM_ZG_JUGDE_APPLY T
   WHERE TRUNC(T.APPLY_TIME) = TRUNC(SYSDATE)
   AND T.IS_ALL_SCRAP != '3'
   ]]>
	</query>
	<query id = "FrmPlanMaterialJgx.insertQcm" desc = "写入申请判定单号">
	<![CDATA[
	DECLARE
BEGIN
  FOR MYROW IN (SELECT SUM(T.ACT_COUNT) ACT_COUNT,
                       SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT,
                       SUM(NVL(T.PONDER_GROSS_WT, T.ACT_WEIGHT)) ACT_WEIGHT,
                       SUM(T.ACT_LEN) ACT_LEN,
                       T.JUDGE_STOVE_NO,
                       T.BATCH_NO,
                       T.BATCH_GROUD_NO,
                       MAX(T.FACE_RESULT_CODE) FACE_RESULT_CODE,
                       MAX(T.SPEC_RESULT_CODE) SPEC_RESULT_CODE,
                       MAX(T.CHEM_RESULT_CODE) CHEM_RESULT_CODE,
                       MAX(T.PHY_RESULT_CODE) PHY_RESULT_CODE,
                       MAX(T.DETECT_RESULT_CODE) DETECT_RESULT_CODE,
                       MAX(T.WPRESSURE_RESULT_CODE) WPRESSURE_RESULT_CODE,
                       T.PLINE_CODE,
                       MAX(T.PRO_ORDER_ID) PRO_ORDER_ID,
                       MAX(T.GX_PLAN_NO) GX_PLAN_NO,
                       T.LOT_NO,
                       T.PLINE_NAME,
                       MAX(T.PRO_ORDER_NO) PRO_ORDER_NO,
                       T.TARGET,
                       T.PROCESS_STATUS,
                       T.ACT_DIMATER,
                       T.Act_Height,
                       T.ACT_LEN_MIN,
                       T.ACT_LEN_MAX,
                       MAX(T.CRAF_NO) CRAF_NO,
                       T.MATERIAL_NO,
                       T.MATERIAL_NAME,
                       T.PRODUCCODE,
                       T.PRODUCNAME,
                       T.SPEC_CODE,
                       T.SPEC_NAME,
                       T.STEELCODE,
                       T.STEELNAME,
                       T.MODEL_CODE,
                       T.MODEL_DESC,
                       MAX(T.STD_CODE)STD_CODE,
                       MAX(T.STD_NAME)STD_NAME,
                       T.STD_STYLE,
                       T.STD_STYLE_DESC,
                       T.GRADECODE,
                       T.GRADENAME,
                       T.CRAFT_SEQ,
                       T.CIC,
                       T.ORD_LN_DLY_PK,
                       T.BELONG_CODE,
                       T.BELONG_NAME,
                       MAX(T.STOVE_NO) STOVE_NO,
                       MAX(T.judge_std_des) STEEL_STANDRAD,
                       T.PRO_PLAN_ID_NEXT,
                       MAX(T.GX_PLAN_NO_NEXT) GX_PLAN_NO_NEXT,
                       T.HEAT_PLAN_NO_NEXT,
                       T.HEAT_PLAN_NO,
                       T.lock_liku LK_FLAG,
                       MAX(T.NEXT_PROCESS_CDOE) NEXT_PROCESS_CDOE,
                       T.JUGDE_APPLY_CODE,
                       T.JUGDE_APPLY_SEQUENO
                  FROM MAT_BC_M T LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#OLD_PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                   AND NVL(T.ACT_LEN_MIN,'/') = NVL('#ACT_LEN_MIN#','/')
                   AND NVL(T.ACT_LEN_MAX,'/') = NVL('#ACT_LEN_MAX#','/')
                   AND NVL(S.STORAGE_NO,'/') = NVL('#STORAGE_NO#','/')
                   AND T.QCM_STAUS = '00'
                   AND ROWNUM <= #ACT_COUNT#
                 GROUP BY T.JUDGE_STOVE_NO,
                          T.BATCH_NO,
                          T.BATCH_GROUD_NO,
                          T.PLINE_CODE,
                          T.LOT_NO,
                          T.PLINE_NAME,
                          T.TARGET,
                          T.PROCESS_STATUS,
                          T.ACT_DIMATER,
                          T.Act_Height,
                          T.ACT_LEN_MIN,
                          T.ACT_LEN_MAX,
                          T.MATERIAL_NO,
                          T.MATERIAL_NAME,
                          T.PRODUCCODE,
                          T.PRODUCNAME,
                          T.SPEC_CODE,
                          T.SPEC_NAME,
                          T.STEELCODE,
                          T.STEELNAME,
                          T.MODEL_CODE,
                          T.MODEL_DESC,
                          T.STD_STYLE,
                          T.STD_STYLE_DESC,
                          T.GRADECODE,
                          T.GRADENAME,
                          T.CRAFT_SEQ,
                          T.CIC,
                          T.ORD_LN_DLY_PK,
                          T.BELONG_CODE,
                          T.PRO_PLAN_ID_NEXT,
                          T.HEAT_PLAN_NO_NEXT,
                          T.HEAT_PLAN_NO,
                          T.lock_liku,
                          T.BELONG_NAME,
                          T.JUGDE_APPLY_CODE,
                       T.JUGDE_APPLY_SEQUENO
                       ) LOOP
                          INSERT INTO QCM_ZG_JUGDE_APPLY
        (JUGDE_APPLY_CODE,
         JUDGE_STOVE_NO,
         BATCH_NO,
         BATCH_GROUD_NO,
         PROCESS_CODE,
         PLINE_CODE,
         ACT_COUNT,
         ACT_WEIGHT,
         ACT_THEORY_WEIGHT,
         PRO_ORDER_ID,
         FACE_RESULT_CODE,
         SPEC_RESULT_CODE,
         CHEM_RESULT_CODE,
         PHY_RESULT_CODE,
         DETECT_RESULT_CODE,
         WPRESSURE_RESULT_CODE,
         APPLY_NAME,
         APPLY_TIME,
         QUALITY_GROUP,
         LOT_NO,
         PLINE_NAME,
         PRO_ORDER_NO,
         TARGET,
         PROCESS_STATUS,
         ACT_DIMATER,
         Act_Height,
         ACT_LEN_MIN,
         ACT_LEN_MAX,
         CRAF_NO,
         MATERIAL_NO,
         MATERIAL_NAME,
         PRODUCCODE,
         PRODUCNAME,
         SPEC_CODE,
         SPEC_NAME,
         STEELCODE,
         STEELNAME,
         MODEL_CODE,
         MODEL_DESC,
         STD_CODE,
         STD_NAME,
         STD_STYLE,
         STD_STYLE_DESC,
         GRADECODE,
         GRADENAME,
         ORD_LN_DLY_PK,
         BELONG_CODE,
         BELONG_NAME,
         ACT_LEN,
         GX_PLAN_NO,
         BELONG_CODE_JUGDE,
         BELONG_NAME_JUGDE,
         INPUT_COUNT,
         INPUT_WEIGHT,
         OUTPUT_COUNT,
         OUTPUT_WEIGHT,
         STOVE_NO,
         STEEL_STANDRAD,
         LK_FLAG,
         JUGDE_APPLY_SEQUENO,
         DELIVERY_STATE_CODE,
         DELIVERY_STATE_NAME,
         LOAD_JUDGE_STOVE_NO,
         CRAFT_SEQ,
         CIC,
         PIC,
         SIC,
         DIC,
         WIC,
         GIC,
         LOAD_BATCH_NO,
         INDEX_SEQ,
         MCH_WATERGAGE_RESULT,
         MCH_PATH_RESULT,
         MCH_CHAMFERING_RESULT,
         MCH_TWISTINGLY_RESULT,
         MCH_DIMENSIONS_RESULT,
         MCH_VISUAL_RESULT,
         MCH_THREAD_INSPECTION_RESULT,
         MCH_REMANENCE_RESULT,
         MCH_RADIOACTIVITY_RESULT,
         MCH_BEVEL_RESULT,
         MAT_GOWHERE_CODE,
         MAT_GOWHERE_NAME,
         IS_ALL_SCRAP,
         HEAT_PLAN_NO,
         SUPPLY_UNIT,
         SUPPLY_UNIT_DESC
         )
      VALUES
        (MYROW.JUGDE_APPLY_CODE,
         MYROW.JUDGE_STOVE_NO,
         MYROW.BATCH_NO,
         MYROW.BATCH_GROUD_NO,
         'G',
         '#PLINE_CODE#',
         MYROW.ACT_COUNT,
         MYROW.ACT_WEIGHT,
         MYROW.ACT_THEORY_WEIGHT,
         '#PRO_ORDER_ID#',
         MYROW.FACE_RESULT_CODE,
         MYROW.SPEC_RESULT_CODE,
         MYROW.CHEM_RESULT_CODE,
         MYROW.PHY_RESULT_CODE,
         MYROW.DETECT_RESULT_CODE,
         MYROW.WPRESSURE_RESULT_CODE,
         '#APPLY_NAME#',
         TO_DATE('#APPLY_TIME#','YYYY-MM-DD HH24:MI:SS'),
         '1',
         MYROW.LOT_NO,
         '#PLINE_NAME#',
         '#PRO_ORDER_NO#',
         MYROW.TARGET,
         MYROW.PROCESS_STATUS,
         '#ACT_DIMATER#',
         '#ACT_HEIGHT#',
         MYROW.ACT_LEN_MIN,
         MYROW.ACT_LEN_MAX,
         '#CRAF_NO#',
         '#MATERIAL_NO#',
         '#MATERIAL_NAME#',
         '#PRODUCCODE#',
         '#PRODUCNAME#',
         '#SPEC_CODE#',
         '#SPEC_NAME#',
         '#STEELCODE#',
         '#STEELNAME#',
         '#MODEL_CODE#',
         '#MODEL_DESC#',
         MYROW.STD_CODE,
         MYROW.STD_NAME,
         '#STD_STYLE#',
         '#STD_STYLE_DESC#',
         MYROW.GRADECODE,
         MYROW.GRADENAME,
         '#ORD_LN_DLY_PK#',
         '#BELONG_CODE#',
         '#BELONG_NAME#',
         MYROW.ACT_LEN,
         '#GX_PLAN_NO#',
         '002001001',
         '生产计划部',
         '0',
        '0',
         '0',
        '0',
         MYROW.STOVE_NO,
         '#STEEL_STANDRAD#',
         '1',
         MYROW.JUGDE_APPLY_SEQUENO,
         '#DELIVERY_STATE_CODE#',
         '#DELIVERY_STATE_NAME#',
         MYROW.JUDGE_STOVE_NO,
         '#CRAFT_SEQ#',
         '#CIC#',
         '#PIC#',
         '#SIC#',
         '#DIC#',
         '#WIC#',
         '#GIC#',
         MYROW.BATCH_NO,
         '#INDEX_SEQ#',
         '合格',
         '合格',
         '合格',
         '合格',
         '合格',
         '合格',
         '合格',
         '',
         '',
         '',
         '/',
         '/',
         '#IS_ALL_SCRAP#',
         '#HEAT_PLAN_NO#',
         '#SUPPLY_UNIT#',
         '#SUPPLY_UNIT_DESC#');
  END LOOP;
END;
	]]>
	</query>
	<query id = "FrmPlanMaterialJgx.selectBelong" desc = "查询所属权">
	SELECT T.DEPARTMENT_CODE,T.DEPARTMENT_DESC FROM COM_BASE_PLINE T WHERE T.PLINE_CODE = ?
	</query>
	<query id = "FrmPlanMaterialJgx.SelectDesignKey" desc = "查询desKey">
	SELECT T.DESGIN_KEY
  FROM CRAFT_ORD_DESIGN T
 WHERE T.CRAFT_NO = ?
   AND T.CRAFT_SEQ = ?
	</query>
	<query id = "FrmPlanMaterialJgx.SelectBaseCode1" desc = "查找交货状态">
SELECT T.BASECODE, T.BASENAME
  FROM COM_BASE_INFO T
 WHERE T.BASECODE = (SELECT GET_SHIPPED_STATE(?,?,?) SORTCODE
                       FROM DUAL)
                       AND T.SORTCODE='4100'
</query>
<query id = "FrmPlanMaterialJgx.selectHeatPlanNo" desc = "查询炉计划Id">
SELECT T.HEAT_PLAN_NO
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.PROCESS_CODE = 'G'
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
</query>
	<query id = "FrmPlanMaterialJgx.getOutDocCq" desc = "生成产权出库">
		SELECT 'CQ' || TO_CHAR(SYSDATE, 'YYMMDD') ||
		LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) OUTSTOCK_DOC
		FROM YDM_BC_OUTLIST T
		WHERE T.OUTSTOCK_TYPE_CODE = '800809'
		AND T.OUTSTOCK_DOC LIKE 'CQ' || TO_CHAR(SYSDATE, 'YYMMDD') || '_____'
	</query>
	<query id = "FrmPlanMaterialJgx.insertYdmOut" desc = "新增产权出库">
		DECLARE
		V_OUTSTOCK_SQE YDM_BC_OUTLIST.OUTSTOCK_SQE%TYPE := NULL; --出库流水
		V_ICOUNT       NUMBER := 1;
		V_TIME         YDM_BC_OUTLIST.CREATE_TIME%TYPE := TO_DATE('#CREATE_TIME#',
		'YYYY-MM-DD HH24:MI:SS');
		V_BATHYEAR     YDM_BC_OUTLIST.BAL_YEAR_MONTH%TYPE := TO_CHAR(SYSDATE,
		'YYYYMM');

		BEGIN
		SELECT '#OUTSTOCK_DOC#' ||
		LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_SQE, LENGTH(T.OUTSTOCK_SQE) - 3)),
		0) + 1,
		4,
		0)
		INTO V_OUTSTOCK_SQE
		FROM YDM_BC_OUTLIST T
		WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#';
		FOR MYROW IN (SELECT T.*,S.STORAGE_NO,S.LOCATION_NO
		FROM MAT_BC_M T
		LEFT JOIN YDM_BC_BUTTRESS S
		ON T.MAT_NO = S.MAT_NO
		WHERE T.MAT_NO = '#MAT_NO#') LOOP
		INSERT INTO YDM_BC_OUTLIST
		(FLAG_STOVE_NO_ZG,
		OUTSTOCK_SQE,
		OUTSTOCK_DOC,
		OUTSTOCK_TYPE_CODE,
		OUTSTOCK_TYPE_NAME,
		MAT_NO,
		LOT_NO,
		STOVE_NO,
		JUDGE_STOVE_NO,
		BATCH_NO,
		BATCH_GROUD_NO,
		MATERIAL_NO,
		MATERIAL_NAME,
		PRODUCCODE,
		PRODUCNAME,
		STD_CODE,
		STD_NAME,
		GRADECODE,
		GRADENAME,
		STEELCODE,
		STEELNAME,
		STD_STYLE,
		STD_STYLE_DESC,
		SPEC_CODE,
		SPEC_NAME,
		MODEL_CODE,
		MODEL_DESC,
		PRO_ORDER_NO,
		PLINE_CODE,
		PLINE_NAME,
		ACT_DIMATER,
		ACT_HEIGHT,
		ACT_LEN,
		ACT_LEN_MIN,
		ACT_LEN_MAX,
		ACT_COUNT,
		ACT_WEIGHT,
		ACT_THEORY_WEIGHT,
		BELONG_CODE,
		BELONG_NAME,
		STORAGE_NO,
		LOCATION_NO,
		OUTSTOCK_TIME,
		CREATE_NAME,
		CREATE_TIME,
		ORD_PK,
		ORD_LN_PK,
		ORD_LN_DLY_PK,
		ORDER_NO,
		ORDER_SEQ,
		DELIVERY_NO,
		PRODUCT_FLAG,
		MAT_STATUS,
		JUDGE_STD_NAME,
		BAL_YEAR_MONTH,
		LOAD_PLINE_CODE,
		LOAD_PLINE_NAME,
		PROCESS_CDOE,
		PROCESS_DESC)
		VALUES
		(MYROW.FLAG_STOVE_NO_ZG,
		V_OUTSTOCK_SQE,
		'#OUTSTOCK_DOC#',
		'800809',
		'产权出库',
		MYROW.MAT_NO,
		MYROW.LOT_NO,
		MYROW.STOVE_NO,
		MYROW.JUDGE_STOVE_NO,
		MYROW.BATCH_NO,
		MYROW.BATCH_GROUD_NO,
		MYROW.MATERIAL_NO,
		MYROW.MATERIAL_NAME,
		MYROW.PRODUCCODE,
		MYROW.PRODUCNAME,
		MYROW.STD_CODE,
		MYROW.STD_NAME,
		MYROW.GRADECODE,
		MYROW.GRADENAME,
		MYROW.STEELCODE,
		MYROW.STEELNAME,
		MYROW.STD_STYLE,
		MYROW.STD_STYLE_DESC,
		MYROW.SPEC_CODE,
		MYROW.SPEC_NAME,
		MYROW.MODEL_CODE,
		MYROW.MODEL_DESC,
		MYROW.PRO_ORDER_NO,
		MYROW.PLINE_CODE,
		MYROW.PLINE_NAME,
		MYROW.ACT_DIMATER,
		MYROW.ACT_HEIGHT,
		MYROW.ACT_LEN,
		MYROW.ACT_LEN_MIN,
		MYROW.ACT_LEN_MAX,
		MYROW.ACT_COUNT,
		MYROW.ACT_WEIGHT,
		MYROW.ACT_THEORY_WEIGHT,
		MYROW.BELONG_CODE,
		MYROW.BELONG_NAME,
		MYROW.STORAGE_NO,
		MYROW.LOCATION_NO,
		V_TIME,
		'#CREATE_NAME#',
		V_TIME,
		MYROW.ORD_PK,
		MYROW.ORD_LN_PK,
		MYROW.ORD_LN_DLY_PK,
		MYROW.ORDER_NO,
		MYROW.ORDER_SEQ,
		MYROW.ORDER_SEQ_NO,
		MYROW.PRODUCT_FLAG,
		MYROW.MAT_STATUS,
		MYROW.JUDGE_STD_NAME,
		V_BATHYEAR,
		'#LOAD_PLINE_CODE#',
		'#LOAD_PLINE_NAME#',
		MYROW.PROCESS_CDOE,
		MYROW.PROCESS_DESC);
		END LOOP;
		END;
	</query>
</queryMap>