<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="利库">
	<query id="FrmPlanMaterialJg.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.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.PRO_ORDER_NO,t.cic,T.CODE_JG_BL,T.CRAF_NO,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO
  FROM MAT_BC_M T
 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(?, T.MATERIAL_NO) > 0 OR T.CODE_JG_BL=?)
 GROUP BY 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,
          T.HEAT_PLAN_NO,
          T.PRO_PLAN_ID_NEXT,
          T.GX_PLAN_NO_NEXT,
          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.ACT_DIMATER,
          T.ACT_HEIGHT,
          T.ACT_LEN,
          T.ACT_LEN_MIN,
          T.ACT_LEN_MAX,
          T.PRODUCT_FLAG,
          T.MAT_STATUS,
          T.BELONG_NAME,
          T.ORDER_NO,
          T.ORDER_SEQ,
          T.PRO_ORDER_NO,t.cic,T.CODE_JG_BL,T.CRAF_NO,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO
              ]]>
	</query>
	<query id = "FrmPlanMaterialJg.queryMaterialJg" 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.PRO_ORDER_NO,t.cic,T.CODE_JG_BL,T.CRAF_NO,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO,
       MAX(TO_CHAR(T.INSTOCK_TIME,'YYYY-MM-DD HH:MM:SS'))INSTOCK_TIME
  FROM MAT_BC_M T
 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(?, T.MATERIAL_NO) > 0 OR T.CODE_JG_BL=?)
   AND T.ACT_DIMATER >= (SELECT S2.MIN_D_CP FROM COM_MSC_JG S2 WHERE S2.CODE_JG = ?)
   AND (T.ACT_DIMATER - 2*T.ACT_HEIGHT) <= (SELECT S3.MAX_D_CP FROM COM_MSC_JG S3 WHERE S3.CODE_JG = ?)
    AND (T.STEELCODE = ? OR INSTR(
        (SELECT listagg(STEELCODE_JG, ';') WITHIN GROUP(ORDER BY STEELCODE_JG)
           FROM COM_MSC_JG_R_STEEL
          WHERE STEELCODE = ?), T.STEELCODE) > 0)
     AND T.BELONG_CODE = '002001001'
 GROUP BY 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,
          T.HEAT_PLAN_NO,
          T.PRO_PLAN_ID_NEXT,
          T.GX_PLAN_NO_NEXT,
          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,
          T.PRODUCT_FLAG,
          T.MAT_STATUS,
          T.BELONG_NAME,
          T.ORDER_NO,
          T.ORDER_SEQ,
          T.PRO_ORDER_NO,t.cic,T.CODE_JG_BL,T.CRAF_NO,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO
          ]]>
	</query>
	<query id="FrmPlanMaterialJg.UpdateMatGp" desc="修改坯子库存信息">
             <![CDATA[     
    UPDATE MAT_BC_M T
   SET T.MAT_STATUS     = ?,
       T.PRO_PLAN_ID_NEXT = ?,
       T.GX_PLAN_NO_NEXT = ?,
       T.HANGING_FLAG=?,
       T.LOCK_LIKU=?,
       T.NEXT_PROCESS_CDOE=?,
       T.NEXT_PROCESS_DESC=?,
       T.HEAT_PLAN_NO_NEXT=''    
 WHERE T.MAT_NO = ?
             ]]>
	</query>
	<query id="FrmPlanMaterialJg.QueryMatGp" desc="查询管坯物料状态">
             <![CDATA[ 
Select *
  from (SELECT T.*
          FROM MAT_BC_M T
         WHERE T.QCM_STAUS = '00'     
           AND T.HANGING_FLAG = '0'
           AND T.JUDGE_STOVE_NO = ?
           AND T.BATCH_NO = ?
        --   AND T.LOCK_FLAG='0' AND T.MNG_LOCK_FLAG='0'
           AND NVL(T.BATCH_GROUD_NO,'/') = NVL(?,'/')
              ]]>
	</query>
	<query id="FrmPlanMaterialJg.getQureyMatTrack" desc="查询管坯物料赋值履历表">
             <![CDATA[ 

SELECT 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,
       SUM(ACT_COUNT) ACT_COUNT,
       SUM(ACT_WEIGHT) ACT_WEIGHT,
       SUM(ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       BELONG_CODE,
       BELONG_NAME,
       PROCESS_CDOE,
       GRADECODE,
       GRADENAME
  FROM MAT_BC_M
 WHERE QCM_STAUS = '00'
   AND JUDGE_STOVE_NO = ?
   AND BATCH_NO = ?
  -- AND LOCK_FLAG='0' AND MNG_LOCK_FLAG='0'
   AND NVL(BATCH_GROUD_NO,'/') = NVL(?,'/')
              ]]>
	</query>
	<query id="FrmPlanMaterialJg.addMatBcTrack" desc="新增利库，脱单日志表">
             <![CDATA[  
               INSERT INTO MAT_BC_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,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        MANAGEMENT_NO,
        MANAGEMENT_NAME,
        PROCESS_CDOE,
        GRADECODE,
        GRADENAME)
 VALUES( 
        '#RESUME_SEQ#',
        '#EVENT_ID#',
        '#EVENT_DESC#',
        '#FORM_NAME#',
        '#CALL_FUNC_CODING#',
        '#KEYVALUE1#',
        '#KEYVALUE1_DESC#',
        '#KEYVALUE2#',
        '#KEYVALUE2_DESC2#',
        '#KEYVALUE3#',
        '#KEYVALUE3_DESC3#',
        '#KEYVALUE4#',
        '#KEYVALUE4_DESC4#',
        '#KEYVALUE5#',
        '#KEYVALUE5_DESC5#',
        '#KEYVALUE6#',
        '#KEYVALUE6_DESC6#',
        '#KEYVALUE7#',
        '#KEYVALUE7_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#',
        TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#DEPARTMENT_CODE#',
        '#DEPARTMENT_DESC#',
        '#MANAGEMENT_NO#',
        '#MANAGEMENT_NAME#',
        '#PROCESS_CDOE#',
        '#GRADECODE#',
        '#GRADENAME#')
              ]]>
	</query>
	<query id="FrmPlanMaterialJg.updatePlnZgM" desc="修改接箍虚拟炉计划">
		<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT SUM(T.USE_BL_NUM) V_NUM, SUM(T.USE_BL_WT) V_WT
                  FROM PLN_ZY_JG_C T
                 WHERE T.HEAT_PLAN_NO = ?) LOOP
    UPDATE PLN_ZY_JG_M T
       SET T.PLAN_BL_NUM = MYROW.V_NUM,
           T.PLAN_BL_WT  = MYROW.V_WT,
           T.PLAN_JG_NUM = MYROW.V_NUM * T.SINGLE_CUT_NUN
     WHERE T.HEAT_PLAN_NO = ?;
  END LOOP;
