<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="利库">
	<query id="FrmPlanMaterialDbk.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_CODE,
       T.PLINE_NAME,
       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.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(?, T.MATERIAL_NO) > 0

              ]]>
	</query>
	<query id="FrmPlanMaterialDbk.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="FrmPlanMaterialDbk.UpdateMatGpB" 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='',
       T.JUDGE_RESULT_CODE = '',
       T.JUDGE_RESULT = '',
       T.JUDGE_RESULT_TIME = '',
       T.JUGDE_APPLY_CODE = ?,
       T.JUGDE_APPLY_SEQUENO = '1',
       T.BELONG_CODE = ?,
       T.BELONG_NAME = ?,
       T.PRO_ORDER_NO = ?,
       T.PLINE_CODE = ?,
       T.PLINE_NAME = ?,
       T.CRAF_NO = ?,
       T.CRAFT_SEQ = ?
 WHERE T.MAT_NO = ?
 AND T.QCM_STAUS = '00'
             ]]>
	</query>
	<query id="FrmPlanMaterialDbk.QueryMatGp" desc="查询管坯物料状态">
             <![CDATA[ 
Select *
  from (SELECT T.*
          FROM MAT_BC_M T LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
         WHERE T.QCM_STAUS = '00'     
           AND T.HANGING_FLAG = '0'
           AND T.JUDGE_STOVE_NO = ?
           AND T.BATCH_NO = ?
           AND T.BATCH_GROUD_NO = ?
           AND NVL(S.STORAGE_NO,'/') = NVL(?,'/')
           AND T.PLINE_CODE = ?
           AND NVL(T.MATERIAL_NO,'/') = NVL(?,'/')
           AND 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')
   
              ]]>
	</query>
	<query id="FrmPlanMaterialDbk.QueryMatGpB" desc="查询管坯物料状态">
             <![CDATA[ 
Select *
  from (SELECT T.*
          FROM MAT_BC_M T LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
         WHERE T.QCM_STAUS = '00'     
           AND T.HANGING_FLAG = '0'
           AND T.JUDGE_STOVE_NO = ?
           AND T.BATCH_NO = ?
           AND T.BATCH_GROUD_NO = ?
           AND NVL(S.STORAGE_NO,'/') = NVL(?,'/')
           AND 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.PROCESS_CDOE = 'G'
   
              ]]>
	</query>
	<query id="FrmPlanMaterialDbk.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 BATCH_GROUD_NO = ?

              ]]>
	</query>
	<query id="FrmPlanMaterialDbk.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="FrmPlanMaterialDbk.updatePlnZgM" desc="修改镦拔扩虚拟炉计划">
		<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT SUM(T.PLAN_INDOUBLE_NUM) V_NUM,
                       SUM(T.PLAN_INDOUBLE_WT) V_WT,
                       NVL(C.BURNOUT_RATE, 0) / 100 V_BURNOUT_RATE,
                       (TO_NUMBER(NVL(S.LEN_CUTHEAD, 0)) +
                       TO_NUMBER(NVL(S.LEN_CUTEND, 0)))/1000 V_LENCUT
                  FROM PLN_ZY_DBK_C T, COM_BASE_PLINE C, PLN_ORDER_DBK_S S
                 WHERE T.PLINE_CODE = C.PLINE_CODE
                   AND S.PRO_PLAN_ID = T.PRO_PLAN_ID
                   AND S.GX_PLAN_NO = T.GX_PLAN_NO
                   AND T.HEAT_PLAN_NO = ?
                 GROUP BY C.BURNOUT_RATE, S.LEN_CUTHEAD, S.LEN_CUTEND) LOOP
    UPDATE PLN_ZY_DBK_M T
       SET T.PLN_INSINGLE_NUM  = MYROW.V_NUM,
           T.PLN_INSINGLE_WT   = MYROW.V_WT,
           T.PLN_OUTSINGLE_NUM = MYROW.V_NUM,
           T.PLN_OUTSINGLE_W   = MYROW.V_WT - MYROW.V_WT * MYROW.V_BURNOUT_RATE -
                                 MYROW.V_LENCUT
     WHERE T.HEAT_PLAN_NO = ?;
  END LOOP;
END;


		]]>
	</query>
	<query id="FrmPlanMaterialDbk.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 T.BATCH_GROUD_NO = ?
           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="FrmPlanMaterialDbk.queryBaseMaterialEPl" 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,T.GRADENAME
   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="FrmPlanMaterialDbk.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,T.GRADENAME
   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="FrmPlanMaterialDbk.queryBaseMaterialGPl" desc="查询Bom投入物料加工线">
		<![CDATA[
	SELECT CASE
         WHEN T.WHOLE_BACKLOG = 'G' AND T.I_IN_MATERIAL_NO IS NULL THEN
         T4.IN_MATERIAL_DESC
         ELSE
          T.I_IN_MATERIAL_DESC
       END IN_MATERIAL_DESC,
       
       CASE
         WHEN T.WHOLE_BACKLOG = 'G' AND T.I_OUT_MATERIAL_NO IS NULL THEN
         T4.OUT_MATERIAL_DESC
         ELSE
          T.I_OUT_MATERIAL_DESC
       END OUT_MATERIAL_DESC,
       
       CASE
         WHEN T.WHOLE_BACKLOG = 'G' AND T.I_OUT_MATERIAL_NO IS NULL THEN
          T4.OUT_MATERIAL_NO
         ELSE
          T.I_OUT_MATERIAL_NO
       END OUT_MATERIAL_NO,
       T.MATERIAL_NO,
       T.MATERIAL_DESC,
       T.SPEC_CODE_C,
       T.SPEC_NAME_C,
       T.BOM,
      CASE
         WHEN T.WHOLE_BACKLOG = 'G' AND T.I_IN_MATERIAL_NO IS NULL THEN
         T4.In_Material_No
         ELSE
          T.I_IN_MATERIAL_NO
       END IN_MATERIAL_NO,
       T.WHOLE_BACKLOG,
       T.GRADENAME
  FROM SLM_ORD_DESIGN_BOM T,
       CRAFT_ORD_LINE_BOM T1,
       CRAFT_ORD_DESIGN   T2,
       PLN_SALEORD        T3,
       SLM_ORD_DESIGN_BOM_K T4
 WHERE T.BOM = T1.BOM
   AND T1.DESGIN_KEY = T2.DESGIN_KEY
   AND T2.ORD_LN_PK = T3.ORD_LN_PK
   AND T4.BOM=T.BOM
    -- AND T2.VALIDFLAG != '0'
    AND T3.ORD_LN_DLY_PK = ?
    AND T.MSC_PLINE=?
    AND T2.CRAFT_SEQ=?
		]]>
	</query>
	<query id="FrmPlanMaterialDbk.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,T.GRADENAME
   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="FrmPlanMaterialDbk.queryCic" desc="获取炼钢CIC">
		<![CDATA[
SELECT DISTINCT C.CIC, D.GRADECODE
  FROM PLN_ORDER_DBK_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>
</queryMap>