<?xml version="1.0" encoding="UTF-8"?>
<queryMap>
<query id = "FrmGeneralStatistics.doQuery" desc = "查询">

SELECT BELONG_NAME,
       SUM(ONDAYINWGT) ONDAYINWGT,
       SUM(INALLWGT)INALLWGT,
       SUM(ONDAYOUTWGT)ONDAYOUTWGT,
       SUM(SUMWGT)SUMWGT,
       SUM(RAILWAYWGT)RAILWAYWGT,
       SUM(TARGETWGT)TARGETWGT,
       SUM(ENDWGT)ENDWGT,
       SUM(ENDWGT - BEGINWGT)INCREMENTWGT FROM
       (
SELECT T.BELONG_NAME,
       SUM(T.ACT_WEIGHT) ONDAYINWGT,
       0 INALLWGT,
       0 ONDAYOUTWGT,
       0 SUMWGT,
       0 RAILWAYWGT,
       0 TARGETWGT,
       0 ENDWGT,
       0 BEGINWGT
  FROM YDM_ZC_INLIST T
 WHERE TRUNC(T.INSTOCK_TIME) = TRUNC(SYSDATE)
   AND T.BAL_YEAR_MONTH = ?
   AND T.INSTOCK_TYPE_CODE IN ('800701', '800702', '800704', '800706')
   AND T.BELONG_CODE IN ('100101','100102','100103')
 GROUP BY T.BELONG_NAME
UNION ALL
SELECT T.BELONG_NAME,
       0 ONDAYINWGT,
       SUM(T.ACT_WEIGHT) INALLWGT,
       0 ONDAYOUTWGT,
       0 SUMWGT,
       0 RAILWAYWGT,
       0 TARGETWGT,
       0 ENDWGT,
       0 BEGINWGT
  FROM YDM_ZC_INLIST T
 WHERE T.INSTOCK_TYPE_CODE IN ('800701', '800702', '800704', '800706')
 AND T.BAL_YEAR_MONTH = ?
 AND T.BELONG_CODE IN ('100101','100102','100103')
 GROUP BY T.BELONG_NAME
UNION ALL
SELECT BELONG_NAME,
       0 ONDAYINWGT,
       0 INALLWGT,
       SUM(WEIGHT) ONDAYOUTWGT,
       0 SUMWGT,
       0 RAILWAYWGT,
       0 TARGETWGT,
       0 ENDWGT,
       0 BEGINWGT
  FROM (SELECT T.BELONG_NAME,
               0 ONDAYINWGT,
               0 INALLWGT,
               CASE
                 WHEN T.PONDER_NO IS NULL THEN
                  NVL(T.ACT_WEIGHT, 0)
                 ELSE
                  NVL(T.PONDER_GROSS_WT, 0)
               END AS WEIGHT,
               0 SUMWGT,
               0 RAILWAYWGT,
               0 TARGETWGT,
               0 ENDWGT,
               0 BEGINWGT
          FROM YDM_ZC_OUTLIST T
         WHERE TRUNC(T.OUTSTOCK_TIME) = TRUNC(SYSDATE)
           AND T.BAL_YEAR_MONTH = ?
           AND T.OUTSTOCK_TYPE_CODE IN
               ('800802', '800805', '800806', '800808')
               AND T.BELONG_CODE IN ('100101','100102','100103'))
 GROUP BY BELONG_NAME
UNION ALL
SELECT BELONG_NAME,
       0 ONDAYINWGT,
       0 INALLWGT,
       0 ONDAYOUTWGT,
       SUM(WEIGHT) SUMWGT,
       0 RAILWAYWGT,
       0 TARGETWGT,
       0 ENDWGT,
       0 BEGINWGT
  FROM (SELECT T.BELONG_NAME,
               0 ONDAYINWGT,
               0 INALLWGT,
               0 ONDAYOUTWGT,
               CASE
                 WHEN T.PONDER_NO IS NULL THEN
                  NVL(T.ACT_WEIGHT, 0)
                 ELSE
                  NVL(T.PONDER_GROSS_WT, 0)
               END AS WEIGHT,
               0 RAILWAYWGT,
               0 TARGETWGT,
               0 ENDWGT,
               0 BEGINWGT
          FROM YDM_ZC_OUTLIST T
         WHERE T.OUTSTOCK_TYPE_CODE IN
               ('800802', '800805', '800806', '800808')
               AND T.BAL_YEAR_MONTH = ?
               AND T.BELONG_CODE IN ('100101','100102','100103'))    
 GROUP BY BELONG_NAME
UNION ALL
SELECT T.BELONG_NAME,
       0 ONDAYINWGT,
       0 INALLWGT,
       0 ONDAYOUTWGT,
       0 SUMWGT,
       SUM(T.ACT_WEIGHT) RAILWAYWGT,
       0 TARGETWGT,
       0 ENDWGT,
       0 BEGINWGT
  FROM YDM_ZC_OUTLIST T, YDM_ZC_LOADVEHICLE_MAT S
 WHERE T.MAT_NO = S.MAT_NO
   AND S.TRANS_TPE = '110502'
   AND T.OUTSTOCK_TYPE_CODE IN
               ('800802', '800805', '800806', '800808')
   AND T.BAL_YEAR_MONTH = ?
   AND T.BELONG_CODE IN ('100101','100102','100103')
 GROUP BY T.BELONG_NAME
UNION ALL
SELECT BELONG_NAME,
       0 ONDAYINWGT,
       0 INALLWGT,
       0 ONDAYOUTWGT,
       0 SUMWGT,
       0 RAILWAYWGT,
       SUM(WEIGHT) TARGETWGT,
       0 ENDWGT,
       0 BEGINWGT
  FROM (SELECT T.BELONG_NAME,
               0 ONDAYINWGT,
               0 INALLWGT,
               0 ONDAYOUTWGT,
               0 SUMWGT,
               0 RAILWAYWGT,
               CASE
                 WHEN T.PONDER_NO IS NULL THEN
                  NVL(T.ACT_WEIGHT, 0)
                 ELSE
                  NVL(T.PONDER_GROSS_WT, 0)
               END AS WEIGHT,
               0 ENDWGT,
               0 BEGINWGT
          FROM YDM_ZC_OUTLIST T
          LEFT JOIN SLM_ORDER_LINE_DELIVERY S ON T.ORD_LN_DLY_PK =
                                                 S.ORD_LN_DLY_PK
         WHERE T.OUTSTOCK_TYPE_CODE IN ('800802', '800805', '800806', '800808')
           AND T.BAL_YEAR_MONTH = ?
           AND T.BELONG_CODE IN ('100101','100102','100103')
           AND (S.DELVRY_ADDR IN
               ('客户库-腾飞', '客户库-宝仓', '客户库-安利', '客户库-润德', '客户库-三圆南' ,'客户库-思创' ,'客户库-滨城')
               OR T.STORAGE_NO IN ('LJZ1','LYD1','LZG1')))
 GROUP BY BELONG_NAME
UNION ALL
SELECT T1.BELONG_NAME,
       0 ONDAYINWGT,
       0 INALLWGT,
       0 ONDAYOUTWGT,
       0 SUMWGT,
       0 RAILWAYWGT,
       0 TARGETWGT,
       SUM(T1.ACT_WEIGHT) ENDWGT,
       0 BEGINWGT
  FROM (SELECT T.BELONG_NAME, T.ACT_WEIGHT
          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
         WHERE T.MAT_NO = S.MAT_NO
           AND T.PRODUCT_FLAG = '801402'
           AND T.BELONG_CODE IN ('100101', '100102', '100103','100105')
        UNION ALL
        SELECT T.BELONG_NAME, T.ACT_WEIGHT
          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
         WHERE T.MAT_NO = S.MAT_NO
           AND T.PRODUCT_FLAG = '801403'
           AND T.BELONG_CODE IN ('100101', '100102', '100103','100105'))T1
 GROUP BY T1.BELONG_NAME
UNION ALL
SELECT T.BELONG_NAME,
       0 ONDAYINWGT,
       0 INALLWGT,
       0 ONDAYOUTWGT,
       0 SUMWGT,
       0 RAILWAYWGT,
       0 TARGETWGT,
       0 ENDWGT,
       SUM(T.ACT_WEIGHT) BEGINWGT
  FROM YDM_ZC_INITIAL T
 WHERE T.BAL_YEAR_MONTH = ?
 AND T.BELONG_CODE IN ('100101','100102','100103')
 GROUP BY T.BELONG_NAME
 )
 GROUP BY BELONG_NAME
</query>
<query id = "FrmGeneralStatistics.doQueryDataB" desc = "查询">
SELECT * FROM RPT_YDMSTOCK_STATISTICS T WHERE T.BAL_YEAR_MONTH = ?
</query>
</queryMap>