<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "运行年月收发存">
<query id = "FrmRunTimeRptCw.getOriginalLast" desc = "获取期初重量">
<![CDATA[
select t.JUDGE_STOVE_NO,t.BATCH_NO,t.BATCH_GROUD_NO,T.PRODUCNAME,T.STD_STYLE_DESC,T.STEELNAME,T.SPEC_NAME,T.MODEL_DESC,
                    sum(nvl(t.ACT_COUNT,0))count,
                    sum(nvl(t.ACT_WEIGHT, 0)) weight
                    from ydm_zc_initial t
                    where 1=1 and t.HANDLE_LOG = '1' and  t.BAL_YEAR_MONTH LIKE '%'||?||'%' 
                    --and T.JUDGE_STOVE_NO = '012602'
                     #condtions#
                    
                    ]]>
</query>
<query id = "FrmRunTimeRptCw.getThisIn" desc = "本期入库量">
<![CDATA[
                     select t.JUDGE_STOVE_NO,t.BATCH_NO,t.BATCH_GROUD_NO,T.PRODUCNAME,T.STD_STYLE_DESC,T.STEELNAME,T.SPEC_NAME,T.MODEL_DESC,
                                   nvl(sum(case
                                        when t.BAL_YEAR_MONTH = ? then
                                         nvl(t.count, 0)
                                      end),
                                   0) weight_monthcount,
                              nvl(sum(case
                                        when t.BAL_YEAR_MONTH = ? then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_month  
                          from (select t.JUDGE_STOVE_NO,t.BATCH_NO,t.BATCH_GROUD_NO,t.BELONG_CODE,T.PRODUCNAME,T.STD_STYLE_DESC,T.STEELNAME,T.SPEC_NAME,T.MODEL_DESC,
                                     t.BAL_YEAR_MONTH,  
                                      nvl(t.ACT_COUNT,0)count,
                                       nvl(t.ACT_WEIGHT, 0) weight
                                  from ydm_zc_inlist t
                                 where t.validflag = '1'
                                  and t.INSTOCK_TYPE_CODE in ('800701','800702','800704','800706','800707','800712')
                                  and t.BAL_YEAR_MONTH = ?
                                  --and T.JUDGE_STOVE_NO = '012602'
                                    #condtions# 
                                   )t where 1=1
                                   
                             ]]>
</query>
<query id = "FrmRunTimeRptCw.getThisOut" desc = "本期出库量">
<![CDATA[
                      select t.JUDGE_STOVE_NO,t.BATCH_NO,t.BATCH_GROUD_NO,T.PRODUCNAME,T.STD_STYLE_DESC,T.STEELNAME,T.SPEC_NAME,T.MODEL_DESC,
                                  nvl(sum(case
                                         when t.BAL_YEAR_MONTH = ? then
                                         nvl(t.count, 0)
                                      end),
                                  0) weight_monthcount,
                              nvl(sum(case
                                         when t.BAL_YEAR_MONTH = ? then
                                         nvl(t.weight, 0)
                                      end),
                                  0) weight_month
                         from (select t.JUDGE_STOVE_NO,t.BATCH_NO,t.BATCH_GROUD_NO,t.BELONG_CODE,T.PRODUCNAME,T.STD_STYLE_DESC,T.STEELNAME,T.SPEC_NAME,T.MODEL_DESC,
                         t.BAL_YEAR_MONTH,
                                    nvl(t.ACT_COUNT,0)count,
                                    case when t.PONDER_NO is null
                                       then nvl(t.ACT_WEIGHT, 0)
                                       else nvl(t.PONDER_GROSS_WT, 0) end as weight
                             from ydm_zc_outlist t
                           where t.OUTSTOCK_TYPE_CODE in ('800805','800804','800802','800808','800806','800812')
                               and t.validflag = '1'
                               --and T.JUDGE_STOVE_NO = '012602'
                               and t.BAL_YEAR_MONTH = ?
                                     #condtions# 
                             )t where 1=1
                             
                             ]]>
</query>

<query id = "FrmRunTimeRptCw.getAdjust" desc = "本期调差量">
<![CDATA[
                             select t.JUDGE_STOVE_NO,t.BATCH_NO,t.BATCH_GROUD_NO,T.PRODUCNAME,T.STD_STYLE_DESC,T.STEELNAME,T.SPEC_NAME,T.MODEL_DESC,
                               sum(nvl(t.weight, 0)) aweight
                          from (select t.JUDGE_STOVE_NO,t.BATCH_NO,t.BATCH_GROUD_NO,t.BELONG_CODE,T.PRODUCNAME,T.STD_STYLE_DESC,T.STEELNAME,T.SPEC_NAME,T.MODEL_DESC,
                                    nvl(t.ACT_WEIGHT, 0) weight
                                 from ydm_zc_stocktakinglist t
                               where 1=1
                                and t.VALIDFLAG = '1'
                                   and t.BAL_YEAR_MONTH = ?
                                   --and T.JUDGE_STOVE_NO = '012602'
                                  #condtions#)t where 1=1
                       
                          ]]>    
</query>
<query id = "FrmRunTimeRptCw.insertTal" desc = "中转期初数据">
 INSERT INTO YDM_ZC_TIAL(
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        ACT_COUNT,
        ACT_WEIGHT,
        ORIGINAL_DATE,
        BAL_YEAR_MONTH,
        HANDLE_LOG,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        BELONG_CODE,
        BELONG_NAME)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,?)
</query>
<query id = "FrmRunTimeRptCw.SelectMatZc" desc = "查询库存信息">
<![CDATA[
	SELECT
  sum(T.Act_Count)Act_Count,
  sum(T.Act_Weight)Act_Weight,
       T.BELONG_CODE,
       T.BELONG_NAME
       --T.Ord_Pk,
       --T.Ord_Ln_Pk,
       --T.Ord_Ln_Dly_Pk
  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 = ?
   group by T.BELONG_CODE,
       T.BELONG_NAME
       --T.Ord_Pk,
       --T.Ord_Ln_Pk,
       --T.Ord_Ln_Dly_Pk
   
   ]]>
</query>


<query id = "FrmRunTimeRptCw.getTal" desc = "获取中转数据">
 SELECT 
       INITIAL_ID,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       ACT_COUNT,
       ACT_WEIGHT,
       ORIGINAL_DATE,
       BAL_YEAR_MONTH,
       DECODE(HANDLE_LOG,'0','未结转','1','已结转')HANDLE_LOG,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       BELONG_CODE,
       BELONG_NAME
 FROM YDM_ZC_TIAL 
 WHERE BAL_YEAR_MONTH LIKE '%'||?||'%'
 and JUDGE_STOVE_NO LIKE '%'||?||'%'
 and HANDLE_LOG = '0'
</query>
<query id = "FrmRunTimeRptCw.insertInital" desc = "插入期初数据">
<![CDATA[
 INSERT INTO YDM_ZC_INITIAL(
        JUDGE_STD_NAME,
        INSTOCK_TIME,
        BELONG_CODE,
        BELONG_NAME,
        MEMO1,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        STD_CODE,
        STD_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        DIMATER,
        HEIGHT,
        LEN,
        LEN_MIN,
        LEN_MAX,
        ACT_COUNT,
        ACT_WEIGHT,
        STORAGE_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        ORDER_NO,
        ORDER_SEQ,
        ORDER_SEQ_NO,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        MANAGEMENT_NO,
        MANAGEMENT_NAME,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        ORIGINAL_DATE,
        BAL_YEAR_MONTH,
        GRADECODE,
        GRADENAME,
        PLINE_CODE,
        PLINE_NAME,
        HANDLE_LOG)
 VALUES( 
        ?,
        to_date(?,'yyyy-MM-dd HH24:mi:ss'),
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        nvl(?,'0'),
        nvl(?,'0'),
        nvl(?,'0'),
        nvl(?,'0'),
        nvl(?,'0'),
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?
        )
        ]]>
</query>
<query id = "FrmRunTimeRptCw.selectInitalMat" desc = "查询材料信息">
SELECT sum(T.Act_Count) Act_Count,
       sum(T.Act_Weight) Act_Weight,
       sum(T.ACT_LEN) ACT_LEN,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       max(T.ACT_LEN_MIN) ACT_LEN_MIN,
       max(T.ACT_LEN_MAX) ACT_LEN_MAX,
       T.BELONG_CODE,
       T.BELONG_NAME,
       max(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       T.MEMO,
       
       T.JUDGE_STD_NAME,
       T.PIPMEMO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
      
       T.PLINE_CODE,
       T.PLINE_NAME,
       max(B.STORAGE_NO)STORAGE_NO
  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 = ?
 group by T.ACT_DIMATER,
          T.ACT_HEIGHT,
          T.BELONG_CODE,
          T.BELONG_NAME,
          T.MEMO,
          T.JUDGE_STD_NAME,
          T.PIPMEMO,
          T.JUDGE_STOVE_NO,
          T.BATCH_NO,
          T.BATCH_GROUD_NO,
          T.MATERIAL_NO,
          T.MATERIAL_NAME,
          T.PRODUCCODE,
          T.PRODUCNAME,
          T.STEELCODE,
          T.STEELNAME,
          T.GRADECODE,
          T.GRADENAME,
          T.SPEC_CODE,
          T.SPEC_NAME,
          T.MODEL_CODE,
          T.MODEL_DESC,
          T.STD_CODE,
          T.STD_NAME,
          T.STD_STYLE,
          T.STD_STYLE_DESC,
          T.PLINE_CODE,
          T.PLINE_NAME
          --B.STORAGE_NO
</query>
<query id = "FrmRunTimeRptCw.updateTal" desc = "修改中转表">
update ydm_zc_tial t set t.HANDLE_LOG = '1' where t.INITIAL_ID = ?
</query>
<query id = "FrmRunTimeRptCw.getIntal" desc = "查询中转数据是否存在">
SELECT COUNT(1) ACOUNT
  FROM YDM_ZC_TIAL T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.BAL_YEAR_MONTH = ?
</query>
<query id = "FrmRunTimeRptCw.doQueryTail" desc = "查询是否已存在结转年月的中转数据了">
SELECT COUNT(1) ACOUNT
  FROM YDM_ZC_TIAL T
 WHERE T.BAL_YEAR_MONTH = ?
</query>
<query id = "FrmRunTimeRptCw.getIntalJZ" desc = "查询是否已存在结转年月的结转数据了">
SELECT COUNT(1) ACOUNT
  FROM YDM_ZC_INITIAL T
 WHERE T.BAL_YEAR_MONTH = ?
    AND T.SUPPLY_UNIT_CODE = ?
</query>
<query id = "FrmRunTimeRptCw.insertTal_" desc = "插入">
<![CDATA[
declare
  v_Act_count   NUMBER := 0;
  v_Act_Weight  NUMBER := 0;
  v_BELONG_CODE VARCHAR2(20) := '';
  v_BELONG_NAME VARCHAR2(20) := '';
  v_s number := 0;
begin
   select count(1) into v_s 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 T.BATCH_GROUD_NO = ?
       AND T.BELONG_CODE IN ('100101','100102','100103');
       if v_s >0 then 
    SELECT sum(T.Act_Count) Act_Count,
           sum(T.Act_Weight) Act_Weight,
           T.BELONG_CODE,
           T.BELONG_NAME
      INTO v_Act_count, v_Act_Weight, v_BELONG_CODE, v_BELONG_NAME
      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 T.BATCH_GROUD_NO = ?
       and rownum = 1
       #condtions#
     group by T.BELONG_CODE, T.BELONG_NAME;
  else
  SELECT sum(T.Act_Count) Act_Count,
           sum(T.Act_Weight) Act_Weight,
           T.BELONG_CODE,
           T.BELONG_NAME
      INTO v_Act_count, v_Act_Weight, v_BELONG_CODE, v_BELONG_NAME
      FROM YDM_ZC_INLIST T
      where T.JUDGE_STOVE_NO = ?
       AND T.BATCH_NO = ?
       AND T.BATCH_GROUD_NO = ?
       AND T.INSTOCK_TYPE_CODE = '800701'
       and rownum = 1
       #condtions#
     group by T.BELONG_CODE, T.BELONG_NAME;
  end if;
  INSERT INTO YDM_ZC_TIAL
      (JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       ACT_COUNT,
       ACT_WEIGHT,
       ORIGINAL_DATE,
       BAL_YEAR_MONTH,
       HANDLE_LOG,
       BELONG_CODE,
       BELONG_NAME)
    VALUES
      (?, ?, ?, ?, ?, ?, ?, ?, v_BELONG_CODE, v_BELONG_NAME);
end;
]]>
</query>
<query id = "FrmRunTimeRptCw.insertInital_" desc = "结转插入">
<![CDATA[
declare
  v_Act_count   mat_zc_m.act_count%type :=null;
  v_Act_Weight  mat_zc_m.act_weight%type:= null;
  v_ACT_LEN     mat_zc_m.act_len%type:= null;
  v_ACT_DIMATER mat_zc_m.act_dimater%type:= null;
  v_ACT_HEIGHT mat_zc_m.act_height%type := null;
  v_ACT_LEN_MIN mat_zc_m.act_len_min%type := null;
  v_ACT_LEN_MAX mat_zc_m.act_len_max%type := null;
  v_INSTOCK_TIME mat_zc_m.instock_time%type := null;
  v_MEMO mat_zc_m.memo%type := null;
  v_JUDGE_STD_NAME mat_zc_m.judge_std_name%type := null;
  v_PIPMEMO mat_zc_m.pipmemo%type := null;
  v_MATERIAL_NO mat_zc_m.material_no%type := null;
  v_MATERIAL_NAME mat_zc_m.material_name%type := null;
  v_PRODUCCODE mat_zc_m.produccode%type := null;
  v_PRODUCNAME mat_zc_m.producname%type := null;
  v_STEELCODE mat_zc_m.steelcode%type := null;
  v_STEELNAME mat_zc_m.steelname%type := null;
  v_GRADECODE mat_zc_m.gradecode%type := null;
  v_GRADENAME mat_zc_m.gradename%type := null;
  v_SPEC_CODE mat_zc_m.spec_code%type := null;
  v_SPEC_NAME mat_zc_m.spec_name%type := null;
  v_MODEL_CODE mat_zc_m.model_code%type := null;
  v_MODEL_DESC mat_zc_m.model_desc%type := null;
  v_STD_CODE mat_zc_m.std_code%type := null;
  v_STD_NAME mat_zc_m.std_name%type := null;
  v_STD_STYLE mat_zc_m.std_style%type := null;
  v_STD_STYLE_DESC mat_zc_m.std_style_desc%type := null;
  v_PLINE_CODE mat_zc_m.pline_code%type := null;
  v_PLINE_NAME mat_zc_m.pline_name%type := null;
  v_STORAGE_NO ydm_zc_buttress.storage_no%type := null;
  v_count number :=0;
begin
 SELECT count(1) into v_count 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 T.BATCH_GROUD_NO = ?
   AND T.BELONG_CODE IN ('100101','100102','100103')
   AND ROWNUM = 1;
          if v_count > 0 then 
SELECT sum(T.Act_Count) Act_Count,
       sum(T.Act_Weight) Act_Weight,
       sum(T.ACT_LEN) ACT_LEN,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       max(T.ACT_LEN_MIN) ACT_LEN_MIN,
       max(T.ACT_LEN_MAX) ACT_LEN_MAX,
       max(T.INSTOCK_TIME) INSTOCK_TIME,
       T.MEMO,
       T.JUDGE_STD_NAME,
       T.PIPMEMO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.PLINE_CODE,
       T.PLINE_NAME,
       max(B.STORAGE_NO) STORAGE_NO
       into v_Act_count,v_Act_Weight,v_ACT_LEN,v_ACT_DIMATER,v_ACT_HEIGHT,v_ACT_LEN_MIN,v_ACT_LEN_MAX,v_INSTOCK_TIME,
  v_MEMO,
  v_JUDGE_STD_NAME ,
  v_PIPMEMO ,
  v_MATERIAL_NO ,
  v_MATERIAL_NAME ,
  v_PRODUCCODE ,
  v_PRODUCNAME ,
  v_STEELCODE ,
  v_STEELNAME ,
  v_GRADECODE ,
  v_GRADENAME ,
  v_SPEC_CODE ,
  v_SPEC_NAME ,
  v_MODEL_CODE,
  v_MODEL_DESC ,
  v_STD_CODE ,
  v_STD_NAME ,
  v_STD_STYLE ,
  v_STD_STYLE_DESC ,
  v_PLINE_CODE ,
  v_PLINE_NAME,
  v_STORAGE_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 T.BATCH_GROUD_NO = ?
   AND T.BELONG_CODE IN ('100101','100102','100103')
   AND ROWNUM = 1
 group by T.ACT_DIMATER,
          T.ACT_HEIGHT,
          T.MEMO,
          T.JUDGE_STD_NAME,
          T.PIPMEMO,
          T.MATERIAL_NO,
          T.MATERIAL_NAME,
          T.PRODUCCODE,
          T.PRODUCNAME,
          T.STEELCODE,
          T.STEELNAME,
          T.GRADECODE,
          T.GRADENAME,
          T.SPEC_CODE,
          T.SPEC_NAME,
          T.MODEL_CODE,
          T.MODEL_DESC,
          T.STD_CODE,
          T.STD_NAME,
          T.STD_STYLE,
          T.STD_STYLE_DESC,
          T.PLINE_CODE,
          T.PLINE_NAME;
        else
      SELECT sum(T.Act_Count) Act_Count,
       sum(T.Act_Weight) Act_Weight,
       sum(T.ACT_LEN) ACT_LEN,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       max(T.ACT_LEN_MIN) ACT_LEN_MIN,
       max(T.ACT_LEN_MAX) ACT_LEN_MAX,
       max(T.INSTOCK_TIME) INSTOCK_TIME,
       T.MEMO,
       T.JUDGE_STD_NAME,
       T.PIPMEMO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.PLINE_CODE,
       T.PLINE_NAME
       into v_Act_count,v_Act_Weight,v_ACT_LEN,v_ACT_DIMATER,v_ACT_HEIGHT,v_ACT_LEN_MIN,v_ACT_LEN_MAX,v_INSTOCK_TIME,
  v_MEMO,
  v_JUDGE_STD_NAME ,
  v_PIPMEMO ,
  v_MATERIAL_NO ,
  v_MATERIAL_NAME ,
  v_PRODUCCODE ,
  v_PRODUCNAME ,
  v_STEELCODE ,
  v_STEELNAME ,
  v_GRADECODE ,
  v_GRADENAME ,
  v_SPEC_CODE ,
  v_SPEC_NAME ,
  v_MODEL_CODE,
  v_MODEL_DESC ,
  v_STD_CODE ,
  v_STD_NAME ,
  v_STD_STYLE ,
  v_STD_STYLE_DESC ,
  v_PLINE_CODE ,
  v_PLINE_NAME
  
  FROM YDM_ZC_INLIST T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.BELONG_CODE IN ('100101','100102','100103')
   AND T.INSTOCK_TYPE_CODE = '800701'
   AND ROWNUM = 1
 group by T.ACT_DIMATER,
          T.ACT_HEIGHT,
          T.MEMO,
          T.JUDGE_STD_NAME,
          T.PIPMEMO,
          T.MATERIAL_NO,
          T.MATERIAL_NAME,
          T.PRODUCCODE,
          T.PRODUCNAME,
          T.STEELCODE,
          T.STEELNAME,
          T.GRADECODE,
          T.GRADENAME,
          T.SPEC_CODE,
          T.SPEC_NAME,
          T.MODEL_CODE,
          T.MODEL_DESC,
          T.STD_CODE,
          T.STD_NAME,
          T.STD_STYLE,
          T.STD_STYLE_DESC,
          T.PLINE_CODE,
          T.PLINE_NAME;
          end if;  
  INSERT INTO YDM_ZC_INITIAL(
        JUDGE_STD_NAME,
        INSTOCK_TIME,
        BELONG_CODE,
        BELONG_NAME,
        MEMO1,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        STD_CODE,
        STD_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        DIMATER,
        HEIGHT,
        LEN,
        LEN_MIN,
        LEN_MAX,
        ACT_COUNT,
        ACT_WEIGHT,
        STORAGE_NO,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        ORIGINAL_DATE,
        BAL_YEAR_MONTH,
        GRADECODE,
        GRADENAME,
        PLINE_CODE,
        PLINE_NAME,
        HANDLE_LOG)
 VALUES( 
        v_JUDGE_STD_NAME,
        v_INSTOCK_TIME,
        ?,
        ?,
        v_PIPMEMO,
        ?,
        ?,
        ?,
        v_MATERIAL_NO,
        v_MATERIAL_NAME,
        v_PRODUCCODE,
        v_PRODUCNAME,
        v_STEELCODE,
        v_STEELNAME,
        v_SPEC_CODE,
        v_SPEC_NAME,
        v_MODEL_CODE,
        v_MODEL_DESC,
        v_STD_CODE,
        v_STD_NAME,
        v_STD_STYLE,
        v_STD_STYLE_DESC,
        nvl(v_ACT_DIMATER,'0'),
        nvl(v_ACT_HEIGHT,'0'),
        nvl(v_ACT_LEN,'0'),
        nvl(v_ACT_LEN_MIN,'0'),
        nvl(v_ACT_LEN_MAX,'0'),
        nvl(?,'0'),
        nvl(?,'0'),
        v_STORAGE_NO,
        v_MEMO,
        ?,
        SYSDATE,
        ?,
        ?,
        v_GRADECODE,
        v_GRADENAME,
        v_PLINE_CODE,
        v_PLINE_NAME,
        ?
        );
  end;
]]>
</query>
<query id = "FrmRunTimeRptCw.insertInital1_" desc = "结转">
    DECLARE BEGIN
    DELETE FROM YDM_ZC_INITIAL_CW WHERE BAL_YEAR_MONTH = TO_CHAR(ADD_MONTHS(TO_DATE(?, 'YYYYMM'),1),'YYYYMM');
    FOR MYROW IN ( SELECT * FROM YDM_ZC_INITIAL_CW_R WHERE BAL_YEAR_MONTH = ? AND END_COUNT != 0 )
    LOOP
    INSERT INTO YDM_ZC_INITIAL_CW (
    JUDGE_STOVE_NO,
    BATCH_NO,
    BATCH_GROUD_NO,
    PRODUCNAME,
    STEELNAME,
    SPEC_NAME,
    MODEL_DESC,
    STD_NAME,
    STD_STYLE_DESC,
    GRADENAME,
    BAL_YEAR_MONTH,
    BELONG_CODE,
    BELONG_NAME,
    SUPPLY_UNIT_CODE,
    SUPPLY_UNIT,
    IS_DEALER,
    ACT_COUNT,
    ACT_WEIGHT,INSTOCK_TIME
    )
    VALUES
    (
    MYROW.JUDGE_STOVE_NO,
    MYROW.BATCH_NO,
    MYROW.BATCH_GROUD_NO,
    MYROW.PRODUCNAME,
    MYROW.STEELNAME,
    MYROW.SPEC_NAME,
    MYROW.MODEL_DESC,
    MYROW.STD_NAME,
    MYROW.STD_STYLE_DESC,
    MYROW.GRADENAME,
    TO_CHAR(ADD_MONTHS(TO_DATE(MYROW.BAL_YEAR_MONTH, 'YYYYMM'),1),'YYYYMM'),
    MYROW.BELONG_CODE,
    MYROW.BELONG_NAME,
    MYROW.SUPPLY_UNIT_CODE,
    MYROW.SUPPLY_UNIT,
    MYROW.IS_DEALER,
    MYROW.END_COUNT,
    MYROW.END_AMOUNT,MYROW.INSTOCK_TIME
    ) ;
    END LOOP;
    END;
</query>
<query id = "FrmRunTimeRptCw.updateQcmFlag" desc = "修改结转标识">
UPDATE QCM_ZG_JUGDE_APPLY T
   SET T.IS_CARRY_VOER = '1'
 WHERE T.BAL_YEAR_MONTH = ?
   AND ((T.VALIDFLAG = '20' AND T.JUDGE_RESULT_CODE = '40740701') OR
       (T.VALIDFLAG = '00' AND T.INSTANCY_FLAG = '1'))
   AND T.IS_FLAG = '0'
   AND T.TARGET = 'A'
   #BELONG_CODE_JUDGE#
</query>
<query id = "FrmRunTimeRptCw.getQueryData" desc = "查询">
SELECT JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PRODUCNAME,
       STD_STYLE_DESC,
       STEELNAME,
       SPEC_NAME,
       MODEL_DESC,
       BELONG_CODE,
       BELONG_NAME,
    GRADENAME,
    DECODE(IS_DEALER,'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
       SUM(ORIGINAL_COUNT) ORIGINAL_COUNT,
       SUM(ORIGINAL_AMOUNT) ORIGINAL_AMOUNT,
       SUM(MONTH_1COUNT) MONTH_1COUNT,
       SUM(MONTH_1) MONTH_1,
       SUM(MONTH_2COUNT) MONTH_2COUNT,
       SUM(MONTH_2) MONTH_2,
       SUM(AWEIGHT) AWEIGHT,
       SUM((ORIGINAL_COUNT + MONTH_1COUNT - MONTH_2COUNT)) AS END_COUNT,
       SUM((ORIGINAL_AMOUNT + MONTH_1 - MONTH_2 + AWEIGHT)) AS END_AMOUNT
  FROM (SELECT JUDGE_STOVE_NO,
               BATCH_NO,
               BATCH_GROUD_NO,
               PRODUCNAME,
               STD_STYLE_DESC,
               STEELNAME,
               SPEC_NAME,
               MODEL_DESC,
               BELONG_CODE,
               BELONG_NAME,
               GRADENAME,
    NVL(IS_DEALER,'0')IS_DEALER,
               NVL(SUM(ACT_COUNT), 0) ORIGINAL_COUNT,
               NVL(SUM(ACT_WEIGHT), 0) ORIGINAL_AMOUNT,
               0 MONTH_1COUNT,
               0 MONTH_1,
               0 MONTH_2COUNT,
               0 MONTH_2,
               0 AWEIGHT
          FROM YDM_ZC_INITIAL_CW T
         WHERE T.BAL_YEAR_MONTH = '#BAL_YEAR_MONTH#' #CONDTIONS#
         GROUP BY T.JUDGE_STOVE_NO,
                  T.BATCH_NO,
                  T.BATCH_GROUD_NO,
                  T.PRODUCNAME,
                  T.STD_STYLE_DESC,
                  T.STEELNAME,
                  T.SPEC_NAME,
                  T.MODEL_DESC,
                  T.BELONG_CODE,
                  T.BELONG_NAME,
    T.GRADENAME,
    T.IS_DEALER
        UNION ALL
        SELECT JUDGE_STOVE_NO,
               BATCH_NO,
               BATCH_GROUD_NO,
               PRODUCNAME,
               STD_STYLE_DESC,
               STEELNAME,
               SPEC_NAME,
               MODEL_DESC,
    BELONG_CODE,
               BELONG_NAME,
    GRADENAME,
    NVL(IS_DEALER,'0')IS_DEALER,
               0 ORIGINAL_COUNT,
               0 ORIGINAL_AMOUNT,
               NVL(SUM(ACT_COUNT), 0) MONTH_1COUNT,
               NVL(SUM(ACT_WEIGHT), 0) MONTH_1,
               0 MONTH_2COUNT,
               0 MONTH_2,
               0 AWEIGHT
          FROM YDM_ZC_INLIST T
         WHERE INSTOCK_TYPE_CODE IN
               ('800701', '800702', '800704', '800706', '800707', '800712')
           AND T.BAL_YEAR_MONTH = '#BAL_YEAR_MONTH#' #CONDTIONS#
         GROUP BY T.JUDGE_STOVE_NO,
                  T.BATCH_NO,
                  T.BATCH_GROUD_NO,
                  T.PRODUCNAME,
                  T.STD_STYLE_DESC,
                  T.STEELNAME,
                  T.SPEC_NAME,
                  T.MODEL_DESC,
    T.BELONG_CODE,
                  T.BELONG_NAME,
    T.GRADENAME,
    T.IS_DEALER
        UNION ALL

    SELECT
    T.JUDGE_STOVE_NO,
    T.BATCH_NO,
    T.BATCH_GROUD_NO,
    T.PRODUCNAME,
    T.STD_STYLE_DESC,
    T.STEELNAME,
    T.SPEC_NAME,
    T.MODEL_DESC,
    T.BELONG_CODE,
    T.BELONG_NAME,
    T.GRADENAME,
    NVL( T.IS_DEALER, '0' ) IS_DEALER,
    0 ORIGINAL_COUNT,
    0 ORIGINAL_AMOUNT,
    0 MONTH_1COUNT,
    0 MONTH_1,
    NVL( SUM( T.ACT_COUNT ), 0 ) MONTH_2COUNT,
    NVL(
    SUM( CASE WHEN T.PONDER_NO IS NULL THEN NVL( T.ACT_WEIGHT, 0 ) ELSE NVL( T.PONDER_GROSS_WT, 0 ) END ),
    0
    ) MONTH_2,
    0 AWEIGHT
    FROM
    SLM_BALANCEINFO A
    LEFT JOIN (SELECT B.* FROM YDM_ZC_BILL_M A LEFT JOIN YDM_ZC_BILL_C B ON A.BILL_NO = B.BILL_NO AND A.ORD_LN_DLY_PK = B.ORD_LN_DLY_PK) BILL ON A.ASKPLAN_ID = BILL.BILL_NO
    LEFT JOIN YDM_ZC_OUTLIST T  ON T.MAT_NO = BILL.MAT_NO AND (T.BILL_NO = BILL.BILL_NO OR T.m_BILL_NO= BILL.BILL_NO)
    WHERE
    T.OUTSTOCK_TYPE_CODE IN ( '800805', '800804', '800802', '800808', '800806', '800812' )
    AND A.BALANCESTATUS = '3'
    AND GET_FISCAL_MONTH1(A.INVOICEDATE)= '#BAL_YEAR_MONTH#'
    AND T.BELONG_CODE IN ( '100101' )
    AND ( T.SUPPLY_UNIT_CODE = '120501' OR T.SUPPLY_UNIT_CODE IS NULL )
    GROUP BY
    T.JUDGE_STOVE_NO,
    T.BATCH_NO,
    T.BATCH_GROUD_NO,
    T.PRODUCNAME,
    T.STD_STYLE_DESC,
    T.STEELNAME,
    T.SPEC_NAME,
    T.MODEL_DESC,
    T.BELONG_CODE,
    T.BELONG_NAME,
    T.GRADENAME,
    T.IS_DEALER
    ) K
 GROUP BY JUDGE_STOVE_NO,
          BATCH_NO,
          BATCH_GROUD_NO,
          PRODUCNAME,
          STD_STYLE_DESC,
          STEELNAME,
          SPEC_NAME,
          MODEL_DESC,
          BELONG_CODE,
          BELONG_NAME,
    GRADENAME,
    IS_DEALER
</query>
    <query id = "FrmRunTimeRptCw.getQueryData1" desc = "查询">
        SELECT T.*,DECODE(T.IS_DEALER,'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER FROM YDM_ZC_INITIAL_CW_R t WHERE T.BAL_YEAR_MONTH = '#BAL_YEAR_MONTH#'
    </query>
<query id = "FrmRunTimeRptCw.selectMatCount" desc = "查询库存信息">
    SELECT SUM(ACOUNT)ACOUNT
    FROM (SELECT COUNT(1) ACOUNT
    FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
    WHERE T.MAT_NO = S.MAT_NO
    AND T.JUDGE_STOVE_NO = ?
    AND T.BATCH_NO = ?
    AND T.BATCH_GROUD_NO = ?
    AND NVL(T.PRODUCNAME, '/') = NVL(?, '/')
    AND NVL(T.STD_STYLE_DESC, '/') = NVL(?, '/')
    AND NVL(T.STEELNAME, '/') = NVL(?, '/')
    AND NVL(T.SPEC_NAME, '/') = NVL(?, '/')
    AND NVL(T.MODEL_DESC, '/') = NVL(?, '/')
    AND T.BELONG_CODE = ?
    --#CONDITIONS#
    UNION ALL
    SELECT COUNT(1) ACOUNT
    FROM YDM_ZC_OUTLIST T
    WHERE T.JUDGE_STOVE_NO = ?
    AND T.BATCH_NO = ?
    AND T.BATCH_GROUD_NO = ?
    AND NVL(T.PRODUCNAME, '/') = NVL(?, '/')
    AND NVL(T.STD_STYLE_DESC, '/') = NVL(?, '/')
    AND NVL(T.STEELNAME, '/') = NVL(?, '/')
    AND NVL(T.SPEC_NAME, '/') = NVL(?, '/')
    AND NVL(T.MODEL_DESC, '/') = NVL(?, '/')
    AND T.BELONG_CODE = ?
    --#CONDITIONS#
    )
</query>
</queryMap>