<?xml version="1.0" encoding="UTF-8"?>
<queryMap  desc = "调差实际操作">
<query id = "FrmPipeAdjust.getStorgeData" desc = "查询库存信息">
<![CDATA[
select 
 --max(T.mat_no) as mat_no,
       T.judge_stove_no,
       T.batch_no,
       T.Memo,
       T.BATCH_GROUD_NO,
       T.MAT_STATUS,
       max(T.producname) as producname,
       max(T.steelname) as steelname,
       max(T.gradename) as gradename,
       max(T.model_desc) as model_desc,
       max(T.std_name) as std_name,
       max(T.std_style_desc) as std_style_desc,
       T.order_no,
       T.order_seq,
       T.order_seq_no,
       max(T.ORD_LN_DLY_PK)as ORD_LN_DLY_PK,
       --max(T.pline_name) as pline_name,
       --max(T.mat_origin_name) as mat_origin_name,
       t.product_flag,
       --max(T.mat_status) as mat_status,
       max(T.act_dimater) as act_dimater,
       max(T.act_height) as act_height,
       max(T.act_len_min) as ACT_LENGTH_MIN,
       max(T.act_len_max) as ACT_LENGTH_MAX,
       max(T.BELONG_CODE) as BELONG_CODE,
       max(T.belong_name) as belong_name,
       max(T.judge_result) as judge_result,
       --max(T.rpo_time) as rpo_time,
       --max(T.create_name) AS create_name,
       --max(T.create_time) as create_time,
       B.STORAGE_NO,
       MAX(B.LOCATION_NO)LOCATION_NO,
       MAX(C.STORAGE_NAME) AS STORAGE_NAME,
       --NVL(sum(T.act_len), 0) as act_len,
       NVL(sum(T.act_count), 0) as TOTAL_COUNT,
       NVL(sum(T.act_weight), 0) as TOTAL_WEIGHT,
       NVL(sum(T.act_theory_weight), 0) as TOTAL_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
       '' ADJ_WEIGHT,
       '' REASON,
       FINISHPRO_MOLD,
       IN_MOLD,
       T.SUPPLY_UNIT_CODE,
       T.SUPPLY_UNIT,
       T.PROCESS_CDOE,
       T.PROCESS_DESC
  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 T.judge_stove_no LIKE '%'||?||'%'
  AND B.STORAGE_NO LIKE '%'||?||'%'
  ]]>
