<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "出库结算统计">
<query id = "FrmrptSendClosing.getSOutWgt" desc="取出库实单量">
<![CDATA[
SELECT BILL_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PRODUCNAME,
       STD_STYLE_DESC,
       STEELNAME,
       SPEC_NAME,
       MODEL_DESC,
       SUM(SOUTCOUNT) SOUTCOUNT,
       SUM(SOUTWEIGHT)SOUTWEIGHT
  FROM (SELECT F.BILL_NO,
               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,
               SUM(T.ACT_COUNT) AS SOUTCOUNT,
               SUM(CASE
                     WHEN T.PONDER_NO IS NULL THEN
                      NVL(T.ACT_WEIGHT, 0)
                     ELSE
                      NVL(T.PONDER_GROSS_WT, 0)
                   END) AS SOUTWEIGHT
          FROM YDM_ZC_OUTLIST T,
               (SELECT S.BILL_NO, Z.MAT_NO
                  FROM (SELECT BILL_NO
                          FROM YDM_ZC_BILL_M
                         WHERE LOADVEHICLE_TYPE = '1'
                         AND RETURN_FLAG='0'
                         GROUP BY BILL_NO) S,
                       YDM_ZC_BILL_C Z
                 WHERE S.BILL_NO = Z.BILL_NO
                 AND Z.RETURN_FLAG='0') F
         WHERE T.MAT_NO = F.MAT_NO
           AND T.OUTSTOCK_TYPE_CODE = '800805'
           AND T.BAL_YEAR_MONTH = ?
         GROUP BY F.BILL_NO,
                  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
        UNION ALL
        SELECT T.M_BILL_NO AS BILL_NO,
               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,
               SUM(T.ACT_COUNT) SOUTCOUNT,
               SUM(CASE
                     WHEN T.PONDER_NO IS NULL THEN
                      NVL(T.ACT_WEIGHT, 0)
                     ELSE
                      NVL(T.PONDER_GROSS_WT, 0)
                   END) AS SOUTWEIGHT
          FROM YDM_ZC_OUTLIST T
         WHERE
            T.OUTSTOCK_TYPE_CODE = '800806'
            AND T.BAL_YEAR_MONTH = ?
            AND T.HAND_FLAG = '0'
         GROUP BY T.M_BILL_NO,
                  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)
 WHERE 1 = 1
 ]]>
