<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "收发存信息统计">
<query id = "FrmrptProductStorage.getOriginaldate" desc = "收发货期初时间查询">
<![CDATA[
select distinct min(t.original_date) over() original_date,
                max(case
                      when substr(t.original_date, 1, 4) <
                           substr(?, 1, 4) then
                       t.original_date
                    end) over() original_date1,
                max(case
                      when t.original_date <= ? then
                       t.original_date
                    end) over() original_date_last
  from ydm_zc_initial t WHERE1=1
]]>
</query>
<query id = "FrmrptProductStorage.getOriginalLast" desc = "查询上期期初">
<![CDATA[
select t.PRODUCNAME,t.STEELNAME,t.SPEC_NAME,t.MODEL_DESC,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,t.PROCESS_CDOE,
DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                    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 '%'||?||'%'
                     #condtions#
                    
                    ]]>
</query>

    <query id = "FrmrptProductStorage.getOriginalLast1" desc = "查询上期期初">
        <![CDATA[
select t.PRODUCNAME,t.STEELNAME,t.SPEC_NAME,t.MODEL_DESC,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,
DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                    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 '%'||?||'%'
                     #condtions#

                    ]]>
    </query>

<query id = "FrmrptProductStorage.getLastIn" desc = "上期入库量">
<![CDATA[
                             select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             t.PROCESS_CDOE,
                             t.IS_DEALER,
                              sum(nvl(t.count,0))count,
                               sum(nvl(t.weight, 0)) weight
                          from (select t.PRODUCNAME,
                          t.STEELNAME,
                          t.SPEC_NAME,
                          t.MODEL_DESC,
                          t.STD_STYLE_DESC,
                          t.BELONG_CODE,
                          t.BELONG_NAME,
                          t.GRADENAME,
                          t.PROCESS_CDOE,
                          DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                           nvl(t.ACT_COUNT,0) count,
                                    nvl(t.ACT_WEIGHT, 0) weight
                                 from ydm_zc_inlist t
                               where 1=1
                                and t.VALIDFLAG = '1'
                                and t.INSTOCK_TYPE_CODE in ('800701','800702','800704','800712')                                
                                and t.BAL_YEAR_MONTH >=?
                                   --and trunc(t.INSTOCK_TIME) >= to_date(?, 'yyyymmdd')
                                  and trunc(t.INSTOCK_TIME) <= to_date(?, 'yyyymmdd') 
                                  #condtions#)t where 1= 1
                       
                          ]]>                  
</query>
    <query id = "FrmrptProductStorage.getLastIn1" desc = "上期入库量">
        <![CDATA[
                             select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             t.IS_DEALER,
                              sum(nvl(t.count,0))count,
                               sum(nvl(t.weight, 0)) weight
                          from (select t.PRODUCNAME,
                          t.STEELNAME,
                          t.SPEC_NAME,
                          t.MODEL_DESC,
                          t.STD_STYLE_DESC,
                          t.BELONG_CODE,
                          t.BELONG_NAME,
                          t.GRADENAME,
                          DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                           nvl(t.ACT_COUNT,0) count,
                                    nvl(t.ACT_WEIGHT, 0) weight
                                 from ydm_zc_inlist t
                               where 1=1
                                and t.VALIDFLAG = '1'
                                and t.INSTOCK_TYPE_CODE in ('800701','800702','800704','800712')
                                and t.BAL_YEAR_MONTH >=?
                                   --and trunc(t.INSTOCK_TIME) >= to_date(?, 'yyyymmdd')
                                  and trunc(t.INSTOCK_TIME) <= to_date(?, 'yyyymmdd')
                                  #condtions#)t where 1= 1

                          ]]>
    </query>
<query id = "FrmrptProductStorage.getLastOut" desc = "上期出库量">
<![CDATA[
select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             t.PROCESS_CDOE,
                             t.IS_DEALER,
                             sum(nvl(t.count,0))count,
                               sum(nvl(t.weight, 0)) weight
                          from (select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_CODE,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             t.PROCESS_CDOE,
                             DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                             nvl(t.ACT_COUNT,0)count,
                                       nvl(t.ACT_WEIGHT, 0) weight
                                  from ydm_zc_outlist t
                                where t.OUTSTOCK_TYPE_CODE in ('800805','800806','800802','800804','800812')
                                  and t.validflag = '1'
                                  and t.BAL_YEAR_MONTH >=?
                                   and trunc(t.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd') #condtions# 
                                  )t where 1=1
                                   ]]>
</query>
    <query id = "FrmrptProductStorage.getLastOut1" desc = "上期出库量">
        <![CDATA[
select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,

                             t.IS_DEALER,
                             sum(nvl(t.count,0))count,
                               sum(nvl(t.weight, 0)) weight
                          from (select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_CODE,
                             t.BELONG_NAME,
                             t.GRADENAME,

                             DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                             nvl(t.ACT_COUNT,0)count,
                                       nvl(t.ACT_WEIGHT, 0) weight
                                  from ydm_zc_outlist t
                                where t.OUTSTOCK_TYPE_CODE in ('800805','800806','800802','800804','800812')
                                  and t.validflag = '1'
                                  and t.BAL_YEAR_MONTH >=?
                                   and trunc(t.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd') #condtions#
                                  )t where 1=1
                                   ]]>
    </query>
<!-- 
 -->
<query id = "FrmrptProductStorage.getThisIn" desc = "本期入库量">
<![CDATA[
                     select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             t.PROCESS_CDOE,
                             t.IS_DEALER,
                              nvl(sum(case
                                        when trunc(t.INSTOCK_TIME) = to_date(?, 'yyyymmdd') then
                                         nvl(t.count, 0)
                                      end),
                                   0) weight_daycount,
                               nvl(sum(case
                                        when trunc(t.INSTOCK_TIME) = to_date(?, 'yyyymmdd') then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_day,
                                   nvl(sum(case
                                        when t.BAL_YEAR_MONTH >=? and
                                            trunc(t.INSTOCK_TIME) <= to_date(?, 'yyyymmdd') then
                                            nvl(t.count,0)
                                      end),
                                   0) weight_monthcount,
                              nvl(sum(case
                                        when t.BAL_YEAR_MONTH >=? and
                                            trunc(t.INSTOCK_TIME) <= to_date(?, 'yyyymmdd') then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_month
                          from (select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_CODE,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             t.PROCESS_CDOE,
                             DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                                     t.INSTOCK_TIME,  
                                     nvl(t.ACT_COUNT,0)count,
                                       nvl(t.ACT_WEIGHT, 0) weight,
                                       t.BAL_YEAR_MONTH
                                  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 trunc(t.INSTOCK_TIME) >= to_date(?, 'yyyymmdd')
                                   and trunc(t.INSTOCK_TIME) <= to_date(?, 'yyyymmdd')  #condtions# 
                                   )t where 1= 1  
                             ]]>
</query>
    <query id = "FrmrptProductStorage.getThisIn1" desc = "本期入库量">
        <![CDATA[
                     select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,

                             t.IS_DEALER,
                              nvl(sum(case
                                        when trunc(t.INSTOCK_TIME) = to_date(?, 'yyyymmdd') then
                                         nvl(t.count, 0)
                                      end),
                                   0) weight_daycount,
                               nvl(sum(case
                                        when trunc(t.INSTOCK_TIME) = to_date(?, 'yyyymmdd') then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_day,
                                   nvl(sum(case
                                        when t.BAL_YEAR_MONTH >=? and
                                            trunc(t.INSTOCK_TIME) <= to_date(?, 'yyyymmdd') then
                                            nvl(t.count,0)
                                      end),
                                   0) weight_monthcount,
                              nvl(sum(case
                                        when t.BAL_YEAR_MONTH >=? and
                                            trunc(t.INSTOCK_TIME) <= to_date(?, 'yyyymmdd') then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_month
                          from (select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_CODE,
                             t.BELONG_NAME,
                             t.GRADENAME,

                             DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                                     t.INSTOCK_TIME,
                                     nvl(t.ACT_COUNT,0)count,
                                       nvl(t.ACT_WEIGHT, 0) weight,
                                       t.BAL_YEAR_MONTH
                                  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 trunc(t.INSTOCK_TIME) >= to_date(?, 'yyyymmdd')
                                   and trunc(t.INSTOCK_TIME) <= to_date(?, 'yyyymmdd')  #condtions#
                                   )t where 1= 1
                             ]]>
    </query>
<query id = "FrmrptProductStorage.getThisOut" desc = "本期出库量">
<![CDATA[
                      select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             t.PROCESS_CDOE,
                             t.IS_DEALER,
                              nvl(sum(case
                                        when trunc(t.OUTSTOCK_TIME) = to_date(?, 'yyyymmdd') then
                                         nvl(t.count, 0)
                                      end),
                                   0) weight_daycount,
                               nvl(sum(case
                                        when trunc(t.OUTSTOCK_TIME) = to_date(?, 'yyyymmdd') then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_day,
                                   nvl(sum(case
                                        when t.BAL_YEAR_MONTH >=? and
                                            trunc(t.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd') then
                                            nvl(t.count,0)
                                      end),
                                   0) weight_monthcount,
                              nvl(sum(case
                                        when t.BAL_YEAR_MONTH >=? and
                                            trunc(t.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd') then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_month
                          from (select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_CODE,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             T.PROCESS_CDOE,
                             DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                                     t.OUTSTOCK_TIME,  
                                     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,
                                       t.BAL_YEAR_MONTH
                                  from ydm_zc_outlist t
                                 where t.validflag = '1'
                                 --and t.OUTSTOCK_TYPE_CODE in ('800805','800804','800802','800808','800806','800812')
                                  and t.BAL_YEAR_MONTH >=?
                                   and trunc(t.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd')  #condtions# 
                                   )t where 1= 1 
                             ]]>
</query>

    <query id = "FrmrptProductStorage.getThisOut1" desc = "本期出库量">
        <![CDATA[
                      select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,

                             t.IS_DEALER,
                              nvl(sum(case
                                        when trunc(t.OUTSTOCK_TIME) = to_date(?, 'yyyymmdd') then
                                         nvl(t.count, 0)
                                      end),
                                   0) weight_daycount,
                               nvl(sum(case
                                        when trunc(t.OUTSTOCK_TIME) = to_date(?, 'yyyymmdd') then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_day,
                                   nvl(sum(case
                                        when t.BAL_YEAR_MONTH >=? and
                                            trunc(t.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd') then
                                            nvl(t.count,0)
                                      end),
                                   0) weight_monthcount,
                              nvl(sum(case
                                        when t.BAL_YEAR_MONTH >=? and
                                            trunc(t.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd') then
                                         nvl(t.weight, 0)
                                      end),
                                   0) weight_month
                          from (select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_CODE,
                             t.BELONG_NAME,
                             t.GRADENAME,

                             DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                                     t.OUTSTOCK_TIME,
                                     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,
                                       t.BAL_YEAR_MONTH
                                  from ydm_zc_outlist t
                                 where t.validflag = '1'
                                 and t.OUTSTOCK_TYPE_CODE in ('800805','800804','800802','800808','800806','800812')
                                  and t.BAL_YEAR_MONTH >=?
                                   and trunc(t.OUTSTOCK_TIME) <= to_date(?, 'yyyymmdd')  #condtions#
                                   )t where 1= 1
                             ]]>
    </query>

<query id = "FrmrptProductStorage.getAdjust" desc = "本期调差量">
<![CDATA[
                             select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,
                             t.PROCESS_CDOE,
                             t.IS_DEALER,
                               sum(nvl(t.weight, 0)) aweight
                          from (select t.PRODUCNAME,
                          t.STEELNAME,
                          t.SPEC_NAME,
                          t.MODEL_DESC,
                          t.STD_STYLE_DESC,
                          t.BELONG_CODE,
                          t.BELONG_NAME,
                          t.GRADENAME,
                          T.PROCESS_CDOE,
                          DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                                    nvl(t.ACT_WEIGHT, 0) weight
                                 from ydm_zc_stocktakinglist t
                               where 1=1
                                and t.VALIDFLAG = '1'
                                 and t.BAL_YEAR_MONTH >= ?
                                  and trunc(t.STOCKTAKING_TIME) <= to_date(?, 'yyyymmdd')
                                  and t.STOCKTAKING_TYPE_CODE = '800603'
                                  #condtions#)t where 1=1
                       
                          ]]>    
</query>
    <query id = "FrmrptProductStorage.getAdjust1" desc = "本期调差量">
        <![CDATA[
                             select t.PRODUCNAME,
                             t.STEELNAME,
                             t.SPEC_NAME,
                             t.MODEL_DESC,
                             t.STD_STYLE_DESC,
                             t.BELONG_NAME,
                             t.GRADENAME,

                             t.IS_DEALER,
                               sum(nvl(t.weight, 0)) aweight
                          from (select t.PRODUCNAME,
                          t.STEELNAME,
                          t.SPEC_NAME,
                          t.MODEL_DESC,
                          t.STD_STYLE_DESC,
                          t.BELONG_CODE,
                          t.BELONG_NAME,
                          t.GRADENAME,

                          DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
                                    nvl(t.ACT_WEIGHT, 0) weight
                                 from ydm_zc_stocktakinglist t
                               where 1=1
                                and t.VALIDFLAG = '1'
                                 and t.BAL_YEAR_MONTH >= ?
                                  and trunc(t.STOCKTAKING_TIME) <= to_date(?, 'yyyymmdd')
                                  and t.STOCKTAKING_TYPE_CODE = '800603'
                                  #condtions#)t where 1=1

                          ]]>
    </query>
<query id = "FrmrptProductStorage.getMatData" desc = "实时库存量">
<![CDATA[
select t.PRODUCNAME,
       t.STEELNAME,
       t.SPEC_NAME,
       t.MODEL_DESC,
       t.STD_STYLE_DESC,
       t.BELONG_NAME,
       t.GRADENAME,
       T.PROCESS_CDOE,
       t.IS_DEALER,
       sum(nvl(t.count,0))count,
       sum(nvl(t.weight, 0)) aweight
  from (select t.PRODUCNAME,
               t.STEELNAME,
               t.SPEC_NAME,
               t.MODEL_DESC,
               t.STD_STYLE_DESC,
               t.BELONG_CODE,
               t.BELONG_NAME,
               t.GRADENAME,
               t.PROCESS_CDOE,
               DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
               nvl(t.ACT_COUNT,0)count,
               nvl(t.ACT_WEIGHT, 0) weight
          from mat_zc_m t,ydm_zc_buttress s
         where 1 = 1
           and t.MAT_NO = s.mat_no
           and t.PRODUCT_FLAG = '801402'
         #condtions#
         UNION ALL
         select t.PRODUCNAME,
               t.STEELNAME,
               t.SPEC_NAME,
               t.MODEL_DESC,
               t.STD_STYLE_DESC,
               t.BELONG_CODE,
               t.BELONG_NAME,
               t.GRADENAME,
               T.PROCESS_CDOE,
               DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
               nvl(t.ACT_COUNT,0)count,
               nvl(t.ACT_WEIGHT, 0) weight
          from mat_zc_m t,ydm_zc_buttress s
         where 1 = 1
           and t.MAT_NO = s.mat_no
           and t.PRODUCT_FLAG = '801403'
         #condtions#) t
 where 1 = 1
 ]]>  
</query>
    <query id = "FrmrptProductStorage.getMatData1" desc = "实时库存量">
        <![CDATA[
select t.PRODUCNAME,
       t.STEELNAME,
       t.SPEC_NAME,
       t.MODEL_DESC,
       t.STD_STYLE_DESC,
       t.BELONG_NAME,
       t.GRADENAME,

       t.IS_DEALER,
       sum(nvl(t.count,0))count,
       sum(nvl(t.weight, 0)) aweight
  from (select t.PRODUCNAME,
               t.STEELNAME,
               t.SPEC_NAME,
               t.MODEL_DESC,
               t.STD_STYLE_DESC,
               t.BELONG_CODE,
               t.BELONG_NAME,
               t.GRADENAME,

               DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
               nvl(t.ACT_COUNT,0)count,
               nvl(t.ACT_WEIGHT, 0) weight
          from mat_zc_m t,ydm_zc_buttress s
         where 1 = 1
           and t.MAT_NO = s.mat_no
           and t.PRODUCT_FLAG = '801402'
         #condtions#
         UNION ALL
         select t.PRODUCNAME,
               t.STEELNAME,
               t.SPEC_NAME,
               t.MODEL_DESC,
               t.STD_STYLE_DESC,
               t.BELONG_CODE,
               t.BELONG_NAME,
               t.GRADENAME,

               DECODE(NVL(T.IS_DEALER,0),'0','自售','1','双经销','2','来料加工','3','定销订购')IS_DEALER,
               nvl(t.ACT_COUNT,0)count,
               nvl(t.ACT_WEIGHT, 0) weight
          from mat_zc_m t,ydm_zc_buttress s
         where 1 = 1
           and t.MAT_NO = s.mat_no
           and t.PRODUCT_FLAG = '801403'
         #condtions#) t
 where 1 = 1
 ]]>
    </query>
</queryMap>