<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "领导报表">
<query id = "FrmLeaderRpt.getOriginalLast" desc = "期初库存">
SELECT T.BELONG_NAME,
 sum(T.ACT_WEIGHT)ACT_WEIGHT
  FROM YDM_ZC_INITIAL T
 WHERE T.HANDLE_LOG = '1'
   AND T.BAL_YEAR_MONTH = ?
   group by T.BELONG_NAME
</query>
<query id = "FrmLeaderRpt.getThisIn" desc = "入库量">
SELECT T.BELONG_NAME,
 sum(T.ACT_WEIGHT)RKWGT
  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
</query>
<query id = "FrmLeaderRpt.getThisOut" desc = "出库量">
SELECT T.BELONG_NAME,
       SUM(CASE
             WHEN T.PONDER_NO IS NOT NULL THEN
              T.PONDER_GROSS_WT
             ELSE
              T.ACT_WEIGHT
           END) CKWGT
  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 T.BELONG_NAME
</query>
<query id = "FrmLeaderRpt.getAdjustWgt" desc = "调差量">
SELECT T.BELONG_NAME, SUM(NVL(T.ACT_WEIGHT, 0)) AS ADJUSTWGT
  FROM YDM_ZC_STOCKTAKINGLIST T
 WHERE T.BAL_YEAR_MONTH = ?
 AND T.BELONG_CODE IN ('100101','100102','100103')
 GROUP BY T.BELONG_NAME
</query>
<query id = "FrmLeaderRpt.getThisSwMat" desc = "实物库存">
SELECT T2.BELONG_NAME,
  SUM(T2.ACT_WEIGHT)SWWGT
  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')
 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'))T2
 GROUP BY T2.BELONG_NAME
</query>
<query id = "FrmLeaderRpt.getThisSwMat1" desc = "下月期初">
SELECT T.BELONG_NAME,
 sum(T.ACT_WEIGHT)SWWGT
  FROM YDM_ZC_INITIAL T
 WHERE T.HANDLE_LOG = '1'
   AND T.BAL_YEAR_MONTH = ?
   group by T.BELONG_NAME