</query>
<query id = "FrmrptSendClosing.getXOutWgt" desc = "取出库虚单量">
<![CDATA[
SELECT T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.GROUP_NO AS BATCH_GROUD_NO,
       T.PRODUCNAME,
               T.STD_STYLE_DESC,
               T.STEELNAME,
               T.SPEC_NAME,
               T.MODEL_DESC,
       SUM(T.ACT_COUNT) AS XOUTCOUNT,
       SUM(T.ACT_WEIGHT) AS XOUTWEIGHT,
       T.BILL_NO
  FROM YDM_ZC_BILL_C T,
       (SELECT BILL_NO,SALE_ORG
          FROM YDM_ZC_BILL_M
         WHERE (ISPRECLOSE >'0'
           or bill_status > '3')
           AND LOADVEHICLE_TYPE = '2'
           AND BAL_YEAR_MONTH = ?
         GROUP BY BILL_NO,SALE_ORG) S
 WHERE T.BILL_NO = S.BILL_NO
 
]]>
</query>
<query id = "FrmrptSendClosing.getSClosingWgt" 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(T.ACT_COUNT)SCLOSINGCOUNT,
       SUM(T.ACT_WGT)SCLOSINGWEIGHT,
       T.BILL_NO
  FROM (SELECT SUBSTR(B.BATCH_NO, 0, INSTR(B.BATCH_NO, '/') - 1) JUDGE_STOVE_NO,
               SUBSTR(B.BATCH_NO, INSTR(B.BATCH_NO, '/') + 1) BATCH_NO,
               B.INV_NO AS BATCH_GROUD_NO,
               B.PD_NAME AS PRODUCNAME,
               B.STD_STYLE_DESC,
               B.STEELNAME,
               B.SPETKEY AS SPEC_NAME,
               B.MODEL_DESC,
               CASE
                 WHEN A.BALANCESTATUS_ORG = '3' AND
                      A.REALINVOICENO_ORG IS NOT NULL THEN
                  '1'
                 ELSE
                  '0'
               END INVFLAG,
               B.PRD_QTY AS ACT_COUNT,
               B.ACT_WGT AS ACT_WGT,
               A.FORECORPCODE,
               B.ASKPLAN_ID AS BILL_NO
  FROM SLM_BALANCEINFO A
  JOIN SLM_BALANCEDETAIL_ALL B ON A.ORD_NO = B.ORD_NO
                              AND A.ORD_SEQ = B.ORD_SEQ
                              AND A.ORD_LN_DLY = B.ORD_LN_DLY
                              AND A.ASKPLAN_ID = B.ASKPLAN_ID
                              AND A.ASKPLAN_ID_SEQ = B.ASKPLAN_ID_SEQ
                              AND A.STEELCODEKEY = B.STEELCODEKEY
                              AND A.SPETKEY = B.SPETKEY
 WHERE A.FORECORPCODE = '国际贸易部' AND B.ISPRECLOSE = '0'
 AND A.INVOICE_MONTH = ?
 UNION ALL 
 SELECT SUBSTR(B.BATCH_NO, 0, INSTR(B.BATCH_NO, '/') - 1) JUDGE_STOVE_NO,
               SUBSTR(B.BATCH_NO, INSTR(B.BATCH_NO, '/') + 1) BATCH_NO,
               B.INV_NO AS BATCH_GROUD_NO,
               B.PD_NAME AS PRODUCNAME,
               B.STD_STYLE_DESC,
               B.STEELNAME,
               B.SPETKEY AS SPEC_NAME,
               B.MODEL_DESC,
       CASE
         WHEN A.BALANCESTATUS = '3' AND A.REALINVOICENO IS NOT NULL THEN
          '1'
         ELSE
          '0'
       END INVFLAG,
       B.PRD_QTY AS ACT_COUNT,
               B.ACT_WGT AS ACT_WGT,
               A.FORECORPCODE,
               B.ASKPLAN_ID AS BILL_NO
  FROM SLM_BALANCEINFO A
  JOIN SLM_BALANCEDETAIL_ALL B ON A.ORD_NO = B.ORD_NO
                              AND A.ORD_SEQ = B.ORD_SEQ
                              AND A.ORD_LN_DLY = B.ORD_LN_DLY
                              AND A.ASKPLAN_ID = B.ASKPLAN_ID
                              AND A.ASKPLAN_ID_SEQ = B.ASKPLAN_ID_SEQ
                              AND A.STEELCODEKEY = B.STEELCODEKEY
                              AND A.SPETKEY = B.SPETKEY
WHERE A.FORECORPCODE <> '国际贸易部' AND B.ISPRECLOSE = '0' 
 AND A.INVOICE_MONTH = ?
   ) T
 WHERE T.INVFLAG = '1' 
 
  ]]>
</query>
<query id = "FrmrptSendClosing.getXClosingWgt" 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(T.ACT_COUNT)XCLOSINGCOUNT,
       SUM(T.ACT_WGT)XCLOSINGWEIGHT,
       T.BILL_NO
  FROM (SELECT SUBSTR(B.BATCH_NO, 0, INSTR(B.BATCH_NO, '/') - 1) JUDGE_STOVE_NO,
               SUBSTR(B.BATCH_NO, INSTR(B.BATCH_NO, '/') + 1) BATCH_NO,
               B.INV_NO AS BATCH_GROUD_NO,
               B.PD_NAME AS PRODUCNAME,
               B.STD_STYLE_DESC,
               B.STEELNAME,
               B.SPETKEY AS SPEC_NAME,
               B.MODEL_DESC,
               CASE
                 WHEN A.BALANCESTATUS_ORG = '3' AND
                      A.REALINVOICENO_ORG IS NOT NULL THEN
                  '1'
                 ELSE
                  '0'
               END INVFLAG,
               B.PRD_QTY AS ACT_COUNT,
               B.ACT_WGT AS ACT_WGT,
               A.FORECORPCODE,
               B.ASKPLAN_ID AS BILL_NO
  FROM SLM_BALANCEINFO A
  JOIN SLM_BALANCEDETAIL_ALL B ON A.ORD_NO = B.ORD_NO
                              AND A.ORD_SEQ = B.ORD_SEQ
                              AND A.ORD_LN_DLY = B.ORD_LN_DLY
                              AND A.ASKPLAN_ID = B.ASKPLAN_ID
                              AND A.ASKPLAN_ID_SEQ = B.ASKPLAN_ID_SEQ
                              AND A.STEELCODEKEY = B.STEELCODEKEY
                              AND A.SPETKEY = B.SPETKEY
 WHERE A.FORECORPCODE = '国际贸易部' AND B.ISPRECLOSE = '1'
   AND A.INVOICE_MONTH = ?
 UNION ALL 
 SELECT SUBSTR(B.BATCH_NO, 0, INSTR(B.BATCH_NO, '/') - 1) JUDGE_STOVE_NO,
               SUBSTR(B.BATCH_NO, INSTR(B.BATCH_NO, '/') + 1) BATCH_NO,
               B.INV_NO AS BATCH_GROUD_NO,
               B.PD_NAME AS PRODUCNAME,
               B.STD_STYLE_DESC,
               B.STEELNAME,
               B.SPETKEY AS SPEC_NAME,
               B.MODEL_DESC,
       CASE
         WHEN A.BALANCESTATUS = '3' AND A.REALINVOICENO IS NOT NULL THEN
          '1'
         ELSE
          '0'
       END INVFLAG,
       B.PRD_QTY AS ACT_COUNT,
               B.ACT_WGT AS ACT_WGT,
               A.FORECORPCODE,
               B.ASKPLAN_ID AS BILL_NO
  FROM SLM_BALANCEINFO A
  JOIN SLM_BALANCEDETAIL_ALL B ON A.ORD_NO = B.ORD_NO
                              AND A.ORD_SEQ = B.ORD_SEQ
                              AND A.ORD_LN_DLY = B.ORD_LN_DLY
                              AND A.ASKPLAN_ID = B.ASKPLAN_ID
                              AND A.ASKPLAN_ID_SEQ = B.ASKPLAN_ID_SEQ
                              AND A.STEELCODEKEY = B.STEELCODEKEY
                              AND A.SPETKEY = B.SPETKEY
WHERE A.FORECORPCODE <> '国际贸易部' AND B.ISPRECLOSE = '1' 
 AND A.INVOICE_MONTH = ?
   ) T
 WHERE T.INVFLAG = '1'
 
  ]]>
