<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="">


	<query id = "FrmHttRunTimeRpt.doQueryHttNew" desc = "">
		<![CDATA[
  SELECT *
  FROM (SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH,
               PRODUCCODE,
               PRODUCNAME,
               STEELCODE,
               STEELNAME,
               GRADECODE,
               GRADENAME,
               DIMATER,
               HEIGHT,
               PRO_ORDER_NO,
               MODEL_CODE,
               MODEL_DESC,
               MAX(WATING_DECISION_MEMO) WATING_DECISION_MEMO,
               JUDGE_STOVE_NO,
               PLINE_CODE,
               PLINE_NAME,
               SUM(ACT_COUNT) ACT_COUNT,
               SUM(ACT_WEIGHT) ACT_WEIGHT,
               SUM(SOURCE_NUM_TOTAL) SOURCE_NUM_TOTAL,
               SUM(SOURCE_WT_TOTAL) SOURCE_WT_TOTAL,
               SUM(JUDGE_NUM) JUDGE_NUM,
               SUM(JUDGE_WT) JUDGE_WT,
               SUM(FAIL_NUM) FAIL_NUM,
               SUM(FAIL_WT) FAIL_WT,
               SUM(GROUP_NUM) GROUP_NUM,
               SUM(GROUP_WT) GROUP_WT,
               SUM(END_NUM) END_NUM,
               SUM(END_WT) END_WT,
               SUM(NVL(XS_ACT_COUNT,0)) XS_ACT_COUNT,
                SUM(NVL(XS_ACT_WEIGHT,0)) XS_ACT_WEIGHT,
               (SUM(JUDGE_NUM) - SUM(NVL(XS_ACT_COUNT,0))) CZ_NUM,
               (SUM(JUDGE_WT) - SUM(NVL(XS_ACT_WEIGHT,0))) CZ_WEIGHT
          FROM (SELECT ---期初
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 DIMATER,
                 HEIGHT,
                 PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 PLINE_CODE,
                 PLINE_NAME,
                 ACT_COUNT,
                 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM YDM_HTT_INITIAL T
                 WHERE T.BAL_YEAR_MONTH = '#BALYEARMONTH#' #PLINECODE#
                 #PROSTATION#
                 #JUDGE_STOVE_NO#
                UNION ALL
                SELECT -- 上料
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 M.OUTDIAMETER DIMATER,
                 M.WALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 T.PRO_NUM SOURCE_NUM_TOTAL,
                 T.PRO_WT SOURCE_WT_TOTAL,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM HTT_LOADING_RESULT T, PLN_ZY_RCL_M M
                 WHERE   T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                 AND  T.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                   AND  T.PROCESS_SEQ='1'
                 #PLINECODE#
                  #PROSTATION#
                  #JUDGE_STOVE_NO2#
                     UNION ALL
                   SELECT ---- 当月审核的废品  和当月组炉
                          M.PRODUCCODE,
                          M.PRODUCNAME,
                          M.STEELCODE,
                          M.STEELNAME,
                          M.GRADECODE,
                          M.GRADENAME,
                          M.OUTDIAMETER DIMATER,
                          M.WALLTHICK HEIGHT,
                          M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                          M.MODEL_CODE,
                          M.MODEL_DESC,
                          T.JUDGE_STOVE_NO,
                          T.PLINE_CODE,
                          T.PLINE_NAME,
                          0 ACT_COUNT,
                          0 ACT_WEIGHT,
                          ''  WATING_DECISION_MEMO,
                          0 SOURCE_NUM_TOTAL,
                          0 SOURCE_WT_TOTAL,
                          0 JUDGE_NUM,
                          0 JUDGE_WT,
                          DECODE(T.MAT_STATUS, '10', 1, '40', 1, 0) FAIL_NUM,
                          DECODE(T.MAT_STATUS,
                                 '10',
                                 T.ACT_WEIGHT,
                                 '40',
                                 T.ACT_WEIGHT,
                                 0) FAIL_WT,
                          DECODE(T.MAT_STATUS, '30', 1, 0) GROUP_NUM,
                          DECODE(T.MAT_STATUS, '30', T.ACT_WEIGHT, 0) GROUP_WT,
                          0 END_NUM,
                          0 END_WT,
                          0 XS_ACT_COUNT,
				          0 XS_ACT_WEIGHT
                           FROM PORT_HTT_BATCH_SAMPLE_RESULT T ,PLN_ZY_RCL_M M
                          WHERE  T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                           AND T.VALIDFLAG = '1' #PLINECODE#
                          #PROSTATION#
                          #JUDGE_STOVE_NO#
                            AND IS_FAIL_CHECK = '1'
                            AND BAL_YEAR_MONTH_FAIL IS NOT NULL
                            AND BAL_YEAR_MONTH_FAIL = '#BALYEARMONTH#'

                         UNION ALL
                         SELECT --- 当月判定支
                               M.PRODUCCODE,
                 M.PRODUCNAME,
                 M.STEELCODE,
                 M.STEELNAME,
                 M.GRADECODE,
                 M.GRADENAME,
                 M.OUTDIAMETER DIMATER,
                 M.WALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 M.MODEL_CODE,
                 M.MODEL_DESC,
                          T.JUDGE_STOVE_NO,
                          T.PLINE_CODE,
                          T.PLINE_NAME,
                          0 ACT_COUNT,
                          0 ACT_WEIGHT,
                          '' WATING_DECISION_MEMO,
                          0 SOURCE_NUM_TOTAL,
                          0 SOURCE_WT_TOTAL,
                          ACT_COUNT JUDGE_NUM,
                          ACT_WEIGHT JUDGE_WT,
                          0 FAIL_NUM,
                          0 FAIL_WT,
                          0 GROUP_NUM,
                          0 GROUP_WT,
                          0 END_NUM,
                          0 END_WT,
                          0 XS_ACT_COUNT,
				          0 XS_ACT_WEIGHT
                           FROM QCM_ZG_JUGDE_APPLY T,PLN_ZY_RCL_M M
                          WHERE M.HEAT_PLAN_NO = T.HEAT_PLAN_NO
                            AND T.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                          #JUDGE_STOVE_NO#
                            AND T.PROCESS_CODE = 'F'
                            AND  (((JUDGE_RESULT_CODE = '40740701' OR JUDGE_RESULT_CODE = '40740709' OR
       EXISTS (SELECT 1
                   FROM QCM_BC_PASS_APPLY
                  WHERE JUGDE_APPLY_CODE = T.JUGDE_APPLY_CODE
                    AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                    AND BATCH_NO = T.BATCH_NO
                    AND VALIDFLAG = '1'
                    AND TYPE = '1')) AND TARGET <> 'A') OR
       (TARGET = 'A' AND (JUDGE_TOLRESULT_CODE = '40740701' OR
       JUDGE_TOLRESULT_CODE = '40740709')))
                            AND IS_FLAG = '0'
                            AND IS_ALL_SCRAP IN ('0', '2', '7') #PLINECODE#
                          #PROSTATION#
                          #JUDGE_STOVE_NO#
UNION ALL
SELECT ---已结算的期末
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 DIMATER,
                 HEIGHT,
                 PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 PLINE_CODE,
                 PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 MEMO WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 ACT_COUNT END_NUM,
                 ACT_WEIGHT END_WT,
                 0 XS_ACT_COUNT,
				         0 XS_ACT_WEIGHT
                  FROM YDM_HTT_INITIAL T
                 WHERE T.BAL_YEAR_MONTH = '#BALYEARMONTH_NEXT#' #PLINECODE#
                 #PROSTATION#
                 #JUDGE_STOVE_NO#
UNION ALL
SELECT  --- 未结算的期末
       M.PRODUCCODE,
       M.PRODUCNAME,
       M.STEELCODE,
       M.STEELNAME,
       M.GRADECODE,
       M.GRADENAME,
       M.OUTDIAMETER DIMATER,
       M.WALLTHICK HEIGHT,
       M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
       M.MODEL_CODE,
       M.MODEL_DESC,
       M.JUDGE_STOVE_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       0 ACT_COUNT,
       0 ACT_WEIGHT,
       M.WAITING_DECISION_MEMO WATING_DECISION_MEMO,
       0 SOURCE_NUM_TOTAL,
       0 SOURCE_WT_TOTAL,
       0 JUDGE_NUM,
       0 JUDGE_WT,
       0 FAIL_NUM,
       0 FAIL_WT,
       0 GROUP_NUM,
       0 GROUP_WT,
       T.END_NUM,
       T.END_WT,
       0 XS_ACT_COUNT,
			 0 XS_ACT_WEIGHT
  FROM (SELECT SUM(END_NUM) END_NUM,
               SUM(END_WT) END_WT,
               HEAT_PLAN_NO,
               JUDGE_STOVE_NO,
               PLINE_CODE,
               PLINE_NAME
          FROM (SELECT T.HEAT_PLAN_NO,
                        T.JUDGE_STOVE_NO,
                       T.PLINE_CODE,
                       T.PLINE_NAME,
                       T.ACT_COUNT END_NUM,
                      ACT_WEIGHT END_WT
                  FROM PORT_HTT_BATCH_SAMPLE_RESULT T
                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                   AND T.BAL_YEAR_MONTH > '201807'
                   AND T.VALIDFLAG = '1'
                   AND T.MAT_STATUS = '20'
                      UNION ALL
                SELECT T.HEAT_PLAN_NO,
                   T.JUDGE_STOVE_NO,
                       T.PLINE_CODE,
                       T.PLINE_NAME,
                       T.ACT_COUNT END_NUM,
                      ACT_WEIGHT END_WT
                  FROM PORT_HTT_BATCH_SAMPLE_RESULT T
                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                   AND T.BAL_YEAR_MONTH > '201807'
                   AND T.VALIDFLAG = '1'
                   AND T.MAT_STATUS IN ('30')
                   AND   T.BAL_YEAR_MONTH_FAIL >= '#BALYEARMONTH_NEXT#'
                UNION ALL
                SELECT T.HEAT_PLAN_NO,
                   T.JUDGE_STOVE_NO,
                       T.PLINE_CODE,
                       T.PLINE_NAME,
                       T.ACT_COUNT END_NUM,
                      ACT_WEIGHT END_WT
                  FROM PORT_HTT_BATCH_SAMPLE_RESULT T
                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                   AND T.BAL_YEAR_MONTH > '201807'
                   AND T.VALIDFLAG = '1'
                   AND T.MAT_STATUS IN ('10', '40')
                   AND (T.IS_FAIL_CHECK = '0' OR
                       T.BAL_YEAR_MONTH_FAIL >= '#BALYEARMONTH_NEXT#')
                UNION ALL
                SELECT T.HEAT_PLAN_NO,
                   T.JUDGE_STOVE_NO,
                       T.PLINE_CODE,
                       T.PLINE_NAME,
                       T.ACT_COUNT END_NUM,
                      ACT_WEIGHT END_WT
                  FROM PORT_HTT_BATCH_SAMPLE_RESULT T
                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                   AND T.BAL_YEAR_MONTH > '201807'
                   AND T.VALIDFLAG = '1'
                   AND T.MAT_STATUS = '00'

                   AND NOT EXISTS
                 (SELECT 1
                          FROM QCM_ZG_JUGDE_APPLY QCM
                         WHERE 1 = 1
                           AND IS_FLAG = '0'
                           AND IS_ALL_SCRAP IN ('0', '2', '7')
                           AND PROCESS_CODE = 'F'
                           AND  (((JUDGE_RESULT_CODE = '40740701' OR JUDGE_RESULT_CODE = '40740709' OR
       EXISTS (SELECT 1
                   FROM QCM_BC_PASS_APPLY
                  WHERE JUGDE_APPLY_CODE = QCM.JUGDE_APPLY_CODE
                    AND JUDGE_STOVE_NO = QCM.JUDGE_STOVE_NO
                    AND BATCH_NO = QCM.BATCH_NO
                    AND VALIDFLAG = '1'
                    AND TYPE = '1')) AND TARGET <> 'A') OR
       (TARGET = 'A' AND (JUDGE_TOLRESULT_CODE = '40740701' OR
       JUDGE_TOLRESULT_CODE = '40740709')))

                           AND BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                           AND JUGDE_APPLY_CODE = NVL(T.JUGDE_APPLY_CODE, '/')
                   AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                   AND BATCH_NO = T.PHY_BATCH_NO))
         GROUP BY HEAT_PLAN_NO,  JUDGE_STOVE_NO, PLINE_CODE, PLINE_NAME) T,
       PLN_ZY_RCL_M M
 WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
   AND NOT EXISTS (SELECT 1
          FROM YDM_HTT_INITIAL
         WHERE PLINE_CODE = T.PLINE_CODE
           AND BAL_YEAR_MONTH = '#BALYEARMONTH_NEXT#'
           AND ROWNUM = 1)
            #PLINECODE#
             #PROSTATION#
             #JUDGE_STOVE_NO#
          UNION ALL
           SELECT ---销售
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 ACT_DIMATER,
                 ACT_HEIGHT,
                 PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 PLINE_CODE,
                 PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 ACT_COUNT XS_ACT_COUNT,
				         ACT_WEIGHT XS_ACT_WEIGHT
                  FROM YDM_ZC_INLIST T
                 WHERE T.BAL_YEAR_MONTH = '#BALYEARMONTH#' #PLINECODE#
                 #PROSTATION#
                 #JUDGE_STOVE_NO#
                 AND INSTOCK_TYPE_CODE != '800713'
                    
                )
         WHERE 1 = 1 #PLN#
         GROUP BY PRODUCCODE,
                  PRODUCNAME,
                  STEELCODE,
                  STEELNAME,
                  GRADECODE,
                  GRADENAME,
                  DIMATER,
                  HEIGHT,
                  PRO_ORDER_NO,
                  MODEL_CODE,
                  MODEL_DESC,
                  JUDGE_STOVE_NO,
                  PLINE_CODE,
                  PLINE_NAME)
 WHERE ACT_COUNT > 0
    OR SOURCE_NUM_TOTAL > 0
    OR JUDGE_NUM > 0
    OR FAIL_NUM > 0
    OR GROUP_NUM > 0
    OR END_NUM > 0
 ORDER BY PLINE_CODE, JUDGE_STOVE_NO

]]>
	</query>


	<query id = "FrmHttRunTimeRpt.doQueryMchNew" desc = "">
		<![CDATA[
SELECT  ss.*, b.FINAL_USER_DESC  customer
  FROM (SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH,
               PRODUCCODE,
               PRODUCNAME,
               STEELCODE,
               STEELNAME,
               GRADECODE,
               GRADENAME,
               DIMATER,
               HEIGHT,
               PRO_ORDER_NO,
               MODEL_CODE,
               MODEL_DESC,
               MAX(WATING_DECISION_MEMO) WATING_DECISION_MEMO,
               JUDGE_STOVE_NO,
               BATCH_NO,
               PLINE_CODE,
               PLINE_NAME,
               SUM(ACT_COUNT) ACT_COUNT,
               SUM(ACT_WEIGHT) ACT_WEIGHT,
               SUM(SOURCE_NUM_TOTAL) SOURCE_NUM_TOTAL,
               SUM(SOURCE_WT_TOTAL) SOURCE_WT_TOTAL,
               SUM(SOURCE_NUM_TOTAL) SOURCE_NUM_TOTAL2,
               SUM(SOURCE_WT_TOTAL) SOURCE_WT_TOTAL2,
               SUM(NVL(SOURCE_NUM0, 0)) SOURCE_NUM0,
               SUM(NVL(SOURCE_WT0, 0)) SOURCE_WT0,
               SUM(NVL(SOURCE_NUM1, 0)) SOURCE_NUM1,
               SUM(NVL(SOURCE_WT1, 0)) SOURCE_WT1,
               SUM(NVL(SOURCE_NUM2, 0)) SOURCE_NUM2,
               SUM(NVL(SOURCE_WT2, 0)) SOURCE_WT2,
               SUM(JUDGE_NUM) JUDGE_NUM,
               SUM(JUDGE_WT) JUDGE_WT,
               SUM(FAIL_NUM) FAIL_NUM,
               SUM(FAIL_WT) FAIL_WT,
               SUM(GROUP_NUM) GROUP_NUM,
               SUM(GROUP_WT) GROUP_WT,
               SUM(END_NUM) END_NUM,
               SUM(END_WT) END_WT,
               SUM(NVL(COUPLING_NUM, 0)) COUPLING_NUM,
               SUM(NVL(COUPLING_WT, 0)) COUPLING_WT,
			   SUM(NVL(XS_ACT_COUNT,0)) XS_ACT_COUNT,
			   SUM(NVL(XS_ACT_WEIGHT,0)) XS_ACT_WEIGHT,
			   (SUM(JUDGE_NUM) - SUM(NVL(XS_ACT_COUNT,0))) CZ_NUM,
			   (SUM(JUDGE_WT) - SUM(NVL(XS_ACT_WEIGHT,0))) CZ_WEIGHT
          FROM (SELECT ---期初
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 DIMATER,
                 HEIGHT,
                 PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 BATCH_NO,
                 PLINE_CODE,
                 PLINE_NAME,
                 ACT_COUNT,
                 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 SOURCE_NUM0,
                 0 SOURCE_WT0,
                 0 SOURCE_NUM1,
                 0 SOURCE_WT1,
                 0 SOURCE_NUM2,
                 0 SOURCE_WT2,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 0 COUPLING_NUM,
                 0 COUPLING_WT,
				 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM YDM_HTT_INITIAL T
                 WHERE T.BAL_YEAR_MONTH = '#BALYEARMONTH#' #PLINECODE#
                 #PROSTATION# #JUDGE_STOVE_NO#
                UNION ALL
                SELECT -- 上料
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 M.OUTDIAMETER DIMATER,
                 M.WALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 T.JUDGE_STOVE_NO,
                 T.BATCH_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 T.PRO_NUM SOURCE_NUM_TOTAL,
                 T.PRO_WT SOURCE_WT_TOTAL,
                 DECODE(MAT_SOURCE, '0', PRO_NUM, 0) SOURCE_NUM0,
                 DECODE(MAT_SOURCE, '0', PRO_WT, 0) SOURCE_WT0,
                 DECODE(MAT_SOURCE, '1', PRO_NUM, 0) SOURCE_NUM1,
                 DECODE(MAT_SOURCE, '1', PRO_WT, 0) SOURCE_WT1,
                 DECODE(MAT_SOURCE, '2', PRO_NUM, 0) SOURCE_NUM2,
                 DECODE(MAT_SOURCE, '2', PRO_WT, 0) SOURCE_WT2,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 0 COUPLING_NUM,
                 0 COUPLING_WT,
				 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM MCH_LOADING_RESULT T, PLN_ZY_JGX_M M
                 WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                   AND T.BAL_YEAR_MONTH = '#BALYEARMONTH#' #PLINECODE#
                 #PROSTATION# #JUDGE_STOVE_NO2#
                 UNION ALL
              SELECT --  成品红冲 利库短节备料 计入收料  缴库
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 T.ACT_DIMATER DIMATER,
                 T.ACT_HEIGHT HEIGHT,
                 T.PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 T.JUDGE_STOVE_NO,
                 T.BATCH_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 T.ACT_COUNT SOURCE_NUM_TOTAL,
                 T.ACT_WEIGHT SOURCE_WT_TOTAL,
                  T.ACT_COUNT SOURCE_NUM0,
                 T.ACT_WEIGHT SOURCE_WT0,
                0 SOURCE_NUM1,
                 0 SOURCE_WT1,
                 0 SOURCE_NUM2,
                 0 SOURCE_WT2,
               ACT_COUNT JUDGE_NUM,
                 ACT_WEIGHT JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 0 COUPLING_NUM,
                 0 COUPLING_WT,
				 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM QCM_ZG_JUGDE_APPLY T
                 WHERE T.IS_ALL_SCRAP = '5'
                  AND T.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                   AND T.PROCESS_CODE = 'G'
                   AND  (((JUDGE_RESULT_CODE = '40740701' OR JUDGE_RESULT_CODE = '40740709' OR
       EXISTS (SELECT 1
                   FROM QCM_BC_PASS_APPLY
                  WHERE JUGDE_APPLY_CODE = T.JUGDE_APPLY_CODE
                    AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                    AND BATCH_NO = T.BATCH_NO
                    AND VALIDFLAG = '1'
                    AND TYPE = '1')) AND TARGET <> 'A') OR
       (TARGET = 'A' AND (JUDGE_TOLRESULT_CODE = '40740701' OR
       JUDGE_TOLRESULT_CODE = '40740709')))
                   AND T.IS_FLAG = '0'
                    #PLINECODE#
                 #PROSTATION# #JUDGE_STOVE_NO#

                UNION ALL
                SELECT ---- 当月审核的废品  和当月组炉
                 M.PRODUCCODE,
                 M.PRODUCNAME,
                 M.STEELCODE,
                 M.STEELNAME,
                 M.GRADECODE,
                 M.GRADENAME,
                 M.OUTDIAMETER DIMATER,
                 M.WALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 M.MODEL_CODE,
                 M.MODEL_DESC,
                 T.JUDGE_STOVE_NO,
                 T.BATCH_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 SOURCE_NUM0,
                 0 SOURCE_WT0,
                 0 SOURCE_NUM1,
                 0 SOURCE_WT1,
                 0 SOURCE_NUM2,
                 0 SOURCE_WT2,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 DECODE(T.MAT_STATUS, '10', 1, '40', 1, 0) FAIL_NUM,
                 DECODE(T.MAT_STATUS,
                        '10',
                        T.ACT_THEORY_WEIGHT,
                        '40',
                        T.ACT_THEORY_WEIGHT,
                        0) FAIL_WT,
                 DECODE(T.MAT_STATUS, '30', 1, 0) GROUP_NUM,
                 DECODE(T.MAT_STATUS, '30', T.ACT_THEORY_WEIGHT, 0) GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 0 COUPLING_NUM,
                 0 COUPLING_WT,
				 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM PORT_MCH_BATCH_SAMPLE_RESULT T, PLN_ZY_JGX_M M
                 WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                   AND T.VALIDFLAG = '1' #PLINECODE# #PROSTATION#
                 #JUDGE_STOVE_NO#
                   AND IS_FAIL_CHECK = '1'
                   AND BAL_YEAR_MONTH_FAIL IS NOT NULL
                   AND BAL_YEAR_MONTH_FAIL = '#BALYEARMONTH#'

                UNION ALL
                SELECT --- 当月判定支
                    M.PRODUCCODE,
                 M.PRODUCNAME,
                 M.STEELCODE,
                 M.STEELNAME,
                 M.GRADECODE,
                 M.GRADENAME,
                 M.OUTDIAMETER DIMATER,
                 M.WALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 M.MODEL_CODE,
                 M.MODEL_DESC,
                 T.JUDGE_STOVE_NO,
                 T.BATCH_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 SOURCE_NUM0,
                 0 SOURCE_WT0,
                 0 SOURCE_NUM1,
                 0 SOURCE_WT1,
                 0 SOURCE_NUM2,
                 0 SOURCE_WT2,
                 ACT_COUNT JUDGE_NUM,
                 ACT_WEIGHT JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 0 COUPLING_NUM,
                 0 COUPLING_WT,
				 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM QCM_ZG_JUGDE_APPLY T, PLN_ZY_JGX_M M
                 WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                  AND T.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                 #JUDGE_STOVE_NO#
                   AND T.PROCESS_CODE = 'G'
                   AND  (((JUDGE_RESULT_CODE = '40740701' OR JUDGE_RESULT_CODE = '40740709' OR
       EXISTS (SELECT 1
                   FROM QCM_BC_PASS_APPLY
                  WHERE JUGDE_APPLY_CODE = T.JUGDE_APPLY_CODE
                    AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                    AND BATCH_NO = T.BATCH_NO
                    AND VALIDFLAG = '1'
                    AND TYPE = '1')) AND TARGET <> 'A') OR
       (TARGET = 'A' AND (JUDGE_TOLRESULT_CODE = '40740701' OR
       JUDGE_TOLRESULT_CODE = '40740709')))
                   AND T.IS_FLAG = '0'
                   AND T.IS_ALL_SCRAP IN ('0', '2', '7') #PLINECODE#
                 #PROSTATION# #JUDGE_STOVE_NO#
                UNION ALL
                SELECT ---已结算的期末
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 DIMATER,
                 HEIGHT,
                 PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 BATCH_NO,
                 PLINE_CODE,
                 PLINE_NAME,
                 0              ACT_COUNT,
                 0              ACT_WEIGHT,
                 MEMO           WATING_DECISION_MEMO,
                 0              SOURCE_NUM_TOTAL,
                 0              SOURCE_WT_TOTAL,
                 0              SOURCE_NUM0,
                 0              SOURCE_WT0,
                 0              SOURCE_NUM1,
                 0              SOURCE_WT1,
                 0              SOURCE_NUM2,
                 0              SOURCE_WT2,
                 0              JUDGE_NUM,
                 0              JUDGE_WT,
                 0              FAIL_NUM,
                 0              FAIL_WT,
                 0              GROUP_NUM,
                 0              GROUP_WT,
                 ACT_COUNT      END_NUM,
                 ACT_WEIGHT     END_WT,
                 0              COUPLING_NUM,
                 0              COUPLING_WT,
				 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM YDM_HTT_INITIAL T
                 WHERE T.BAL_YEAR_MONTH = '#BALYEARMONTH_NEXT#' #PLINECODE#
                 #PROSTATION# #JUDGE_STOVE_NO#
                UNION ALL
                SELECT --- 未结算的期末
                 M.PRODUCCODE,
                 M.PRODUCNAME,
                 M.STEELCODE,
                 M.STEELNAME,
                 M.GRADECODE,
                 M.GRADENAME,
                 M.OUTDIAMETER DIMATER,
                 M.WALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 M.MODEL_CODE,
                 M.MODEL_DESC,
                 M.JUDGE_STOVE_NO,
                 T.BATCH_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 M.WAITING_DECISION_MEMO WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 SOURCE_NUM0,
                 0 SOURCE_WT0,
                 0 SOURCE_NUM1,
                 0 SOURCE_WT1,
                 0 SOURCE_NUM2,
                 0 SOURCE_WT2,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 T.END_NUM,
                 T.END_WT,
                 0 COUPLING_NUM,
                 0 COUPLING_WT,
				 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM (SELECT SUM(END_NUM) END_NUM,
                               SUM(END_WT) END_WT,
                               HEAT_PLAN_NO,
                               JUDGE_STOVE_NO,
                               BATCH_NO,
                               PLINE_CODE,
                               PLINE_NAME
                          FROM (SELECT T.HEAT_PLAN_NO,
                                       T.JUDGE_STOVE_NO,
                                       T.PHY_BATCH_NO BATCH_NO,
                                       T.PLINE_CODE,
                                       T.PLINE_NAME,
                                       T.ACT_COUNT * T.OUTNUM_CUT      END_NUM,
                                       ACT_THEORY_WEIGHT       END_WT
                                  FROM PORT_MCH_BATCH_SAMPLE_RESULT T
                                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                                   AND T.BAL_YEAR_MONTH > '201810'
                                   AND T.VALIDFLAG = '1'
                                   AND T.MAT_STATUS = '20'
                                   UNION ALL
                                   SELECT T.HEAT_PLAN_NO,
                                       T.JUDGE_STOVE_NO,
                                       T.PHY_BATCH_NO BATCH_NO,
                                       T.PLINE_CODE,
                                       T.PLINE_NAME,
                                       T.ACT_COUNT * T.OUTNUM_CUT      END_NUM,
                                       ACT_THEORY_WEIGHT       END_WT
                                  FROM PORT_MCH_BATCH_SAMPLE_RESULT T
                                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                                   AND T.BAL_YEAR_MONTH > '201810'
                                   AND  T.BAL_YEAR_MONTH_FAIL >=
                                       '#BALYEARMONTH_NEXT#'
                                   AND T.VALIDFLAG = '1'
                                   AND T.MAT_STATUS = '30'
                                UNION ALL
                                SELECT T.HEAT_PLAN_NO,
                                       T.JUDGE_STOVE_NO,
                                         T.PHY_BATCH_NO BATCH_NO,
                                       T.PLINE_CODE,
                                       T.PLINE_NAME,
                                       T.ACT_COUNT *  T.OUTNUM_CUT    END_NUM,
                                       ACT_THEORY_WEIGHT       END_WT
                                  FROM PORT_MCH_BATCH_SAMPLE_RESULT T
                                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                                   AND T.BAL_YEAR_MONTH > '201807'
                                   AND T.VALIDFLAG = '1'
                                   AND T.MAT_STATUS IN ('10', '40')
                                   AND (T.IS_FAIL_CHECK = '0' OR
                                       T.BAL_YEAR_MONTH_FAIL >=
                                       '#BALYEARMONTH_NEXT#')
                                UNION ALL
                                SELECT T.HEAT_PLAN_NO,
                                       T.JUDGE_STOVE_NO,
                                         T.PHY_BATCH_NO BATCH_NO,
                                       T.PLINE_CODE,
                                       T.PLINE_NAME,
                                       T.ACT_COUNT *  T.OUTNUM_CUT      END_NUM,
                                       ACT_THEORY_WEIGHT       END_WT
                                  FROM PORT_MCH_BATCH_SAMPLE_RESULT T
                                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                                   AND T.BAL_YEAR_MONTH > '201807'
                                   AND T.VALIDFLAG = '1'
                                   AND T.MAT_STATUS = '00'
                                   AND NOT EXISTS
                                 (SELECT 1
                                          FROM QCM_ZG_JUGDE_APPLY QCM
                                         WHERE 1 = 1
                                           AND IS_FLAG = '0'
                                           AND IS_ALL_SCRAP IN   ('0', '2', '5', '7')
                                           AND PROCESS_CODE = 'G'
                                           AND  (((JUDGE_RESULT_CODE = '40740701' OR JUDGE_RESULT_CODE = '40740709' OR
       EXISTS (SELECT 1
                   FROM QCM_BC_PASS_APPLY
                  WHERE JUGDE_APPLY_CODE = QCM.JUGDE_APPLY_CODE
                    AND JUDGE_STOVE_NO = QCM.JUDGE_STOVE_NO
                    AND BATCH_NO = QCM.BATCH_NO
                    AND VALIDFLAG = '1'
                    AND TYPE = '1')) AND TARGET <> 'A') OR
       (TARGET = 'A' AND (JUDGE_TOLRESULT_CODE = '40740701' OR
       JUDGE_TOLRESULT_CODE = '40740709')))
                                           AND BAL_YEAR_MONTH <
                                               '#BALYEARMONTH_NEXT#'
                                           AND JUGDE_APPLY_CODE =
                                               NVL(T.JUGDE_APPLY_CODE, '/')
                                           AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                                           AND BATCH_NO = T.PHY_BATCH_NO))
                         GROUP BY HEAT_PLAN_NO,
                                  JUDGE_STOVE_NO,
                                  BATCH_NO,
                                  PLINE_CODE,
                                  PLINE_NAME) T,
                       PLN_ZY_JGX_M M
                 WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                   AND NOT EXISTS
                 (SELECT 1
                          FROM YDM_HTT_INITIAL
                         WHERE PLINE_CODE = T.PLINE_CODE
                           AND BAL_YEAR_MONTH = '#BALYEARMONTH_NEXT#'
                           AND ROWNUM = 1) #PLINECODE# #PROSTATION#
                 #JUDGE_STOVE_NO#
                UNION ALL
                SELECT --- 当月接箍个数
                  M.PRODUCCODE,
                 M.PRODUCNAME,
                 M.STEELCODE,
                 M.STEELNAME,
                 M.GRADECODE,
                 M.GRADENAME,
                 M.OUTDIAMETER DIMATER,
                 M.WALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 M.MODEL_CODE,
                 M.MODEL_DESC,
                 T.JUDGE_STOVE_NO,
                 T.BATCH_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 SOURCE_NUM0,
                 0 SOURCE_WT0,
                 0 SOURCE_NUM1,
                 0 SOURCE_WT1,
                 0 SOURCE_NUM2,
                 0 SOURCE_WT2,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 COUPLING_NUM COUPLING_NUM,
                 COUPLING_WT COUPLING_WT,
                 0 XS_ACT_COUNT,
                 0 XS_ACT_WEIGHT
                  FROM MCH_TWISTINGLY_RESULT T, PLN_ZY_JGX_M M
                 WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                   AND T.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                 #JUDGE_STOVE_NO# #PLINECODE# #PROSTATION#
                 UNION ALL

                    SELECT  -- 短节精整利库 或返线 的  加上料支数
                  M.PRODUCCODE,
                 M.PRODUCNAME,
                 M.STEELCODE,
                 M.STEELNAME,
                 M.GRADECODE,
                 M.GRADENAME,
                 M.OUTDIAMETER DIMATER,
                 M.WALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 M.MODEL_CODE,
                 M.MODEL_DESC,
                 M.JUDGE_STOVE_NO,
                 (SELECT MAX(batch_no) FROM pln_zy_jgx_c WHERE heat_plan_no=M.heat_plan_no ) ,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 M.PLN_INSINGLE_NUM SOURCE_NUM_TOTAL,
                 M.PLN_INSINGLE_WT SOURCE_WT_TOTAL,
                  DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  M.HEAT_PLAN_NO_OLD),'0',M.PLN_INSINGLE_NUM,0)
                    SOURCE_NUM0,
                 DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  M.HEAT_PLAN_NO_OLD),'0',M.PLN_INSINGLE_WT,0)
                  SOURCE_WT0,
                DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  M.HEAT_PLAN_NO_OLD),'1',M.PLN_INSINGLE_NUM,0)
                    SOURCE_NUM1,
                 DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  M.HEAT_PLAN_NO_OLD),'1',M.PLN_INSINGLE_WT,0)
                  SOURCE_WT1,
                 DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  M.HEAT_PLAN_NO_OLD),'2',M.PLN_INSINGLE_NUM,0)
                    SOURCE_NUM2,
                 DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  M.HEAT_PLAN_NO_OLD),'2',M.PLN_INSINGLE_WT,0)
                  SOURCE_WT2,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                  0 COUPLING_NUM ,
                  0 COUPLING_WT,
				 0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                  FROM PLN_ZY_JGX_M T,PLN_ZY_JGX_M M
                  WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO_OLD
                    AND M.IF_MATCH_ODD ='6'
                               AND M.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                               AND EXISTS
                             (SELECT *
                                      FROM COM_BASE_PRODUCT
                                     WHERE PRODUCCODE = M.PRODUCCODE
                                       AND PRODUC_STYLE = '405004')
                                            AND EXISTS (SELECT 1 FROM MCH_LOADING_RESULT L
                                         WHERE L.HEAT_PLAN_NO = T.HEAT_PLAN_NO AND L.BAL_YEAR_MONTH ='#BALYEARMONTH#')
                                            AND EXISTS (SELECT 1 FROM PORT_MCH_BATCH_SAMPLE_RESULT WHERE HEAT_PLAN_NO = M.HEAT_PLAN_NO)
                  #PLINECODE#
                   #PROSTATION#
                 #JUDGE_STOVE_NO#

                      UNION ALL  -- 部分精整返线转短节  上料支数减去
                          SELECT
                 T.PRODUCCODE,
                 T.PRODUCNAME,
                 T.STEELCODE,
                 T.STEELNAME,
                 T.GRADECODE,
                 T.GRADENAME,
                 T.OUTDIAMETER DIMATER,
                 T.WALLTHICK HEIGHT,
                 T.ORDER_NO || '/' || T.ORDER_SEQ PRO_ORDER_NO,
                 T.MODEL_CODE,
                 T.MODEL_DESC,
                 T.JUDGE_STOVE_NO,
                 (SELECT MAX(batch_no) FROM pln_zy_jgx_c WHERE heat_plan_no=M.heat_plan_no ) ,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                  0- M.PLN_INSINGLE_NUM SOURCE_NUM_TOTAL,
                 0 - M.PLN_INSINGLE_WT SOURCE_WT_TOTAL,
                  DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  T.HEAT_PLAN_NO),'0', 0- M.PLN_INSINGLE_NUM,0)
                    SOURCE_NUM0,
                 DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  T.HEAT_PLAN_NO),'0',0- M.PLN_INSINGLE_WT,0)
                  SOURCE_WT0,
                DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  T.HEAT_PLAN_NO),'1',0-M.PLN_INSINGLE_NUM,0)
                    SOURCE_NUM1,
                 DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  T.HEAT_PLAN_NO),'1',0-M.PLN_INSINGLE_WT,0)
                  SOURCE_WT1,
                 DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  T.HEAT_PLAN_NO),'2',0-M.PLN_INSINGLE_NUM,0)
                    SOURCE_NUM2,
                 DECODE((SELECT MAX(MAT_SOURCE) FROM MCH_LOADING_RESULT L WHERE L.HEAT_PLAN_NO =  T.HEAT_PLAN_NO),'2',0-M.PLN_INSINGLE_WT,0)
                  SOURCE_WT2,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                  0 COUPLING_NUM ,
                  0 COUPLING_WT,
				  0 XS_ACT_COUNT,
				 0 XS_ACT_WEIGHT
                   FROM PLN_ZY_JGX_M T,PLN_ZY_JGX_M M
                  WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO_OLD
                    AND M.IF_MATCH_ODD ='6'
                               AND M.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                               AND EXISTS
                             (SELECT *
                                      FROM COM_BASE_PRODUCT
                                     WHERE PRODUCCODE = M.PRODUCCODE
                                       AND PRODUC_STYLE = '405004')
                                         AND EXISTS (SELECT 1 FROM MCH_LOADING_RESULT L
                                         WHERE L.HEAT_PLAN_NO = T.HEAT_PLAN_NO AND L.BAL_YEAR_MONTH ='#BALYEARMONTH#')
                                         AND EXISTS (SELECT 1 FROM PORT_MCH_BATCH_SAMPLE_RESULT WHERE HEAT_PLAN_NO = M.HEAT_PLAN_NO)
                  #PLINECODE#
                   #PROSTATION#
                 #JUDGE_STOVE_NO#
	         UNION ALL
 SELECT          T.PRODUCCODE,
                 T.PRODUCNAME,
                 T.STEELCODE,
                 T.STEELNAME,
                 T.GRADECODE,
                 T.GRADENAME,
                 T.ACT_DIMATER DIMATER, 
                 T.ACT_HEIGHT HEIGHT,
                 T.PRO_ORDER_NO,
                 T.MODEL_CODE,
                 T.MODEL_DESC,
                 T.JUDGE_STOVE_NO,
                 T.BATCH_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 SOURCE_NUM0,
                 0 SOURCE_WT0,
                 0 SOURCE_NUM1,
                 0 SOURCE_WT1,
                 0 SOURCE_NUM2,
                 0 SOURCE_WT2,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT,
                 0 COUPLING_NUM,
                 0 COUPLING_WT,
				 T.ACT_COUNT XS_ACT_COUNT,
				 T.ACT_WEIGHT XS_ACT_WEIGHT
                 FROM YDM_ZC_INLIST T
                 WHERE T.BAL_YEAR_MONTH = '#BALYEARMONTH#' #PLINECODE#
                 #PROSTATION# #JUDGE_STOVE_NO#	
                 AND INSTOCK_TYPE_CODE not in('800713','800712')   	 
                 )
				 
         WHERE 1 = 1 #PLN#
         GROUP BY PRODUCCODE,
                  PRODUCNAME,
                  STEELCODE,
                  STEELNAME,
                  GRADECODE,
                  GRADENAME,
                  DIMATER,
                  HEIGHT,
                  PRO_ORDER_NO,
                  MODEL_CODE,
                  MODEL_DESC,
                  JUDGE_STOVE_NO,
                  BATCH_NO,
                  PLINE_CODE,
                  PLINE_NAME) ss    LEFT JOIN (
 SELECT
  tt.FINAL_USER_DESC,td.order_no,tt.ORDER_SEQ
 FROM
  SLM_ORDER_HEAD td,
  SLM_ORDER_LINE tt
 WHERE
  td.ord_pk = tt.ord_pk
  AND TD.VALIDFLAG = '1'
 AND TT.VALIDFLAG = '1'
 ) b ON ss.PRO_ORDER_NO = ( b.ORDER_NO || '/' || b.order_seq )
 WHERE ACT_COUNT > 0
    OR SOURCE_NUM_TOTAL > 0
    OR JUDGE_NUM > 0
    OR FAIL_NUM > 0
    OR GROUP_NUM > 0
    OR END_NUM > 0
 ORDER BY PLINE_CODE, JUDGE_STOVE_NO, BATCH_NO
]]>
	</query>


	<query id = "FrmHttRunTimeRpt.doQueryVrpNew" desc = "">
		<![CDATA[
  SELECT *
  FROM (SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH,
               PRODUCCODE,
               PRODUCNAME,
               STEELCODE,
               STEELNAME,
               GRADECODE,
               GRADENAME,
               DIMATER,
               HEIGHT,
               PRO_ORDER_NO,
               MODEL_CODE,
               MODEL_DESC,
               MAX(WATING_DECISION_MEMO) WATING_DECISION_MEMO,
               JUDGE_STOVE_NO,
               PLINE_CODE,
               PLINE_NAME,
               SUM(ACT_COUNT) ACT_COUNT,
               SUM(ACT_WEIGHT) ACT_WEIGHT,
               SUM(SOURCE_NUM_TOTAL) SOURCE_NUM_TOTAL,
               SUM(SOURCE_WT_TOTAL) SOURCE_WT_TOTAL,
               SUM(JUDGE_NUM) JUDGE_NUM,
               SUM(JUDGE_WT) JUDGE_WT,
               SUM(FAIL_NUM) FAIL_NUM,
               SUM(FAIL_WT) FAIL_WT,
               SUM(GROUP_NUM) GROUP_NUM,
               SUM(GROUP_WT) GROUP_WT,
               SUM(END_NUM) END_NUM,
               SUM(END_WT) END_WT
          FROM (SELECT ---期初
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 DIMATER,
                 HEIGHT,
                 PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 PLINE_CODE,
                 PLINE_NAME,
                 ACT_COUNT,
                 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT
                  FROM YDM_HTT_INITIAL T
                 WHERE T.BAL_YEAR_MONTH = '#BALYEARMONTH#' #PLINECODE#
                 #PROSTATION#
                 #JUDGE_STOVE_NO#
                UNION ALL
                SELECT -- 上料
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                   M.AIMOUTDIAMETER DIMATER,
                 M.AIMWALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 T.PLINE_CODE,
                 T.PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 '' WATING_DECISION_MEMO,
                 T.PRO_NUM SOURCE_NUM_TOTAL,
                 T.PRO_WT SOURCE_WT_TOTAL,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 0 END_NUM,
                 0 END_WT
                  FROM VRP_LOADING_RESULT T, PLN_ZY_DBK_M M
                 WHERE   T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                 AND  T.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                 #PLINECODE#
                  #PROSTATION#
                  #JUDGE_STOVE_NO2#
                     UNION ALL
                   SELECT ---- 当月审核的废品  和当月组炉
                          M.PRODUCCODE,
                          M.PRODUCNAME,
                          M.STEELCODE,
                          M.STEELNAME,
                          M.GRADECODE,
                          M.GRADENAME,
                             M.AIMOUTDIAMETER DIMATER,
                 M.AIMWALLTHICK HEIGHT,
                          M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                          M.MODEL_CODE,
                          M.MODEL_DESC,
                          T.JUDGE_STOVE_NO,
                          T.PLINE_CODE,
                          T.PLINE_NAME,
                          0 ACT_COUNT,
                          0 ACT_WEIGHT,
                          ''  WATING_DECISION_MEMO,
                          0 SOURCE_NUM_TOTAL,
                          0 SOURCE_WT_TOTAL,
                          0 JUDGE_NUM,
                          0 JUDGE_WT,
                          DECODE(T.MAT_STATUS, '10', 1, '40', 1, 0) FAIL_NUM,
                          DECODE(T.MAT_STATUS,
                                 '10',
                                 T.ACT_WEIGHT,
                                 '40',
                                 T.ACT_WEIGHT,
                                 0) FAIL_WT,
                          DECODE(T.MAT_STATUS, '30', 1, 0) GROUP_NUM,
                          DECODE(T.MAT_STATUS, '30', T.ACT_WEIGHT, 0) GROUP_WT,
                          0 END_NUM,
                          0 END_WT
                           FROM PORT_VRP_BATCH_SAMPLE_RESULT T ,PLN_ZY_DBK_M M
                          WHERE  T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
                           AND T.VALIDFLAG = '1' #PLINECODE#
                          #PROSTATION#
                          #JUDGE_STOVE_NO#
                            AND IS_FAIL_CHECK = '1'
                            AND BAL_YEAR_MONTH_FAIL IS NOT NULL
                            AND BAL_YEAR_MONTH_FAIL = '#BALYEARMONTH#'

                         UNION ALL
                         SELECT --- 当月判定支
                               M.PRODUCCODE,
                 M.PRODUCNAME,
                 M.STEELCODE,
                 M.STEELNAME,
                 M.GRADECODE,
                 M.GRADENAME,
                   M.AIMOUTDIAMETER DIMATER,
                 M.AIMWALLTHICK HEIGHT,
                 M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
                 M.MODEL_CODE,
                 M.MODEL_DESC,
                          T.JUDGE_STOVE_NO,
                          T.PLINE_CODE,
                          T.PLINE_NAME,
                          0 ACT_COUNT,
                          0 ACT_WEIGHT,
                          '' WATING_DECISION_MEMO,
                          0 SOURCE_NUM_TOTAL,
                          0 SOURCE_WT_TOTAL,
                          ACT_COUNT JUDGE_NUM,
                          ACT_WEIGHT JUDGE_WT,
                          0 FAIL_NUM,
                          0 FAIL_WT,
                          0 GROUP_NUM,
                          0 GROUP_WT,
                          0 END_NUM,
                          0 END_WT
                           FROM QCM_ZG_JUGDE_APPLY T,PLN_ZY_DBK_M M
                          WHERE M.HEAT_PLAN_NO = T.HEAT_PLAN_NO
                            AND T.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                          #JUDGE_STOVE_NO#
                            AND T.PROCESS_CODE = 'E'
                            AND  (((JUDGE_RESULT_CODE = '40740701' OR JUDGE_RESULT_CODE = '40740709' OR
       EXISTS (SELECT 1
                   FROM QCM_BC_PASS_APPLY
                  WHERE JUGDE_APPLY_CODE = T.JUGDE_APPLY_CODE
                    AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                    AND BATCH_NO = T.BATCH_NO
                    AND VALIDFLAG = '1'
                    AND TYPE = '1')) AND TARGET <> 'A') OR
       (TARGET = 'A' AND (JUDGE_TOLRESULT_CODE = '40740701' OR
       JUDGE_TOLRESULT_CODE = '40740709')))
                            AND IS_FLAG = '0'
                            AND IS_ALL_SCRAP IN ('0', '2', '5', '7') #PLINECODE#
                          #PROSTATION#
                          #JUDGE_STOVE_NO#
UNION ALL
SELECT ---已结算的期末
                 PRODUCCODE,
                 PRODUCNAME,
                 STEELCODE,
                 STEELNAME,
                 GRADECODE,
                 GRADENAME,
                 DIMATER,
                 HEIGHT,
                 PRO_ORDER_NO,
                 MODEL_CODE,
                 MODEL_DESC,
                 JUDGE_STOVE_NO,
                 PLINE_CODE,
                 PLINE_NAME,
                 0 ACT_COUNT,
                 0 ACT_WEIGHT,
                 MEMO WATING_DECISION_MEMO,
                 0 SOURCE_NUM_TOTAL,
                 0 SOURCE_WT_TOTAL,
                 0 JUDGE_NUM,
                 0 JUDGE_WT,
                 0 FAIL_NUM,
                 0 FAIL_WT,
                 0 GROUP_NUM,
                 0 GROUP_WT,
                 ACT_COUNT END_NUM,
                 ACT_WEIGHT END_WT
                  FROM YDM_HTT_INITIAL T
                 WHERE T.BAL_YEAR_MONTH = '#BALYEARMONTH_NEXT#' #PLINECODE#
                 #PROSTATION#
                 #JUDGE_STOVE_NO#
UNION ALL
SELECT  --- 未结算的期末
       M.PRODUCCODE,
       M.PRODUCNAME,
       M.STEELCODE,
       M.STEELNAME,
       M.GRADECODE,
       M.GRADENAME,
        M.AIMOUTDIAMETER DIMATER,
                 M.AIMWALLTHICK HEIGHT,
       M.ORDER_NO || '/' || M.ORDER_SEQ PRO_ORDER_NO,
       M.MODEL_CODE,
       M.MODEL_DESC,
       M.JUDGE_STOVE_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       0 ACT_COUNT,
       0 ACT_WEIGHT,
       M.WAITING_DECISION_MEMO WATING_DECISION_MEMO,
       0 SOURCE_NUM_TOTAL,
       0 SOURCE_WT_TOTAL,
       0 JUDGE_NUM,
       0 JUDGE_WT,
       0 FAIL_NUM,
       0 FAIL_WT,
       0 GROUP_NUM,
       0 GROUP_WT,
       T.END_NUM,
       T.END_WT
  FROM (SELECT SUM(END_NUM) END_NUM,
               SUM(END_WT) END_WT,
               HEAT_PLAN_NO,
               JUDGE_STOVE_NO,
               PLINE_CODE,
               PLINE_NAME
          FROM (SELECT T.HEAT_PLAN_NO,
                        T.JUDGE_STOVE_NO,
                       T.PLINE_CODE,
                       T.PLINE_NAME,
                       T.ACT_COUNT END_NUM,
                      ACT_WEIGHT END_WT
                  FROM PORT_VRP_BATCH_SAMPLE_RESULT T
                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                   AND T.BAL_YEAR_MONTH > '201807'
                   AND T.VALIDFLAG = '1'
                   AND T.MAT_STATUS = '20'
                UNION ALL
                SELECT T.HEAT_PLAN_NO,
                   T.JUDGE_STOVE_NO,
                       T.PLINE_CODE,
                       T.PLINE_NAME,
                       T.ACT_COUNT END_NUM,
                      ACT_WEIGHT END_WT
                  FROM PORT_VRP_BATCH_SAMPLE_RESULT T
                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                   AND T.BAL_YEAR_MONTH > '201807'
                   AND T.VALIDFLAG = '1'
                   AND T.MAT_STATUS IN ('10', '40')
                   AND (T.IS_FAIL_CHECK = '0' OR
                       T.BAL_YEAR_MONTH_FAIL >= '#BALYEARMONTH_NEXT#')
                UNION ALL
                SELECT T.HEAT_PLAN_NO,
                   T.JUDGE_STOVE_NO,
                       T.PLINE_CODE,
                       T.PLINE_NAME,
                       T.ACT_COUNT END_NUM,
                      ACT_WEIGHT END_WT
                  FROM PORT_VRP_BATCH_SAMPLE_RESULT T
                 WHERE T.BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                   AND T.BAL_YEAR_MONTH > '201807'
                   AND T.VALIDFLAG = '1'
                   AND T.MAT_STATUS = '00'
                   AND NOT EXISTS
                 (SELECT 1
                          FROM QCM_ZG_JUGDE_APPLY QCM
                         WHERE 1 = 1
                           AND IS_FLAG = '0'
                           AND IS_ALL_SCRAP IN ('0', '2', '7')
                           AND PROCESS_CODE = 'E'
                           AND  (((JUDGE_RESULT_CODE = '40740701' OR JUDGE_RESULT_CODE = '40740709' OR
       EXISTS (SELECT 1
                   FROM QCM_BC_PASS_APPLY
                  WHERE JUGDE_APPLY_CODE = QCM.JUGDE_APPLY_CODE
                    AND JUDGE_STOVE_NO = QCM.JUDGE_STOVE_NO
                    AND BATCH_NO = QCM.BATCH_NO
                    AND VALIDFLAG = '1'
                    AND TYPE = '1')) AND TARGET <> 'A') OR
       (TARGET = 'A' AND (JUDGE_TOLRESULT_CODE = '40740701' OR
       JUDGE_TOLRESULT_CODE = '40740709')))
                           AND BAL_YEAR_MONTH < '#BALYEARMONTH_NEXT#'
                           AND JUGDE_APPLY_CODE = NVL(T.JUGDE_APPLY_CODE, '/')
                   AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                   AND BATCH_NO = T.PHY_BATCH_NO))
         GROUP BY HEAT_PLAN_NO,  JUDGE_STOVE_NO, PLINE_CODE, PLINE_NAME) T,
       PLN_ZY_DBK_M M
 WHERE T.HEAT_PLAN_NO = M.HEAT_PLAN_NO
   AND NOT EXISTS (SELECT 1
          FROM YDM_HTT_INITIAL
         WHERE PLINE_CODE = T.PLINE_CODE
           AND BAL_YEAR_MONTH = '#BALYEARMONTH_NEXT#'
           AND ROWNUM = 1)
            #PLINECODE#
             #PROSTATION#
             #JUDGE_STOVE_NO#
                )
         WHERE 1 = 1 #PLN#
         GROUP BY PRODUCCODE,
                  PRODUCNAME,
                  STEELCODE,
                  STEELNAME,
                  GRADECODE,
                  GRADENAME,
                  DIMATER,
                  HEIGHT,
                  PRO_ORDER_NO,
                  MODEL_CODE,
                  MODEL_DESC,
                  JUDGE_STOVE_NO,
                  PLINE_CODE,
                  PLINE_NAME)
 WHERE ACT_COUNT > 0
    OR SOURCE_NUM_TOTAL > 0
    OR JUDGE_NUM > 0
    OR FAIL_NUM > 0
    OR GROUP_NUM > 0
    OR END_NUM > 0
 ORDER BY PLINE_CODE, JUDGE_STOVE_NO

]]>
	</query>

	<query id = "FrmHttRunTimeRpt.doQuery" desc = "">
		<![CDATA[
SELECT BAL_YEAR_MONTH,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       MODEL_CODE,
       MODEL_DESC,
       ACT_DIMATER DIMATER,
       ACT_HEIGHT HEIGHT,
       PRO_ORDER_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       SUM(BEG_NUM) BEG_NUM, --期初支
       SUM(BEG_WT) BEG_WT, --期初吨
       PLINE_NAME_IN, -- 入库产线
       SUM(IN_NUM) IN_NUM, --入库支
       SUM(IN_WT) IN_WT, -- 入库吨
       DECODE(COUNT(1),
              1,
              MAX(STORAGE_NAME),
              DBMS_LOB.SUBSTR(WMSYS.WM_CONCAT(STORAGE_NAME || IN_NUM_ALL || '/' ||
                                              TO_CHAR(IN_WT_ALL,
                                                      'fm999990.099')),
                              4000)) IN_STORAGE,
       IN_YEAR_MONTH, --入库年月
       PLINE_NAME_OUT, -- 出库产线
       SUM(OUT_NUM) OUT_NUM, --出库支
       SUM(OUT_WT) OUT_WT, -- 出库吨
       SUM(END_NUM) END_NUM, --期末支
       SUM(END_WT) END_WT --期末吨
  FROM (SELECT BAL_YEAR_MONTH,
               PRODUCCODE,
               PRODUCNAME,
               STEELCODE,
               STEELNAME,
               GRADECODE,
               GRADENAME,
               MODEL_CODE,
               MODEL_DESC,
               ACT_DIMATER,
               ACT_HEIGHT,
               PRO_ORDER_NO,
               JUDGE_STOVE_NO,
               BATCH_NO,
               SUM(BEG_NUM) BEG_NUM, --期初支
               SUM(BEG_WT) BEG_WT, --期初吨
               PLINE_NAME_IN, -- 入库产线
               SUM(IN_NUM_ALL) IN_NUM_ALL,
               SUM(IN_WT_ALL) IN_WT_ALL,
               SUM(IN_NUM) IN_NUM, --入库支
               SUM(IN_WT) IN_WT, -- 入库吨
               B.STORAGE_NAME, -- 入库仓库
               IN_YEAR_MONTH, --入库年月
               PLINE_NAME_OUT, -- 出库产线
               SUM(OUT_NUM) OUT_NUM, --出库支
               SUM(OUT_WT) OUT_WT, -- 出库吨
               SUM(END_NUM) END_NUM, --期末支
               SUM(END_WT) END_WT --期末吨
          FROM (SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH, -- 库存表年月小于当月的数据      计算 期初  期末
                       M.PRODUCCODE,
                       M.PRODUCNAME,
                       M.STEELCODE,
                       M.STEELNAME,
                       M.GRADECODE,
                       M.GRADENAME,
                       M.MODEL_CODE,
                       M.MODEL_DESC,
                       M.ACT_DIMATER,
                       M.ACT_HEIGHT,
                       M.PRO_ORDER_NO,
                       M.JUDGE_STOVE_NO,
                       M.BATCH_NO,
                       1 BEG_NUM, --期初支
                       M.ACT_WEIGHT BEG_WT, --期初吨
                       M.PLINE_NAME PLINE_NAME_IN, -- 入库产线
                       1 IN_NUM_ALL, --入库支
                       M.ACT_WEIGHT IN_WT_ALL, -- 入库吨
                       0 IN_NUM, --入库支
                       0 IN_WT, -- 入库吨
                       B.STORAGE_NO, -- 入库仓库
                       I.BAL_YEAR_MONTH IN_YEAR_MONTH, --入库年月
                       '' PLINE_NAME_OUT, -- 出库产线
                       0 OUT_NUM, --出库支
                       0 OUT_WT, -- 出库吨
                       1 END_NUM, --期末支
                       M.ACT_WEIGHT END_WT --期末吨
                  FROM MAT_BC_M M, YDM_BC_BUTTRESS B, YDM_BC_INLIST I
                 WHERE M.MAT_NO = B.MAT_NO
                   AND I.INSTOCK_TYPE_CODE = '800709'
                   AND M.MAT_NO = I.MAT_NO
                   AND M.PLINE_CODE = I.PLINE_CODE
                   AND M.BELONG_CODE = '002001001'
                   AND I.CUT_FLAG IS NULL

                   AND  I.BAL_YEAR_MONTH < '#BALYEARMONTH#'
                   AND M.QCM_STAUS = '00'
                   AND NOT EXISTS (SELECT 1 FROM QCM_ZG_JUGDE_APPLY WHERE IS_ALL_SCRAP  = '5'
                      AND  JUGDE_APPLY_CODE = M.JUGDE_APPLY_CODE
                      AND  JUGDE_APPLY_SEQUENO  = M.JUGDE_APPLY_SEQUENO )
                      #PLINECODE#
                      #PlnCondition#

                UNION ALL
                SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH, -- 库存表年月小于当月的数据      计算  入库支  期末
                       M.PRODUCCODE,
                       M.PRODUCNAME,
                       M.STEELCODE,
                       M.STEELNAME,
                       M.GRADECODE,
                       M.GRADENAME,
                       M.MODEL_CODE,
                       M.MODEL_DESC,
                       M.ACT_DIMATER,
                       M.ACT_HEIGHT,
                       M.PRO_ORDER_NO,
                       M.JUDGE_STOVE_NO,
                       M.BATCH_NO,
                       0 BEG_NUM, --期初支
                       0 BEG_WT, --期初吨
                       M.PLINE_NAME PLINE_NAME_IN, -- 入库产线
                       1 IN_NUM_ALL, --入库支
                       M.ACT_WEIGHT IN_WT_ALL, -- 入库吨
                       1 IN_NUM, --入库支
                       M.ACT_WEIGHT IN_WT, -- 入库吨
                       B.STORAGE_NO, -- 入库仓库
                       I.BAL_YEAR_MONTH IN_YEAR_MONTH, --入库年月
                       '' PLINE_NAME_OUT, -- 出库产线
                       0 OUT_NUM, --出库支
                       0 OUT_WT, -- 出库吨
                       1 END_NUM, --期末支
                       M.ACT_WEIGHT END_WT --期末吨
                  FROM MAT_BC_M M, YDM_BC_BUTTRESS B, YDM_BC_INLIST I
                 WHERE M.MAT_NO = B.MAT_NO
                   AND I.INSTOCK_TYPE_CODE = '800709'
                   AND M.MAT_NO = I.MAT_NO
                   AND M.PLINE_CODE = I.PLINE_CODE
                   AND M.BELONG_CODE = '002001001'
                      AND I.CUT_FLAG IS NULL
                   AND I.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                   AND M.QCM_STAUS = '00'
                    AND NOT EXISTS (SELECT 1 FROM QCM_ZG_JUGDE_APPLY WHERE IS_ALL_SCRAP  = '5'
                      AND  JUGDE_APPLY_CODE = M.JUGDE_APPLY_CODE
                      AND  JUGDE_APPLY_SEQUENO  = M.JUGDE_APPLY_SEQUENO
                      )
                      #PLINECODE#
                      #PlnCondition#
                UNION ALL
                SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH, -- 库存备份表中  出库和入库都是当月的数据      计算  入库支  出库支
                       M.PRODUCCODE,
                       M.PRODUCNAME,
                       M.STEELCODE,
                       M.STEELNAME,
                       M.GRADECODE,
                       M.GRADENAME,
                       M.MODEL_CODE,
                       M.MODEL_DESC,
                       M.ACT_DIMATER,
                       M.ACT_HEIGHT,
                       M.PRO_ORDER_NO,
                       M.JUDGE_STOVE_NO,
                       M.BATCH_NO,
                       0 BEG_NUM, --期初支
                       0 BEG_WT, --期初吨
                       M.PLINE_NAME PLINE_NAME_IN, -- 入库产线
                       1 IN_NUM_ALL, --入库支
                       M.ACT_WEIGHT IN_WT_ALL, -- 入库吨
                       1 IN_NUM, --入库支
                       M.ACT_WEIGHT IN_WT, -- 入库吨
                       O.STORAGE_NO, -- 入库仓库
                       DECODE(M.JUDGE_STOVE_NO,'595313','201910', I.BAL_YEAR_MONTH) IN_YEAR_MONTH, --入库年月
                       O.LOAD_PLINE_NAME PLINE_NAME_OUT, -- 出库产线
                       1 OUT_NUM, --出库支
                       M.ACT_WEIGHT OUT_WT, -- 出库吨
                       0 END_NUM, --期末支
                       0 END_WT --期末吨
                  FROM MAT_BC_BACKUP M, YDM_BC_INLIST I, YDM_BC_OUTLIST O
                 WHERE M.BELONG_CODE = '002001001'
                   AND O.OUTSTOCK_TYPE_CODE = '800809'
                   AND I.INSTOCK_TYPE_CODE = '800709'
                   AND M.MAT_NO = I.MAT_NO
                   AND M.MAT_NO = O.MAT_NO
                   AND M.PLINE_CODE = I.PLINE_CODE
                   AND M.PLINE_CODE = O.PLINE_CODE
                   AND (O.BAL_YEAR_MONTH = '#BALYEARMONTH#' OR (M.JUDGE_STOVE_NO = '595313' AND '#BALYEARMONTH#'='201910'))
                   AND (I.BAL_YEAR_MONTH = '#BALYEARMONTH#' OR  (M.JUDGE_STOVE_NO = '595313' AND '#BALYEARMONTH#'='201910'))
                   AND I.BAL_YEAR_MONTH IS NOT NULL
                   AND O.BAL_YEAR_MONTH IS NOT NULL
                   AND I.MAT_NO IS NOT NULL
                   AND I.PLINE_CODE IS NOT NULL
                      AND I.CUT_FLAG IS NULL
                   AND O.MAT_NO IS NOT NULL
                   AND O.PLINE_CODE IS NOT NULL
                   AND O.OUTSTOCK_TYPE_CODE IS NOT NULL
                   AND I.INSTOCK_TYPE_CODE IS NOT NULL
                   AND O.BAL_YEAR_MONTH IS NOT NULL
                   AND M.QCM_STAUS = '00'
                    AND NOT EXISTS (SELECT 1 FROM QCM_ZG_JUGDE_APPLY WHERE IS_ALL_SCRAP  = '5'
                      AND  JUGDE_APPLY_CODE = M.JUGDE_APPLY_CODE
                      AND  JUGDE_APPLY_SEQUENO  = M.JUGDE_APPLY_SEQUENO
                      )
                      #PLINECODE#
                      #PlnCondition#
                UNION ALL
                SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH, -- 库存备份表中  入库是当月  出库大于当月的数据        计算  入库支  期末
                       M.PRODUCCODE,
                       M.PRODUCNAME,
                       M.STEELCODE,
                       M.STEELNAME,
                       M.GRADECODE,
                       M.GRADENAME,
                       M.MODEL_CODE,
                       M.MODEL_DESC,
                       M.ACT_DIMATER,
                       M.ACT_HEIGHT,
                       M.PRO_ORDER_NO,
                       M.JUDGE_STOVE_NO,
                       M.BATCH_NO,
                       0 BEG_NUM, --期初支
                       0 BEG_WT, --期初吨
                       M.PLINE_NAME PLINE_NAME_IN, -- 入库产线
                       1 IN_NUM_ALL, --入库支
                       M.ACT_WEIGHT IN_WT_ALL, -- 入库吨
                       1 IN_NUM, --入库支
                       M.ACT_WEIGHT IN_WT, -- 入库吨
                       O.STORAGE_NO, -- 入库仓库
                       I.BAL_YEAR_MONTH IN_YEAR_MONTH, --入库年月
                       '' PLINE_NAME_OUT, -- 出库产线
                       0 OUT_NUM, --出库支
                       0 OUT_WT, -- 出库吨
                       1 END_NUM, --期末支
                       M.ACT_WEIGHT END_WT --期末吨
                  FROM MAT_BC_BACKUP M, YDM_BC_INLIST I, YDM_BC_OUTLIST O
                 WHERE M.BELONG_CODE = '002001001'

                   AND O.OUTSTOCK_TYPE_CODE = '800809'
                   AND I.INSTOCK_TYPE_CODE = '800709'
                   AND M.MAT_NO = I.MAT_NO
                   AND M.MAT_NO = O.MAT_NO
                   AND M.PLINE_CODE = I.PLINE_CODE
                   AND M.PLINE_CODE = O.PLINE_CODE
                   AND O.BAL_YEAR_MONTH > '#BALYEARMONTH#'
                   AND I.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                   AND I.BAL_YEAR_MONTH IS NOT NULL
                   AND O.BAL_YEAR_MONTH IS NOT NULL
                   AND I.MAT_NO IS NOT NULL
                   AND I.PLINE_CODE IS NOT NULL
                      AND I.CUT_FLAG IS NULL
                   AND O.MAT_NO IS NOT NULL
                   AND O.PLINE_CODE IS NOT NULL
                   AND O.OUTSTOCK_TYPE_CODE IS NOT NULL
                   AND I.INSTOCK_TYPE_CODE IS NOT NULL
                   AND O.BAL_YEAR_MONTH IS NOT NULL
                   AND M.QCM_STAUS = '00'
                    AND NOT EXISTS (SELECT 1 FROM QCM_ZG_JUGDE_APPLY WHERE IS_ALL_SCRAP  = '5'
                      AND  JUGDE_APPLY_CODE = M.JUGDE_APPLY_CODE
                      AND  JUGDE_APPLY_SEQUENO  = M.JUGDE_APPLY_SEQUENO
                      )
                      #PLINECODE#
                      #PlnCondition#
                UNION ALL
                SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH, -- 库存备份表中  入库小于当月  出库是当月的数据        计算  期初  出库
                       M.PRODUCCODE,
                       M.PRODUCNAME,
                       M.STEELCODE,
                       M.STEELNAME,
                       M.GRADECODE,
                       M.GRADENAME,
                       M.MODEL_CODE,
                       M.MODEL_DESC,
                       M.ACT_DIMATER,
                       M.ACT_HEIGHT,
                       M.PRO_ORDER_NO,
                       M.JUDGE_STOVE_NO,
                       M.BATCH_NO,
                       1 BEG_NUM, --期初支
                       M.ACT_WEIGHT BEG_WT, --期初吨
                       M.PLINE_NAME PLINE_NAME_IN, -- 入库产线
                       1 IN_NUM_ALL, --入库支
                       M.ACT_WEIGHT IN_WT_ALL, -- 入库吨
                       0 IN_NUM, --入库支
                       0 IN_WT, -- 入库吨
                       O.STORAGE_NO, -- 入库仓库
                       I.BAL_YEAR_MONTH IN_YEAR_MONTH, --入库年月
                       O.LOAD_PLINE_NAME PLINE_NAME_OUT, -- 出库产线
                       1 OUT_NUM, --出库支
                       M.ACT_WEIGHT OUT_WT, -- 出库吨
                       0 END_NUM, --期末支
                       0 END_WT --期末吨
                  FROM MAT_BC_BACKUP M, YDM_BC_INLIST I, YDM_BC_OUTLIST O
                 WHERE M.BELONG_CODE = '002001001'

                   AND O.OUTSTOCK_TYPE_CODE = '800809'
                   AND I.INSTOCK_TYPE_CODE = '800709'
                   AND M.MAT_NO = I.MAT_NO
                   AND M.MAT_NO = O.MAT_NO
                   AND M.PLINE_CODE = I.PLINE_CODE
                   AND M.PLINE_CODE = O.PLINE_CODE
                   AND O.BAL_YEAR_MONTH = '#BALYEARMONTH#'
                   AND I.BAL_YEAR_MONTH < '#BALYEARMONTH#'
                   AND I.BAL_YEAR_MONTH IS NOT NULL
                   AND O.BAL_YEAR_MONTH IS NOT NULL
                   AND I.MAT_NO IS NOT NULL
                   AND I.PLINE_CODE IS NOT NULL
                      AND I.CUT_FLAG IS NULL
                   AND O.MAT_NO IS NOT NULL
                   AND O.PLINE_CODE IS NOT NULL
                   AND O.OUTSTOCK_TYPE_CODE IS NOT NULL
                   AND I.INSTOCK_TYPE_CODE IS NOT NULL
                   AND O.BAL_YEAR_MONTH IS NOT NULL
                   AND M.QCM_STAUS = '00'
                    AND NOT EXISTS (SELECT 1 FROM QCM_ZG_JUGDE_APPLY WHERE IS_ALL_SCRAP  = '5'
                      AND  JUGDE_APPLY_CODE = M.JUGDE_APPLY_CODE
                      AND  JUGDE_APPLY_SEQUENO  = M.JUGDE_APPLY_SEQUENO
                      )
                      #PLINECODE#
                      #PlnCondition#
                UNION ALL
                SELECT '#BALYEARMONTH#' BAL_YEAR_MONTH, -- 库存备份表中  入库小于当月  出库大于当月的数据        计算  期初  期末
                       M.PRODUCCODE,
                       M.PRODUCNAME,
                       M.STEELCODE,
                       M.STEELNAME,
                       M.GRADECODE,
                       M.GRADENAME,
                       M.MODEL_CODE,
                       M.MODEL_DESC,
                       M.ACT_DIMATER,
                       M.ACT_HEIGHT,
                       M.PRO_ORDER_NO,
                       M.JUDGE_STOVE_NO,
                       M.BATCH_NO,
                       1 BEG_NUM, --期初支
                       M.ACT_WEIGHT BEG_WT, --期初吨
                       M.PLINE_NAME PLINE_NAME_IN, -- 入库产线
                       1 IN_NUM_ALL, --入库支
                       M.ACT_WEIGHT IN_WT_ALL, -- 入库吨
                       0 IN_NUM, --入库支
                       0 IN_WT, -- 入库吨
                       O.STORAGE_NO, -- 入库仓库
                       I.BAL_YEAR_MONTH IN_YEAR_MONTH, --入库年月
                       '' PLINE_NAME_OUT, -- 出库产线
                       0 OUT_NUM, --出库支
                       0 OUT_WT, -- 出库吨
                       1 END_NUM, --期末支
                       M.ACT_WEIGHT END_WT --期末吨
                  FROM MAT_BC_BACKUP M, YDM_BC_INLIST I, YDM_BC_OUTLIST O
                 WHERE M.BELONG_CODE = '002001001'

                   AND O.OUTSTOCK_TYPE_CODE = '800809'
                   AND I.INSTOCK_TYPE_CODE = '800709'
                   AND M.MAT_NO = I.MAT_NO
                   AND M.MAT_NO = O.MAT_NO
                   AND M.PLINE_CODE = I.PLINE_CODE
                   AND M.PLINE_CODE = O.PLINE_CODE
                   AND O.BAL_YEAR_MONTH > '#BALYEARMONTH#'
                   AND I.BAL_YEAR_MONTH < '#BALYEARMONTH#'
                   AND I.BAL_YEAR_MONTH IS NOT NULL
                   AND O.BAL_YEAR_MONTH IS NOT NULL
                   AND I.MAT_NO IS NOT NULL
                   AND I.PLINE_CODE IS NOT NULL
                      AND I.CUT_FLAG IS NULL
                   AND O.MAT_NO IS NOT NULL
                   AND O.PLINE_CODE IS NOT NULL
                   AND O.OUTSTOCK_TYPE_CODE IS NOT NULL
                   AND I.INSTOCK_TYPE_CODE IS NOT NULL
                   AND O.BAL_YEAR_MONTH IS NOT NULL
                   AND M.QCM_STAUS = '00'
                    AND NOT EXISTS (SELECT 1 FROM QCM_ZG_JUGDE_APPLY WHERE IS_ALL_SCRAP  = '5'
                      AND  JUGDE_APPLY_CODE = M.JUGDE_APPLY_CODE
                      AND  JUGDE_APPLY_SEQUENO  = M.JUGDE_APPLY_SEQUENO
                      )
                      #PLINECODE#
                      #PlnCondition#
                      ) M
                       LEFT JOIN YDM_BS_STORAGE B
            ON M.STORAGE_NO = B.STORAGE_NO
         GROUP BY BAL_YEAR_MONTH,
                  PRODUCCODE,
                  PRODUCNAME,
                  STEELCODE,
                  STEELNAME,
                  GRADECODE,
                  GRADENAME,
                  MODEL_CODE,
                  MODEL_DESC,
                  ACT_DIMATER,
                  ACT_HEIGHT,
                  PRO_ORDER_NO,
                  JUDGE_STOVE_NO,
                  BATCH_NO,
                  PLINE_NAME_IN,
                  IN_YEAR_MONTH,
                  PLINE_NAME_OUT,
                  B.STORAGE_NAME)
 GROUP BY BAL_YEAR_MONTH,
          PRODUCCODE,
          PRODUCNAME,
          STEELCODE,
          STEELNAME,
          GRADECODE,
          GRADENAME,
          MODEL_CODE,
          MODEL_DESC,
          ACT_DIMATER,
          ACT_HEIGHT,
          PRO_ORDER_NO,
          JUDGE_STOVE_NO,
          BATCH_NO,
          PLINE_NAME_IN,
          IN_YEAR_MONTH,
          PLINE_NAME_OUT


]]>
	</query>


	<query id = "FrmHttRunTimeRpt.SelectCount" desc = "">
		<![CDATA[
SELECT COUNT(1) COUNT FROM YDM_HTT_INITIAL WHERE BAL_YEAR_MONTH = ?
]]>
	</query>
	
	<query id = "FrmHttRunTimeRpt.SelectCountJg" desc = "">
		<![CDATA[
SELECT COUNT(1) COUNT FROM YDM_ZC_INITIAL_JG_HSK WHERE BAL_YEAR_MONTH = ?
]]>
	</query>

	<query id = "FrmHttRunTimeRpt.DeleteTal" desc = "">
		<![CDATA[
DELETE FROM YDM_HTT_INITIAL WHERE BAL_YEAR_MONTH = ?
]]>
	</query>
	
	<query id = "FrmHttRunTimeRpt.DeleteTalJg" desc = "">
		<![CDATA[
DELETE FROM YDM_ZC_INITIAL_JG_HSK WHERE BAL_YEAR_MONTH = ?
]]>
	</query>

	<query id = "FrmHttRunTimeRpt.insertTal" desc = "">
		<![CDATA[
INSERT INTO YDM_HTT_INITIAL
  ( JUDGE_STOVE_NO,
   BATCH_NO,
   PRODUCCODE,
   PRODUCNAME,
   STEELCODE,
   STEELNAME,
   SPEC_CODE,
   SPEC_NAME,
   MODEL_CODE,
   MODEL_DESC,
   STD_CODE,
   STD_NAME,
   STD_STYLE,
   STD_STYLE_DESC,
   ACT_COUNT,
   ACT_WEIGHT,
   PRO_ORDER_NO,
   MEMO,
   CREATE_NAME,
   CREATE_TIME,
   BAL_YEAR_MONTH,
   GRADECODE,
   GRADENAME,
   PLINE_CODE,
   PLINE_NAME,
   OUTNUM_CUT,
   DIMATER,
   HEIGHT)
VALUES
  ( '#JUDGE_STOVE_NO#',
   '#BATCH_NO#',
   '#PRODUCCODE#',
   '#PRODUCNAME#',
   '#STEELCODE#',
   '#STEELNAME#',
   '#SPEC_CODE#',
   '#SPEC_NAME#',
   '#MODEL_CODE#',
   '#MODEL_DESC#',
   '#STD_CODE#',
   '#STD_NAME#',
   '#STD_STYLE#',
   '#STD_STYLE_DESC#',
   '#END_NUM#',
   '#END_WT#',
   '#PRO_ORDER_NO#',
   '#WATING_DECISION_MEMO#',
   '#CREATE_NAME#',
   '#CREATE_TIME#',
   '#BAL_YEAR_MONTH#',
   '#GRADECODE#',
   '#GRADENAME#',
   '#PLINE_CODE#',
   '#PLINE_NAME#',
   '#OUTNUM_CUT#',
   '#DIMATER#',
   '#HEIGHT#')

]]>
	</query>
	
	<query id = "FrmHttRunTimeRpt.insertTalJg" desc = "">
		<![CDATA[
 INSERT INTO YDM_ZC_INITIAL_JG_HSK(
        INITIAL_ID,
        JUDGE_STOVE_NO,
        BATCH_NO,
        WO_ID,
        PLINE_CODE,
        PLINE_NAME,
        STEELCODE,
        STEELNAME,
        GRADECODE,
        GRADENAME,
        DIMATER,
        HEIGHT,
        MODEL_CODE,
        MODEL_DESC,
        PRODUCCODE,
        PRODUCNAME,
        ACT_COUNT,
        ACT_WEIGHT,
        CREATE_NAME,
        CREATE_TIME,
        BAL_YEAR_MONTH)
 VALUES( 
        '#INITIAL_ID#',
        '#JUDGE_STOVE_NO#',
        '#BATCH_NO#',
        '#WO_ID#',
        '#PLINE_CODE#',
        '#PLINE_NAME#',
        '#STEELCODE#',
        '#STEELNAME#',
        '#GRADECODE#',
        '#GRADENAME#',
        '#DIMATER#',
        '#HEIGHT#',
        '#MODEL_CODE#',
        '#MODEL_DESC#',
        '#PRODUCCODE#',
        '#PRODUCNAME#',
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        '#CREATE_NAME#',
        SYSDATE,
        '#BAL_YEAR_MONTH#')
]]>
	</query>
	
	<query id = "FrmHttRunTimeRpt.doQueryJg" desc = "">
		<![CDATA[
SELECT AA.PRODUCNAME,
       AA.PLINE_CODE,
       AA.PLINE_NAME,
       AA.STEELNAME, --钢级
       AA.GRADENAME, --钢种
       AA.DIMATER,
       AA.HEIGHT,
       AA.MODEL_DESC,
       AA.JUDGE_STOVE_NO,
       AA.BATCH_NO,
       AA.WO_ID,
       NVL(SUM(AA.ACT_COUNT),0) ACT_COUNT, --期初
       NVL(SUM(AA.ACT_WEIGHT),0) ACT_WEIGHT,
       NVL(SUM(AA.LOAD_PIECES),0) LOAD_PIECES, --收料
       NVL(SUM(AA.LOAD_WEIGHT),0) LOAD_WEIGHT,
       NVL(SUM(AA.PRO_NUM),0) PRO_NUM, --缴库
       NVL(SUM(AA.PRO_WT),0) PRO_WT,
       NVL(SUM(AA.REJECTED_PCS),0) REJECTED_PCS, --废品
       NVL(SUM(AA.REJECTED_WT),0) REJECTED_WT,
       NVL(MAX(AA.VALIDFLAG), '00') VALIDFLAG

  FROM (SELECT '接箍' PRODUCNAME,
               TA.PLINE_CODE,
               TA.PLINE_NAME,
               MAX(TA.STEELNAME) STEELNAME, --钢级
               MAX(TA.GRADENAME) GRADENAME, --钢种
               MAX(JG.MIN_D) AS DIMATER,
               MAX(JG.MIN_H) AS HEIGHT,
               MAX(t3.model_desc) MODEL_DESC,
               TA.JUDGE_STOVE_NO,
               TA.BATCH_NO,
               TA.WO_ID,
               0 ACT_COUNT, --期初
               0 ACT_WEIGHT,
               SUM(TA.LOAD_PIECES) LOAD_PIECES, --收料
               SUM(TA.LOAD_WEIGHT) LOAD_WEIGHT,
               (SELECT SUM(M.COL_COUNT)
                  FROM COUPLING_PHOSPHATE_RESULT M
                 WHERE TA.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
                   AND M.WO_ID = TA.WO_ID) PRO_NUM, --缴库
               
               (SELECT ROUND((SUM(M.COL_COUNT)) / 1000 * MAX(JG.WEIGHT_JG), 3)
                  FROM COUPLING_PHOSPHATE_RESULT M
                 WHERE TA.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
                   AND M.WO_ID = TA.WO_ID) PRO_WT,
               
               (SELECT SUM(M.REJECTED_PCS)
                  FROM COUPLING_THREADING_RESULT M
                 WHERE TA.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
                   AND M.WO_ID = TA.WO_ID) REJECTED_PCS, --废品
               ROUND(MAX(JG.WEIGHT_JG / 1000) *
                     (SELECT SUM(M.REJECTED_PCS)
                        FROM COUPLING_THREADING_RESULT M
                       WHERE TA.WO_ID = M.WO_ID),
                     3) REJECTED_WT,
               NVL(MAX(T1.VALIDFLAG), '00') VALIDFLAG
          FROM (SELECT T.PLINE_CODE,
                       T.PLINE_NAME,
                       T.WO_ID,
                       T.JUDGE_STOVE_NO,
                       T.BATCH_NO,
                       SUM(T.LOAD_PIECES) LOAD_PIECES,
                       SUM(T.LOAD_WEIGHT) LOAD_WEIGHT,
                       MAX(T.STEELNAME) STEELNAME,
                       MAX(T.GRADENAME) GRADENAME
                  FROM COUPLING_LOADING_RESULT T
                 WHERE T.LOAD_TIME >
                       ADD_MONTHS(TO_DATE(#BALYEARMONTH# || '-25 20:59:59',
                                          'YYYY-MM-DD hh24:mi:ss'),
                                  -1)
                   AND T.LOAD_TIME <=
                       TO_DATE(#BALYEARMONTH# || '-25 20:59:59',
                               'YYYY-MM-DD hh24:mi:ss')
                 GROUP BY T.PLINE_CODE,
                          T.PLINE_NAME,
                          T.WO_ID,
                          T.JUDGE_STOVE_NO,
                          T.BATCH_NO) TA,
               PLN_ZY_JG_WORKBILL t3,
               COM_MSC_JG JG,
               QCM_ZG_JUGDE_APPLY T1
         WHERE TA.WO_ID = t3.WO_ID
           AND T3.CODE_JG = JG.CODE_JG
           AND T3.WO_ID = T1.PRO_ORDER_ID(+)
        --AND TA.JUDGE_STOVE_NO = '515940'
         GROUP BY TA.PLINE_CODE,
                  TA.PLINE_NAME,
                  TA.JUDGE_STOVE_NO,
                  TA.BATCH_NO,
                  TA.WO_ID,
                  JG.WEIGHT_JG
        
        UNION ALL
        
        SELECT T2.PRODUCNAME,
               T2.PLINE_CODE,
               T2.PLINE_NAME,
               T2.STEELNAME, --钢级
               T2.GRADENAME, --钢种
               T2.DIMATER,
               T2.HEIGHT,
               T2.MODEL_DESC,
               T2.JUDGE_STOVE_NO,
               T2.BATCH_NO,
               T2.WO_ID,
               T2.ACT_COUNT,
               T2.ACT_WEIGHT,
               0 LOAD_PIECES,
               0 LOAD_WEIGHT,
               0 PRO_NUM,
               0 PRO_WT,
               0 REJECTED_PCS,
               0 REJECTED_WT,
               NVL(T1.VALIDFLAG, '00') VALIDFLAG
          FROM YDM_ZC_INITIAL_JG_HSK T2, QCM_ZG_JUGDE_APPLY T1
         WHERE T2.WO_ID = T1.PRO_ORDER_ID(+)
           AND T2.BAL_YEAR_MONTH = #BALYEARMONTH#) AA
           WHERE 1=1
           #PLINECODE#
           #JUDGE_STOVE_NO#
 GROUP BY AA.PRODUCNAME,
          AA.PLINE_CODE,
          AA.PLINE_NAME,
          AA.STEELNAME, --钢级
          AA.GRADENAME, --钢种
          AA.DIMATER,
          AA.HEIGHT,
          AA.MODEL_DESC,
          AA.JUDGE_STOVE_NO,
          AA.BATCH_NO,
          AA.WO_ID

]]>
	</query>
</queryMap>