<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="钢管倒库出库管理">
	<query id="FrmPipeMoveOut.queryInventory" desc="库存实绩查询">
	<![CDATA[
 SELECT T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MEMO,
       DECODE(T.MAT_STATUS,
              '80150101',
              '材料产出等待',
              '80150102',
              '材料管理封锁',
              '80150103',
              '材料质量封锁',
              '80150104',
              '材料可编计划',
              '80150105',
              '材料已编计划',
              '80150106',
              '材料为余材',
              '80150201',
              '材料产出等待（未综合判定）',
              '80150202',
              '材料产出（已综合判定）',
              '80150203',
              '材料为余材（已综合判定）',
              '80150204',
              '材料脱单余材(销售组织脱单)',
              '80150301',
              '材料可编计划（发运控制）',
              '80150302',
              '材料已编计划（发运控制）',
              '80150303',
              '销售出厂') AS MAT_STATUS,
       T.PRODUCNAME,
       T.STEELNAME,
       T.SPEC_NAME,
       T.GRADENAME,
       T.MODEL_DESC,
       T.STD_NAME,
       T.STD_STYLE_DESC,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.ORDER_SEQ_NO,
       T.PLINE_NAME,
       T.MAT_ORIGIN_NAME,
       DECODE(T.PRODUCT_FLAG,
              '801401',
              '在制品',
              '801402',
              '成品',
              '801403',
              '商品') AS PRODUCT_FLAG,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.BELONG_NAME,
       T.JUDGE_RESULT,
       MIN(TO_CHAR(T.RPO_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS RPO_TIME,
       T.CREATE_NAME,
       MIN(TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS CREATE_TIME,
       B.STORAGE_NO,
       B.LOCATION_NO,
       C.STORAGE_NAME,
       NVL(SUM(T.ACT_LEN), 0) AS ACT_LEN,
       NVL(SUM(T.ACT_COUNT), 0) AS ACT_COUNT,
       NVL(SUM(T.ACT_WEIGHT), 0) AS ACT_WEIGHT,
       NVL(SUM(T.ACT_THEORY_WEIGHT), 0) AS ACT_THEORY_WEIGHT,
       NVL(SUM(T.ACT_COUNT), 0) AS PLA_COUNT,
       NVL(SUM(T.ACT_WEIGHT), 0) AS PLA_WEIGHT,
       NVL(SUM(T.ACT_THEORY_WEIGHT), 0) AS PLA_THEORY_WEIGHT
  from mat_zc_m T, YDM_ZC_BUTTRESS B
  LEFT JOIN YDM_BS_STORAGE C ON C.STORAGE_NO = B.STORAGE_NO
 WHERE T.MAT_NO = B.MAT_NO  AND T.MAT_STATUS <> '80150302' AND 1= 1 #CONDITION# #CONDITION1#
 
	]]>

	</query>
	
	<query id="FrmPipeMoveOut.queryInventory1" desc="半成品库存实绩查询">
	<![CDATA[
 SELECT T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MEMO,
       DECODE(T.MAT_STATUS,
              '80150101',
              '材料产出等待',
              '80150102',
              '材料管理封锁',
              '80150103',
              '材料质量封锁',
              '80150104',
              '材料可编计划',
              '80150105',
              '材料已编计划',
              '80150106',
              '材料为余材',
              '80150201',
              '材料产出等待（未综合判定）',
              '80150202',
              '材料产出（已综合判定）',
              '80150203',
              '材料为余材（已综合判定）',
              '80150204',
              '材料脱单余材(销售组织脱单)',
              '80150301',
              '材料可编计划（发运控制）',
              '80150302',
              '材料已编计划（发运控制）',
              '80150303',
              '销售出厂') AS MAT_STATUS,
       T.PRODUCNAME,
       T.STEELNAME,
       T.SPEC_NAME,
       T.GRADENAME,
       T.MODEL_DESC,
       T.STD_NAME,
       T.STD_STYLE_DESC,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.ORDER_SEQ_NO,
       T.PLINE_NAME,
       T.MAT_ORIGIN_NAME,
       DECODE(T.PRODUCT_FLAG,
              '801401',
              '在制品',
              '801402',
              '成品',
              '801403',
              '商品') AS PRODUCT_FLAG,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.BELONG_NAME,
       T.JUDGE_RESULT,
       MIN(TO_CHAR(T.RPO_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS RPO_TIME,
       T.CREATE_NAME,
       MIN(TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS CREATE_TIME,
       B.STORAGE_NO,
       B.LOCATION_NO,
       C.STORAGE_NAME,
       NVL(SUM(T.ACT_LEN), 0) AS ACT_LEN,
       NVL(SUM(T.ACT_COUNT), 0) AS ACT_COUNT,
       NVL(SUM(T.ACT_WEIGHT), 0) AS ACT_WEIGHT,
       NVL(SUM(T.ACT_THEORY_WEIGHT), 0) AS ACT_THEORY_WEIGHT,
       NVL(SUM(T.ACT_COUNT), 0) AS PLA_COUNT,
       NVL(SUM(T.ACT_WEIGHT), 0) AS PLA_WEIGHT,
       NVL(SUM(T.ACT_THEORY_WEIGHT), 0) AS PLA_THEORY_WEIGHT
  from mat_zc_m T, YDM_ZC_BUTTRESS B
  LEFT JOIN YDM_BS_STORAGE C ON C.STORAGE_NO = B.STORAGE_NO
 WHERE T.MAT_NO = B.MAT_NO  AND T.MAT_STATUS <> '80150302' AND 1= 1 #CONDITION# #CONDITION1#
 
	]]>

	</query>
	
	<query id="FrmPipeMoveOut.queryOutList" desc="查询出库流水号">
	<![CDATA[
   SELECT ? ||
         LPAD(SUBSTR(NVL(MAX(T.OUTSTOCK_SQE), '0000'), -4, 4) + 1, 4, '0') AS OUTSTOCK_SQE
    FROM YDM_ZC_OUTLIST T
   WHERE TO_CHAR(T.CREATE_TIME,'YYYY-MM-DD') =?
     AND T.OUTSTOCK_TYPE_CODE =?
     AND T.OUTSTOCK_DOC = ?
	]]>
	</query>
	<query id="FrmPipeMoveOut.queryOutBillList" desc="查询出库单号">
	<![CDATA[
    SELECT ?|| LPAD(SUBSTR(NVL(MAX(T.OUTSTOCK_DOC), '00000'), -5, 5) + 1, 5, '0') AS OUTSTOCK_DOC
   FROM YDM_ZC_OUTLIST T
  WHERE TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') = ?
    AND T.OUTSTOCK_TYPE_CODE = ?
	]]>
	</query>
	<query id="FrmPipeMoveOut.queryLibrary" desc="根据炉批组号查询MAT_ZC_M材料是否入库">
	<![CDATA[
	select t.mat_No from MAT_ZC_M t,ydm_zc_buttress b 
	where t.mat_no=b.mat_no 
       and t.judge_stove_no =?
	   and t.batch_no=? 
	   and b.storage_no = ?
	   and b.location_no = ?
	   and t.batch_groud_no =?
   	   and t.MAT_STATUS <>'80150302'
   	   and rownum <?
	]]>
	</query>
	<query id="FrmPipeMoveOut.queryOutPerfo" desc="查询倒库实绩">
    <![CDATA[
	SELECT T.OUTSTOCK_DOC,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NAME,
       T.PRODUCNAME,
       T.STD_NAME,
       T.GRADENAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.BELONG_NAME,
       MIN(TO_CHAR(T.RPO_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS RPO_TIME,
       T.PRO_BC,
       T.PRO_BZ,
       T.TAR_STORAGE_NO,
       T.TAR_LOCATION_NO,
       B.STORAGE_NAME,
       T.TAR_STORAGE_ATTR_NAME,
       T.TAR_STORAGE_TYPE_NAME,
       T.MANAGEMENT_NAME,
       T.CREATE_NAME,
       MIN(TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS CREATE_TIME,
       DECODE(T.TAR_REC_FLAG, '0', '未接受', '1', '已接受') AS TAR_REC_FLAG,
       NVL(SUM(T.ACT_LEN), 0) AS ACT_LEN,
       NVL(SUM(T.ACT_COUNT), 0) AS ACT_COUNT,
       NVL(SUM(T.ACT_WEIGHT), 0) AS ACT_WEIGHT,
       NVL(SUM(T.ACT_THEORY_WEIGHT), 0) AS ACT_THEORY_WEIGHT,
       T.ICCAR_NO
  from ydm_zc_outlist t
  LEFT JOIN YDM_BS_STORAGE B ON B.STORAGE_NO=t.TAR_STORAGE_NO
  where 1=1 #CONDITION#
  
     ]]>
	</query>
	<query id="FrmPipeMoveOut.queryOutPerfo1" desc="查询半成品倒库实绩">
    <![CDATA[
	SELECT T.OUTSTOCK_DOC,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NAME,
       T.PRODUCNAME,
       T.STD_NAME,
       T.GRADENAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.BELONG_NAME,
       MIN(TO_CHAR(T.RPO_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS RPO_TIME,
       T.PRO_BC,
       T.PRO_BZ,
       T.TAR_STORAGE_NO,
       T.TAR_LOCATION_NO,
       B.STORAGE_NAME,
       T.TAR_STORAGE_ATTR_NAME,
       T.TAR_STORAGE_TYPE_NAME,
       T.MANAGEMENT_NAME,
       T.CREATE_NAME,
       MIN(TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS CREATE_TIME,
       DECODE(T.TAR_REC_FLAG, '0', '未接受', '1', '已接受') AS TAR_REC_FLAG,
       NVL(SUM(T.ACT_LEN), 0) AS ACT_LEN,
       NVL(SUM(T.ACT_COUNT), 0) AS ACT_COUNT,
       NVL(SUM(T.ACT_WEIGHT), 0) AS ACT_WEIGHT,
       NVL(SUM(T.ACT_THEORY_WEIGHT), 0) AS ACT_THEORY_WEIGHT,
       T.ICCAR_NO
  from MAT_ZC_M S,ydm_zc_outlist t
  LEFT JOIN YDM_BS_STORAGE B ON B.STORAGE_NO=t.TAR_STORAGE_NO
  where T.MAT_NO = S.MAT_NO AND 1=1 #CONDITION# #CONDITION1#
  
     ]]>
	</query>
	<query id="FrmPipeMoveOut.queryCount" desc="根据炉批组号查询MAT_ZC_M">
	<![CDATA[
	 select sum(ACT_COUNT) as ACT_COUNT  from MAT_ZC_M where 
	 judge_stove_no =?
	   and batch_no=? 
	   --and batch_groud_no =?
   	   --and PRODUCT_FLAG like'%'||?||'%'
	]]>
	</query>
	<query id="FrmPipeMoveOut.queryTager" desc="查询目标库号信息">
	<![CDATA[
	SELECT B.ROW_NO,
       B.COL_NO,
       T.STORAGE_ATTR,
       T.STORAGE_ATTR_NAME,
       T.STORAGE_TYPE_NO,
       T.STORAGE_TYPE_NAME,
       T.MANAGEMENT_NO,
       T.MANAGEMENT_NAME,
       B.LOCATION_NO
  FROM YDM_BS_STORAGE T
  LEFT JOIN YDM_BS_LOCATION B
    ON T.STORAGE_NO = B.STORAGE_NO
 WHERE T.STORAGE_NO = ?
	]]>
	</query>
	<query id="FrmPipeMoveOut.QueryAdd" desc="查询要新增的数据">
	<![CDATA[
	SELECT T1.*
  FROM (SELECT T.MAT_NO,
               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.SPEC_CODE,
               T.SPEC_NAME,
               T.GRADECODE,
               T.GRADENAME,
               T.STEELCODE,
               T.STEELNAME,
               T.STD_STYLE,
               T.STD_STYLE_DESC,
               T.STD_CODE,
               T.STD_NAME,
               T.MODEL_CODE,
               T.MODEL_DESC,
               T.PRO_ORDER_NO,
               T.PLINE_CODE,
               T.PLINE_NAME,
               T.ACT_DIMATER,
               T.ACT_HEIGHT,
               T.ACT_LEN,
               T.ACT_LEN_MIN,
               T.ACT_LEN_MAX,
               T.ACT_COUNT,
               T.ACT_WEIGHT,
               T.ACT_THEORY_WEIGHT,
               T.BELONG_CODE,
               T.BELONG_NAME,
               T.RPO_TIME,
               T.PRO_BC,
               T.PRO_BZ,
               B.STORAGE_NO,
               B.LOCATION_NO,
               B.LARY_NO,
               B.LOC_NO,
               B.STORAGE_ATTR,
               B.STORAGE_ATTR_NAME,
               B.STORAGE_TYPE_NO,
               B.STORAGE_TYPE_NAME,
               B.MANAGEMENT_NO,
               B.MANAGEMENT_NAME,
               T.ORDER_NO,
               T.ORDER_SEQ,
               T.ORDER_SEQ_NO,
               T.ORD_PK,
               T.ORD_LN_PK,
               T.ORD_LN_DLY_PK,
               T.PRODUCT_FLAG,
               T.MAT_STATUS
          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS B
         WHERE T.MAT_NO = B.MAT_NO
           AND T.JUDGE_STOVE_NO = ?
           AND T.BATCH_NO = ?
           AND B.STORAGE_NO = ?
           AND T.BATCH_GROUD_NO = ?
           AND T.MAT_STATUS <> '80150302'
         ORDER BY T.MAT_NO ASC) T1
 WHERE ROWNUM < ?
	]]>
	</query>
	<query id="FrmPipeMoveOut.AddMoveList" desc="新增出库（倒库）记录">
    <![CDATA[insert into ydm_zc_outlist
  (OUTSTOCK_SQE, OUTSTOCK_DOC,vehicle_no, 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,out_bc, out_bz,rpo_time,pro_bc,pro_bz, 
   tar_storage_no,tar_location_no,TAR_LARY_NO,TAR_LOC_NO,tar_storage_attr,tar_storage_attr_name,
   tar_storage_type_no,tar_storage_type_name,tar_management_no,tar_management_name,
   storage_no,location_no,lary_no,loc_no,storage_attr,
   storage_attr_name,storage_type_no,storage_type_name,
   management_no,management_name,create_name,OUTSTOCK_TYPE_CODE,OUTSTOCK_TYPE_NAME,ORDER_NO,ORDER_SEQ,DELIVERY_NO,ORD_PK,ORD_LN_PK,ORD_LN_DLY_PK,PRODUCT_FLAG,MAT_STATUS,create_time,outstock_time,
   ICCAR_NO)
values
  (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
   ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,to_date(?,'YYYY/MM/DD HH24:MI:SS'),
   ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,to_date(?,'YYYY/MM/DD HH24:MI:SS'),to_date(?,'YYYY/MM/DD HH24:MI:SS'),?
   )
    ]]>
	</query>
	<query id="FrmPipeMoveOut.queryMoveList" desc="查询出库倒库实绩主键（流水号）">
    <![CDATA[
	select OUTSTOCK_SQE from(select OUTSTOCK_SQE from ydm_zc_outlist
	where OUTSTOCK_DOC=? 
	and JUDGE_STOVE_NO = ?  
	and BATCH_NO = ? 
	and BATCH_GROUD_NO = ? AND VALIDFLAG = '1' order by OUTSTOCK_SQE) ydm_zc_outlist 
	where ROWNUM< ? 
	]]>
	</query>
	<query id="FrmPipeMoveOut.queryOutMat" desc="根据出库倒库实绩主键（流水号）查询材料号">
    <![CDATA[
	select MAT_NO from ydm_zc_outlist where OUTSTOCK_SQE = ?
	]]>
	</query>
	<query id="FrmPipeMoveOut.queryOutMatList" desc="作废时根据出库表中的材料号查询要新增的数据">
    <![CDATA[
	SELECT T.*
  FROM (SELECT OUTSTOCK_SQE,
               MAT_NO,
               JUDGE_STOVE_NO,
               BATCH_NO,
               BATCH_GROUD_NO,
               STORAGE_NO,
               LOCATION_NO,
               LARY_NO,
               LOC_NO,
               STORAGE_ATTR,
               STORAGE_ATTR_NAME,
               STORAGE_TYPE_NO,
               STORAGE_TYPE_NAME,
               MANAGEMENT_NO,
               MANAGEMENT_NAME
          FROM YDM_ZC_OUTLIST
         WHERE OUTSTOCK_DOC = ?
           AND JUDGE_STOVE_NO = ?
           AND BATCH_NO = ?
           AND BATCH_GROUD_NO = ?
           AND VALIDFLAG = '1'
         ORDER BY OUTSTOCK_SQE) T
 WHERE ROWNUM < ?
	]]>
	</query>
	<query id="FrmPipeMoveOut.AddButtress" desc="新增库位信息">
    <![CDATA[	
	insert into ydm_zc_buttress
	  (mat_no, judge_stove_no, batch_no, batch_groud_no, storage_no, location_no, 
	  lary_no, loc_no, storage_attr, storage_attr_name,storage_type_no, 
	  storage_type_name, management_no, management_name,create_name, create_time)
	values
	  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'))
	]]>
	</query>
	<query id="FrmPipeMoveOut.getStoreAll" desc="获取所有目标库">
	<![CDATA[	
	SELECT T.STORAGE_NO,T.STORAGE_NAME FROM YDM_BS_STORAGE T WHERE T.VALIDFLAG='1'
	]]>
	
	<query id = "FrmPipeMoveOut.getStoreAllByType" desc = "查询所有仓库">
SELECT T.STORAGE_NO,T.STORAGE_NAME FROM YDM_BS_STORAGE T WHERE T.STORAGE_TYPE_NO IN('800202','800205') AND T.VALIDFLAG = '1'
</query>

	</query>
	<query id="FrmPipeMoveOut.getActualCount" desc="查询符合倒库的总支数">
	<![CDATA[	
	SELECT COUNT(1) ACOUNT
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS M
 WHERE T.MAT_NO = M.MAT_NO
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   --AND T.BATCH_GROUD_NO = ?
   AND M.STORAGE_NO = ?
   AND M.LOCATION_NO = ?
   ]]>
	</query>
	<query id="FrmPipeMoveOut.getMatStaus" desc="查询物料状态是否改变">
	<![CDATA[	
	select count(1) ACOUNT
  from mat_zc_m t
 where t.mat_status not in ('80150301', '80150202', '80150204', '80150205')
   and t.judge_stove_no = ?
   and t.batch_no = ?
   and t.batch_groud_no = ?
   ]]>
	</query>
	<query id="FrmPipeMoveOut.DeleteButtre" desc="删除材料位置表">
	<![CDATA[	
	delete ydm_zc_buttress where mat_no=?
   ]]>
	</query>
	<query id="FrmPipeMoveOut.deleteOutlist" desc="删除出库表">
	<![CDATA[	
	delete ydm_zc_outlist where OUTSTOCK_SQE=?
   ]]>
	</query>
</queryMap>