</query>
<query id = "FrmrptSendClosing.getRealNoClosingWgt" 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(T.ACT_COUNT)TIMEPOINTCOUNT,
       SUM(T.ACT_WGT)TIMEPOINTWEIGHT,
       T.BILL_NO
  FROM (SELECT SUBSTR(B.BATCH_NO, 0, INSTR(B.BATCH_NO, '/') - 1) JUDGE_STOVE_NO,
               SUBSTR(B.BATCH_NO, INSTR(B.BATCH_NO, '/') + 1) BATCH_NO,
               B.INV_NO AS BATCH_GROUD_NO,
                B.PD_NAME AS PRODUCNAME,
               B.STD_STYLE_DESC,
               B.STEELNAME,
               B.SPETKEY AS SPEC_NAME,
               B.MODEL_DESC,
               CASE
                 WHEN A.BALANCESTATUS_ORG = '3' AND
                      A.REALINVOICENO_ORG IS NOT NULL THEN
                  '1'
                 ELSE
                  '0'
               END INVFLAG,
               B.PRD_QTY AS ACT_COUNT,
               B.ACT_WGT AS ACT_WGT,
               A.FORECORPCODE,
               B.ASKPLAN_ID AS BILL_NO
  FROM SLM_BALANCEINFO A
  JOIN SLM_BALANCEDETAIL_ALL B ON A.ORD_NO = B.ORD_NO
                              AND A.ORD_SEQ = B.ORD_SEQ
                              AND A.ORD_LN_DLY = B.ORD_LN_DLY
                              AND A.ASKPLAN_ID = B.ASKPLAN_ID
                              AND A.ASKPLAN_ID_SEQ = B.ASKPLAN_ID_SEQ
                              AND A.STEELCODEKEY = B.STEELCODEKEY
                              AND A.SPETKEY = B.SPETKEY
 WHERE A.FORECORPCODE = '国际贸易部'
 AND A.INVOICE_MONTH = ? 
 UNION ALL 
 SELECT SUBSTR(B.BATCH_NO, 0, INSTR(B.BATCH_NO, '/') - 1) JUDGE_STOVE_NO,
               SUBSTR(B.BATCH_NO, INSTR(B.BATCH_NO, '/') + 1) BATCH_NO,
               B.INV_NO AS BATCH_GROUD_NO,
                B.PD_NAME AS PRODUCNAME,
               B.STD_STYLE_DESC,
               B.STEELNAME,
               B.SPETKEY AS SPEC_NAME,
               B.MODEL_DESC,
       CASE
         WHEN A.BALANCESTATUS = '3' AND A.REALINVOICENO IS NOT NULL THEN
          '1'
         ELSE
          '0'
       END INVFLAG,
       B.PRD_QTY AS ACT_COUNT,
               B.ACT_WGT AS ACT_WGT,
               A.FORECORPCODE,
               B.ASKPLAN_ID AS BILL_NO
  FROM SLM_BALANCEINFO A
  JOIN SLM_BALANCEDETAIL_ALL B ON A.ORD_NO = B.ORD_NO
                              AND A.ORD_SEQ = B.ORD_SEQ
                              AND A.ORD_LN_DLY = B.ORD_LN_DLY
                              AND A.ASKPLAN_ID = B.ASKPLAN_ID
                              AND A.ASKPLAN_ID_SEQ = B.ASKPLAN_ID_SEQ
                              AND A.STEELCODEKEY = B.STEELCODEKEY
                              AND A.SPETKEY = B.SPETKEY
WHERE A.FORECORPCODE <> '国际贸易部' 
AND INVOICE_MONTH = ?
   ) T
 WHERE T.INVFLAG = '0'
 
   ]]>
