<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="排产合同综合查询">
	<query id="CoreQueryOrdProcInf.queryOrdProcInf" desc="查询排产合同">
		<![CDATA[
			SELECT M.DESGIN_KEY,
			       T.ORD_PK,
			       T.ORD_LN_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.ORDERWEIGHT,
			       DECODE(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,
					CASE
						WHEN H.ORDER_NO LIKE 'TH%' THEN
							(SELECT SALE_ORG_DESC FROM SLM_ORDER_HEAD WHERE ORDER_NO = (
							SELECT CUSTM_ORDER_NO FROM SLM_ORDER_HEAD WHERE ORDER_NO = H.ORDER_NO and VALIDFLAG = '1'
							) and VALIDFLAG = '1')
						ELSE
							( SELECT A.BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = T.ORDERFROM )
					END 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,
			       E.PRDCRPRO,
			       T.SPECSTANDARD,
			       T.PSC,
			       T.MSC,
			       T.CODE_JG,
			       T.CODE_DJ_BL,
			       T.PLANWEIGHT,
			       T.PAYDOWNWEIGHT,
			       DECODE(E.ORDER_SOURCE, '补量需求', R.REQ_NAME, T.CREATE_NAME) CREATE_NAME,
			       TO_CHAR(DECODE(E.ORDER_SOURCE, '补量需求', R.REQ_TIME, T.CREATE_TIME),
			       			'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       DECODE(E.ORDER_SOURCE, '补量需求', R.PLAN_DEAL_NAME, T.UPDATE_NAME) UPDATE_NAME,
			       TO_CHAR(DECODE(E.ORDER_SOURCE,
			                      '补量需求',
			                      R.PLAN_DEAL_TIME,
			                      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,
			       E.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,
			       DECODE(E.ORDER_SOURCE,
			              '补量需求',
			              R.ACCEPT_NO,
			              T.ACCEPT_NO) ACCEPT_NO,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
			       		CASE
						WHEN H.ORDER_NO LIKE 'TH%' THEN
							(SELECT SALE_AREA_DESC FROM SLM_ORDER_HEAD WHERE ORDER_NO = (
							SELECT CUSTM_ORDER_NO FROM SLM_ORDER_HEAD WHERE ORDER_NO = H.ORDER_NO and VALIDFLAG = '1'
							) and VALIDFLAG = '1')
						WHEN H.ORDER_NO LIKE 'HG%' THEN
							(SELECT
								SALE_AREA_DESC
							FROM
								SLM_ORDER_HEAD
							WHERE
								ord_pk IN ( SELECT SUBSTR( ORD_LN_DLY_PK, 0, length( ORD_LN_DLY_PK ) - 6 )
								FROM PLN_ORDER_ZG_S WHERE TH_ORDER_NO_SEQ IS NOT NULL AND TH_ORDER_NO_SEQ =  (T.ORDER_NO || '/' || T.ORDER_SEQ)))
						ELSE
							H.SALE_AREA_DESC
						END SALE_AREA_DESC,
			       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.PAYDOWN_NUM,
			       T.HEIGHT_ORD_MIN,
			       T.HEIGHT_ORD_MAX,
			       L.AW,
			       E.PRIORITY_MEMO,
			       (SELECT A.BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = E.PRIORITY) PRIORITY,
			       E.ORDER_SOURCE,
			       E.ORD_LN_DLY_PK,
			       E.PLN_DIVIDE_ID,
			       E.R_NUM_ID,
			       E.CRAFT_SEQ,
			       E.CRAFT_FILE_NO,
			       E.CRAFT_NO_V,
			       (SELECT T1.CRAFT_NAME
			          FROM CRAFT_ORD_DESIGN_APPOINT T1
			         WHERE T1.ORD_LN_PK = T.ORD_LN_PK) CRAFT_FILE_MAN,
			       (SELECT MAX(T1.CRAFT_NO)
			          FROM CRAFT_ORD_DESIGN T1
			         WHERE T1.ORD_LN_PK = T.ORD_LN_PK
			           AND T1.VALIDFLAG = '1') CRAFT_NO_NEW,
			       (SELECT MAX(T1.CRAFT_NO_V)
			          FROM CRAFT_ORD_DESIGN T1
			         WHERE T1.ORD_LN_PK = T.ORD_LN_PK
			           AND T1.VALIDFLAG = '1') CRAFT_NO_V_NEW,
			       DECODE(E.CRAFT_SEQ,
			       		  NVL((SELECT MAX(T1.CRAFT_SEQ)
			       		  		 FROM CRAFT_ORD_DESIGN T1
			       		  		WHERE T1.ORD_LN_PK = T.ORD_LN_PK
			       		  		  AND T1.VALIDFLAG = '1'),
			       		  	  E.CRAFT_SEQ),
			       		  '无更新',
			       		  DECODE(E.PLANSTATUS, '4', '无更新', '5', '无更新', '待替换')) CRAFT_RENEW_ST,
			       E.INDEX_SEQ,
			       E.PROCESS_SEQ,
			       (SELECT P.WHOLE_BACKLOG_DESC
			          FROM CRAFT_ORD_DESIGN_MSC_PL P
			         WHERE P.DESGIN_KEY = M.DESGIN_KEY
			           AND P.MSC_PLINE = E.INDEX_SEQ) WHOLE_BACKLOG_DESC,
			       E.BOM,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = E.GROUP_JGX) GROUP_JGX,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = E.GROUP_RCL) GROUP_RCL,
			       DECODE(E.PLANSTATUS,
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '3',
			              '生产中',
			              '4',
			              '生产完成',
			              '5',
			              '缴库完成',
			              '8',
			              '关闭',
			              '9',
			              '取消') PLANSTATUS,
			       E.GRADECODE_ALL,
			       (SELECT A.GRADENAME
			          FROM COM_BASE_GRADE A
			         WHERE A.GRADECODE = E.GRADECODE) GRADECODE,
			       E.GROUP_ROLL_ALL,
			       (SELECT A.PLINE_NAME
			          FROM COM_BASE_PLINE A
			         WHERE A.PLINE_CODE = E.GROUP_ROLL) GROUP_ROLL,
			       E.BJ_TYPE,
			       E.E_IN_MATERIAL_NO,
			       E.E_IN_MATERIAL_DESC,
			       E.DIMATER_YLG,
			       E.HEIGHT_YLG,
			       E.STUFF_PROPERTY,
			       E.WEIGHT_PER_M,
			       E.PLAN_TOT_LEN_D,
			       E.ORDER_QTY_D,
			       E.ORDER_UNIT,
			       E.PLAN_WT_D,
			       E.PLAN_NUM_D,
			       E.FINISH_WT,
			       DECODE(E.IF_CHANGE, '1', '是', '0', '否') IF_CHANGE,
			       E.PLAN_WT_BEGIN,
			       E.PLAN_NUM_BEGIN,
			       E.HEIGHT_NK_MIN,
			       E.HEIGHT_NK_MAX,
			       E.AIM_LEN_END,
			       E.AIM_LEN_ROLL,
			       E.TOT_LEN_ONE_P,
			       E.CUT_NUM_P,
			       E.AIM_WALLTHICK,
			       E.ROLL_LENGTH,
			       E.PLAN_P_MAIN,
			       E.ISSUED_MAN,
			       E.IF_EXPORT,
			       TO_CHAR(E.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
			       DECODE(E.F_IS_OK, '0', '否', '1', '是', '2', '/') F_IS_OK,
			       DECODE(E.IF_ALLOW_ISSUE, '0', '否', '1', '是') IF_ALLOW_ISSUE,
			       DECODE(E.G_IS_OK, '0', '否', '1', '是', '2', '/') G_IS_OK,
			       DECODE(E.GRADECODE_IS_OK, '0', '否', '1', '是') GRADECODE_IS_OK,
			       DECODE(E.D_IS_OK, '0', '否', '1', '是', '2', '/') D_IS_OK,
			       DECODE(E.PLAN_IS_OK, '0', '否', '1', '是') PLAN_IS_OK,
			       DECODE(E.E_IS_OK, '0', '否', '1', '是', '2', '/') E_IS_OK,
			       T.ORDER_QTY
			  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', PLN_SALEORD_PROC E
			  LEFT JOIN PLN_SALEORD E2
			  	ON E.ORD_LN_DLY_PK = E2.ORD_LN_DLY_PK
			  LEFT JOIN CRAFT_ORD_DESIGN M
			    ON M.ORD_LN_PK = E2.ORD_LN_PK
			   AND M.CRAFT_SEQ = E.CRAFT_SEQ
			  LEFT JOIN PLN_SALEORDER_R_NUM R
			    ON R.R_NUM_ID = E.R_NUM_ID
			 WHERE T.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK
			   AND NVL(E.ROLL_MONTH, '1') LIKE '%' || NVL(?, NVL(E.ROLL_MONTH, '1')) || '%'
			   AND (DECODE(E.ORDER_SOURCE,
			               '补量需求',
			               R.ACCEPT_NO,
			               NVL(T.ACCEPT_NO, '1')) LIKE
			       '%' || NVL(NLS_UPPER(?),
			                   DECODE(E.ORDER_SOURCE,
			                          '补量需求',
			                          R.ACCEPT_NO,
			                          NVL(T.ACCEPT_NO, '1'))) || '%')
			   AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND E.PLANSTATUS LIKE '%' || ? || '%'
			   AND E.ORDER_SOURCE LIKE '%' || ? || '%'
		]]>
	</query>
</queryMap>