<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="销售合同接收下发">
	<query id="CorePlnSaleOrder.querySaleOrder" desc="查询销售合同">
		<![CDATA[
			SELECT T.ORD_PK,
			       T.ORD_LN_PK,
			       T.ORD_LN_DLY_PK,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       (T.ORDER_NO || '/' || T.ORDER_SEQ) ORDER_NO_SEQ,
			       (SELECT A.PRODUC_DESC
			          FROM COM_BASE_PRODUCT A
			         WHERE A.PRODUCCODE = T.PRODUCCODE
			           AND A.VALIDFLAG = '1') PRD_CLS,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.SPEC_CODE,
			       T.SPEC_NAME,
			       T.ORDERNUM,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.LEN_UNIT,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.LENGTHDISC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.ORDER_UNIT,
			       T.ORDER_QTY,
			       T.ORDERWEIGHT,
			       DECODE(T.ORDER_UNIT, '米', '吨', '英尺', '吨', T.ORDER_UNIT) ORDERWEIGHTUNIT,
			       DECODE(T.TOTLENGTH, 0, '', T.TOTLENGTH) TOTLENGTH,
			       T.TOTLENGTH_UNIT,
			       T.DELVRY_RANGE_TPE,
			       T.DELVRY_RANGE_MIN,
			       T.DELVRY_RANGE_MAX,
			       '(-' || TO_CHAR(ABS(T.DELVRY_RANGE_MIN)) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
			       TO_CHAR(T.DELVRY_RANGE_MAX) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
			       T.BUYER_ID,
			       t.BUYER_NAME,
			       T.ORDER_SPECIAL_DESC,
			       T.ADD_ASK_NO,
			       L.ORDER_ADD_DESC,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.ORDERFROM) ORDERFROM,
			       T.FINAL_USER,
			       NVL((SELECT A.ABRVITION
			             FROM SLM_BASE_CUSTOMER A
			            WHERE A.CUSTOMER_NO = DECODE(T.FINAL_USER,
			                                         NULL,
			                                         T.BUYER_ID,
			                                         '/',
			                                         T.BUYER_ID,
			                                         T.FINAL_USER)),
			           DECODE(T.FINAL_USER_DESC,
			                  NULL,
			                  T.BUYER_NAME,
			                  '/',
			                  T.BUYER_NAME,
			                  T.FINAL_USER_DESC)) FINAL_USER_DESC,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.MONITORDEMAND) MONITORDEMAND,
			       T.SPECSTANDARD,
			       DECODE(T.PORDERSTATUS,
			              '0',
			              '待接收',
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '3',
			              '生产中',
			              '4',
			              '生产完成',
			              '5',
			              '缴库完成') PORDERSTATUS,
			       T.PSC,
			       T.MSC,
			       T.CODE_JG,
			       T.CODE_DJ_BL,
			       T.PLANWEIGHT,
			       T.PAYDOWNWEIGHT,
			       T.CREATE_NAME,
			       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       T.UPDATE_NAME,
			       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       T.ENDGXNAME,
			       T.MERGETYPE,
			       DECODE(T.JZ_FILE_IF_ALL, '1', '是', '0', '否') JZ_FILE_IF_ALL,
			       T.PRDCR_NO,
			       T.ROLL_MONTH,
			       T.MATERIAL_NO,
			       T.MATERIAL_DESC,
			       T.BL_GROUP_NUM,
			       T.SHRT_LEN_RATO,
			       T.SHORTEST,
			       T.LONG_LEN_RATO,
			       T.LONGEST,
			       T.SHRT_STOVE,
			       T.AVG_LEN_MIN,
			       T.DIFRNC_LEN_MAX,
			       T.SIGL_LEN,
			       T.ENDLEN_SPECSTD,
			       T.STATION_NO,
			       NVL(T.STATION_NM,
			           (SELECT A.STATION_NM
			              FROM SLM_BASE_STATION A
			             WHERE A.STATION_NO = T.STATION_NO)) STATION_NM,
			       T.PRODUCE_SORT,
			       T.USE_CODE,
			       T.USE_DESC,
			       DECODE(T.TOTLENGTH_M, 0, '', T.TOTLENGTH_M) TOTLENGTH_M,
			       NVL(TRIM(T.OUTS_BILLET_FL), '121802') OUTS_BILLET_FL,
			       T.PIPE_PROPERTY,
			       T.LEN_TOEND_MIN,
			       T.LEN_TOEND_MAX,
			       T.LENGTH_JG,
			       T.WEIGH_TYPE,
			       T.TRANSIT_TYP,
			       T.ACCEPT_NO,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
			       DECODE(T.JGORD_IS_OK, '0', '否', '1', '是', '2', '/') JGORD_IS_OK,
			       DECODE(T.JGL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') JGL_REQ_IS_OK,
			       DECODE(T.DJBL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') DJBL_REQ_IS_OK,
			       DECODE(T.IF_SALE_FREEZE, '1', '是', '0', '否') IF_SALE_FREEZE,
			       T.ASK_TYPE_STATUS,
			       T.STD_STYLE_DESC,
			       NVL(T.ROLL_WELL_MONTH, T.ROLL_MONTH) ROLL_WELL_MONTH,
			       T.WEIGHT_PER_M,
			       T.PAYDOWN_NUM,
			       T.PAYDOWN_WT_MIN,
			       T.PAYDOWN_WT_MAX,
			       T.SUPPLY_UNIT_CODE,
			       T.SUPPLY_UNIT,
			       T.DELVRY_ADDR,
			       (SELECT SUM(B.REQWEIGHT)
			          FROM PLN_SALEORDER_R_NUM B
			         WHERE B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) REQ_QTYSUM,
			       (SELECT SUM(B.CONFIRM_WT)
			          FROM PLN_SALEORDER_R_NUM B
			         WHERE B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) CONFIRM_WT_SUM,
			       T.HEIGHT_ORD_MIN,
			       T.HEIGHT_ORD_MAX,
			       H.SALE_AREA_DESC,
			       M.UNIT_DESC_PROCESS UNIT_DESC,
			       F.DEPARTNAME,
			       T2.DESIGN_STS,
			       DECODE(T.IS_BACKORD,'1','是','否') IS_BACKORD,
			       (SELECT MAX (CRAFT_NO) FROM  CRAFT_ORD_DESIGN
                    WHERE ORD_LN_PK = T.ORD_LN_PK AND VALIDFLAG = '1') CRAFT_FILE_NO_NEW,
                     T.OUTD_ORD_MIN,
       T.OUTD_ORD_MAX,
       TO_CHAR(T.HEIGHT_ORD_MIN) || DECODE(T.HEIGHT_ORD_MIN, '', '', '%,') ||
       TO_CHAR(T.HEIGHT_ORD_MAX) || DECODE(T.HEIGHT_ORD_MAX, '', '', '%') HEIGHT_ORD,
       TO_CHAR(T.OUTD_ORD_MIN) || DECODE(T.OUTD_ORD_MIN, '', '', '%,') ||
       TO_CHAR(T.OUTD_ORD_MAX) || DECODE(T.OUTD_ORD_MAX, '', '', '%') OUTD_ORD,
       NVL((SELECT T1.CHECK_J_VAL
             FROM COM_MSC_JG T1
            WHERE T1.CODE_JG = T.CODE_JG
              AND T1.VALIDFLAG = '1'),
           0) CHECK_J_VAL,
       NVL((SELECT T1.WEIGHT_JG
             FROM COM_MSC_JG T1
            WHERE T1.CODE_JG = T.CODE_JG
              AND T1.VALIDFLAG = '1'),
           0) WEIGHT_JG,
           DECODE(T.CONFIRM_XS,'2','已确认','未确认') CONFIRM_XS
			  FROM PLN_SALEORD T
			  LEFT JOIN SLM_ORDER_LINE L
			    ON L.ORD_LN_PK = T.ORD_LN_PK
			   AND L.VALIDFLAG = '1'
			  LEFT JOIN SLM_ORDER_HEAD H
			    ON H.ORD_PK = T.ORD_PK
			   AND H.VALIDFLAG = '1'
			  LEFT JOIN (SELECT DECODE(K.DESIGN_STS,
			                           'W',
			                           '等待',
			                           'S',
			                           '通过',
			                           'F',
			                           '失败') DESIGN_STS,
			                    H.ORD_LN_PK
			               FROM SLM_ORDER_LINE H, CRAFT_ORD_DESIGN M
			               LEFT JOIN CRAFT_ORD_DESIGN_STS_TKLG K
			                 ON K.DESGIN_KEY = M.DESGIN_KEY
			                AND K.VALIDFLAG = '1'
			              WHERE M.CRAFT_SEQ =
			                    (SELECT MAX(CRAFT_SEQ)
			                       FROM CRAFT_ORD_DESIGN
			                      WHERE ORD_LN_PK = M.ORD_LN_PK)
			                AND H.VALIDFLAG <> '0'
			                AND M.ORD_LN_PK = H.ORD_LN_PK
			                AND M.VALIDFLAG <> '0') T2
			    ON T2.ORD_LN_PK = T.ORD_LN_PK
			  LEFT JOIN COM_MSC M
			  LEFT JOIN CORE_APP_DEPARTMENT E
			    ON E.DEPARTID = M.UNIT_CODE_PROCESS
			  LEFT JOIN CORE_APP_DEPARTMENT F
			    ON F.DEPARTID = E.PID ON T.MSC = M.MSC
			 WHERE NVL(T.ROLL_MONTH, '2') LIKE '%' || NVL(?, '2') || '%'
			   --AND NVL(T.ACCEPT_NO, '1') LIKE '%' || NVL(NLS_UPPER(?), '1') || '%'
			   AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND T.PORDERSTATUS LIKE '%' || ? || '%'
			   AND DECODE(?, '1', T.JGORD_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND DECODE(?, '1', T.DJBL_REQ_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND DECODE(?, '1', T.MERGETYPE, 1) = DECODE(?, '1', '3', 1)
			   AND T.PORDERSTATUS < '6'
			   AND T.ORDER_TYPE = '1'
			   and t.order_no not like 'MG%' --过滤母管合同
		]]>
	</query>

	<query id="CorePlnSaleOrder.querySaleOrder1" desc="查询销售合同">
		<![CDATA[
			SELECT T.ORD_PK,
			       T.ORD_LN_PK,
			       T.ORD_LN_DLY_PK,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       (T.ORDER_NO || '/' || T.ORDER_SEQ) ORDER_NO_SEQ,
			       (SELECT A.PRODUC_DESC
			          FROM COM_BASE_PRODUCT A
			         WHERE A.PRODUCCODE = T.PRODUCCODE
			           AND A.VALIDFLAG = '1') PRD_CLS,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME || DECODE(T.USE_DESC, NULL, '', '/', '', ',' || T.USE_DESC) STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.SPEC_CODE,
			       T.SPEC_NAME,
			       T.ORDERNUM,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.LEN_UNIT,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.LENGTHDISC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.ORDER_UNIT,
			       T.ORDER_QTY,
			       T.ORDERWEIGHT,
			       DECODE(T.ORDER_UNIT, '米', '吨', '英尺', '吨', T.ORDER_UNIT) ORDERWEIGHTUNIT,
			       DECODE(T.TOTLENGTH, 0, '', T.TOTLENGTH) TOTLENGTH,
			       T.TOTLENGTH_UNIT,
			       T.DELVRY_RANGE_TPE,
			       T.DELVRY_RANGE_MIN,
			       T.DELVRY_RANGE_MAX,
			       '(-' || TO_CHAR(ABS(T.DELVRY_RANGE_MIN)) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
			       TO_CHAR(T.DELVRY_RANGE_MAX) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
			       T.BUYER_ID,
			       (SELECT A.ABRVITION
			          FROM SLM_BASE_CUSTOMER A
			         WHERE A.CUSTOMER_NO = T.BUYER_ID) BUYER_NAME,
			       T.ORDER_SPECIAL_DESC,
			       T.ADD_ASK_NO,
			       L.ORDER_ADD_DESC,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.ORDERFROM) ORDERFROM,
			       T.FINAL_USER,
			       NVL((SELECT A.ABRVITION
			             FROM SLM_BASE_CUSTOMER A
			            WHERE A.CUSTOMER_NO = DECODE(T.FINAL_USER,
			                                         NULL,
			                                         T.BUYER_ID,
			                                         '/',
			                                         T.BUYER_ID,
			                                         T.FINAL_USER)),
			           DECODE(T.FINAL_USER_DESC,
			                  NULL,
			                  T.BUYER_NAME,
			                  '/',
			                  T.BUYER_NAME,
			                  T.FINAL_USER_DESC)) FINAL_USER_DESC,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.MONITORDEMAND) MONITORDEMAND,
			       T.SPECSTANDARD,
			       DECODE(T.PORDERSTATUS,
			              '0',
			              '待接收',
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '3',
			              '生产中',
			              '4',
			              '生产完成',
			              '5',
			              '缴库完成') PORDERSTATUS,
			       T.PSC,
			       T.MSC,
			       T.CODE_JG,
			       T.CODE_DJ_BL,
			       T.PLANWEIGHT,
			       T.PAYDOWNWEIGHT,
			       T.CREATE_NAME,
			       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       T.UPDATE_NAME,
			       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       T.ENDGXNAME,
			       T.MERGETYPE,
			       DECODE(T.JZ_FILE_IF_ALL, '1', '是', '0', '否') JZ_FILE_IF_ALL,
			       T.PRDCR_NO,
			       T.ROLL_MONTH,
			       T.MATERIAL_NO,
			       T.MATERIAL_DESC,
			       T.BL_GROUP_NUM,
			       T.SHRT_LEN_RATO,
			       T.SHORTEST,
			       T.LONG_LEN_RATO,
			       T.LONGEST,
			       T.SHRT_STOVE,
			       T.AVG_LEN_MIN,
			       T.DIFRNC_LEN_MAX,
			       T.SIGL_LEN,
			       T.ENDLEN_SPECSTD,
			       T.STATION_NO,
			       NVL(T.STATION_NM,
			           (SELECT A.STATION_NM
			              FROM SLM_BASE_STATION A
			             WHERE A.STATION_NO = T.STATION_NO)) STATION_NM,
			       T.PRODUCE_SORT,
			       T.USE_CODE,
			       T.USE_DESC,
			       DECODE(T.TOTLENGTH_M, 0, '', T.TOTLENGTH_M) TOTLENGTH_M,
			       NVL(TRIM(T.OUTS_BILLET_FL), '121802') OUTS_BILLET_FL,
			       T.PIPE_PROPERTY,
			       T.LEN_TOEND_MIN,
			       T.LEN_TOEND_MAX,
			       T.LENGTH_JG,
			       T.WEIGH_TYPE,
			       T.TRANSIT_TYP,
			       T.ACCEPT_NO,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
			       DECODE(T.JGORD_IS_OK, '0', '否', '1', '是', '2', '/') JGORD_IS_OK,
			       DECODE(T.JGL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') JGL_REQ_IS_OK,
			       DECODE(T.DJBL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') DJBL_REQ_IS_OK,
			       DECODE(T.IF_SALE_FREEZE, '1', '是', '0', '否') IF_SALE_FREEZE,
			       T.ASK_TYPE_STATUS,
			       T.STD_STYLE_DESC,
			       NVL(T.ROLL_WELL_MONTH, T.ROLL_MONTH) ROLL_WELL_MONTH,
			       T.WEIGHT_PER_M,
			       T.PAYDOWN_NUM,
			       T.PAYDOWN_WT_MIN,
			       T.PAYDOWN_WT_MAX,
			       T.SUPPLY_UNIT_CODE,
			       T.SUPPLY_UNIT,
			       T.DELVRY_ADDR,
			       (SELECT SUM(B.REQWEIGHT)
			          FROM PLN_SALEORDER_R_NUM B
			         WHERE B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) REQ_QTYSUM,
			       (SELECT SUM(B.CONFIRM_WT)
			          FROM PLN_SALEORDER_R_NUM B
			         WHERE B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) CONFIRM_WT_SUM,
			       T.HEIGHT_ORD_MIN,
			       T.HEIGHT_ORD_MAX,
			       H.SALE_AREA_DESC,
			       M.UNIT_DESC_PROCESS UNIT_DESC,
			       F.DEPARTNAME,
			       T2.DESIGN_STS,
			       DECODE(T.IS_BACKORD,'1','是','否') IS_BACKORD,
			       (SELECT MAX (CRAFT_NO) FROM  CRAFT_ORD_DESIGN 
                    WHERE ORD_LN_PK = T.ORD_LN_PK AND VALIDFLAG = '1') CRAFT_FILE_NO_NEW,
                     T.OUTD_ORD_MIN,
       T.OUTD_ORD_MAX,
       TO_CHAR(T.HEIGHT_ORD_MIN) || DECODE(T.HEIGHT_ORD_MIN, '', '', '%,') ||
       TO_CHAR(T.HEIGHT_ORD_MAX) || DECODE(T.HEIGHT_ORD_MAX, '', '', '%') HEIGHT_ORD,
       TO_CHAR(T.OUTD_ORD_MIN) || DECODE(T.OUTD_ORD_MIN, '', '', '%,') ||
       TO_CHAR(T.OUTD_ORD_MAX) || DECODE(T.OUTD_ORD_MAX, '', '', '%') OUTD_ORD,
       NVL((SELECT T1.CHECK_J_VAL
             FROM COM_MSC_JG T1
            WHERE T1.CODE_JG = T.CODE_JG
              AND T1.VALIDFLAG = '1'),
           0) CHECK_J_VAL,
       NVL((SELECT T1.WEIGHT_JG
             FROM COM_MSC_JG T1
            WHERE T1.CODE_JG = T.CODE_JG
              AND T1.VALIDFLAG = '1'),
           0) WEIGHT_JG,
           DECODE(T.CONFIRM_XS,'1','已确认','2','已确认','未确认') CONFIRM_XS,
               MAT.ACT_WEIGHT,
               MAT.ACT_COUNT
			  FROM PLN_SALEORD T
			  LEFT JOIN SLM_ORDER_LINE L
			    ON L.ORD_LN_PK = T.ORD_LN_PK
			   AND L.VALIDFLAG = '1'
			  LEFT JOIN SLM_ORDER_HEAD H
			    ON H.ORD_PK = T.ORD_PK
			   AND H.VALIDFLAG = '1'
			  LEFT JOIN (SELECT DECODE(K.DESIGN_STS,
			                           'W',
			                           '等待',
			                           'S',
			                           '通过',
			                           'F',
			                           '失败') DESIGN_STS,
			                    H.ORD_LN_PK
			               FROM SLM_ORDER_LINE H, CRAFT_ORD_DESIGN M
			               LEFT JOIN CRAFT_ORD_DESIGN_STS_TKLG K
			                 ON K.DESGIN_KEY = M.DESGIN_KEY
			                AND K.VALIDFLAG = '1'
			              WHERE M.CRAFT_SEQ =
			                    (SELECT MAX(CRAFT_SEQ)
			                       FROM CRAFT_ORD_DESIGN
			                      WHERE ORD_LN_PK = M.ORD_LN_PK)
			                AND H.VALIDFLAG <> '0'
			                AND M.ORD_LN_PK = H.ORD_LN_PK
			                AND M.VALIDFLAG <> '0') T2
			    ON T2.ORD_LN_PK = T.ORD_LN_PK
			  LEFT JOIN COM_MSC M
			  LEFT JOIN CORE_APP_DEPARTMENT E
			    ON E.DEPARTID = M.UNIT_CODE_PROCESS
			  LEFT JOIN CORE_APP_DEPARTMENT F
			    ON F.DEPARTID = E.PID ON T.MSC = M.MSC
			  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 T.PRODUCCODE = MAT.PRODUCCODE
			   AND T.STEELCODE = MAT.STEELCODE
			   AND T.SPEC_CODE = MAT.SPEC_CODE
			   AND T.MODEL_CODE = MAT.MODEL_CODE
			   AND DECODE(L.STD_STYLE, NULL, '1', L.STD_STYLE) =
				   DECODE(MAT.STD_STYLE, NULL, '1', MAT.STD_STYLE)
			   AND T.SUPPLY_UNIT_CODE=MAT.SUPPLY_UNIT_CODE
			   AND DECODE(T.ORDERFROM, '100102', '100102', '100101') =
				   MAT.BELONG_CODE

			  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) OM ON T.ORD_LN_DLY_PK = OM.ORD_LN_DLY_PK
			 WHERE NVL(T.ROLL_MONTH, '2') LIKE '%' || NVL(?, '2') || '%'
			   --AND NVL(T.ACCEPT_NO, '1') LIKE '%' || NVL(NLS_UPPER(?), '1') || '%'
			   --AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND T.PORDERSTATUS LIKE '%' || ? || '%'
			   --AND DECODE(?, '1', T.JGORD_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   --AND DECODE(?, '1', T.DJBL_REQ_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   --AND DECODE(?, '1', T.MERGETYPE, 1) = DECODE(?, '1', '3', 1)
			   AND T.PORDERSTATUS < '6'
			   AND T.ORDER_TYPE = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryOrdCraftOrdDesign" desc="查询交货行工艺">
		<![CDATA[
			SELECT T.CRAFT_NO,
       M1.CRAFT_NAME,
       T.DESGIN_KEY,
       T.CRAFT_SEQ,
       T.CRAFT_NO_V,
       T.VALIDFLAG
  FROM CRAFT_ORD_DESIGN T
  LEFT JOIN CRAFT_ORD_DESIGN_APPOINT M1
    ON M1.ORD_LN_PK = T.ORD_LN_PK
  LEFT JOIN CRAFT_ORD_DESIGN_STS_TKLG K
    ON K.DESGIN_KEY = T.DESGIN_KEY
   AND K.VALIDFLAG = '1'
 WHERE T.DESGIN_KEY IS NOT NULL
   AND T.VALIDFLAG != '0'
   AND K.DESIGN_STS = 'S'
 AND T.ORD_LN_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryOrdLineDepartUnit" desc="查询合同行部门科室">
		<![CDATA[
			SELECT M.UNIT_CODE_PROCESS,
                M.UNIT_DESC_PROCESS,
                F.DEPARTID,
                F.DEPARTNAME
           FROM SLM_ORDER_LINE T, COM_MSC M
           LEFT JOIN CORE_APP_DEPARTMENT E
             ON E.DEPARTID = M.UNIT_CODE_PROCESS
           LEFT JOIN CORE_APP_DEPARTMENT F
             ON F.DEPARTID = E.PID
          WHERE T.MSC = M.MSC
            AND T.ORD_LN_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.querySaleByPrimary" desc="通过合同号有无重复">
		<![CDATA[
			SELECT COUNT(*) AS DLY_NUM
			  FROM PLN_SALEORD T
			 WHERE T.ORDER_NO = ?
			   AND T.ORDER_SEQ = ?
			   AND T.DELIVERY_NO = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryBaseinfoAll" desc="查询基础维护数据">
		<![CDATA[
			SELECT T.BASECODE, T.BASENAME, T.SORTCODE
		        FROM COM_BASE_INFO T
		       WHERE T.SORTCODE = '1218'
		          OR T.SORTCODE = '2004'
		          OR T.SORTCODE = '2005'
		          OR T.SORTCODE = '2006'
		         AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.querySaleStatus" desc="查询销售合同状态">
		<![CDATA[
			SELECT T.PORDERSTATUS,
			       T.ORDER_QTY,
			       T.ORDER_UNIT,
			       T.ORDERWEIGHT,
			       T.ORDERNUM,
			       T.PLANWEIGHT,
			       T.WEIGHT_PER_M,
			       T.JGORD_IS_OK,
			       T.DJBL_REQ_IS_OK,
			       T.ROLL_MONTH,
			       T.CODE_JG,
			       T.OUTS_STL_PIPE_FL,
			       DECODE(T.PORDERSTATUS,'0','待接收','1','已接收','2','已下发','3','生产中','4','生产完成','5',
			       '缴库完成','发运完毕','7','结算完毕','8','合同关闭') PORDERSTATUS1,
			       T.CONFIRM_XS,t.ORDERFROM
			  FROM PLN_SALEORD T
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryPlnDivideId" desc="查询交货行排产流水号">
		<![CDATA[
			SELECT T.ORD_LN_DLY_PK, T.PLN_DIVIDE_ID
			  FROM PLN_SALEORD_PROC T
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryProducType" desc="查询品名基础表">
		<![CDATA[
			SELECT T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.PRODUC_STYLE,
			       T.PRODUC_DESC,
			       T.PRODUC_JX,
			       T.PRODUC_ENG,
			       T.PRODUCCODE_OLD,
			       T.PRODUC_HEAD,
			       T.PRODUC_TYPE
			  FROM COM_BASE_PRODUCT T
			 WHERE T.PRODUCCODE = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryWeighType" desc="查询计重方式">
		<![CDATA[
			SELECT ADD_ASK_NO,
			       ASK_ITME,
			       ASK_ITME_DESC,
			       ASK_SUB_ITME,
			       ASK_SUB_ITME_DESC,
			       ASK_SUB_ITME_VAL,
			       ASK_SUB_ITME_VAL_DESC,
			       PIC,
			       CUSTOMER_NO,
			       CUSTOMER_NM,
			       PSC,
			       PSC_DESC,
			       ADD_ASK_STATUS,
			       ADD_ASK_TYPE,
			       REVIEW_F_RS
			  FROM SLM_ORDER_ADD_ASK T
			 WHERE T.ADD_ASK_NO = ?
			   AND T.ASK_ITME = '121005'
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryTransit" desc="查询交货到站">
		<![CDATA[
			SELECT T.STATION_NO,
			       (SELECT A.STATION_NM
			          FROM SLM_BASE_STATION A
			         WHERE A.STATION_NO = T.STATION_NO) STATION_NM
			  FROM SLM_ORDER_DELIVERY_TRANSIT T
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryTranType" desc="查询交货运输方案">
		<![CDATA[
			SELECT (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.TRANSIT_TYP) TRANSIT_TYP
			  FROM SLM_ORDER_LINE_DELIVERY T
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryDesginPl" desc="查询质量设计制程">
		<![CDATA[ 
		SELECT  T.MSC_PLINE,
                T.WHOLE_BACKLOG,
                T.WHOLE_BACKLOG_DESC,
                (SELECT LISTAGG(C.GRADENAME, ',') WITHIN GROUP(ORDER BY C.PRIORITY ASC, C.GRADECODE)
                   FROM (SELECT DISTINCT B.GRADENAME, B.GRADECODE, B.PRIORITY
                           FROM CRAFT_ORD_DESIGN_MSC_PL_GZ B,
                                CRAFT_ORD_DESIGN_MSC_PL    B1
                          WHERE B.DESGIN_KEY = B1.DESGIN_KEY
                            AND B.MSC_PLINE = B1.MSC_PLINE
                            AND B.PRIORITY<'100'
                            AND B1.DESGIN_KEY =? 
                          ORDER BY B.PRIORITY ASC, B.GRADECODE ASC) C) GRADENAME
           FROM CRAFT_ORD_DESIGN_MSC_PL T
          WHERE T.DESGIN_KEY = ?
            AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryMscplPrc" desc="销售合同查询制程工序">
		<![CDATA[
			SELECT DESGIN_KEY,
	              MSC_PLINE,
	              WHOLE_BACKLOG,
	              WHOLE_BACKLOG_DESC,
	              BACKLOG_SEQ,
	              PROCESS_CODE,
	              PROCESS_DESC,
	              PROCESS_SEQ,
	              PROCESS_CODE_C,
	              PROCESS_DESC_C,
	              MINUTE_PRODUCT,
	              MINUTE_PRODUCT_OUT,
	              MINUTE_WAITE,
	              MINUTE_WAITE_OUT,
	              BATCH_WAITE,
	              BATCH_WAITE_OUT,
	              SIC
	         FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T
	       WHERE T.DESGIN_KEY = ?
	         AND T.MSC_PLINE = ?
	       ORDER BY T.BACKLOG_SEQ ASC
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryAsselFl" desc="查询是否Assel">
		<![CDATA[
			SELECT T.ASSEL_FL FROM SLM_ORDER_LINE T WHERE T.ORD_LN_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryLinePrdcr" desc="查询监制基础表">
		<![CDATA[
			SELECT T.PRDCR_NO,
			       T.PRDCR_DESC,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.PRDCR_DESC) MONITORDEMAND
			  FROM SLM_ORDER_LINE_PRDCR T
			 WHERE T.PRDCR_NO = ?
			   AND T.MSC_PLINE = ?
			   AND T.CODE_JG IS NULL
			   AND T.CODE_BL IS NULL
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryJgCode" desc="根据DESGIN_KEY查询接箍码">
		<![CDATA[
			SELECT T.CODE_JG, nvl(B.WEIGHT_JG,0) WEIGHT_JG, B.LENGTH_JG, NVL(B.CHECK_J_VAL,0) CHECK_J_VAL
			  FROM CRAFT_ORD_DESIGN_MSC_JG T, COM_MSC_JG B
			 WHERE B.CODE_JG = T.CODE_JG
			   AND T.DESGIN_KEY = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryJgBase" desc="查询接箍基础信息">
		<![CDATA[
			SELECT SPEC_JG,
			       SPEC_JG_DESC,
			       PRODUCCODE_JG,
			       PRODUCCODE_JG_DESC,
			       STEELCODE_JG,
			       STEELCODE_JG_DESC,
			       MODEL_CODE,
			       MODEL_DESC,
			       STYLE_JG,
			       MIN_D,
			       MIN_H,
			       DIAMETER_JG,
			       HEIGHT_JG,
			       LENGTH_JG,
			       WEIGHT_JG,
			       NVL(WEIGHT_JG, 0) WEIGHT_JG,
                   NVL(CHECK_J_VAL, 0) CHECK_J_VAL
			  FROM COM_MSC_JG T
			 WHERE T.CODE_JG = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryBlCode" desc="根据DESGIN_KEY查询短节备料码">
		<![CDATA[
			SELECT T.PSC_BL, T.GROUP_NUM, T.DESGIN_KEY_BL
			  FROM CRAFT_ORD_DESIGN_MSC_BL T
			 WHERE T.DESGIN_KEY = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryAddAsk" desc="查询附加要求信息">
		<![CDATA[
			SELECT T.ASK_SUB_ITME_DESC || ':' || T.ASK_SUB_ITME_VAL_DESC || ';' ASKDESC,
			       T.ASK_ITME,
			       T.ADD_ASK_TYPE,
			       T.PIC
			  FROM SLM_ORDER_ADD_ASK T
			 WHERE T.ADD_ASK_NO = ?
			   AND T.VALIDFLAG = '1'
			 ORDER BY T.ASK_ITME ASC
		]]>
	</query>

	<query id="CorePlnSaleOrder.queryPutRate" desc="查询投料原则，投料率">
		<![CDATA[
			SELECT T.PUT_RATE,T.COEFFI_JG
			  FROM PLN_MAT_PUT_MONTH T
			 WHERE T.PUT_YEAR = ?
			   AND T.PUT_MONTH = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.getAcceptNum" desc="接收版本号">
		<![CDATA[
			SELECT 'X' || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
			               LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.ACCEPT_NO, 10)) + 1), '1'),
			                    2,
			                    '0') ACCEPTNO
			          FROM PLN_SALEORD T
			         WHERE SUBSTR(T.ACCEPT_NO, 0, 9) =
			               ('X' || TO_CHAR(SYSDATE, 'YYYYMMDD'))
		]]>
	</query>

	<query id="CorePlnSaleOrder.updateSaleOrder" desc="合同接收主表信息更新">
		<![CDATA[
			UPDATE PLN_SALEORD T
			   SET T.ACCEPT_NO         = '#ACCEPT_NO#',
			       T.PRD_CLS           = '#PRD_CLS#',
			       T.CODE_JG           = '#CODE_JG#',
			       T.WEIGH_TYPE        = '#WEIGH_TYPE#',
			       T.TRANSIT_TYP       = '#TRANSIT_TYP#',
			       T.STATION_NO        = '#STATION_NO#',
			       T.STATION_NM        = ('#STATION_NM#' ||
                      (SELECT DECODE(D.DELVRY_ADDR,
                                     '客户库-腾飞',
                                     ' 客户库-腾飞',
                                     '客户库-宝仓',
                                     ' 客户库-宝仓',
                                     '客户库-安利',
                                     ' 客户库-安利',
                                     '客户库-润德',
                                     ' 客户库-润德',
                                     '客户库-三圆南',
                                     ' 客户库-三圆南',
                                     '客户库-思创',
                                     ' 客户库-思创',
                                     '客户库-滨城',
                                     ' 客户库-滨城',
                                     NULL)
                         FROM SLM_ORDER_LINE_DELIVERY D
                        WHERE D.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK)),
			       T.WEIGHT_PER_M      = '#WEIGHT_PER_M#',
			       T.ORDERNUM          = '#ORDERNUM#',
			       T.ORDERWEIGHT       = '#ORDERWEIGHT#',
			       T.PLANWEIGHT        = '#PLANWEIGHT#',
			       T.PAYDOWN_WT_MAX    = '#PAYDOWN_WT_MAX#',
			       T.PAYDOWN_WT_MIN    = '#PAYDOWN_WT_MIN#',
			       T.SHRT_STOVE        = '#SHRT_STOVE#',
			       T.LEN_UNIT          = '#LEN_UNIT#',
			       T.LENGTHMAX         = '#LENGTHMAX#',
			       T.LENGTHMIN         = '#LENGTHMIN#',
			       T.SHORTEST          = '#SHORTEST#',
			       T.LONGEST           = '#LONGEST#',
			       T.AVG_LEN_MIN       = '#AVG_LEN_MIN#',
			       T.DIFRNC_LEN_MAX    = '#DIFRNC_LEN_MAX#',
			       T.SIGL_LEN          = '#SIGL_LEN#',
			       T.ENDLEN_SPECSTD    = '#ENDLEN_SPECSTD#',
			       T.TOTLENGTH_M       = '#TOTLENGTH_M#',
			       T.LENGTH_JG         = '#LENGTH_JG#',
			       T.ENDGXNAME         = '#ENDGXNAME#',
			       T.PRODUCE_SORT      = '#PRODUCE_SORT#',
			       T.PIPE_PROPERTY     = '#PIPE_PROPERTY#',
			       T.PORDERSTATUS      = '1',
			       T.MERGETYPE         = '#MERGETYPE#',
			       T.MONITORDEMAND     = '#MONITORDEMAND#',
			       T.BL_GROUP_NUM     =
			       (SELECT MIN(A.GROUP_NUM)
			          FROM CRAFT_ORD_DESIGN_MSC_BL A
			         WHERE A.DESGIN_KEY = '#BL_GROUP_NUM#'),
			       T.SPECSTANDARD     =
			       (SELECT B.SIC
			          FROM CRAFT_ORD_DESIGN_STD B
			         WHERE B.DESGIN_KEY = '#SPECSTANDARD#'),
			       T.UPDATE_NAME       = '#UPDATE_NAME#',
			       T.UPDATE_TIME       = SYSDATE,
			       T.JGORD_IS_OK       = '#JGORD_IS_OK#',
			       T.JGL_REQ_IS_OK     = '#JGL_REQ_IS_OK#',
			       T.DJBL_REQ_IS_OK    = '#DJBL_REQ_IS_OK#',
			       T.HEIGHT_ORD_MAX    = '#HEIGHT_ORD_MAX#',
			       T.HEIGHT_ORD_MIN    = '#HEIGHT_ORD_MIN#',
			       T.LEN_TOEND_MAX     = '#LEN_TOEND_MAX#',
			       T.LEN_TOEND_MIN     = '#LEN_TOEND_MIN#',
			       T.CRAFT_FILE_NO_IN =
			       (SELECT B.CRAFT_FILE_NO
			          FROM (SELECT B.CRAFT_FILE_NO,
			                       B.CRAFT_FILE_MAN,
			                       B.ORDER_NO,
			                       B.ORDER_SEQ
			                  FROM PLN_ORD_CRAFT_FILE B
			                 ORDER BY B.VERSION_NO DESC) B
			         WHERE B.ORDER_NO = T.ORDER_NO
			           AND B.ORDER_SEQ = T.ORDER_SEQ
			           AND ROWNUM = '1'),
			       T.CRAFT_FILE_MAN_IN =
			       (SELECT B.CRAFT_FILE_MAN
			          FROM (SELECT B.CRAFT_FILE_NO,
			                       B.CRAFT_FILE_MAN,
			                       B.ORDER_NO,
			                       B.ORDER_SEQ
			                  FROM PLN_ORD_CRAFT_FILE B
			                 ORDER BY B.VERSION_NO DESC) B
			         WHERE B.ORDER_NO = T.ORDER_NO
			           AND B.ORDER_SEQ = T.ORDER_SEQ
			           AND ROWNUM = '1'),
			       T.OUTS_BILLET_FL    = DECODE(T.OUTS_STL_PIPE_FL,
                                    '121903',
                                    '',
                                    '121902',
                                    '',
                                    T.OUTS_BILLET_FL),
                    T.OUTD_ORD_MIN='#OUTD_ORD_MIN#',
                    T.OUTD_ORD_MAX='#OUTD_ORD_MAX#'
			 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		]]>
	</query>

	<query id="CorePlnSaleOrder.addSaleOrderPrc" desc="新增交货行拆分合同">
		<![CDATA[
			INSERT INTO PLN_SALEORD_PROC
  (ORD_LN_DLY_PK,
   PLN_DIVIDE_ID,
   ORDER_SOURCE,
   ROLL_MONTH,
   ORDER_NO,
   ORDER_SEQ,
   DELIVERY_NO,
   PSC,
   CRAFT_SEQ,
   CRAFT_NO_V,
   CRAFT_FILE_NO,
   CRAFT_FILE_MAN,
   MSC,
   INDEX_SEQ,
   PROCESS_SEQ,
   BOM,
   GRADECODE_ALL,
   GRADECODE,
   G_IS_OK,
   GROUP_JGX,
   F_IS_OK,
   GROUP_RCL,
   GROUP_ROLL_ALL,
   GROUP_ROLL,
   GROUP_ROLL_NAME,
   BJ_TYPE,
   ABC,
   E_IN_MATERIAL_NO,
   E_IN_MATERIAL_DESC,
   DIMATER_YLG,
   HEIGHT_YLG,
   MATERIAL_NO,
   MATERIAL_DESC,
   STUFF_PROPERTY,
   GRADECODE_IS_OK,
   D_IS_OK,
   E_IS_OK,
   WEIGHT_PER_M,
   PLAN_WT_D,
   PLAN_NUM_D,
   FINISH_WT,
   PLANSTATUS,
   IF_ALLOW_ISSUE,
   HEIGHT_NK_MIN,
   HEIGHT_NK_MAX,
   ORDER_QTY_D,
   ORDER_UNIT,
   AIM_LEN_ROLL,
   AIM_LEN_END,
   PLAN_P_MAIN,
   PLAN_TOT_LEN_D,
   TOT_LEN_ONE_P,
   CUT_NUM_P,
   AIM_WALLTHICK,
   ROLL_LENGTH,
   LEN_ROLL_MAX,
   LEN_ROLL_MIN,
   PRDCRPRO,
   IF_EXPORT,
   PROC_DESC_C_RCL,
   OUT_MULT_D,AIM_OUTDIAMETER,FEED_RATE,COEFFICIENT,COEFFICIENT_MIN,PLAN_P_MAIN_MIN,AIM_WT_END,WEIGHT_KZ_M)
  SELECT B.ORD_LN_DLY_PK,
         '01',
         '销售合同',
         B.ROLL_MONTH,
         B.ORDER_NO,
         B.ORDER_SEQ,
         B.DELIVERY_NO,
         B.PSC,
         '#CRAFT_SEQ#',
         '#CRAFT_NO_V#',
         '#CRAFT_FILE_NO#',
         '#CRAFT_FILE_MAN#',
         B.MSC,
         '#INDEX_SEQ#',
         '#PROCESS_SEQ#',
         '#BOM#',
         '#GRADECODE_ALL#',
         '#GRADECODE#',
         '#G_IS_OK#',
         '#GROUP_JGX#',
         '#F_IS_OK#',
         '#GROUP_RCL#',
         '#GROUP_ROLL_ALL#',
         '#GROUP_ROLL#',
         (SELECT B.PLINE_NAME
            FROM COM_BASE_PLINE B
           WHERE B.PLINE_CODE = '#GROUP_ROLL#'),
         '#BJ_TYPE#',
         '#ABC#',
         '#E_IN_MATERIAL_NO#',
         '#E_IN_MATERIAL_DESC#',
         '#DIMATER_YLG#',
         '#HEIGHT_YLG#',
         '#MATERIAL_NO#',
         '#MATERIAL_DESC#',
         '#STUFF_PROPERTY#',
         '0',
         '#D_IS_OK#',
         '#E_IS_OK#',
         '#WEIGHT_PER_M#',
         '#PLAN_WT_D#',
         '#PLAN_NUM_D#',
         '0',
         '1',
         '0',
         '#HEIGHT_NK_MIN#',
         '#HEIGHT_NK_MAX#',
         B.ORDER_QTY,
         B.ORDER_UNIT,
         '#AIM_LEN_ROLL#',
         '#AIM_LEN_END#',
         '#PLAN_P_MAIN#',
         '#PLAN_TOT_LEN_D#',
         '#TOT_LEN_ONE_P#',
         '#CUT_NUM_P#',
         '#AIM_WALLTHICK#',
         '#ROLL_LENGTH#',
         '#LEN_ROLL_MAX#',
         '#LEN_ROLL_MIN#',
         '#PRDCRPRO#',
         '#IF_EXPORT#',
         '#PROC_DESC_C_RCL#',
         '#OUT_MULT_D#','#AIM_OUTDIAMETER#','#FEED_RATE#','#COEFFICIENT#','#COEFFICIENT_MIN#','#PLAN_P_MAIN_MIN#','#AIM_WT_END#','#WEIGHT_KZ_M#'
    FROM PLN_SALEORD B
    LEFT JOIN SLM_BASE_CUSTOMER R
      ON R.VALIDFLAG = '1'
     AND R.CUSTOMER_NO = NVL(B.FINAL_USER, B.BUYER_ID)
   WHERE B.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		]]>
	</query>

	<query id="CorePlnSaleOrder.addCancelAcpLog" desc="新增撤销记录">
		<![CDATA[
			INSERT INTO PLN_SALEORD_BACKLOG T
				  (T.BACKLOG_ID,
				   T.ORD_PK,
				   T.ORD_LN_PK,
				   T.ORD_LN_DLY_PK,
				   T.ORDER_NO,
				   T.ORDER_SEQ,
				   T.DELIVERY_NO,
				   T.PRODUCNAME,
				   T.SPEC_NAME,
				   T.ORDER_UNIT,
				   T.ORDER_QTY,
				   T.BUYER_NAME,
				   T.FINAL_USER_DESC,
				   T.DELVRY_EDATE,
				   T.ROLL_MONTH,
				   T.BACK_REASON,
				   T.CREATE_NAME,
				   T.CREATE_TIME)
				  SELECT (SELECT TO_CHAR(SYSDATE, 'YYYYMMDD') ||
				                 LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.BACKLOG_ID, 9)) + 1), '1'),
				                      10,
				                      '0')
				            FROM PLN_SALEORD_BACKLOG T
				           WHERE SUBSTR(T.BACKLOG_ID, 0, 8) = TO_CHAR(SYSDATE, 'YYYYMMDD')),
				         B.ORD_PK,
				         B.ORD_LN_PK,
				         B.ORD_LN_DLY_PK,
				         B.ORDER_NO,
				         B.ORDER_SEQ,
				         B.DELIVERY_NO,
				         B.PRODUCNAME,
				         B.SPEC_NAME,
				         B.ORDER_UNIT,
				         B.ORDER_QTY,
				         B.BUYER_NAME,
				         B.FINAL_USER_DESC,
				         B.DELVRY_EDATE,
				         B.ROLL_MONTH,
				         ?,
				         ?,
				         SYSDATE
				    FROM PLN_SALEORD B
				   WHERE B.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.updateCancelAcp" desc="取消接收">
		<![CDATA[
			UPDATE PLN_SALEORD T
			   SET T.PORDERSTATUS = '0', T.ACCEPT_NO = '', T.IS_BACKORD = '1'
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.updateConfirmXs" desc="修改销售确认状态，减排产量">
		<![CDATA[
			UPDATE PLN_SALEORD T
			   SET T.CONFIRM_XS = ?,
			   		T.ORDER_QTY = ?,
				 	T.ORDERWEIGHT = ?,
				 	T.ORDERNUM = ?,
				 	T.TOTLENGTH = ?
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.deleteCancelAcp" desc="删除拆分合同">
		<![CDATA[
			DELETE FROM PLN_SALEORD_PROC T WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.updatePlnSaleOrderStatus" desc="修改销售合同提报表状态">
		<![CDATA[
			UPDATE PLN_SALEORD T SET T.PORDERSTATUS = ? WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.selectOrdFinaLuser" desc="查询最终用户">
		<![CDATA[
			SELECT T.FINAL_USER, T.BUYER_ID
			  FROM PLN_SALEORD T
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.selectCustomerRegion" desc="查询客户编号地区">
		<![CDATA[
			SELECT T.REGION_NO FROM SLM_BASE_CUSTOMER T WHERE T.CUSTOMER_NO = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.getPlnSaleordByPk" desc="查询接收表的信息">
		<![CDATA[
			SELECT T.* FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnSaleOrder.getSelectCicGroup" desc="查询钢种索引码集合">
		<![CDATA[
			  SELECT * FROM (SELECT DISTINCT T.CIC
    FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T
   WHERE T.DESGIN_KEY = ?
     AND T.PROCESS_CODE = 'A'
     --AND T.MSC_PLINE = ?
    -- AND T.BACKLOG_SEQ = '1'
    and 1=1)
    ORDER BY LENGTH(CIC) DESC

		]]>
	</query>
</queryMap>