</query>
<query id = "FrmrptSendClosing.getReaggedWgt" desc = "票据未对齐">
<![CDATA[
SELECT BILL_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PRODUCNAME,
       STD_STYLE_DESC,
       STEELNAME,
       SPEC_NAME,
       MODEL_DESC,
       SUM(ACT_COUNT) RAGGEDCOUNT,
       SUM(ACT_WEIGHT) RAGGEDWEIGHT
  FROM (SELECT T.BILL_NO,
               T.JUDGE_STOVE_NO,
               T.BATCH_NO,
               T.GROUP_NO AS BATCH_GROUD_NO,
               T.PRODUCNAME,
               T.STD_STYLE_DESC,
               T.STEELNAME,
               T.SPEC_NAME,
               T.MODEL_DESC,
               SUM(T.ACT_COUNT) ACT_COUNT,
               SUM(CASE
                     WHEN T.PONDER_NO IS NULL THEN
                      NVL(T.ACT_WEIGHT, 0)
                     ELSE
                      NVL(T.PONDER_GROSS_WT, 0)
                   END) AS ACT_WEIGHT,
               F.SALE_ORG
          FROM YDM_ZC_LOADVEHICLE_MAT T,
               (SELECT BILL_NO, SALE_ORG
                  FROM YDM_ZC_BILL_M
                 WHERE BILL_TICKET_STATUS IN ('0', '1')
                   AND LOADVEHICLE_TYPE = '1' 
                 GROUP BY BILL_NO, SALE_ORG) F
         WHERE T.BILL_NO = F.BILL_NO
           AND T.VALIDFLAG > '1'
           AND T.BAL_YEAR_MONTH = ?
         GROUP BY T.BILL_NO,
                  T.JUDGE_STOVE_NO,
                  T.BATCH_NO,
                  T.GROUP_NO,
                  F.SALE_ORG,
                  T.PRODUCNAME,
               T.STD_STYLE_DESC,
               T.STEELNAME,
               T.SPEC_NAME,
               T.MODEL_DESC
        UNION ALL
        SELECT S.BILL_NO,
               S.JUDGE_STOVE_NO,
               S.BATCH_NO,
               S.GROUP_NO AS BATCH_GROUD_NO,
               S.PRODUCNAME,
               S.STD_STYLE_DESC,
               S.STEELNAME,
               S.SPEC_NAME,
               S.MODEL_DESC,
               SUM(S.ACT_COUNT) ACT_COUNT,
               SUM(S.ACT_WEIGHT) ACT_WEIGHT,
               T.SALE_ORG
          FROM (SELECT BILL_NO, SALE_ORG,BAL_YEAR_MONTH
                  FROM YDM_ZC_BILL_M
                 WHERE BILL_TICKET_STATUS IN ('0', '1')
                   AND LOADVEHICLE_TYPE = '2'
                   AND ISPRECLOSE > '0'
                 GROUP BY BILL_NO, SALE_ORG,BAL_YEAR_MONTH) T,
               YDM_ZC_BILL_C S
         WHERE T.BILL_NO = S.BILL_NO
         AND T.BAL_YEAR_MONTH = ?
         GROUP BY S.BILL_NO,
                  S.JUDGE_STOVE_NO,
                  S.BATCH_NO,
                  S.GROUP_NO,
                  T.SALE_ORG,
                  S.PRODUCNAME,
               S.STD_STYLE_DESC,
               S.STEELNAME,
               S.SPEC_NAME,
               S.MODEL_DESC)
                  where 1 = 1 
                  
]]>
</query>
</queryMap>