END;
		]]>
	</query>
	<query id="FrmPlanMaterialJg.queryMatWeigth" desc="查询库存吨数">
		<![CDATA[
		SELECT NVL(SUM(T1.ACT_WEIGHT), 0) ACT_WEIGHT
  FROM (SELECT T.ACT_WEIGHT
          FROM MAT_BC_M T
          WHERE (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.HANGING_FLAG = '0'
           AND T.QCM_STAUS = '00'
           AND T.JUDGE_STOVE_NO = ?
           AND T.BATCH_NO = ?
           AND NVL(T.BATCH_GROUD_NO,'/') = NVL(?,'/')
           AND T.MATERIAL_NO = ?
         --AND T.LOCK_FLAG='0' AND T.MNG_LOCK_FLAG='0'
         ORDER BY T.MAT_NO ASC) T1
 WHERE ROWNUM <= ?
		]]>
	</query>
	<query id="FrmPlanMaterialJg.queryBaseMaterialHPl" desc="查询Bom投入物料接箍">
		<![CDATA[
		 SELECT T.E_IN_MATERIAL_DESC IN_MATERIAL_DESC,
		 T.E_OUT_MATERIAL_DESC OUT_MATERIAL_DESC,
		 T.E_OUT_MATERIAL_NO OUT_MATERIAL_NO,
		 T.MATERIAL_NO,
		 T.MATERIAL_DESC,T.SPEC_CODE_C,
		 T.SPEC_NAME_C,T.BOM,T.E_IN_MATERIAL_NO IN_MATERIAL_NO,
		 T.WHOLE_BACKLOG
   FROM SLM_ORD_DESIGN_BOM T,
        CRAFT_ORD_LINE_BOM T1,
        CRAFT_ORD_DESIGN   T2,
        PLN_SALEORD        T3
  WHERE T.BOM = T1.BOM
    AND T1.DESGIN_KEY = T2.DESGIN_KEY
    AND T2.ORD_LN_PK = T3.ORD_LN_PK
    AND T2.VALIDFLAG != '0'
    AND T3.ORD_LN_DLY_PK = ?
    AND T.MSC_PLINE=?
    AND T2.CRAFT_SEQ=?
    
		]]>
	</query>
		<query id="FrmPlanMaterialJg.queryBaseMaterialFPl" desc="查询Bom投入物料热处理">
		<![CDATA[
		 SELECT T.F_IN_MATERIAL_DESC IN_MATERIAL_DESC,
		 T.F_OUT_MATERIAL_DESC OUT_MATERIAL_DESC,
		 T.F_OUT_MATERIAL_NO OUT_MATERIAL_NO,
		 T.MATERIAL_NO,
		 T.MATERIAL_DESC,T.SPEC_CODE_C,
		 T.SPEC_NAME_C,T.BOM,T.F_IN_MATERIAL_NO IN_MATERIAL_NO,
		 T.WHOLE_BACKLOG
   FROM SLM_ORD_DESIGN_BOM T,
        CRAFT_ORD_LINE_BOM T1,
        CRAFT_ORD_DESIGN   T2,
        PLN_SALEORD        T3
  WHERE T.BOM = T1.BOM
    AND T1.DESGIN_KEY = T2.DESGIN_KEY
    AND T2.ORD_LN_PK = T3.ORD_LN_PK
    AND T2.VALIDFLAG != '0'
    AND T3.ORD_LN_DLY_PK = ?
    AND T.MSC_PLINE=?
    AND T2.CRAFT_SEQ=?
		]]>
	</query>
		<query id="FrmPlanMaterialJg.queryBaseMaterialGPl" desc="查询Bom投入物料加工线">
		<![CDATA[
		 SELECT T.I_IN_MATERIAL_DESC IN_MATERIAL_DESC,
		 T.I_OUT_MATERIAL_DESC OUT_MATERIAL_DESC,
		 T.I_OUT_MATERIAL_NO OUT_MATERIAL_NO,
		 T.MATERIAL_NO,
		 T.MATERIAL_DESC,T.SPEC_CODE_C,
		 T.SPEC_NAME_C,T.BOM,T.I_IN_MATERIAL_NO IN_MATERIAL_NO,
		 T.WHOLE_BACKLOG
   FROM SLM_ORD_DESIGN_BOM T,
        CRAFT_ORD_LINE_BOM T1,
        CRAFT_ORD_DESIGN   T2,
        PLN_SALEORD        T3
  WHERE T.BOM = T1.BOM
    AND T1.DESGIN_KEY = T2.DESGIN_KEY
    AND T2.ORD_LN_PK = T3.ORD_LN_PK
     AND T2.VALIDFLAG != '0'
    AND T3.ORD_LN_DLY_PK = ?
    AND T.MSC_PLINE=?
    AND T2.CRAFT_SEQ=?
		]]>
	</query>
	<query id="FrmPlanMaterialJg.queryBaseMaterialDPl" desc="查询Bom投入物料轧管">
		<![CDATA[
		 SELECT T.D_IN_MATERIAL_DESC IN_MATERIAL_DESC,
		 T.D_OUT_MATERIAL_DESC OUT_MATERIAL_DESC,
		 T.D_OUT_MATERIAL_NO OUT_MATERIAL_NO,
		 T.MATERIAL_NO,
		 T.MATERIAL_DESC,T.SPEC_CODE_R SPEC_CODE_C,
		 T.SPEC_NAME_R SPEC_NAME_C,T.BOM,T.D_IN_MATERIAL_NO IN_MATERIAL_NO,
		 T.WHOLE_BACKLOG
   FROM SLM_ORD_DESIGN_BOM T,
        CRAFT_ORD_LINE_BOM T1,
        CRAFT_ORD_DESIGN   T2,
        PLN_SALEORD        T3
  WHERE T.BOM = T1.BOM
    AND T1.DESGIN_KEY = T2.DESGIN_KEY
    AND T2.ORD_LN_PK = T3.ORD_LN_PK
    AND T2.VALIDFLAG != '0'
    AND T3.ORD_LN_DLY_PK = ?
    AND T.MSC_PLINE=?
    AND T2.CRAFT_SEQ=?
		]]>
	</query>
</queryMap>