<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="权限功能表查询">

	<query id="CoreOrderReport.doQuery" desc="查询">
		<![CDATA[
			 SELECT T1.*,DECODE(T2.PROCESS_CODE, 'D','轧制') PROCESS_CODE,
       TO_CHAR(T2.REVIEW_ASK,'YYYY-MM-DD') REVIEW_ASK,T2.REVIEW_ASK_END
       FROM (SELECT B.STEELCODE,
                B.STEELNAME,
                DECODE(D.PORDERSTATUS,'0','待接收','1','已接收','2','已下发','3','生产中','4','生产完成',
                '5','缴库完成','6','发运完毕','7','结算完毕','8','合同关闭','','未提报') PORDERSTATUS,
                 (SELECT CREATE_TIME FROM PLN_SALEORD WHERE ORD_LN_DLY_PK = A.ORD_LN_DLY_PK ) REPORTTIME,
                C.SALE_AREA_DESC,
                (SELECT ABRVITION FROM SLM_BASE_CUSTOMER WHERE C.CUSTOMER_NO = CUSTOMER_NO AND VALIDFLAG = '1') ABRVITION,
                B.ORDER_SPEC_CODE,
                B.ORDER_SPEC_DESC,
                A.DELIVERY_STATUS,
                (SELECT BASENAME
                   FROM COM_BASE_INFO
                  WHERE BASECODE = A.DELIVERY_STATUS) ORDER_LN_STATUS_NM,
                DECODE(B.ASSEL_FL,'1','TRUE','FALSE') ASSEL_FL,
                DECODE(B.PRODUCER_FL,'1','TRUE','FALSE') PRODUCER_FL,
                DECODE(B.MPS_FL,'1','TRUE','FALSE') MPS_FL,
                B.ORD_PK,
                B.ORD_LN_PK,
                A.ORD_LN_DLY_PK,
                C.ORDER_NO,
                B.ORDER_SEQ,
                A.DELIVERY_NO,
                B.PRD_CLS,
                B.PRODUCCODE,
                B.PRODUCNAME,
                B.STD_CODE,
                B.STD_NAME,
                B.DIMATER OUTDIAMETER,
                B.HEIGHT WALLTHICK,
                B.LEN_NO,
                B.LEN_MIN LENGTHMIN,
                B.LEN_MAX LENGTHMAX,
                B.LEN_DESC LENGTHDISC,
                B.MODEL_CODE,
                B.MODEL_DESC,
                B.ORDER_UNIT,
                B.ORDER_QTY,
                A.WGT_ESTMT ORDERWEIGHT,
                DECODE(B.ORDER_UNIT, '支', B.ORDER_QTY, 0) ORDERNUM,
                A.ENSU_TOTL_LEN TOTLENGTH,
                B.DELVRY_RANGE_TPE,
                A.DELVRY_QTY,
                B.DELVRY_RANGE_MIN,
                B.DELVRY_RANGE_MAX,
                C.CUSTOMER_NO BUYER_ID,
                C.CUSTOMER_NM BUYER_NAME,
                B.CUST_ALPHA_NO,
                B.SPEC_CODE,
                B.SPEC_NAME,
                B.ORDER_SPECIAL_DESC,
                B.ADD_ASK_NO,
                B.ORDER_ADD_DESC,
                (SELECT BASENAME
                   FROM COM_BASE_INFO
                  WHERE C.SALE_ORG = BASECODE
                    AND VALIDFLAG = '1') ORDERFROM,
                C.SALE_ORG  ORDERFROMCODE,
                B.FINAL_USER,
                B.FINAL_USER_DESC,
                --B.PRDCR_DESC,
                (SELECT BASENAME
                   FROM COM_BASE_INFO
                  WHERE B.OUTS_BILLET_FL = BASECODE
                    AND VALIDFLAG = '1') OUTS_BILLET_FL,
                B.OUTS_BILLET_FL OUTS_BILLET_FL_CODE,
                B.USE_CODE,
                B.USE_DESC,
                B.LEN_UNIT,
                DECODE(B.DELVRY_RANGE_TPE, '绝对值', B.DELVRY_RANGE_MIN, '') LOWERLIMT,
                DECODE(B.DELVRY_RANGE_TPE, '绝对值', B.DELVRY_RANGE_MAX, '') UPPERLIMIT,
                '(-' || TO_CHAR(B.DELVRY_RANGE_MIN) ||
                DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
                TO_CHAR(B.DELVRY_RANGE_MAX) ||
                DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
                A.DELVRY_BDATE,
                TO_CHAR(A.DELVRY_EDATE,'YYYY-MM-DD') DELVRY_EDATE,
                (SELECT NVL(MAX(LST_PRD_DATE), '')
                   FROM SLM_ORD_DESIGN_MSC_PL_PC_LST
                  WHERE ORD_LN_DLY_PK = A.ORD_LN_DLY_PK
                    AND PROCESS_CODE = 'D') LATEST_PROD_DATE,
                C.CREATE_NAME ORDERCONTACT,
                --B.PRDCR_DESC MONITORDEMAND,
                B.PSC,
                B.MSC,
                DECODE(B.PRODUCER_FL,
                       '0',
                       '0',
                       CASE
                         WHEN TRIM(B.PRDCR_NO) IS NULL THEN
                          '0'
                         ELSE
                          DECODE((SELECT MAX(PRDCR_STS)
                                   FROM SLM_ORDER_LINE_PRDCR
                                  WHERE INSTR(B.PRDCR_NO,PRDCR_NO)>0
                                    AND PRDCR_STS = 'S'),
                                 'S',
                                 '1',
                                 '0')
                       END) JZ_FILE_IF_ALL,
                B.PRDCR_NO,
                (SELECT DISTINCT MATERIAL_NO
                   FROM SLM_ORD_DESIGN_BOM A1,SLM_ORD_LINE_BOM A2, SLM_ORD_DESIGN_MSC A3
                   WHERE A3.ORD_LN_PK = B.ORD_LN_PK
                   AND A3.VALIDFLAG = '1'
                   AND A2.DESGIN_KEY = A3.DESGIN_KEY
                   AND A1.BOM = A2.BOM) MATERIAL_NO,
                 (SELECT DISTINCT MATERIAL_DESC
                   FROM SLM_ORD_DESIGN_BOM A1,SLM_ORD_LINE_BOM A2, SLM_ORD_DESIGN_MSC A3
                   WHERE A3.ORD_LN_PK = B.ORD_LN_PK
                   AND A3.VALIDFLAG = '1'
                   AND A2.DESGIN_KEY = A3.DESGIN_KEY
                   AND A1.BOM = A2.BOM) MATERIAL_DESC,
                  B.SHRT_LEN_RATO,
                  B.SHORTEST,
                  B.LONG_LEN_RATO,
                  B.LONGEST,
                  B.ENDLEN_SPECSTD,
                  B.SHRT_STOVE,
                  B.AVG_LEN_MIN,
                  B.DIFRNC_LEN_MAX,
                  B.SIGL_LEN,
                  B.STD_STYLE_DESC,
                  B.OUTS_STL_PIPE_FL OUTS_STL_PIPE_FL_CODE,
                  B.AW,
                  E.ELIM_NUM,
				  E.ELIM_WGT,
                  E.ELIM_LEN,
                  E.CHARGE_NUM,
                  E.CHARGE_WGT,
                  E.CHARGE_LEN,
                  E.APP_NUM,
                  D.ROLL_MONTH,
                  C.ORDER_TYP,
                 (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = B.OUTS_STL_PIPE_FL AND VALIDFLAG = '1') OUTS_STL_PIPE_FL
           FROM SLM_ORDER_LINE_DELIVERY A,
                SLM_ORDER_LINE          B,
                SLM_ORDER_HEAD          C,
                PLN_SALEORD             D,
                PROCESS_ORDER_M         E
            WHERE A.ORD_PK = B.ORD_PK 
            AND A.ORD_LN_PK = B.ORD_LN_PK 
            AND A.ORD_PK = C.ORD_PK 
            AND A.DELIVERY_STATUS IN (12020301, 12020302, 12020402)
            AND A.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK(+)
            AND LOWER(C.ORDER_NO) LIKE '%' || LOWER(?) || '%'
            AND A.DELIVERY_STATUS || '&' LIKE '%' || ? || '%'
            AND A.ORD_PK = E.ORD_PK(+)
            AND A.ORD_LN_PK = E.ORD_LN_PK(+)
            AND A.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK(+)
            AND C.ORDER_TYP !='120102'
            AND C.ORDER_TYP !='120105'
            AND A.VALIDFLAG = '1'
            AND B.VALIDFLAG = '1'
            AND C.VALIDFLAG = '1'
            AND A.CREATE_TIME >= TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
            AND A.CREATE_TIME <= TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
               #CONDITION#) T1,
        (SELECT PROCESS_CODE,
                DESGIN_KEY,
                ORD_LN_DLY_PK,
                REVIEW_ASK,
                (CASE
                  WHEN PROCESS_CODE = 'G' OR PROCESS_CODE = 'H' THEN
                   TO_CHAR(ADD_MONTHS(REVIEW_ASK, -1), 'yyyy-MM')
                  ELSE
                   TO_CHAR(REVIEW_ASK, 'yyyy-MM')
                END) REVIEW_ASK_END
           FROM (SELECT X.PROCESS_CODE,
                        X.DESGIN_KEY,
                        X.ORD_LN_DLY_PK,
                        TO_DATE(Y.REVIEW_ASK, 'yyyy-MM-dd') REVIEW_ASK
                   FROM (SELECT MIN(T.PROCESS_CODE) PROCESS_CODE,
                                T.DESGIN_KEY,
                                T.ORD_LN_DLY_PK
                           FROM SLM_ORD_DESIGN_MSC_PL_PC_LST T
                          WHERE T.PROCESS_CODE >= 'D'
                          GROUP BY T.DESGIN_KEY, T.ORD_LN_DLY_PK
                         UNION ALL
                         SELECT MAX(V.PROCESS_CODE),
                                V.DESGIN_KEY,
                                V.ORD_LN_DLY_PK
                           FROM SLM_ORD_DESIGN_MSC_PL_PC_LST V
                          WHERE V.DESGIN_KEY || V.ORD_LN_DLY_PK NOT IN
                                (SELECT A.DESGIN_KEY || A.ORD_LN_DLY_PK
                                   FROM (SELECT MIN(T.PROCESS_CODE),
                                                T.DESGIN_KEY,
                                                T.ORD_LN_DLY_PK
                                           FROM SLM_ORD_DESIGN_MSC_PL_PC_LST T
                                          WHERE T.PROCESS_CODE >= 'D'
                                          GROUP BY T.DESGIN_KEY, T.ORD_LN_DLY_PK) A)
                            AND V.PROCESS_CODE < 'D'
                          GROUP BY V.DESGIN_KEY, V.ORD_LN_DLY_PK) X,
                        SLM_ORD_DESIGN_MSC_PL_PC_LST Y
                  WHERE X.PROCESS_CODE = Y.PROCESS_CODE
                    AND X.DESGIN_KEY = Y.DESGIN_KEY
                    AND X.ORD_LN_DLY_PK = Y.ORD_LN_DLY_PK
                    AND Y.REVIEW_ASK IS NOT NULL)) T2
  WHERE T1.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK(+)


		]]>
	</query>
	
	<query id="CoreOrderReport.doQueryImprove" desc="查询（优化后的）">
		<![CDATA[
		 SELECT T1.*,
       DECODE(T2.PROCESS_CODE, 'D', '轧制') PROCESS_CODE,
       TO_CHAR(T2.REVIEW_ASK, 'YYYY-MM-DD') REVIEW_ASK,
       T2.REVIEW_ASK_END
  FROM (SELECT B.STEELCODE,
               B.STEELNAME,
               NVL(D.PORDERSTATUS,'未提报') PORDERSTATUS,
               D.CREATE_TIME REPORTTIME,
               C.SALE_AREA_DESC,
               (SELECT ABRVITION
                  FROM SLM_BASE_CUSTOMER
                 WHERE C.CUSTOMER_NO = CUSTOMER_NO
                   AND VALIDFLAG = '1') ABRVITION,
               B.ORDER_SPEC_CODE,
               B.ORDER_SPEC_DESC,
               A.DELIVERY_STATUS,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE BASECODE = A.DELIVERY_STATUS) ORDER_LN_STATUS_NM,
               DECODE(B.ASSEL_FL, '1', 'TRUE', 'FALSE') ASSEL_FL,
               DECODE(B.PRODUCER_FL, '1', 'TRUE', 'FALSE') PRODUCER_FL,
               DECODE(B.MPS_FL, '1', 'TRUE', 'FALSE') MPS_FL,
               B.ORD_PK,
               B.ORD_LN_PK,
               A.ORD_LN_DLY_PK,
               C.ORDER_NO,
               B.ORDER_SEQ,
               A.DELIVERY_NO,
               B.PRD_CLS,
               B.PRODUCCODE,
               B.PRODUCNAME,
               B.STD_CODE,
               B.STD_NAME,
               B.DIMATER OUTDIAMETER,
               B.HEIGHT WALLTHICK,
               B.LEN_NO,
               B.LEN_MIN LENGTHMIN,
               B.LEN_MAX LENGTHMAX,
               B.LEN_DESC LENGTHDISC,
               B.MODEL_CODE,
               B.MODEL_DESC,
               B.ORDER_UNIT,
               B.ORDER_QTY,
               A.WGT_ESTMT ORDERWEIGHT,
               DECODE(B.ORDER_UNIT, '支', B.ORDER_QTY, 0) ORDERNUM,
               A.ENSU_TOTL_LEN TOTLENGTH,
               B.DELVRY_RANGE_TPE,
               A.DELVRY_QTY,
               B.DELVRY_RANGE_MIN,
               B.DELVRY_RANGE_MAX,
               C.CUSTOMER_NO BUYER_ID,
               C.CUSTOMER_NM BUYER_NAME,
               B.CUST_ALPHA_NO,
               B.SPEC_CODE,
               B.SPEC_NAME,
               B.ORDER_SPECIAL_DESC,
               B.ADD_ASK_NO,
               B.ORDER_ADD_DESC,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE C.SALE_ORG = BASECODE
                   AND VALIDFLAG = '1') ORDERFROM,
               C.SALE_ORG ORDERFROMCODE,
               B.FINAL_USER,
               B.FINAL_USER_DESC,
               --B.PRDCR_DESC,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE B.OUTS_BILLET_FL = BASECODE
                   AND VALIDFLAG = '1') OUTS_BILLET_FL,
               B.OUTS_BILLET_FL OUTS_BILLET_FL_CODE,
               B.USE_CODE,
               B.USE_DESC,
               B.LEN_UNIT,
               DECODE(B.DELVRY_RANGE_TPE, '绝对值', B.DELVRY_RANGE_MIN, '') LOWERLIMT,
               DECODE(B.DELVRY_RANGE_TPE, '绝对值', B.DELVRY_RANGE_MAX, '') UPPERLIMIT,
               '(-' || TO_CHAR(B.DELVRY_RANGE_MIN) ||
               DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
               TO_CHAR(B.DELVRY_RANGE_MAX) ||
               DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
               A.DELVRY_BDATE,
               TO_CHAR(A.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
               /*(SELECT NVL(MAX(LST_PRD_DATE), '')
                  FROM SLM_ORD_DESIGN_MSC_PL_PC_LST
                 WHERE ORD_LN_DLY_PK = A.ORD_LN_DLY_PK
                   AND PROCESS_CODE = 'D') LATEST_PROD_DATE,*/
               C.CREATE_NAME ORDERCONTACT,
               --B.PRDCR_DESC MONITORDEMAND,
               B.PSC,
               B.MSC,
               /*DECODE(B.PRODUCER_FL,
                      '0',
                      '0',
                      CASE
                        WHEN TRIM(B.PRDCR_NO) IS NULL THEN
                         '0'
                        ELSE
                         DECODE((SELECT MAX(PRDCR_STS)
                                  FROM SLM_ORDER_LINE_PRDCR
                                 WHERE INSTR(B.PRDCR_NO, PRDCR_NO) > 0
                                   AND PRDCR_STS = 'S'),
                                'S',
                                '1',
                                '0')
                      END) JZ_FILE_IF_ALL,*/
               B.PRDCR_NO,
               BOM.MATERIAL_NO,
               BOM.MATERIAL_DESC,
               B.SHRT_LEN_RATO,
               B.SHORTEST,
               B.LONG_LEN_RATO,
               B.LONGEST,
               B.ENDLEN_SPECSTD,
               B.SHRT_STOVE,
               B.AVG_LEN_MIN,
               B.DIFRNC_LEN_MAX,
               B.SIGL_LEN,
               B.STD_STYLE_DESC,
               B.OUTS_STL_PIPE_FL OUTS_STL_PIPE_FL_CODE,
               B.AW,
               E.ELIM_NUM,
               E.ELIM_WGT,
               E.ELIM_LEN,
               E.CHARGE_NUM,
               E.CHARGE_WGT,
               E.CHARGE_LEN,
               E.APP_NUM,
               D.ROLL_MONTH,
               C.ORDER_TYP,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE BASECODE = B.OUTS_STL_PIPE_FL
                   AND VALIDFLAG = '1') OUTS_STL_PIPE_FL
          FROM SLM_ORDER_LINE_DELIVERY A
          LEFT JOIN (SELECT DECODE(MAX(PLN.PORDERSTATUS),
                                  '0',
                                  '待接收',
                                  '1',
                                  '已接收',
                                  '2',
                                  '已下发',
                                  '3',
                                  '生产中',
                                  '4',
                                  '生产完成',
                                  '5',
                                  '缴库完成',
                                  '6',
                                  '发运完毕',
                                  '7',
                                  '结算完毕',
                                  '8',
                                  '合同关闭',
                                  '',
                                  '未提报') PORDERSTATUS,
                           MAX(PLN.ROLL_MONTH) ROLL_MONTH,
                           MAX(PLN.Create_Time) Create_Time,
                           PLN.ORD_LN_DLY_PK
                      FROM PLN_SALEORD PLN
                     GROUP BY PLN.ORD_LN_DLY_PK) D
            ON A.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK
        
          LEFT JOIN (SELECT MAX(PRO.ELIM_NUM) ELIM_NUM,
                           MAX(PRO.ELIM_WGT) ELIM_WGT,
                           MAX(PRO.ELIM_LEN) ELIM_LEN,
                           MAX(PRO.CHARGE_NUM) CHARGE_NUM,
                           MAX(PRO.CHARGE_WGT) CHARGE_WGT,
                           MAX(PRO.CHARGE_LEN) CHARGE_LEN,
                           MAX(PRO.APP_NUM) APP_NUM,
                           PRO.ORD_LN_DLY_PK
                      FROM PROCESS_ORDER_M PRO
                     GROUP BY PRO.ORD_LN_DLY_PK) E
            ON A.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK, SLM_ORDER_LINE B
        
          LEFT JOIN (SELECT DISTINCT MAX(A1.MATERIAL_NO) MATERIAL_NO,
                                    MAX(A1.MATERIAL_DESC) MATERIAL_DESC,
                                    A3.ORD_LN_PK
                      FROM SLM_ORD_DESIGN_BOM A1,
                           SLM_ORD_LINE_BOM   A2,
                           SLM_ORD_DESIGN_MSC A3
                     WHERE A3.VALIDFLAG = '1'
                       AND A2.DESGIN_KEY = A3.DESGIN_KEY
                       AND A1.BOM = A2.BOM
                     GROUP BY A3.ORD_LN_PK) BOM
            ON BOM.ORD_LN_PK = B.ORD_LN_PK, SLM_ORDER_HEAD C
        
         WHERE A.ORD_PK = B.ORD_PK
           AND A.ORD_LN_PK = B.ORD_LN_PK
           AND A.ORD_PK = C.ORD_PK
           AND A.DELIVERY_STATUS IN (12020301, 12020302, 12020402)
           AND LOWER(C.ORDER_NO) LIKE '%' || LOWER(?) || '%'
           AND A.DELIVERY_STATUS || '&' LIKE '%' || ? || '%'
           AND C.ORDER_TYP != '120102'
           AND C.ORDER_TYP != '120105'
           AND A.VALIDFLAG = '1'
           AND B.VALIDFLAG = '1'
           AND C.VALIDFLAG = '1'
           AND A.CREATE_TIME >= TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
           AND A.CREATE_TIME <= TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
         #CONDITION#) T1,
       (SELECT PROCESS_CODE,
               DESGIN_KEY,
               ORD_LN_DLY_PK,
               REVIEW_ASK,
               (CASE
                 WHEN PROCESS_CODE = 'G' OR PROCESS_CODE = 'H' THEN
                  TO_CHAR(ADD_MONTHS(REVIEW_ASK, -1), 'yyyy-MM')
                 ELSE
                  TO_CHAR(REVIEW_ASK, 'yyyy-MM')
               END) REVIEW_ASK_END
          FROM (SELECT X.PROCESS_CODE,
                       X.DESGIN_KEY,
                       X.ORD_LN_DLY_PK,
                       TO_DATE(Y.REVIEW_ASK, 'yyyy-MM-dd') REVIEW_ASK
                  FROM (SELECT MIN(T.PROCESS_CODE) PROCESS_CODE,
                               T.DESGIN_KEY,
                               T.ORD_LN_DLY_PK
                          FROM SLM_ORD_DESIGN_MSC_PL_PC_LST T
                         WHERE T.PROCESS_CODE >= 'D'
                         GROUP BY T.DESGIN_KEY, T.ORD_LN_DLY_PK
                        UNION ALL
                        SELECT MAX(V.PROCESS_CODE),
                               V.DESGIN_KEY,
                               V.ORD_LN_DLY_PK
                          FROM SLM_ORD_DESIGN_MSC_PL_PC_LST V
                         WHERE V.DESGIN_KEY || V.ORD_LN_DLY_PK NOT IN
                               (SELECT A.DESGIN_KEY || A.ORD_LN_DLY_PK
                                  FROM (SELECT MIN(T.PROCESS_CODE),
                                               T.DESGIN_KEY,
                                               T.ORD_LN_DLY_PK
                                          FROM SLM_ORD_DESIGN_MSC_PL_PC_LST T
                                         WHERE T.PROCESS_CODE >= 'D'
                                         GROUP BY T.DESGIN_KEY, T.ORD_LN_DLY_PK) A)
                           AND V.PROCESS_CODE < 'D'
                         GROUP BY V.DESGIN_KEY, V.ORD_LN_DLY_PK) X,
                       SLM_ORD_DESIGN_MSC_PL_PC_LST Y
                 WHERE X.PROCESS_CODE = Y.PROCESS_CODE
                   AND X.DESGIN_KEY = Y.DESGIN_KEY
                   AND X.ORD_LN_DLY_PK = Y.ORD_LN_DLY_PK
                   AND Y.REVIEW_ASK IS NOT NULL)) T2
 WHERE T1.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK(+)
		 

		]]>
	</query>
	<query  id = "CoreOrderReport.doQueryImproveWithMats" desc = "提报查询优化加库存数据">
	 SELECT T1.*,
       DECODE(T2.PROCESS_CODE, 'D', '轧制') PROCESS_CODE,
       TO_CHAR(T2.REVIEW_ASK, 'YYYY-MM-DD') REVIEW_ASK,
       T2.REVIEW_ASK_END
  FROM (SELECT LINE.STEELCODE,
               LINE.STEELNAME,
               NVL(D.PORDERSTATUS, '未提报') PORDERSTATUS,
               D.CREATE_TIME REPORTTIME,
               LINE.SALE_AREA_DESC,
               (SELECT ABRVITION
                  FROM SLM_BASE_CUSTOMER
                 WHERE LINE.CUSTOMER_NO = CUSTOMER_NO
                   AND VALIDFLAG = '1') ABRVITION,
               LINE.ORDER_SPEC_CODE,
               LINE.ORDER_SPEC_DESC,
               A.DELIVERY_STATUS,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE BASECODE = A.DELIVERY_STATUS) ORDER_LN_STATUS_NM,
               DECODE(LINE.ASSEL_FL, '1', 'TRUE', 'FALSE') ASSEL_FL,
               DECODE(LINE.PRODUCER_FL, '1', 'TRUE', 'FALSE') PRODUCER_FL,
               DECODE(LINE.MPS_FL, '1', 'TRUE', 'FALSE') MPS_FL,
               LINE.ORD_PK,
               LINE.ORD_LN_PK,
               TO_CHAR(LINE.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,               
               A.ORD_LN_DLY_PK,
               LINE.ORDER_NO,
               LINE.ORDER_SEQ,
               A.DELIVERY_NO,
               LINE.PRD_CLS,
               LINE.PRODUCCODE,
               LINE.PRODUCNAME,
               LINE.STD_CODE,
               LINE.STD_NAME,
               LINE.DIMATER OUTDIAMETER,
               LINE.HEIGHT WALLTHICK,
               LINE.LEN_NO,
               LINE.LEN_MIN LENGTHMIN,
               LINE.LEN_MAX LENGTHMAX,
               LINE.LEN_DESC LENGTHDISC,
               LINE.MODEL_CODE,
               LINE.MODEL_DESC,
               LINE.ORDER_UNIT,
               LINE.ORDER_QTY,
               A.WGT_ESTMT ORDERWEIGHT,
               DECODE(LINE.ORDER_UNIT, '支', LINE.ORDER_QTY, 0) ORDERNUM,
               A.ENSU_TOTL_LEN TOTLENGTH,
               LINE.DELVRY_RANGE_TPE,
               A.DELVRY_QTY,
               LINE.DELVRY_RANGE_MIN,
               LINE.DELVRY_RANGE_MAX,
               LINE.CUSTOMER_NO BUYER_ID,
               LINE.CUSTOMER_NM BUYER_NAME,
               LINE.CUST_ALPHA_NO,
               LINE.SPEC_CODE,
               LINE.SPEC_NAME,
               LINE.ORDER_SPECIAL_DESC,
               LINE.ADD_ASK_NO,
               LINE.ORDER_ADD_DESC,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE LINE.SALE_ORG = BASECODE
                   AND VALIDFLAG = '1') ORDERFROM,
               LINE.SALE_ORG ORDERFROMCODE,
               LINE.FINAL_USER,
               LINE.FINAL_USER_DESC,
               --B.PRDCR_DESC,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE LINE.OUTS_BILLET_FL = BASECODE
                   AND VALIDFLAG = '1') OUTS_BILLET_FL,
               LINE.OUTS_BILLET_FL OUTS_BILLET_FL_CODE,
               LINE.USE_CODE,
               LINE.USE_DESC,
               LINE.LEN_UNIT,
               DECODE(LINE.DELVRY_RANGE_TPE,
                      '绝对值',
                      LINE.DELVRY_RANGE_MIN,
                      '') LOWERLIMT,
               DECODE(LINE.DELVRY_RANGE_TPE,
                      '绝对值',
                      LINE.DELVRY_RANGE_MAX,
                      '') UPPERLIMIT,
               '(-' || TO_CHAR(LINE.DELVRY_RANGE_MIN) ||
               DECODE(LINE.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
               TO_CHAR(LINE.DELVRY_RANGE_MAX) ||
               DECODE(LINE.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
               A.DELVRY_BDATE,
               TO_CHAR(A.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
               LINE.CREATE_NAME ORDERCONTACT,
               --B.PRDCR_DESC MONITORDEMAND,
               LINE.PSC,
               LINE.MSC,
               LINE.PRDCR_NO,
               BOM.MATERIAL_NO,
               BOM.MATERIAL_DESC,
               LINE.SHRT_LEN_RATO,
               LINE.SHORTEST,
               LINE.LONG_LEN_RATO,
               LINE.LONGEST,
               LINE.ENDLEN_SPECSTD,
               LINE.SHRT_STOVE,
               LINE.AVG_LEN_MIN,
               LINE.DIFRNC_LEN_MAX,
               LINE.SIGL_LEN,
               LINE.STD_STYLE_DESC,
               LINE.OUTS_STL_PIPE_FL OUTS_STL_PIPE_FL_CODE,
               LINE.AW,
               D.ROLL_MONTH,
               LINE.ORDER_TYP,
               LINE.SUPPLY_UNIT_CODE,
               LINE.SUPPLY_UNIT,
               A.DELVRY_ADDR,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE BASECODE = LINE.OUTS_STL_PIPE_FL
                   AND VALIDFLAG = '1') OUTS_STL_PIPE_FL,
				CASE LINE.SALE_ORG
				WHEN '100102' THEN
					DECODE(A.PRESENT_STATUS,'1','可提报','2','取消提报','不可提报')
				ELSE
					'可提报'
		END PRESENT_STATUS,
		(SELECT
			DISTINCT T.PRDCR_NO
		FROM
			SLM_ORDER_LINE_PRDCR_LST T
			inner JOIN SLM_USERNAME_GM G ON T.PRDCR_MAN = G.USER_NAME
			OR T.PRDCR_MAN2 = G.USER_NAME OR T.PRDCR_MAN3 = G.USER_NAME
			where t.PRDCR_NO = LINE.PRDCR_NO ) PRDCR_NO_GM
          FROM SLM_ORDER_LINE_DELIVERY A
          LEFT JOIN (SELECT DECODE(MAX(PLN.PORDERSTATUS),
                                  '0',
                                  '待接收',
                                  '1',
                                  '已接收',
                                  '2',
                                  '已下发',
                                  '3',
                                  '生产中',
                                  '4',
                                  '生产完成',
                                  '5',
                                  '缴库完成',
                                  '6',
                                  '发运完毕',
                                  '7',
                                  '结算完毕',
                                  '8',
                                  '合同关闭',
                                  '',
                                  '未提报') PORDERSTATUS,
                           MAX(PLN.ROLL_MONTH) ROLL_MONTH,
                           MAX(PLN.CREATE_TIME) CREATE_TIME,
                           PLN.ORD_LN_DLY_PK
                      FROM PLN_SALEORD PLN
                     GROUP BY PLN.ORD_LN_DLY_PK) D
            ON A.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK,
         (SELECT B.ORD_PK,
                       B.ORD_LN_PK,
                       B.ORDER_SEQ,
                       B.CUST_ALPHA_NO,
                       B.PSC,
                       B.PSC_DESC,
                       B.MSC,
                       B.MSC_DESC,
                       B.MSC_STYLE,
                       B.USE_CODE,
                       B.USE_DESC,
                       B.PRD_CLS,
                       B.PRODUCCODE,
                       B.PRODUCNAME,
                       B.STD_CODE,
                       B.STD_NAME,
                       B.STEELCODE,
                       B.STEELNAME,
                       B.STD_STYLE,
                       B.STD_STYLE_DESC,
                       B.ORDER_SPEC_CODE,
                       B.ORDER_SPEC_DESC,
                       B.SPEC_CODE,
                       B.SPEC_NAME,
                       B.DIMATER,
                       B.HEIGHT,
                       B.MODEL_CODE,
                       B.MODEL_DESC,
                       B.LEN_NO,
                       B.LEN_DESC,
                       B.LEN_UNIT,
                       B.LEN_MIN,
                       B.LEN_MAX,
                       B.SHRT_LEN_RATO,
                       B.SHORTEST,
                       B.LONG_LEN_RATO,
                       B.LONGEST,
                       B.SHRT_STOVE,
                       B.AVG_LEN_MIN,
                       B.DIFRNC_LEN_MAX,
                       B.ENDLEN_SPECSTD,
                       B.SIGL_LEN,
                       B.ORDER_UNIT,
                       B.ORDER_QTY,
                       B.ORD_ENSU_TOTL_LEN,
                       B.PRDCT_WGT,
                       B.DELVRY_RANGE_TPE,
                       B.DELVRY_RANGE_MIN,
                       B.DELVRY_RANGE_MAX,
                       B.FINAL_USER,
                       B.FINAL_USER_DESC,
                       B.OUTS_BILLET_FL,
                       B.OUTS_STL_PIPE_FL,
                       B.ASSEL_FL,
                       B.PRODUCER_FL,
                       B.PRDCR_NO,
                       B.PRDCR_DESC,
                       B.MPS_FL,
                       B.MPS_NO,
                       B.MPS_DESC,
                       B.DELVRY_BDATE,
                       B.DELVRY_EDATE,
                       B.DELVRY_DESC,
                       B.TRANS_DESC,
                       B.ADD_ASK_NO,
                       B.ORDER_ADD_DESC,
                       B.ORDER_SPECIAL_FL,
                       B.ORDER_SPECIAL_DESC,
                       B.ORDER_LN_STATUS,
                       B.CUST_ALPHA_NO2,
                       B.AW,
                       C.ORDER_NO,
                       C.ORDER_TYP,
                       C.SALE_AREA_DESC,
                       C.CUSTOMER_NO,
                       C.CUSTOMER_NM,
                       C.SALE_ORG,
                       C.CREATE_NAME,
                       C.CREATE_TIME,
                       C.SUPPLY_UNIT SUPPLY_UNIT_CODE,
                       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE=C.SUPPLY_UNIT) SUPPLY_UNIT
                        
                  FROM SLM_ORDER_LINE B, SLM_ORDER_HEAD C
                 WHERE B.ORD_PK = C.ORD_PK
                   #ORDER_NO#
                   AND C.ORDER_TYP != '120102'
                   AND C.ORDER_TYP != '120105'
                   AND B.VALIDFLAG = '1'
                   AND C.VALIDFLAG = '1'
                   AND C.CREATE_NAME IS NOT NULL
                   AND B.CREATE_NAME IS NOT NULL
                   AND NOT EXISTS (
                   		SELECT 1 FROM SLM_ORDER_HEAD A
                   		WHERE A.CUSTM_ORDER_NO = C.ORDER_NO AND A.VALIDFLAG = '1' and A.order_no like 'TH%'
                   		)
                   #CONDITION# ) LINE
        
          LEFT JOIN (SELECT DISTINCT MAX(A1.MATERIAL_NO) MATERIAL_NO,
                                    MAX(A1.MATERIAL_DESC) MATERIAL_DESC,
                                    A3.ORD_LN_PK
                      FROM SLM_ORD_DESIGN_BOM A1,
                           SLM_ORD_LINE_BOM   A2,
                           SLM_ORD_DESIGN_MSC A3
                     WHERE A3.VALIDFLAG = '1'
                       AND A2.DESGIN_KEY = A3.DESGIN_KEY
                       AND A1.BOM = A2.BOM
                     GROUP BY A3.ORD_LN_PK) BOM
            ON BOM.ORD_LN_PK = LINE.ORD_LN_PK
        
         WHERE A.ORD_PK = LINE.ORD_PK
           AND A.ORD_LN_PK = LINE.ORD_LN_PK
           AND A.DELIVERY_STATUS = '12020301'
           AND A.VALIDFLAG = '1'
           #SEARCH_DATE#
           #REPORT_DATE#
          ) T1,
       (V_DELVRY_PROCESS) T2
 WHERE T1.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK(+)
	</query>
	
	
	<query  id = "CoreOrderReport.doQueryImproveWithMat" desc = "提报查询优化加库存数据">
	
	<![CDATA[
	
	  SELECT T1.*,
       DECODE(T2.PROCESS_CODE, 'D', '轧制') PROCESS_CODE,
       TO_CHAR(T2.REVIEW_ASK, 'YYYY-MM-DD') REVIEW_ASK,
       case when T2.REVIEW_ASK_END is not null then T2.REVIEW_ASK_END else (select REVIEW_ASK_END from slm_order_line z where z.ord_ln_pk = T1.ord_ln_pk ) end REVIEW_ASK_END
  FROM (SELECT LINE.STEELCODE,
               LINE.STEELNAME,
               NVL(D.PORDERSTATUS, '未提报') PORDERSTATUS,
               D.CREATE_TIME REPORTTIME,
               LINE.SALE_AREA_DESC,
               (SELECT ABRVITION
                  FROM SLM_BASE_CUSTOMER
                 WHERE LINE.CUSTOMER_NO = CUSTOMER_NO
                   AND VALIDFLAG = '1') ABRVITION,
               LINE.ORDER_SPEC_CODE,
               LINE.ORDER_SPEC_DESC,
               A.DELIVERY_STATUS,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE BASECODE = A.DELIVERY_STATUS) ORDER_LN_STATUS_NM,
               DECODE(LINE.ASSEL_FL, '1', 'TRUE', 'FALSE') ASSEL_FL,
               DECODE(LINE.PRODUCER_FL, '1', 'TRUE', 'FALSE') PRODUCER_FL,
               DECODE(LINE.MPS_FL, '1', 'TRUE', 'FALSE') MPS_FL,
               LINE.ORD_PK,
               LINE.ORD_LN_PK,
               TO_CHAR(LINE.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,               
               A.ORD_LN_DLY_PK,
               LINE.ORDER_NO,
               LINE.ORDER_SEQ,
               A.DELIVERY_NO,
               LINE.PRD_CLS,
               LINE.PRODUCCODE,
               LINE.PRODUCNAME,
               LINE.STD_CODE,
               LINE.STD_NAME,
               LINE.DIMATER OUTDIAMETER,
               LINE.HEIGHT WALLTHICK,
               LINE.LEN_NO,
               LINE.LEN_MIN LENGTHMIN,
               LINE.LEN_MAX LENGTHMAX,
               LINE.LEN_DESC LENGTHDISC,
               LINE.MODEL_CODE,
               LINE.MODEL_DESC,
               LINE.ORDER_UNIT,
               LINE.ORDER_QTY,
               A.WGT_ESTMT ORDERWEIGHT,
               DECODE(LINE.ORDER_UNIT, '支', LINE.ORDER_QTY, 0) ORDERNUM,
               A.ENSU_TOTL_LEN TOTLENGTH,
               LINE.DELVRY_RANGE_TPE,
               A.DELVRY_QTY,
               LINE.DELVRY_RANGE_MIN,
               LINE.DELVRY_RANGE_MAX,
               LINE.CUSTOMER_NO BUYER_ID,
               LINE.CUSTOMER_NM BUYER_NAME,
               LINE.CUST_ALPHA_NO,
               LINE.SPEC_CODE,
               LINE.SPEC_NAME,
               LINE.ORDER_SPECIAL_DESC,
               LINE.ADD_ASK_NO,
               LINE.ORDER_ADD_DESC,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE LINE.SALE_ORG = BASECODE
                   AND VALIDFLAG = '1') ORDERFROM,
               LINE.SALE_ORG ORDERFROMCODE,
               LINE.FINAL_USER,
               LINE.FINAL_USER_DESC,
               --B.PRDCR_DESC,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE LINE.OUTS_BILLET_FL = BASECODE
                   AND VALIDFLAG = '1') OUTS_BILLET_FL,
               LINE.OUTS_BILLET_FL OUTS_BILLET_FL_CODE,
               LINE.USE_CODE,
               LINE.USE_DESC,
               LINE.LEN_UNIT,
               DECODE(LINE.DELVRY_RANGE_TPE,
                      '绝对值',
                      LINE.DELVRY_RANGE_MIN,
                      '') LOWERLIMT,
               DECODE(LINE.DELVRY_RANGE_TPE,
                      '绝对值',
                      LINE.DELVRY_RANGE_MAX,
                      '') UPPERLIMIT,
               '(-' || TO_CHAR(LINE.DELVRY_RANGE_MIN) ||
               DECODE(LINE.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
               TO_CHAR(LINE.DELVRY_RANGE_MAX) ||
               DECODE(LINE.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
               A.DELVRY_BDATE,
               TO_CHAR(A.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
               /*(SELECT NVL(MAX(LST_PRD_DATE), '')
                FROM SLM_ORD_DESIGN_MSC_PL_PC_LST
               WHERE ORD_LN_DLY_PK = A.ORD_LN_DLY_PK
                 AND PROCESS_CODE = 'D') LATEST_PROD_DATE,*/
               LINE.CREATE_NAME ORDERCONTACT,
               --B.PRDCR_DESC MONITORDEMAND,
               LINE.PSC,
               LINE.MSC,
               /*DECODE(B.PRODUCER_FL,
               '0',
               '0',
               CASE
                 WHEN TRIM(B.PRDCR_NO) IS NULL THEN
                  '0'
                 ELSE
                  DECODE((SELECT MAX(PRDCR_STS)
                           FROM SLM_ORDER_LINE_PRDCR
                          WHERE INSTR(B.PRDCR_NO, PRDCR_NO) > 0
                            AND PRDCR_STS = 'S'),
                         'S',
                         '1',
                         '0')
               END) JZ_FILE_IF_ALL,*/
               LINE.PRDCR_NO,
               BOM.MATERIAL_NO,
               BOM.MATERIAL_DESC,
               LINE.SHRT_LEN_RATO,
               LINE.SHORTEST,
               LINE.LONG_LEN_RATO,
               LINE.LONGEST,
               LINE.ENDLEN_SPECSTD,
               LINE.SHRT_STOVE,
               LINE.AVG_LEN_MIN,
               LINE.DIFRNC_LEN_MAX,
               LINE.SIGL_LEN,
               LINE.STD_STYLE_DESC,
               LINE.OUTS_STL_PIPE_FL OUTS_STL_PIPE_FL_CODE,
               LINE.AW,
               E.ELIM_NUM,
               E.ELIM_WGT,
               E.ELIM_LEN,
               E.CHARGE_NUM,
               E.CHARGE_WGT,
               E.CHARGE_LEN,
               E.APP_NUM,
               MAT.ACT_WEIGHT,
               MAT.ACT_COUNT,
               D.ROLL_MONTH,
               LINE.ORDER_TYP,
               LINE.SUPPLY_UNIT_CODE,
               LINE.SUPPLY_UNIT,
               A.DELVRY_ADDR,
               (SELECT BASENAME
                  FROM COM_BASE_INFO
                 WHERE BASECODE = LINE.OUTS_STL_PIPE_FL
                   AND VALIDFLAG = '1') OUTS_STL_PIPE_FL,
				CASE LINE.SALE_ORG
				WHEN '100102' THEN
					DECODE(A.PRESENT_STATUS,'1','可提报','2','取消提报','不可提报')
				ELSE
					'可提报'
		END PRESENT_STATUS,
		(SELECT
			DISTINCT T.PRDCR_NO
		FROM
			SLM_ORDER_LINE_PRDCR_LST T
			inner JOIN SLM_USERNAME_GM G ON T.PRDCR_MAN = G.USER_NAME
			OR T.PRDCR_MAN2 = G.USER_NAME OR T.PRDCR_MAN3 = G.USER_NAME
			where t.PRDCR_NO = LINE.PRDCR_NO ) PRDCR_NO_GM
          FROM SLM_ORDER_LINE_DELIVERY A
          LEFT JOIN (SELECT DECODE(MAX(PLN.PORDERSTATUS),
                                  '0',
                                  '待接收',
                                  '1',
                                  '已接收',
                                  '2',
                                  '已下发',
                                  '3',
                                  '生产中',
                                  '4',
                                  '生产完成',
                                  '5',
                                  '缴库完成',
                                  '6',
                                  '发运完毕',
                                  '7',
                                  '结算完毕',
                                  '8',
                                  '合同关闭',
                                  '',
                                  '未提报') PORDERSTATUS,
                           MAX(PLN.ROLL_MONTH) ROLL_MONTH,
                           MAX(PLN.CREATE_TIME) CREATE_TIME,
                           PLN.ORD_LN_DLY_PK
                      FROM PLN_SALEORD PLN
                     GROUP BY PLN.ORD_LN_DLY_PK) D
            ON A.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK
        
          LEFT JOIN (SELECT MAX(PRO.ELIM_NUM) ELIM_NUM,
                           MAX(PRO.ELIM_WGT) ELIM_WGT,
                           MAX(PRO.ELIM_LEN) ELIM_LEN,
                           MAX(PRO.CHARGE_NUM) CHARGE_NUM,
                           MAX(PRO.CHARGE_WGT) CHARGE_WGT,
                           MAX(PRO.CHARGE_LEN) CHARGE_LEN,
                           MAX(PRO.APP_NUM) APP_NUM,
                           PRO.ORD_LN_DLY_PK
                      FROM PROCESS_ORDER_M PRO
                     GROUP BY PRO.ORD_LN_DLY_PK) E
            ON A.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK,
         (SELECT B.ORD_PK,
                       B.ORD_LN_PK,
                       B.ORDER_SEQ,
                       B.CUST_ALPHA_NO,
                       B.PSC,
                       B.PSC_DESC,
                       B.MSC,
                       B.MSC_DESC,
                       B.MSC_STYLE,
                       B.USE_CODE,
                       B.USE_DESC,
                       B.PRD_CLS,
                       B.PRODUCCODE,
                       B.PRODUCNAME,
                       B.STD_CODE,
                       B.STD_NAME,
                       B.STEELCODE,
                       B.STEELNAME,
                       B.STD_STYLE,
                       B.STD_STYLE_DESC,
                       B.ORDER_SPEC_CODE,
                       B.ORDER_SPEC_DESC,
                       B.SPEC_CODE,
                       B.SPEC_NAME,
                       B.DIMATER,
                       B.HEIGHT,
                       B.MODEL_CODE,
                       B.MODEL_DESC,
                       B.LEN_NO,
                       B.LEN_DESC,
                       B.LEN_UNIT,
                       B.LEN_MIN,
                       B.LEN_MAX,
                       B.SHRT_LEN_RATO,
                       B.SHORTEST,
                       B.LONG_LEN_RATO,
                       B.LONGEST,
                       B.SHRT_STOVE,
                       B.AVG_LEN_MIN,
                       B.DIFRNC_LEN_MAX,
                       B.ENDLEN_SPECSTD,
                       B.SIGL_LEN,
                       B.ORDER_UNIT,
                       B.ORDER_QTY,
                       B.ORD_ENSU_TOTL_LEN,
                       B.PRDCT_WGT,
                       B.DELVRY_RANGE_TPE,
                       B.DELVRY_RANGE_MIN,
                       B.DELVRY_RANGE_MAX,
                       B.FINAL_USER,
                       B.FINAL_USER_DESC,
                       B.OUTS_BILLET_FL,
                       B.OUTS_STL_PIPE_FL,
                       B.ASSEL_FL,
                       B.PRODUCER_FL,
                       B.PRDCR_NO,
                       B.PRDCR_DESC,
                       B.MPS_FL,
                       B.MPS_NO,
                       B.MPS_DESC,
                       B.DELVRY_BDATE,
                       B.DELVRY_EDATE,
                       B.DELVRY_DESC,
                       B.TRANS_DESC,
                       B.ADD_ASK_NO,
                       B.ORDER_ADD_DESC,
                       B.ORDER_SPECIAL_FL,
                       B.ORDER_SPECIAL_DESC,
                       B.ORDER_LN_STATUS,
                       B.CUST_ALPHA_NO2,
                       B.AW,
                       b.REVIEW_ASK_END,
                       C.ORDER_NO,
                       C.ORDER_TYP,
                       C.SALE_AREA_DESC,
                       C.CUSTOMER_NO,
                       C.CUSTOMER_NM,
                       C.SALE_ORG,
                       C.CREATE_NAME,
                       C.CREATE_TIME,
                       C.SUPPLY_UNIT SUPPLY_UNIT_CODE,
                       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE=C.SUPPLY_UNIT) SUPPLY_UNIT
                        
                  FROM SLM_ORDER_LINE B, SLM_ORDER_HEAD C
                 WHERE B.ORD_PK = C.ORD_PK
                   /*AND LOWER(C.ORDER_NO) LIKE '%' || ? || '%'*/
                   #ORDER_NO#
                   AND C.ORDER_TYP != '120102'
                   AND C.ORDER_TYP != '120105'
                   AND B.VALIDFLAG = '1'
                   AND C.VALIDFLAG = '1'
                   AND C.CREATE_NAME IS NOT NULL
                   AND B.CREATE_NAME IS NOT NULL
                   AND NOT EXISTS (
                   		SELECT 1 FROM SLM_ORDER_HEAD A
                   		WHERE A.CUSTM_ORDER_NO = C.ORDER_NO AND A.VALIDFLAG = '1' and A.order_no like 'TH%'
                   		)
                   /**#CONDITION#**/ ) LINE
     LEFT JOIN (SELECT SUM(NVL(T1.ACT_COUNT, 0)) AS ACT_COUNT,
                           SUM(NVL(T1.ACT_WEIGHT, 0)) AS ACT_WEIGHT,
                           T1.PRODUCCODE,
                           T1.STEELCODE,
                           T1.SPEC_CODE,
                           T1.MODEL_CODE,
                           T1.STD_STYLE,
                           T1.SUPPLY_UNIT_CODE,
                           DECODE(T1.BELONG_CODE,
                                  '100102',
                                  '100102',
                                  '100101') BELONG_CODE
                    
                      FROM MAT_ZC_M T1, YDM_ZC_BUTTRESS T2
                     WHERE T1.MAT_NO = T2.MAT_NO
                       AND T1.PRODUCT_FLAG = '801402'
                       AND T1.MAT_STATUS IN
                           ('80150202', '80150203', '80150204', '80150205')
                       AND T1.LOCK_FLAG <> '1'
                       AND T1.MNG_LOCK_FLAG <> '1'
                     GROUP BY T1.PRODUCCODE,
                              T1.STEELCODE,
                              T1.SPEC_CODE,
                              T1.MODEL_CODE,
                              T1.STD_STYLE,
                              T1.SUPPLY_UNIT_CODE,
                              DECODE(T1.BELONG_CODE,
                                     '100102',
                                     '100102',
                                     '100101')) MAT
            ON LINE.PRODUCCODE = MAT.PRODUCCODE
           AND LINE.STEELCODE = MAT.STEELCODE
           AND LINE.SPEC_CODE = MAT.SPEC_CODE
           AND LINE.MODEL_CODE = MAT.MODEL_CODE
           AND LINE.SUPPLY_UNIT_CODE=MAT.SUPPLY_UNIT_CODE
           AND DECODE(LINE.SALE_ORG, '100102', '100102', '100101') =
               MAT.BELONG_CODE
           AND DECODE(LINE.STD_STYLE, NULL, '1', LINE.STD_STYLE) =
               DECODE(MAT.STD_STYLE, NULL, '1', MAT.STD_STYLE)
        
          LEFT JOIN (SELECT DISTINCT MAX(A1.MATERIAL_NO) MATERIAL_NO,
                                    MAX(A1.MATERIAL_DESC) MATERIAL_DESC,
                                    A3.ORD_LN_PK
                      FROM SLM_ORD_DESIGN_BOM A1,
                           SLM_ORD_LINE_BOM   A2,
                           SLM_ORD_DESIGN_MSC A3
                     WHERE A3.VALIDFLAG = '1'
                       AND A2.DESGIN_KEY = A3.DESGIN_KEY
                       AND A1.BOM = A2.BOM
                     GROUP BY A3.ORD_LN_PK) BOM
            ON BOM.ORD_LN_PK = LINE.ORD_LN_PK
        
         WHERE A.ORD_PK = LINE.ORD_PK
           AND A.ORD_LN_PK = LINE.ORD_LN_PK
           /*AND A.DELIVERY_STATUS IN ('12020301', '12020302', '12020402')*/
           /*AND A.DELIVERY_STATUS || '&' LIKE '%' || ? || '%'*/
           /*AND A.DELIVERY_STATUS IN (?)*/
           #DELIVERY_STATUS#
           AND A.VALIDFLAG = '1'
           /*AND A.CREATE_TIME >= TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
           AND A.CREATE_TIME <= TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')*/
           #SEARCH_DATE#
           #REPORT_DATE#
          ) T1,
       (V_DELVRY_PROCESS) T2
 WHERE T1.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK(+)
	
	]]>
	

	</query>
	
	<query id="CoreOrderReport.GetDeliverySts" desc="获取交货行状态">
		<![CDATA[
			 SELECT 
			DELIVERY_STATUS 
			FROM SLM_ORDER_LINE_DELIVERY 
			WHERE ORD_PK=?
			AND ORD_LN_PK=?
			AND ORD_LN_DLY_PK=?
			AND VALIDFLAG = '1'
		]]>
	</query>
	
	
	
	<query id="CoreOrderReport.DeletePlnSaleOrderLine" desc="从计划表里面，删除已提报交货行记录">
		<![CDATA[
			DELETE FROM PLN_SALEORD
			WHERE ORD_PK=? 
			AND ORD_LN_PK=?
			AND ORD_LN_DLY_PK=?
		]]>
	</query>
	
	<query id="CoreOrderReport.DeletePlnSaleOrdLine" desc="从计划表里面，删除已提报交货行记录">
		<![CDATA[
			DELETE FROM PLN_SALEORD 
			WHERE ORD_PK=? 
			AND ORD_LN_PK=?
			AND ORD_LN_DLY_PK=?
		]]>
	</query>
	
	
	<query id="CoreOrderReport.GetSts" desc="">
		<![CDATA[
			SELECT BASECODE,BASENAME FROM COM_BASE_INFO WHERE SORTCODE='120204' OR BASECODE = '12020301' ORDER BY BASECODE
		]]>
	</query>
	
	<query id="CoreOrderReport.GetStsNew" desc="">
		<![CDATA[
			SELECT BASECODE,BASENAME FROM COM_BASE_INFO WHERE BASECODE in ('12020301','12020302','12020402') ORDER BY BASECODE
		]]>
	</query>
	
	<query id="CoreOrderReport.InsertPlnSaleOrder" desc="插入合同行信息">
		<![CDATA[
			INSERT INTO PLN_SALEORDER
            (ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, ORDER_NO, ORDER_SEQ,
             DELIVERY_NO, PRD_CLS, PRODUCCODE, PRODUCNAME, STD_CODE,
             STD_NAME,STEELCODE,STEELNAME,SPEC_CODE,SPEC_NAME,OUTDIAMETER, WALLTHICK, LEN_NO, LENGTHMIN, LENGTHMAX,
             LENGTHDISC, MODEL_CODE, MODEL_DESC, ORDER_UNIT, ORDER_QTY,
             ORDERWEIGHT, ORDERNUM, TOTLENGTH, DELVRY_RANGE_TPE,
             DELVRY_RANGE_MIN, DELVRY_RANGE_MAX, BUYER_ID, BUYER_NAME,
             CUST_ALPHA_NO, ORDER_SPECIAL_DESC, ADD_ASK_NO, ORDER_ADD_DESC,
             ORDERFROM, FINAL_USER, FINAL_USER_DESC, UPPERLIMIT,
             DELVRY_BDATE, DELVRY_EDATE,
             LATEST_PROD_DATE, ORDERCONTACT, MONITORDEMAND, PSC, MSC,
             JZ_FILE_IF_ALL, PRDCR_NO, MATERIAL_NO, MATERIAL_DESC,
             SHRT_LEN_RATO, SHORTEST, LONG_LEN_RATO, LONGEST, SIGL_LEN,
             CREATE_NAME, CREATE_TIME,LEN_UNIT,OUTS_BILLET_FL,USE_CODE,
             USE_DESC,ENDLEN_SPECSTD,AVG_LEN_MIN,SHRT_STOVE,DIFRNC_LEN_MAX,
             STD_STYLE_DESC,OUTS_STL_PIPE_FL,ROLL_MONTH,ROLL_WELL_MONTH,
             DELVRY_QTY,CHARGE_NUM,CHARGE_WGT,CHARGE_LEN,ELIM_NUM,ELIM_WGT,ELIM_LEN
             
            )
     VALUES (?, ?, ?, ?, ?,
             ?, ?, ?, ?, ?,
             ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
             ?, ?, ?, ?, ?,
             ?, ?, ?, ?,
             ?, ?, ?, ?,
             ?, ?, ?, ?,
             ?, ?, ?, ?,
             TO_DATE (?, 'YYYY-MM-DD'), TO_DATE (?, 'YYYY-MM-DD'),
             TO_DATE (?, 'YYYY-MM-DD'), ?, ?, ?, ?,
             ?, ?, ?, ?,
             ?, ?, ?, ?, ?,
             ?, SYSDATE,?,?,?,?,
             ?,?,?,?,?,?,?,?,
             ?,?,?,?,?,?,?
            )
		]]>
	</query>
	
	<query id="CoreOrderReport.InsertPlnSaleOrd" desc="提报排产时插入">
		<![CDATA[
			INSERT INTO PLN_SALEORD
            (ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, ORDER_NO, ORDER_SEQ,
             DELIVERY_NO, PRD_CLS, PRODUCCODE, PRODUCNAME, STD_CODE,
             STD_NAME,STEELCODE,STEELNAME,SPEC_CODE,SPEC_NAME,OUTDIAMETER, WALLTHICK, LEN_NO, LENGTHMIN, LENGTHMAX,
             LENGTHDISC, MODEL_CODE, MODEL_DESC, ORDER_UNIT, ORDER_QTY,
             ORDERWEIGHT, ORDERNUM, TOTLENGTH, DELVRY_RANGE_TPE,
             DELVRY_RANGE_MIN, DELVRY_RANGE_MAX, BUYER_ID, BUYER_NAME,
             ORDER_SPECIAL_DESC, ADD_ASK_NO, ORDER_ADD_DESC,
             ORDERFROM, FINAL_USER, FINAL_USER_DESC,
			 DELVRY_EDATE,
             ORDERCONTACT, MONITORDEMAND, PSC, MSC,
             JZ_FILE_IF_ALL, PRDCR_NO, MATERIAL_NO, MATERIAL_DESC,
             SHRT_LEN_RATO, SHORTEST, LONG_LEN_RATO, LONGEST, SIGL_LEN,
             CREATE_NAME, CREATE_TIME,LEN_UNIT,OUTS_BILLET_FL,USE_CODE,
             USE_DESC,ENDLEN_SPECSTD,AVG_LEN_MIN,SHRT_STOVE,DIFRNC_LEN_MAX,
             STD_STYLE_DESC,OUTS_STL_PIPE_FL,ROLL_MONTH,ROLL_WELL_MONTH,
             DELVRY_QTY,CHARGE_NUM,CHARGE_WGT,CHARGE_LEN,ELIM_NUM,ELIM_WGT,ELIM_LEN,TOTLENGTH_UNIT,
             SUPPLY_UNIT_CODE,SUPPLY_UNIT,DELVRY_ADDR,TYPE_FLAG
             
            )
     VALUES (?, ?, ?, ?, ?,
             ?, ?, ?, ?, ?,
             ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
             ?, ?, ?, ?, ?,
             ?, ?, ?, ?,
             ?, ?, ?, ?,
             ?, ?, ?,
             ?, ?, ?, 
             TO_DATE (?, 'YYYY-MM-DD'),
             ?, ?, ?, ?,
             ?, ?, ?, ?,
             ?, ?, ?, ?, ?,
             ?, SYSDATE,?,?,?,?,
             ?,?,?,?,?,?,?,?,
             ?,?,?,?,?,?,?,?,
             ?,?,?,?
            )
		]]>
	</query>
	
	<query id="CoreOrderReport.getLengthMinAndMax" desc="改变交货行状态">
		<![CDATA[
			select min(t.length_min) length_min,max(t.length_max) length_max from COM_BASE_PLINE t where t.process_code='B' and t.pline_name not like '%外购%'
		]]>
	</query>
	
	<query id="CoreOrderReport.UpdateDeliveryStatus" desc="改变交货行状态">
		<![CDATA[
			UPDATE SLM_ORDER_LINE_DELIVERY SET DELIVERY_STATUS=?
              WHERE
              ORD_PK=?
              AND
              ORD_LN_PK=?
              AND
              ORD_LN_DLY_PK=?
		]]>
	</query>
	
	<query id="CoreOrderReport.GetDeliveryCount" desc="查询当前合同行下是否还有生效和旅行生效的交货行">
		<![CDATA[
			SELECT COUNT(*) FROM SLM_ORDER_LINE_DELIVERY WHERE 
              ORD_PK=?
              AND
              ORD_LN_PK=?
              AND
              DELIVERY_STATUS IN (12020301,12020302)
		]]>
	</query>
	
	<query id="CoreOrderReport.UpdateLineStatus" desc="修改合同行状态。">
		<![CDATA[
			UPDATE 
			SLM_ORDER_LINE 
			SET 
			ORDER_LN_STATUS=? 
			WHERE ORD_PK=? 
			AND 
			ORD_LN_PK=?
		]]>
	</query>
	
	
	<query id="CoreOrderReport.UpdateHeadStatus" desc="修改合同状态。">
		<![CDATA[
			UPDATE 
			SLM_ORDER_HEAD 
			SET 
			ORDER_STS=?,
			ORDER_STS_DESC=? 
			WHERE 
			ORD_PK=?
		]]>
	</query>
	
	<query id="CoreOrderReport.GetLineUpdate" desc="查询当前合同头下，合同行状态为开始提报的合同行。">
		<![CDATA[
			SELECT 
			COUNT(*) 
			FROM 
			SLM_ORDER_LINE 
			WHERE 
            ORD_PK=?
            AND
            ORDER_LN_STATUS='12020401'
		]]>
	</query>
	
	<query id="CoreOrderReport.GetOrderDeliveryStatus" desc="合同行下的交货行状态">
		<![CDATA[
			 SELECT 1 FROM SLM_ORDER_LINE_DELIVERY 
			 WHERE ORD_LN_PK = ? AND DELIVERY_STATUS !='12020402' 
			 AND TRIM(VALIDFLAG) = '1'
		]]>
	</query>
	
	<query id="CoreOrderReport.GetOrderHeadStatus" desc="合同头下的合同行状态">
		<![CDATA[
			 SELECT 1 FROM SLM_ORDER_LINE
			 WHERE ORD_PK = ? AND ORDER_LN_STATUS !='12020402'
			 AND TRIM(VALIDFLAG) = '1'
		]]>
	</query>
	
	<query id="CoreOrderReport.GetPLNSaleOrderStatus" desc="获取生产管理交货行状态">
		<![CDATA[
			 SELECT PORDERSTATUS FROM PLN_SALEORD
			 WHERE ORD_PK = ? AND ORD_LN_PK = ?
			 AND ORD_LN_DLY_PK = ?  
		]]>
	</query>
	
	<query id="CoreOrderReport.GetDeliveryOrderStatus" desc="合同行下所有交货行状态">
		<![CDATA[
			 SELECT 1 FROM SLM_ORDER_LINE_DELIVERY
			 WHERE ORD_LN_PK = ?  
			 AND DELIVERY_STATUS ='12020402' 
			 AND VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CoreOrderReport.GetDeliveryOrderStatusWithOrdPk" desc="合同行下所有交货行状态">
		<![CDATA[
			 SELECT 1 FROM SLM_ORDER_LINE_DELIVERY
			 WHERE ORD_PK = ?  
			 AND DELIVERY_STATUS ='12020402'
			 AND VALIDFLAG = '1'
		]]>
	</query>
	
	
	<query id="CoreOrderReport.SelecttPrdCrNull" desc="是否有监制">
		<![CDATA[
			 SELECT 1
			   FROM SLM_ORDER_LINE
			  WHERE ORD_LN_PK = ?
			  AND PRODUCER_FL = '1'
			  AND PRDCR_NO IS NULL
		]]>
	</query>
	
	
	<query id="CoreOrderReport.SelecttPrdCrNotNull" desc="监制是否评审通过">
		<![CDATA[
			 SELECT 1
			  FROM SLM_ORDER_LINE_PRDCR
			 WHERE  INSTR((SELECT PRDCR_NO
			                      FROM SLM_ORDER_LINE
			                      WHERE ORD_LN_PK = ?
			                      AND PRODUCER_FL = '1'),PRDCR_NO)>0
			   AND PRDCR_STS != 'S'

		]]>
	</query>
	
	<query id="CoreOrderReport.GetServerTime" desc="获取服务器时间">
		<![CDATA[
			  SELECT TO_CHAR(SYSDATE, 'YYYY-MM') TIME FROM DUAL
			 
		]]>
	</query>
	
	<query id="CoreOrderReport.GetOrderType" desc="获取服务器时间">
		<![CDATA[
	  SELECT ORDER_TYP FROM SLM_ORDER_HEAD T WHERE  T.ORD_PK = ? AND T.VALIDFLAG = '1'
	
		]]>
	</query>
	
	<query id="CoreOrderReport.GetOrderLineLock" desc="合同行是否锁定">
		<![CDATA[
	  SELECT ISLOCK FROM SLM_ORDER_LINE T WHERE  T.ORD_LN_PK = ? AND T.VALIDFLAG = '1'
	
		]]>
	</query>
	
	<query id="CoreOrderReport.GetProcessOrder" desc="获取进程信息">
		<![CDATA[
	 	SELECT ELIM_NUM,ELIM_WGT,ELIM_LEN,CHARGE_NUM,CHARGE_WGT,CHARGE_LEN
	 	FROM PROCESS_ORDER_M 
	 	WHERE ORD_LN_DLY_PK = ?
	 	
		]]>
	</query>
	
	<query id="CoreOrderReport.UpdateProcessOrderApp" desc="获取进程信息">
		<![CDATA[
	 	UPDATE  PROCESS_ORDER_M 
	 	SET APP_NUM = ROUND(?,3),
	 	    APP_UNIT = ?
	 	WHERE ORD_LN_DLY_PK = ?
	 	
		]]>
	</query>
	
	<query id="CoreOrderReport.ClearProcessOrderApp" desc="获取进程信息">
		<![CDATA[
	 	UPDATE  PROCESS_ORDER_M 
	 	SET APP_NUM = 0,
	 	    APP_UNIT = ''
	 	WHERE ORD_LN_DLY_PK = ?
	 	
		]]>
	</query>
	
	<query id="CoreOrderReport.UpdatePlnSaleOrdEndDly" desc="获取进程信息">
		<![CDATA[
	    UPDATE PLN_SALEORD T
	    SET T.IS_END_DLY = '1'
	    WHERE T.ORD_LN_DLY_PK = (SELECT  MAX(A.ORD_LN_DLY_PK) FROM SLM_ORDER_LINE_DELIVERY A
	                               WHERE A.ORD_LN_PK = ? AND A.VALIDFLAG = '1' )
	 	
		]]>
	</query>
	
	<query id="CoreOrderReport.queryMatInfo" desc="查询材料信息">
	<![CDATA[
	SELECT T1.BELONG_CODE,
       T1.BELONG_NAME,
       T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       (SELECT T3.BASENAME
          FROM COM_BASE_INFO T3
         WHERE T3.BASECODE = T1.PRODUCT_FLAG) PRODUCT_FLAG,
       (SELECT T3.BASENAME
          FROM COM_BASE_INFO T3
         WHERE T3.BASECODE = T1.MAT_STATUS) MAT_STATUS,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.ACT_LEN_MIN,
       T1.ACT_LEN_MAX,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ORD_PK,
       T1.ORD_LN_PK,
       T1.ORD_LN_DLY_PK,
       T1.PRO_ORDER_NO,
       T1.PRO_ORDER_ID,
       TO_CHAR(MIN(T1.INSTOCK_TIME), 'YYYY-MM-DD HH24:MI:SS') INSTOCK_TIME,
       (SELECT T4.STORAGE_NAME
          FROM YDM_BS_STORAGE T4
         WHERE T4.STORAGE_NO = T2.STORAGE_NO) STORAGE_NAME,
       T2.STORAGE_NO,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.MEMO,
       T1.JUDGE_RESULT_CODE,
       T1.JUDGE_RESULT,
       SUM(NVL(T1.ACT_LEN, 0)) AS ACT_LEN,
       SUM(NVL(T1.ACT_COUNT, 0)) AS ACT_COUNT,
       SUM(NVL(T1.ACT_COUNT,0)) AS LKACT_COUNT,
       SUM(NVL(T1.ACT_WEIGHT, 0)) AS ACT_WEIGHT,
       SUM(NVL(T1.ACT_THEORY_WEIGHT, 0)) AS ACT_THEORY_WEIGHT,
       T1.JUDGE_STD_NAME,
       T1.LOCK_FLAG,
       T1.MNG_LOCK_FLAG
  FROM MAT_ZC_M T1, YDM_ZC_BUTTRESS T2
  WHERE T1.MAT_NO = T2.MAT_NO
   AND  T1.PRODUCT_FLAG = '801402'
   AND  T1.MAT_STATUS IN ('80150202','80150203','80150204','80150205')
   AND  T1.PRODUCCODE = ?
   AND  T1.STEELCODE = ?
   AND  T1.SPEC_CODE = ?
   AND  T1.MODEL_CODE = ?
   AND  DECODE(T1.STD_STYLE_DESC, NULL, '1', T1.STD_STYLE_DESC) =  DECODE(?, NULL, '1', ?)
	]]>
	</query>

	<query id="CoreOrderReport.queryMatInfo1" desc="查询材料信息">
		<![CDATA[
	SELECT T1.BELONG_CODE,
       T1.BELONG_NAME,
       T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       (SELECT T3.BASENAME
          FROM COM_BASE_INFO T3
         WHERE T3.BASECODE = T1.PRODUCT_FLAG) PRODUCT_FLAG,
       (SELECT T3.BASENAME
          FROM COM_BASE_INFO T3
         WHERE T3.BASECODE = T1.MAT_STATUS) MAT_STATUS,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.ACT_LEN_MIN,
       T1.ACT_LEN_MAX,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ORD_PK,
       T1.ORD_LN_PK,
       T1.ORD_LN_DLY_PK,
       T1.PRO_ORDER_NO,
       T1.PRO_ORDER_ID,
       TO_CHAR(MIN(T1.INSTOCK_TIME), 'YYYY-MM-DD HH24:MI:SS') INSTOCK_TIME,
       (SELECT T4.STORAGE_NAME
          FROM YDM_BS_STORAGE T4
         WHERE T4.STORAGE_NO = T2.STORAGE_NO) STORAGE_NAME,
       T2.STORAGE_NO,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.MEMO,
       T1.JUDGE_RESULT_CODE,
       T1.JUDGE_RESULT,
       SUM(NVL(T1.ACT_LEN, 0)) AS ACT_LEN,
       SUM(NVL(T1.ACT_COUNT, 0)) AS ACT_COUNT,
       SUM(NVL(T1.ACT_COUNT,0)) AS LKACT_COUNT,
       SUM(NVL(T1.ACT_WEIGHT, 0)) AS ACT_WEIGHT,
       SUM(NVL(T1.ACT_THEORY_WEIGHT, 0)) AS ACT_THEORY_WEIGHT,
       T1.JUDGE_STD_NAME,
       T1.LOCK_FLAG,
       T1.MNG_LOCK_FLAG
  FROM MAT_ZC_M T1, YDM_ZC_BUTTRESS T2
  WHERE T1.MAT_NO = T2.MAT_NO
   AND  T1.PRODUCT_FLAG = '801402'
   AND  T1.MAT_STATUS IN ('80150202','80150203','80150204','80150205')
   AND  T1.PRODUCCODE = ?
   AND  T1.STEELCODE = ?
   AND  T1.SPEC_CODE = ?
   AND  T1.MODEL_CODE = ?
   AND  DECODE(T1.STD_NAME, NULL, '1', T1.STD_NAME) =  DECODE(?, NULL, '1', ?)
	]]>
	</query>
	
	<query id="CoreOrderReport.queryIsLiKuByDlyPk" desc="查询交货行是否利库">
	
	    <![CDATA[
	
	    SELECT  SUM(NVL(T1.ACT_WEIGHT, 0)) AS ACT_WEIGHT  FROM   MAT_ZC_M T1 WHERE T1.ORD_LN_DLY_PK=?
	    ]]>
	
	</query>
	
	<query id="CoreOrderReport.queryIsExistsMat" desc="查询交货行是否有可利库的资源">
	
	    <![CDATA[
	      
	      SELECT Q.ACT_COUNT
  FROM (SELECT SUM(NVL(T1.ACT_COUNT, 0)) AS ACT_COUNT,
               SUM(NVL(T1.ACT_WEIGHT, 0)) AS ACT_WEIGHT,
               DECODE(T1.BELONG_CODE, '100102', '100102', '100101') BELONG_CODE
        
          FROM MAT_ZC_M T1, YDM_ZC_BUTTRESS T2
         WHERE T1.MAT_NO = T2.MAT_NO
           AND T1.PRODUCT_FLAG = '801402'
           AND T1.MAT_STATUS IN
               ('80150202', '80150203', '80150204', '80150205')
           AND T1.PRODUCCODE = ?
           AND T1.STEELCODE = ?
           AND T1.SPEC_CODE = ?
           AND T1.MODEL_CODE = ?
           AND DECODE(T1.STD_STYLE_DESC, NULL, '1', T1.STD_STYLE_DESC) =
               DECODE(?, NULL, '1', ?)
           AND SUPPLY_UNIT_CODE = ?
           AND T1.LOCK_FLAG <> '1'
           AND T1.MNG_LOCK_FLAG <> '1'
         GROUP BY T1.PRODUCCODE,
                  T1.STEELCODE,
                  T1.SPEC_CODE,
                  T1.MODEL_CODE,
                  T1.STD_STYLE,
                  DECODE(T1.BELONG_CODE, '100102', '100102', '100101')) Q
  WHERE Q.BELONG_CODE = DECODE( ?, '100102', '100102', '100101')


	    ]]>
	
	</query>
	
	
	<query id="CoreOrderReport.updateLKFlag" desc="查询交货行是否利库">
	
	    <![CDATA[
	 
		UPDATE SLM_ORDER_LINE_DELIVERY T
		   SET  T.IS_LIKU = '1',
		        T.NLK_RSN = ?,
		        T.NLK_CHECK = ?
	       WHERE T.ORD_LN_DLY_PK=?
	    ]]>
	
	</query>
	
	<query id="CoreOrderReport.queryLKFlag" desc="查询交货行是否利库">
	
	    <![CDATA[
	    
		 SELECT  T.IS_LIKU ,T.NLK_CHECK 
		 FROM SLM_ORDER_LINE_DELIVERY T
	     WHERE T.ORD_LN_DLY_PK=?
	       
	    ]]>
	
	</query>
	
	<query id="CoreOrderReport.queryDlyLkTd" desc="查询交货行是否利库">
	
	    <![CDATA[
	    
		 SELECT  T.LK_ID ,T.TD_ID 
		 FROM SLM_ORDER_LINE_DELIVERY T
	     WHERE T.ORD_LN_DLY_PK=?
	       
	    ]]>
	
	</query>
	
	<query id="CoreOrderReport.queryMatCheck" desc="查询交货行是否利库">
	
	    <![CDATA[
	    
	   SELECT LISTAGG(T.LOCK_LIKU, ',') within GROUP(order by Ord_Ln_dly_PK) CKSTS
       FROM MAT_ZC_M T
       WHERE T.ORD_LN_DLY_PK = ?
       AND T.PRO_NO = ?
	   
	    ]]>
	
	</query>
	
	<query id="CoreOrderReport.queryAllEffect" desc="查询交货行是否利库">
	    <![CDATA[
	    
	    SELECT 1
  FROM SLM_ORDER_LINE T
 WHERE T.ORD_PK = ?
   AND T.VALIDFLAG = '1'
   AND T.ORDER_LN_STATUS <> '12020301'
	    
	    ]]>
	</query>
	
	<query id="CoreOrderReport.getCraftState" desc="获取工艺评审状态">
	    <![CDATA[
SELECT T.VALIDFLAG, T.CRAFT_SOURCE
  FROM CRAFT_ORD_DESIGN T
 WHERE T.ORD_LN_PK = {0}
   AND T.CRAFT_SEQ = (SELECT MAX(A.CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN A
                       WHERE A.ORD_LN_PK = T.ORD_LN_PK)
	    ]]>
	</query>
	
</queryMap>