<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="合同补量申请">
	<query id="CoreReqRequest.querySaleOrder" desc="查询生产完成的合同">
		<![CDATA[
			SELECT 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.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,
			       T.STATION_NM,
			       T.PRODUCE_SORT,
			       T.USE_CODE,
			       T.USE_DESC,
			       DECODE(T.TOTLENGTH_M, 0, '', T.TOTLENGTH_M) TOTLENGTH_M,
			       T.ORDERNUM,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.OUTS_BILLET_FL) 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,
			       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,
			       (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
			  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, '1') LIKE '%' || NVL(?, '1') || '%'
			   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 > '3'
			   AND T.PORDERSTATUS < '6'
		]]>
	</query>
	
	<query id="CoreRequestR.getOrdRNum" desc="查询合同补量申请">
		<![CDATA[
			SELECT T.R_NUM_ID,
			       T.ORD_LN_DLY_PK,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.SPEC_CODE,
			       T.SPEC_NAME,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.LENGTHDISC,
			       T.ORDER_UNIT,
			       T.REQWEIGHT,
			       T.CONFIRM_WT,
			       DECODE(T.ORDER_UNIT, '米', '吨', '英尺', '吨', T.ORDER_UNIT) REQ_WEIGHT_UNIT,
			       T.REP_QTY,
			       T.REP_REASON,
			       T.REQ_NAME,
			       TO_CHAR(T.REQ_TIME, 'YYYY-MM-DD HH24:MI:SS') REQ_TIME,
			       T.PLAN_DEAL_NAME,
			       TO_CHAR(T.PLAN_DEAL_TIME, 'YYYY-MM-DD HH24:MI:SS') PLAN_DEAL_TIME
			  FROM PLN_SALEORDER_R_NUM T
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CoreRequestR.getLastPlnOrdProc" desc="查询最后一个交货行拆分信息">
		<![CDATA[
		SELECT (SELECT DESGIN_KEY
			          FROM CRAFT_ORD_DESIGN B
			         WHERE B.ORD_LN_PK = T1.ORD_LN_PK
			           AND B.CRAFT_SEQ = T.CRAFT_SEQ) DESGIN_KEY,
		       T.PLN_DIVIDE_ID,
		       T.PLANSTATUS,
		       T.INDEX_SEQ,
		       T.BOM,
		       T.GROUP_ROLL,
		       T.PROCESS_SEQ,
		       T.WEIGHT_PER_M,
		       T1.CODE_JG,
		       T.ROLL_MONTH,
		       T1.OUTS_STL_PIPE_FL
		  FROM PLN_SALEORD_PROC T, PLN_SALEORD T1
		 WHERE T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
		   AND T.ORD_LN_DLY_PK = ?
		   AND T.PLN_DIVIDE_ID =
		       (SELECT MAX(T.PLN_DIVIDE_ID)
		          FROM PLN_SALEORD_PROC T
		         WHERE T.ORDER_SOURCE = '销售合同'
		           AND T.ORD_LN_DLY_PK = ?)
		]]>
	</query>
	
	<query id="CoreRequestR.getOrdRNumbyid" desc="查询合同补量申请">
		<![CDATA[
		SELECT T.R_NUM_ID,
		       T.ORD_LN_DLY_PK,
		       T.ORDER_NO,
		       T.ORDER_SEQ,
		       T.DELIVERY_NO,
		       T.ORDER_UNIT,
		       T.REP_QTY,
		       T.REQWEIGHT
		  FROM PLN_SALEORDER_R_NUM T
		 WHERE T.R_NUM_ID = ?
		]]>
	</query>
	
	<query id="CoreRequestR.getReqOrder" desc="查询补量合同">
		<![CDATA[
			SELECT T1.ACCEPT_NO,
			       (SELECT A.PLINE_NAME
			          FROM COM_BASE_PLINE A
			         WHERE A.PLINE_CODE = T2.GROUP_ROLL
			           AND A.VALIDFLAG = '1') GROUP_ROLL,
			       (SELECT A.PRODUC_JX
			          FROM COM_BASE_PRODUCT A
			         WHERE A.PRODUCCODE = T.PRODUCCODE) PRODUC_JX,
			       (DECODE(T.STD_STYLE_DESC || ' ', ' ', '', T.STD_STYLE_DESC || ' ') ||
			       T.STEELNAME) STEELNAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.LENGTHDISC,
			       T.MODEL_DESC,
			       NVL(T1.CONFIRM_WT, T1.REQWEIGHT) CONFIRM_WT,
			       DECODE(DECODE(T.TOTLENGTH, 0, '', NULL, '', T2.PLAN_TOT_LEN_D),
			              '0',
			              '') TOTLENGTH,
			       T.STD_NAME,
			       (T.ORDER_NO || '/' || T.ORDER_SEQ) ORDER_SEQNO,
			       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,
			       L.ORDER_ADD_DESC,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.ORDERFROM) ORDERFROM,
			       T.PRODUCE_SORT,
			       (TO_CHAR(DECODE(T.DELVRY_RANGE_TPE,
			                       '绝对值',
			                       T.DELVRY_RANGE_MAX * 100 / T.ORDER_QTY,
			                       T.DELVRY_RANGE_MAX),
			                'FM9990.00') || '%') RANGE_MAX,
			       ('-' || TO_CHAR(ABS(DECODE(T.DELVRY_RANGE_TPE,
			                                  '绝对值',
			                                  T.DELVRY_RANGE_MIN * 100 / T.ORDER_QTY,
			                                  T.DELVRY_RANGE_MIN)),
			                       'FM9990.00') || '%') RANGE_MIN,
			       TO_CHAR(DECODE(T.DELVRY_RANGE_TPE,
			                      '绝对值',
			                      T.DELVRY_RANGE_MAX / T.ORDER_QTY,
			                      T.DELVRY_RANGE_MAX / 100),
			               'FM90.0000') DELVRY_RANGE_MAX,
			       ('-' || TO_CHAR(ABS(DECODE(T.DELVRY_RANGE_TPE,
			                                  '绝对值',
			                                  T.DELVRY_RANGE_MIN / T.ORDER_QTY,
			                                  T.DELVRY_RANGE_MIN / 100)),
			                       'FM90.0000')) DELVRY_RANGE_MIN,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       (DECODE(T.TRANSIT_TYP || ' ', ' ', '', T.TRANSIT_TYP || ' ') ||
			       T.STATION_NM) STATION_NM,
			       (SELECT A.BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = T.PRD_CLS) PRD_CLS,
			       T2.ROLL_MONTH,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = NVL(TRIM(T.OUTS_BILLET_FL), '121802')) OUTS_BILLET_FL,
			       T.SPEC_NAME,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.MONITORDEMAND) MONITORDEMAND,
			       (TO_CHAR(T.LENGTHMIN, 'FM99990.00') || '-' ||
			       TO_CHAR(T.LENGTHMAX, 'FM99990.00') || 'M') TECHNICALLEN,
			       T.ORDER_SPECIAL_DESC,
			       T1.REP_QTY,
			       T1.ORDER_UNIT,
			       DECODE(T.ORDER_UNIT,
			              '米',
			              '吨',
			              '英尺',
			              '吨',
			              '英磅',
			              '吨',
			              T.ORDER_UNIT) DW2,
			       T2.PLAN_WT_D,
			       DECODE(T.ORDER_UNIT,
			              '米',
			              '吨',
			              '英尺',
			              '吨',
			              '英磅',
			              '吨',
			              T.ORDER_UNIT) DW,
			       T.SHRT_STOVE,
			       T.SIGL_LEN,
			       DECODE(T.ORDER_SPECIAL_DESC, NULL, '普通', '特殊') ORDER_TYPE,
			       T.ENDLEN_SPECSTD,
			       T2.STUFF_PROPERTY,
			       T2.GRADECODE_ALL,
			       (SELECT MAX(D.CRAFT_NO)
			          FROM CRAFT_ORD_DESIGN D
			         WHERE D.ORD_LN_PK = L.ORD_LN_PK
			           AND D.VALIDFLAG = '1') CRAFT_FILE_NO_NEW,
			       T2.CRAFT_FILE_NO,
			       (SELECT M1.CRAFT_NAME
			          FROM CRAFT_ORD_DESIGN_APPOINT M1
			         WHERE M1.ORD_LN_PK = L.ORD_LN_PK) CRAFT_FILE_MAN,
			       T2.HEIGHT_NK_MIN / 100 HEIGHT_NK_MIN,
			       T2.HEIGHT_NK_MAX / 100 HEIGHT_NK_MAX,
			       (SELECT MAX(T1.PROCESS_DESC_C)
			          FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T1
			         WHERE T1.PROCESS_CODE = 'D'
			           AND T1.DESGIN_KEY = M.DESGIN_KEY
			           AND T1.MSC_PLINE = T2.INDEX_SEQ) CRAFT_PATH,
			       (SELECT MAX(T1.PROCESS_DESC_C)
			          FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T1
			         WHERE T1.PROCESS_CODE = 'F'
			           AND T1.DESGIN_KEY = M.DESGIN_KEY
			           AND T1.MSC_PLINE = T2.INDEX_SEQ) RCL_INFO,
			       T2.CRAFT_NO_V VERSION_NO,
			       T2.ORDER_SOURCE ORDERCONTRACT,
			       DECODE(T2.PLANSTATUS,
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '3',
			              '生产中',
			              '4',
			              '生产完成',
			              '5',
			              '缴库完成') PORDERSTATUS,
			       T2.BJ_TYPE,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T2.GROUP_RCL) GROUP_RCL,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T2.GROUP_JGX) GROUP_JGX,
			       T2.ABC,
			       (SELECT P.WHOLE_BACKLOG_DESC
			          FROM CRAFT_ORD_DESIGN_MSC_PL P
			         WHERE P.DESGIN_KEY = M.DESGIN_KEY
			           AND P.MSC_PLINE = T2.INDEX_SEQ) WHOLE_BACKLOG_DESC,
			       T.DELIVERY_NO,
			       DECODE(T.JGORD_IS_OK, '0', '否', '1', '是', '2', '/') JGORD_IS_OK,
			       DECODE(T.DJBL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') DJBL_REQ_IS_OK,
			       (T2.ORD_LN_DLY_PK || '-' || T2.PLN_DIVIDE_ID) ORD_LN_DLY_PK,
			       L.AW,
			       (T.STD_NAME ||'，'|| T.USE_DESC) USE_STAND,
			       T1.REQWEIGHT,
			       T1.REQ_NAME,
			       T1.REP_REASON,
			       TO_CHAR(T1.REQ_TIME, 'YYYY-MM-DD HH24:MI:SS') REQ_TIME,
			       T1.PLAN_DEAL_NAME,
			       TO_CHAR(T1.PLAN_DEAL_TIME, 'YYYY-MM-DD HH24:MI:SS') PLAN_DEAL_TIME,
			       T1.R_NUM_ID
			  FROM PLN_SALEORDER_R_NUM T1
			  LEFT JOIN PLN_SALEORD T
			    ON T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
			  LEFT JOIN SLM_ORDER_LINE L
			    ON L.ORD_LN_PK = T.ORD_LN_PK
			   AND L.VALIDFLAG = '1'
			  LEFT JOIN PLN_SALEORD_PROC T2
			    ON T2.R_NUM_ID = T1.R_NUM_ID
			  LEFT JOIN CRAFT_ORD_DESIGN M
			    ON M.CRAFT_SEQ = T2.CRAFT_SEQ
			   AND M.ORD_LN_PK = T.ORD_LN_PK
			  LEFT JOIN CRAFT_ORD_DESIGN_APPOINT M1
			    ON M1.ORD_LN_PK = T.ORD_LN_PK
			 WHERE (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND TO_DATE(TO_CHAR(T1.REQ_TIME, 'YYYY-MM-DD'), 'YYYY-MM-DD') BETWEEN
			       TO_DATE(?, 'YYYY/MM/DD') AND TO_DATE(?, 'YYYY/MM/DD')
		]]>
	</query>
	
	<query id="CoreRequestR.getAcceptNum" desc="接收版本号">
		<![CDATA[
			SELECT 'B' || 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) =
			               ('B' || TO_CHAR(SYSDATE, 'YYYYMMDD'))
		]]>
	</query>
	
	<query id="CoreRequestR.addOrderRNum" desc="新增合同补量申请">
		<![CDATA[
			 INSERT INTO PLN_SALEORDER_R_NUM
				  (R_NUM_ID,
				   ORD_LN_DLY_PK,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   PRODUCCODE,
				   PRODUCNAME,
				   STD_CODE,
				   STD_NAME,
				   STEELCODE,
				   STEELNAME,
				   SPEC_CODE,
				   SPEC_NAME,
				   MODEL_CODE,
				   MODEL_DESC,
				   OUTDIAMETER,
				   WALLTHICK,
				   LENGTHDISC,
				   ORDER_UNIT,
				   REP_QTY,
				   REQWEIGHT,
				   REP_REASON,
				   REQ_NAME,
				   REQ_TIME)
				  SELECT (SELECT 'REQ' || TO_CHAR(SYSDATE, 'YY') || TO_CHAR(SYSDATE, 'MM') ||
				                 TO_CHAR(SYSDATE, 'DD') ||
				                 LPAD(DECODE((MAX(TO_NUMBER(SUBSTR(T.R_NUM_ID, 10)) + 1)),
				                             '',
				                             '0001',
				                             (MAX(SUBSTR(T.R_NUM_ID, 10)) + 1)),
				                      4,
				                      '0')
				            FROM PLN_SALEORDER_R_NUM T),
				         '#ORD_LN_DLY_PK#',
				         '#ORDER_NO#',
				         '#ORDER_SEQ#',
				         '#DELIVERY_NO#',
				         B.PRODUCCODE,
				         B.PRODUCNAME,
				         B.STD_CODE,
				         B.STD_NAME,
				         B.STEELCODE,
				         B.STEELNAME,
				         B.SPEC_CODE,
				         B.SPEC_NAME,
				         B.MODEL_CODE,
				         B.MODEL_DESC,
				         B.OUTDIAMETER,
				         B.WALLTHICK,
				         B.LENGTHDISC,
				         B.ORDER_UNIT,
				         '#REP_QTY#',
				         '#REQWEIGHT#',
				         '#REP_REASON#',
				         '#REQ_NAME#',
				         SYSDATE
				    FROM PLN_SALEORD B
				   WHERE B.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		]]>
	</query>
	
	<query id="CoreRequestR.deleteOrderRNum" desc="删除合同补量申请">
		<![CDATA[
			DELETE FROM PLN_SALEORDER_R_NUM T WHERE T.R_NUM_ID = ?
		]]>
	</query>
	
	<query id="CoreRequestR.doModify" desc="修改合同补量申请">
		<![CDATA[
			UPDATE PLN_SALEORDER_R_NUM T
			   SET T.REP_QTY    = '#REP_QTY#',
			       T.REP_REASON = '#REP_REASON#',
			       T.REQWEIGHT  = '#REQWEIGHT#'
			 WHERE T.R_NUM_ID = '#R_NUM_ID#'
		]]>
	</query>
	
	<query id="CoreRequestR.confirmOrderRNum" desc="合同补量申请确认">
		<![CDATA[
			UPDATE PLN_SALEORDER_R_NUM T
			   SET T.ACCEPT_NO      = '#ACCEPT_NO#',
			       T.CONFIRM_WT     = '#CONFIRM_WT#',
			       T.PLAN_DEAL_NAME = '#PLAN_DEAL_NAME#',
			       T.PLAN_DEAL_TIME = SYSDATE
			 WHERE T.R_NUM_ID = '#R_NUM_ID#'
		]]>
	</query>
	
	<query id="CoreRequestR.canCelConfirmRNum" desc="取消合同补量申请确认">
		<![CDATA[
			UPDATE PLN_SALEORDER_R_NUM T
			   SET T.ACCEPT_NO      = '',
			       T.PLAN_DEAL_NAME = '',
			       T.PLAN_DEAL_TIME = NULL
			 WHERE T.R_NUM_ID = ?
		]]>
	</query>
	
	<query id="CoreRequestR.canCelOrdProcReq" desc="取消合同补量申请确认">
		<![CDATA[
			DELETE FROM PLN_SALEORD_PROC T WHERE T.R_NUM_ID = ?
		]]>
	</query>
	
	<query id="CoreRequestR.queryIsConfrimProc" desc="查询补量需求是否已经写入下发工序表">
		<![CDATA[
			SELECT T.PLANSTATUS,
			       T.AIM_LEN_END,
			       T.WEIGHT_PER_M,
			       T1.DELVRY_RANGE_MIN,
			       T1.DELVRY_RANGE_MAX,
			       T1.DELVRY_RANGE_TPE,
			       J.WEIGHT_JG,
			       J.CHECK_J_VAL
			  FROM PLN_SALEORD_PROC T, PLN_SALEORD T1
			  left join COM_MSC_JG J
			    ON J.CODE_JG = T1.CODE_JG
			   AND J.VALIDFLAG = '1'
			 WHERE t1.ORD_LN_DLY_PK = t.ORD_LN_DLY_PK
			   and T.R_NUM_ID = ?
		]]>
	</query>
	
	<query id="CoreRequestR.queryRequestOrdPk" desc="查询补量需求合同行，交货行Pk">
		<![CDATA[
		SELECT T1.ORD_LN_DLY_PK, T1.ORD_LN_PK, T2.PLN_DIVIDE_ID
  FROM PLN_SALEORDER_R_NUM T, PLN_SALEORD T1, PLN_SALEORD_PROC T2
 WHERE T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
   AND T2.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
   AND T2.R_NUM_ID=T.R_NUM_ID
   AND T.R_NUM_ID = ?
		]]>
	</query>
	<query id="CoreRequestR.queryRequestOrdPkCX" desc="撤销确认是查询">
		<![CDATA[
SELECT T1.ORD_LN_DLY_PK, T1.ORD_LN_PK
  FROM PLN_SALEORDER_R_NUM T
  LEFT JOIN PLN_SALEORD T1
    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
 WHERE T.R_NUM_ID = ?
		]]>
	</query>
	<query id="CoreRequestR.queryLineStatus" desc="查询和同行状态">
		<![CDATA[
			 SELECT T.ORDER_LN_STATUS FROM SLM_ORDER_LINE T WHERE T.ORD_LN_PK = ?
		]]>
	</query>
	
	<query id="CoreRequestR.updateOrdProcNum" desc="更新补量合同合同支数">
		<![CDATA[
UPDATE PLN_SALEORD_PROC T
   SET T.PLAN_NUM_D     = ?,
       T.PLAN_TOT_LEN_D = ?,
       T.PLAN_P_MAIN    = ?,
       T.PLAN_P_MAIN_MIN  = ?
 WHERE T.R_NUM_ID = ?
		]]>
	</query>
	
	<query id="CoreRequestR.updateOrdRNumProc" desc="更新合同补量确认变化">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET (T.CRAFT_SEQ, T.CRAFT_NO_V, T. CRAFT_FILE_NO, T.CRAFT_FILE_MAN) =
			       (SELECT M.CRAFT_SEQ,
			               M.CRAFT_NO_V,
			               M.CRAFT_NO,
			               (SELECT A.CRAFT_NAME
			                  FROM CRAFT_ORD_DESIGN_APPOINT A
			                 WHERE A.ORD_LN_PK = M.ORD_LN_PK)
			          FROM CRAFT_ORD_DESIGN M, PLN_SALEORD T1
			         WHERE M.ORD_LN_PK = T1.ORD_LN_PK
			           AND T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			           AND M.VALIDFLAG = '1'
			           AND ROWNUM = 1),
			       T.PLAN_WT_D = ?,
			       T.PLAN_P_MAIN = ?,
			       T.ROLL_MONTH = TO_CHAR(SYSDATE, 'YYYY-MM'),
			       T.ORDER_QTY_D = ?
			 WHERE T.R_NUM_ID = ?
		]]>
	</query>
	
	<query id="CoreRequestR.ordRNumToPlnProc" desc="合同补量写入下发工序表">
		<![CDATA[
			INSERT INTO PLN_SALEORD_PROC
				  (ORD_LN_DLY_PK,
				   PLN_DIVIDE_ID,
				   ORDER_SOURCE,
				   ROLL_MONTH,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   R_NUM_ID,
				   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,
				   BJ_TYPE,
				   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,
				   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,
				   ABC,
				   IF_EXPORT,
				   LEN_ROLL_MAX,
				   LEN_ROLL_MIN,
				   OUT_MULT_D,
				   TOT_LEN_ONE_P,
				   CUT_NUM_P,
				   AIM_WALLTHICK,
				   ROLL_LENGTH,
				   GROUP_ROLL_NAME,
				   PRDCRPRO,
				   AIM_OUTDIAMETER,
				   FEED_RATE,
				   COEFFICIENT,
				   COEFFICIENT_MIN,
				   AIM_WT_END,
				   WEIGHT_KZ_M,
				   LEN_CUTHEAD_DBK,
				   LEN_CUTEND_DBK,
				   LEN_LONGER_DBK,RATIO_DBK,PROC_DESC_C_RCL)
				  SELECT T1.ORD_LN_DLY_PK,
				         (SELECT LPAD(NVL(MAX(TO_NUMBER(B.PLN_DIVIDE_ID) + 1), 1), 2, '0')
				            FROM PLN_SALEORD_PROC B
				           WHERE B.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK),
				         '补量需求',
				         TO_CHAR(SYSDATE, 'YYYY-MM'),
				         T2.ORDER_NO,
				         T2.ORDER_SEQ,
				         T2.DELIVERY_NO,
				         T1.R_NUM_ID,
				         T2.PSC,
				         M.CRAFT_SEQ,
				         M.CRAFT_NO_V,
				         M.CRAFT_NO,
				         (SELECT A.CRAFT_NAME
				            FROM CRAFT_ORD_DESIGN_APPOINT A
				           WHERE A.ORD_LN_PK = M.ORD_LN_PK),
				         T2.MSC,
				         T2.INDEX_SEQ,
				         T2.PROCESS_SEQ,
				         T2.BOM,
				         T2.GRADECODE_ALL,
				         T2.GRADECODE,
				         T2.G_IS_OK,
				         T2.GROUP_JGX,
				         T2.F_IS_OK,
				         T2.GROUP_RCL,
				         T2.GROUP_ROLL_ALL,
				         T2.GROUP_ROLL,
				         T2.BJ_TYPE,
				         T2.E_IN_MATERIAL_NO,
				         T2.E_IN_MATERIAL_DESC,
				         T2.DIMATER_YLG,
				         T2.HEIGHT_YLG,
				         T2.MATERIAL_NO,
				         T2.MATERIAL_DESC,
				         T2.STUFF_PROPERTY,
				         T2.GRADECODE_IS_OK,
				         T2.D_IS_OK,
				         T2.E_IS_OK,
				         T2.WEIGHT_PER_M,
				         '#CONFIRM_WT#',
				         '0',
				         '1',
				         '1',
				         T2.HEIGHT_NK_MIN,
				         T2.HEIGHT_NK_MAX,
				         '#REP_QTY#',
				         T2.ORDER_UNIT,
				         T2.AIM_LEN_ROLL,
				         T2.AIM_LEN_END,
				         '#CONFIRM_WT#',
				         T2.ABC,
				         NVL(T2.IF_EXPORT, '#IF_EXPORT#'),
				         T2.LEN_ROLL_MAX,
				         T2.LEN_ROLL_MIN,
				         T2.OUT_MULT_D,
				         T2.TOT_LEN_ONE_P,
				         T2.CUT_NUM_P,
				         T2.AIM_WALLTHICK,
				         T2.ROLL_LENGTH,
				         T2.GROUP_ROLL_NAME,
				         T2.PRDCRPRO,
				         T2.AIM_OUTDIAMETER,T2.FEED_RATE,
				   T2.COEFFICIENT,
				   T2.COEFFICIENT_MIN,
				   T2.AIM_WT_END,
				   T2.WEIGHT_KZ_M,
				   T2.LEN_CUTHEAD_DBK,
				   T2.LEN_CUTEND_DBK,
				   T2.LEN_LONGER_DBK,T2.RATIO_DBK,T2.PROC_DESC_C_RCL
				    FROM PLN_SALEORDER_R_NUM T1, PLN_SALEORD_PROC T2
				    LEFT JOIN PLN_SALEORD T3
				      ON T3.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
				    LEFT JOIN CRAFT_ORD_DESIGN M
				      ON M.ORD_LN_PK = T3.ORD_LN_PK
				     AND M.VALIDFLAG = '1'
				   WHERE T2.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
				     AND T2.PLN_DIVIDE_ID =
				         (SELECT MAX(T.PLN_DIVIDE_ID)
				            FROM PLN_SALEORD_PROC T
				           WHERE T.ORDER_SOURCE = '销售合同'
				             AND T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK)
				     AND T1.R_NUM_ID = '#R_NUM_ID#'
		]]>
	</query>
	
	<query id="CoreRequestR.setModifySale" desc="修改排产合同状态">
		<![CDATA[
			UPDATE PLN_SALEORD T SET T.PORDERSTATUS = ? WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CoreRequestR.setModifySaleProc" desc="修改排产合同状态">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.PLANSTATUS = ?
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.ORDER_SOURCE = '销售合同'
		]]>
	</query>
	
	<query id="CoreRequestR.setLineDeliveryStatus" desc="修改销售交货行表状态">
		<![CDATA[
			UPDATE SLM_ORDER_LINE_DELIVERY T SET T.DELIVERY_STATUS = ? WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CoreRequestR.setOrdLineStatus" desc="修改销售合同行表状态">
		<![CDATA[
			UPDATE SLM_ORDER_LINE T SET T.ORDER_LN_STATUS = ? WHERE T.ORD_LN_PK = ?
		]]>
	</query>
	
	<query id="CoreRequestR.getPlnOrdLineReqQtyMax" desc="查询合同行补量上限">
		<![CDATA[
			SELECT TO_CHAR(SUM(T.ORDER_QTY *
			                   (1.2 + DECODE(T.DELVRY_RANGE_TPE,
			                               '绝对值',
			                               T.DELVRY_RANGE_MAX / T.ORDER_QTY,
			                               T.DELVRY_RANGE_MAX / 100)) -
			                   NVL(ABS(T.PAYDOWNWEIGHT /
			                           TO_NUMBER(DECODE(T.ORDER_UNIT,
			                                            '米',
			                                            T.WEIGHT_PER_M,
			                                            '英尺',
			                                            T.WEIGHT_PER_M * 0.3048,
			                                            1))),
			                       0)),
			               'FM99999990.00') REQ_QTY_MAX,
			       TO_CHAR(SUM(T.ORDER_QTY), 'FM99999990.00') REQ_QTY_SUM,
			       TO_CHAR(SUM(NVL(ABS(T.PAYDOWNWEIGHT), 0)), 'FM99999990.00') PAY_WT_SUM
			  FROM PLN_SALEORD_PROC T1, PLN_SALEORD T
			 WHERE T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			   AND T.ORD_LN_PK = ?
		]]>
	</query>
	
	<query id="CoreRequestR.getLineReqQtySum" desc="查询合同行补量申请量总和">
		<![CDATA[
			SELECT SUM(R.REP_QTY) REP_QTY_SUM
			  FROM PLN_SALEORDER_R_NUM R, PLN_SALEORD T
			 WHERE R.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			   AND R.ORDER_UNIT = T.ORDER_UNIT
			   AND T.ORD_LN_PK = ?
			   AND R.R_NUM_ID NOT IN (SELECT T1.R_NUM_ID
			                            FROM PLN_SALEORD_PROC T1
			                           WHERE T1.R_NUM_ID IS NOT NULL
			                             AND T1.PLANSTATUS > 3)
		]]>
	</query>
	<query id="CoreRequestR.QueryPlnSproc" desc="查询排产补量合同是否下发">
		<![CDATA[
		SELECT  T.PLANSTATUS,DECODE(T.PLANSTATUS,
              '1',
              '已接收',
              '2',
              '已下发',
              '3',
              '生产中',
              '4',
              '生产完成',
              '5',
              '缴库完成',
              '8',
              '关闭',
              '9',
              '取消') PLANSTATUSNAME  FROM PLN_SALEORD_PROC T WHERE T.R_NUM_ID=?
			]]>
	</query>
</queryMap>