</query>
<query id = "FrmLeaderRpt.getThisXsMat" desc = "销售账面库存">
<![CDATA[
SELECT SUM(B.WEIGHT)XSWGT,B.BELONG_NAME
 FROM (SELECT SUM(T.ACT_WEIGHT) AS WEIGHT, T.BELONG_NAME AS BELONG_NAME
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
 WHERE T.MAT_NO = S.MAT_NO
 AND T.BELONG_CODE IN ('100101','100102','100103')
 AND T.PRODUCT_FLAG > '801401'
 GROUP BY T.BELONG_NAME
UNION ALL
SELECT SUM(NVL(T2.ACT_WEIGHT, 0)) AS WEIGHT, T2.SALE_ORG_DESC AS BELONG_NAME
  FROM (SELECT T1.BILL_NO, T1.LOADVEHICLE_TYPE
          FROM YDM_ZC_BILL_M T1 where t1.loadvehicle_type = '2' and t1.ispreclose > '0' and t1.bill_status = '3'
         GROUP BY T1.BILL_NO, T1.LOADVEHICLE_TYPE) T6,
       YDM_ZC_LOADVEHICLE_MAT T2
 WHERE T6.BILL_NO = T2.BILL_NO(+)
   AND T2.VALIDFLAG >'1'
   AND T2.SALE_ORG IN ('100101','100102','100103')
 GROUP BY T2.SALE_ORG_DESC
UNION ALL
SELECT SUM(-T5.WEIGHT) AS WEIGHT, T5.SALE_ORG_DESC AS BELONG_NAME
  FROM (SELECT SUM(NVL(C.ACT_WEIGHT, 0)) AS WEIGHT, T4.SALE_ORG_DESC
          FROM (SELECT T1.BILL_NO, T1.LOADVEHICLE_TYPE, T1.BILL_STATUS,T1.ISPRECLOSE,T1.SALE_ORG_DESC
                  FROM YDM_ZC_BILL_M T1 WHERE T1.LOADVEHICLE_TYPE='2' AND T1.ISPRECLOSE>'0' and t1.bill_status = '3'
                 GROUP BY T1.BILL_NO, T1.LOADVEHICLE_TYPE, T1.BILL_STATUS,T1.ISPRECLOSE,T1.SALE_ORG_DESC) T4,
               YDM_ZC_LOADVEHICLE_MAT T3,YDM_ZC_BILL_C C
         WHERE T4.BILL_NO = C.BILL_NO
         AND C.MAT_NO=T3.MAT_NO(+)       
           --AND C.LOADVEHICLE_FLAG='0'
           AND T3.SALE_ORG IN ('100101','100102','100103')
         GROUP BY T4.SALE_ORG_DESC) T5
 GROUP BY T5.SALE_ORG_DESC)B GROUP BY B.BELONG_NAME
]]>
</query>
<query id = "FrmLeaderRpt.getThisCwMat" desc = "末次财务账面库存">
<![CDATA[
SELECT SUM(G.WEIGHT) CWWGT, G.BELONG_NAME
  FROM (SELECT SUM(T.ACT_WEIGHT) AS WEIGHT, T.BELONG_NAME
          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
         WHERE T.MAT_NO = S.MAT_NO
         AND T.BELONG_CODE IN ('100101','100102','100103')
         AND T.PRODUCT_FLAG > '801401'
         GROUP BY T.BELONG_NAME
        UNION ALL
        SELECT SUM(NVL(T2.ACT_WEIGHT, 0)) AS WEIGHT, T2.SALE_ORG_DESC
          FROM (SELECT T1.BILL_NO, T1.LOADVEHICLE_TYPE
                  FROM YDM_ZC_BILL_M T1 WHERE T1.LOADVEHICLE_TYPE = '2' AND T1.REALINVOICENO IS NULL and t1.ispreclose > '0' and t1.bill_status = '3'
                 GROUP BY T1.BILL_NO, T1.LOADVEHICLE_TYPE) T6,
               YDM_ZC_LOADVEHICLE_MAT T2
         WHERE T6.BILL_NO = T2.BILL_NO
           AND T2.VALIDFLAG > '1'
           --AND T2.BAL_YEAR_MONTH = ?
          AND T2.SALE_ORG IN ('100101','100102','100103')
         GROUP BY T2.SALE_ORG_DESC
        UNION ALL
        SELECT SUM(-T5.WEIGHT) AS WEIGHT, T5.SALE_ORG_DESC
          FROM (SELECT SUM(NVL(C.ACT_WEIGHT, 0)) AS WEIGHT, T4.SALE_ORG_DESC
                  FROM (SELECT T1.BILL_NO,
                               T1.LOADVEHICLE_TYPE,
                               T1.BILL_STATUS,
                               T1.ISPRECLOSE,
                               T1.SALE_ORG_DESC
                          FROM YDM_ZC_BILL_M T1
                         WHERE T1.LOADVEHICLE_TYPE = '2'
                           AND T1.ISPRECLOSE > '0'
                           AND T1.REALINVOICENO IS NULL
                         GROUP BY T1.BILL_NO,
                                  T1.LOADVEHICLE_TYPE,
                                  T1.BILL_STATUS,
                                  T1.ISPRECLOSE,
                                  T1.SALE_ORG_DESC) T4,
                       YDM_ZC_LOADVEHICLE_MAT T3,
                       YDM_ZC_BILL_C C
                 WHERE T4.BILL_NO = C.BILL_NO
                   AND C.MAT_NO = T3.MAT_NO(+)
                   --AND C.LOADVEHICLE_FLAG = '0'
                   --AND T3.BAL_YEAR_MONTH = ?
                   AND T3.SALE_ORG IN ('100101','100102','100103')
                 GROUP BY T4.SALE_ORG_DESC) T5
         GROUP BY T5.SALE_ORG_DESC
        UNION ALL
        SELECT SUM(NVL(T11.WEIGHT, 0)) WEIGHT, T11.SALE_ORG_DESC
          FROM (SELECT T8.SALE_ORG_DESC,
                       SUM(NVL(CASE
                                 WHEN M.PRT_FLAG = '0' AND T9.VALIDFLAG > '1' THEN
                                  T9.ACT_WEIGHT
                                 WHEN M.PRT_FLAG = '1' AND T9.VALIDFLAG > '1' THEN
                                  T9.PONDER_GROSS_WT
                               END,
                               0)) WEIGHT
                
                  FROM (SELECT T7.BILL_NO,
                               T7.LOADVEHICLE_TYPE,
                               T7.BILL_STATUS,
                               T7.SALE_ORG_DESC
                          FROM YDM_ZC_BILL_M T7
                         WHERE T7.LOADVEHICLE_TYPE = '1'
                           AND T7.BILL_STATUS IN ('4', '5')
                           AND T7.REALINVOICENO IS NULL
                         GROUP BY T7.BILL_NO,
                                  T7.LOADVEHICLE_TYPE,
                                  T7.BILL_STATUS,
                                  T7.SALE_ORG_DESC) T8,
                       YDM_ZC_LOADVEHICLE_MAT T9,
                       YDM_ZC_BILL_C M
                 WHERE T8.BILL_NO = T9.BILL_NO
                   AND M.MAT_NO = T9.MAT_NO(+)
                   --AND T9.BAL_YEAR_MONTH = ?
                   AND T9.SALE_ORG IN ('100101','100102','100103')
                 GROUP BY T8.SALE_ORG_DESC) T11
         GROUP BY T11.SALE_ORG_DESC
        UNION ALL
        SELECT SUM(NVL(T11.WEIGHT, 0)) WEIGHT, T11.SALE_ORG_DESC
          FROM (SELECT T8.SALE_ORG_DESC, SUM(NVL(T9.ACT_WEIGHT, 0)) AS WEIGHT
                  FROM (SELECT T7.BILL_NO,
                               T7.LOADVEHICLE_TYPE,
                               T7.BILL_STATUS,
                               T7.SALE_ORG_DESC
                          FROM YDM_ZC_BILL_M T7
                         WHERE T7.LOADVEHICLE_TYPE = '2'
                           AND T7.BILL_STATUS = '4'
                           AND T7.REALINVOICENO IS NULL
                         GROUP BY T7.BILL_NO,
                                  T7.LOADVEHICLE_TYPE,
                                  T7.BILL_STATUS,
                                  T7.SALE_ORG_DESC) T8,
                       YDM_ZC_LOADVEHICLE_MAT T9,
                       YDM_ZC_BILL_C M
                 WHERE T8.BILL_NO = T9.BILL_NO
                   AND M.MAT_NO = T9.MAT_NO(+)
                   --AND T9.BAL_YEAR_MONTH = ?
                   AND T9.SALE_ORG IN ('100101','100102','100103')
                 GROUP BY T8.SALE_ORG_DESC) T11
         GROUP BY T11.SALE_ORG_DESC) G
 GROUP BY G.BELONG_NAME
]]>
</query>
<query id = "FrmLeaderRpt.getThisCwMat1" desc = "首次财务账面库存">
<![CDATA[
SELECT SUM(G.WEIGHT) CWWGT1, G.BELONG_NAME
  FROM (SELECT SUM(T.ACT_WEIGHT) AS WEIGHT, T.BELONG_NAME
          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
         WHERE T.MAT_NO = S.MAT_NO
         AND T.BELONG_CODE IN ('100101','100102','100103')
         AND T.PRODUCT_FLAG > '801401'
         GROUP BY T.BELONG_NAME
        UNION ALL
        SELECT SUM(NVL(T2.ACT_WEIGHT, 0)) AS WEIGHT, T2.SALE_ORG_DESC
          FROM (SELECT T1.BILL_NO, T1.LOADVEHICLE_TYPE
                  FROM YDM_ZC_BILL_M T1 WHERE T1.LOADVEHICLE_TYPE = '2' AND T1.REALINVOICENO1 IS NULL and t1.ispreclose > '0' and t1.bill_status = '3'
                 GROUP BY T1.BILL_NO, T1.LOADVEHICLE_TYPE) T6,
               YDM_ZC_LOADVEHICLE_MAT T2
         WHERE T6.BILL_NO = T2.BILL_NO
           AND T2.VALIDFLAG > '1'
           --AND T2.BAL_YEAR_MONTH = ?
           AND T2.SALE_ORG IN ('100101','100102','100103')
         GROUP BY T2.SALE_ORG_DESC
        UNION ALL
        SELECT SUM(-T5.WEIGHT) AS WEIGHT, T5.SALE_ORG_DESC
          FROM (SELECT SUM(NVL(C.ACT_WEIGHT, 0)) AS WEIGHT, T4.SALE_ORG_DESC
                  FROM (SELECT T1.BILL_NO,
                               T1.LOADVEHICLE_TYPE,
                               T1.BILL_STATUS,
                               T1.ISPRECLOSE,
                               T1.SALE_ORG_DESC
                          FROM YDM_ZC_BILL_M T1
                         WHERE T1.LOADVEHICLE_TYPE = '2'
                           AND T1.ISPRECLOSE > '0'
                           AND T1.REALINVOICENO1 IS NULL
                         GROUP BY T1.BILL_NO,
                                  T1.LOADVEHICLE_TYPE,
                                  T1.BILL_STATUS,
                                  T1.ISPRECLOSE,
                                  T1.SALE_ORG_DESC) T4,
                       YDM_ZC_LOADVEHICLE_MAT T3,
                       YDM_ZC_BILL_C C
                 WHERE T4.BILL_NO = C.BILL_NO
                   AND C.MAT_NO = T3.MAT_NO(+)
                   --AND C.LOADVEHICLE_FLAG = '0'
                   --AND T3.BAL_YEAR_MONTH = ?
                   AND T3.SALE_ORG IN ('100101','100102','100103')
                 GROUP BY T4.SALE_ORG_DESC) T5
         GROUP BY T5.SALE_ORG_DESC
        UNION ALL
        SELECT SUM(NVL(T11.WEIGHT, 0)) WEIGHT, T11.SALE_ORG_DESC
          FROM (SELECT T8.SALE_ORG_DESC,
                       SUM(NVL(CASE
                                 WHEN M.PRT_FLAG = '0' AND T9.VALIDFLAG > '1' THEN
                                  T9.ACT_WEIGHT
                                 WHEN M.PRT_FLAG = '1' AND T9.VALIDFLAG > '1' THEN
                                  T9.PONDER_GROSS_WT
                               END,
                               0)) WEIGHT
                
                  FROM (SELECT T7.BILL_NO,
                               T7.LOADVEHICLE_TYPE,
                               T7.BILL_STATUS,
                               T7.SALE_ORG_DESC
                          FROM YDM_ZC_BILL_M T7
                         WHERE T7.LOADVEHICLE_TYPE = '1'
                           AND T7.BILL_STATUS IN ('4', '5')
                           AND T7.REALINVOICENO1 IS NULL
                         GROUP BY T7.BILL_NO,
                                  T7.LOADVEHICLE_TYPE,
                                  T7.BILL_STATUS,
                                  T7.SALE_ORG_DESC) T8,
                       YDM_ZC_LOADVEHICLE_MAT T9,
                       YDM_ZC_BILL_C M
                 WHERE T8.BILL_NO = T9.BILL_NO
                   AND M.MAT_NO = T9.MAT_NO(+)
                   --AND T9.BAL_YEAR_MONTH = ?
                   AND T9.SALE_ORG IN ('100101','100102','100103')
                 GROUP BY T8.SALE_ORG_DESC) T11
         GROUP BY T11.SALE_ORG_DESC
        UNION ALL
        SELECT SUM(NVL(T11.WEIGHT, 0)) WEIGHT, T11.SALE_ORG_DESC
          FROM (SELECT T8.SALE_ORG_DESC, SUM(NVL(T9.ACT_WEIGHT, 0)) AS WEIGHT
                  FROM (SELECT T7.BILL_NO,
                               T7.LOADVEHICLE_TYPE,
                               T7.BILL_STATUS,
                               T7.SALE_ORG_DESC
                          FROM YDM_ZC_BILL_M T7
                         WHERE T7.LOADVEHICLE_TYPE = '2'
                           AND T7.BILL_STATUS = '4'
                           AND T7.REALINVOICENO1 IS NULL
                         GROUP BY T7.BILL_NO,
                                  T7.LOADVEHICLE_TYPE,
                                  T7.BILL_STATUS,
                                  T7.SALE_ORG_DESC) T8,
                       YDM_ZC_LOADVEHICLE_MAT T9,
                       YDM_ZC_BILL_C M
                 WHERE T8.BILL_NO = T9.BILL_NO
                   AND M.MAT_NO = T9.MAT_NO(+)
                   --AND T9.BAL_YEAR_MONTH = ?
                   AND T9.SALE_ORG IN ('100101','100102','100103')
                 GROUP BY T8.SALE_ORG_DESC) T11
         GROUP BY T11.SALE_ORG_DESC) G
 GROUP BY G.BELONG_NAME
]]>
</query>
<query id = "FrmLeaderRpt.doQueryData" desc = "查询">
SELECT T.INI_NUM AS ACT_WEIGHT,
       T.IN_NUM AS RUWGT,
       T.OUT_NUM AS CKWGT,
       T.ESC_NUM AS ADJUSTWGT,
       T.STG_NUM AS SWWGT,
       T.SEL_NUM AS XSWGT,
       T.FIN_NUM2 AS CWWGT,
        T.FIN_NUM1 AS CWWGT2,
        T.SALE_ORG_DESC AS BELONG_NAME
 FROM RPT_SELYDM_STATISTICS T WHERE T.BAL_YEAR_MONTH = ?
</query>
</queryMap>