</query>
<query id = "FrmPipeAdjust.getAdjustData" desc = "查询调差实绩">
<![CDATA[
select  t.STOCKTAKING_DOC,
     t.judge_stove_no,
       t.batch_no,
       t.batch_groud_no,
       t.STOCKTAKING_RSN_CODE,
       max(t.stocktaking_rsn_name)as stocktaking_rsn_name,
       max(t.material_name) as material_name,
       max(t.producname) as producname,
       max(t.std_name) as std_name,
       max(t.gradename) as gradename,
       max(t.std_style_desc) as std_style_desc,
       max(t.spec_name) as spec_name,
       max(t.model_desc) as model_desc,
       max(t.pline_name) as pline_name,
       max(t.act_dimater) as act_dimater,
       max(t.act_height) as act_height,
       max(t.act_len_min) as act_len_min,
       max(t.act_len_max) as act_len_max, 
       max(t.belong_name) as belong_name,
       max(t.rpo_time) as rpo_time,
       max(t.pro_bc) as pro_bc,
       max(t.pro_bz) as pro_bz,
       t.STORAGE_NO,
       t.LOCATION_NO,
       max(B.STORAGE_NAME) AS STORAGE_NAME,
       --max(t.TAR_STORAGE_ATTR_NAME) as TAR_STORAGE_ATTR_NAME ,
       --max(t.TAR_STORAGE_TYPE_NAME) as TAR_STORAGE_TYPE_NAME,
       max(t.management_name) as management_name,
       max(t.create_name) as create_name,
       max(t.create_time) as create_time,
       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.STEELCODE,
       t.STEELNAME,
       to_char(to_date(t.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       t.SUPPLY_UNIT_CODE,
       t.SUPPLY_UNIT
  from ydm_zc_stocktakinglist t
  LEFT JOIN YDM_BS_STORAGE B ON B.STORAGE_NO=t.STORAGE_NO
  where 1=1 and t.VALIDFLAG = '1'
  AND t.judge_stove_no LIKE '%' || ? || '%'
  
  ]]>
</query>
<query id = "FrmPipeAdjust.getAdjustReason" dec = "获取所有调整原因">
SELECT T.BASENAME,T.BASECODE FROM COM_BASE_INFO T WHERE T.Sortcode = '8012'
</query>
<query id="FrmPipeAdjust.queryAdjustList" desc="查询调差流水号">
	<![CDATA[
    select STOCKTAKING_SQE,STOCKTAKING_DOC from ydm_zc_stocktakinglist 
    where CREATE_TIME LIKE '%'|| to_date(?,'YYYY/MM/DD')||'%'  
    and  STOCKTAKING_TYPE_CODE LIKE '%'|| ? ||'%'
    order by STOCKTAKING_SQE desc
	]]>
	</query>
	
	<query id="FrmPipeAdjust.queryAdjustList1" desc="查询调差流水号">
	<![CDATA[
    select STOCKTAKING_SQE,STOCKTAKING_DOC from ydm_zc_stocktakinglist 
    where CREATE_TIME LIKE '%'|| to_date(?,'YYYY/MM/DD')||'%'  
    and  STOCKTAKING_DOC LIKE '%'|| ? ||'%'
    order by STOCKTAKING_SQE desc
	]]>
	</query>
	<query id = "FrmPipeAdjust.queryAdjustSeq" desc = "生成调差单流水号">
	<![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.PRODUCT_FLAG like'%'||?||'%'
   	   and rownum <?
	]]>
	</query>
	<query id = "FrmPipeAdjust.getMatNo" desc = "获取所调差支数的所有材料号">
	<![CDATA[
	SELECT T.MAT_NO,
	   T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.GRADECODE,
       T.GRADENAME,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       T.SUPPLY_UNIT_CODE
  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.JUDGE_STOVE_NO =  ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.MAT_STATUS = ?
   AND B.STORAGE_NO = ?
   AND NVL(T.ORD_LN_DLY_PK,'/') = NVL(?,'/')
   AND NVL(T.MEMO,'/') = NVL(?,'/')
   AND NVL(T.FINISHPRO_MOLD,'/') = NVL(?,'/')
   AND NVL(T.IN_MOLD,'/') = NVL(?,'/')
   
   ]]>
	</query>
	<query id = "FrmPipeAdjust.QueryAdd" desc = "查询要新增的数据 ">
	 <![CDATA[
	 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
	  from Mat_zc_m t,ydm_zc_buttress b 
	  where t.mat_no=b.mat_no
	  and t.mat_no=? 
	]]>
	</query>
	<query id = "FrmPipeAdjust.AddJustWgt" desc = "新增调整实绩">
	INSERT INTO YDM_ZC_STOCKTAKINGLIST
  (DEPARTMENT_CODE,
   DEPARTMENT_DESC,
   STOCKTAKING_DOC,
   STOCKTAKING_SQE,
   
   STOCKTAKING_TYPE_CODE,
   STOCKTAKING_TYPE_NAME,
   STOCKTAKING_RSN_CODE,
   STOCKTAKING_RSN_NAME,
   JUDGE_STOVE_NO,
   BATCH_NO,
   BATCH_GROUD_NO,
   ACT_COUNT,
   ACT_WEIGHT,
   BELONG_CODE,
   BELONG_NAME,
   STOCKTAKING_TIME,
   MANAGEMENT_NO,
   MANAGEMENT_NAME,
   VALIDFLAG,
   CREATE_NAME,
   CREATE_TIME,
   OLD_WEIGHT,
   BAL_YEAR_MONTH,
   PRODUCCODE,
   PRODUCNAME,
   STEELCODE,
   STEELNAME,
   SPEC_CODE,
   SPEC_NAME,
   MODEL_CODE,
   MODEL_DESC,
   STD_STYLE,
   STD_STYLE_DESC,
   STORAGE_NO,
   F_STOCKTAKING_TIME,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        PROCESS_CDOE,
        PROCESS_DESC,
        GRADECODE,
        GRADENAME,
        PLINE_CODE,
        PLINE_NAME)
VALUES
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   '0',
   ?,
   ?,
   ?,
   SYSDATE,
   ?,
   ?,
   '1',
   ?,
   SYSDATE,?,?,?,?,?,?,?,?,?,?,?,?,?,SYSDATE,?,?,?,?,?,?,?,?)
	</query>
	<query id = "FrmPipeAdjust.updateActWgt" desc = "对物料主表中的重量更新">
	UPDATE MAT_ZC_M T SET T.ACT_WEIGHT = ? WHERE T.MAT_NO = ?
	</query>
	<query id = "FrmPipeAdjust.updateYear" desc = "修改结转年月">
	<![CDATA[
	UPDATE YDM_ZC_STOCKTAKINGLIST T SET T.BAL_YEAR_MONTH = ?,T.STOCKTAKING_TIME = to_date(?,'yyyy-MM-dd HH24:mi:ss') WHERE T.STOCKTAKING_DOC = ?
	]]>
	</query>
	<query id = "FrmPipeAdjust.selectYearMoth" desc = "查询期初中是否存在">
	SELECT COUNT(1) ACOUNT
  FROM YDM_ZC_INITIAL T
 WHERE 
 --T.JUDGE_STOVE_NO = ?
  --AND T.BATCH_NO = ?
   --AND T.BATCH_GROUD_NO = ?
   T.BAL_YEAR_MONTH = ?
        AND T.SUPPLY_UNIT_CODE = '#SUPPLY_UNIT_CODE#'
	</query>
	<query id = "FrmPipeAdjust.updateProcess" desc = "调差写进程表">
	UPDATE PROCESS_ORDER_M T
   SET T.SOK_WGT = TO_NUMBER(NVL(T.SOK_WGT,0)) + TO_NUMBER(?)   
   WHERE ORD_LN_DLY_PK = ?
	</query>
</queryMap>
