<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍排产订单补齐">
	<query id="FrmBlOrderPln.querySaleOrder" desc="查询">
		<![CDATA[
			SELECT E1.* FROM (SELECT M.DESGIN_KEY,
                    (SELECT COUNT(*)
                       FROM CRAFT_ORD_DESIGN_MSC_PL T
                      WHERE T.DESGIN_KEY = M.DESGIN_KEY
                        AND T.VALIDFLAG = '1') WHOLE_BACKLOG_COUNT,
                    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,
                    (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,
                    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,
                    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.PAYDOWN_NUM,
                    T.HEIGHT_ORD_MIN,
                    T.HEIGHT_ORD_MAX,
                    (SELECT A.BASENAME
                       FROM COM_BASE_INFO A
                      WHERE A.BASECODE = E.PRIORITY) PRIORITY,
                    E.PRIORITY_MEMO,
                    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',
                           '缴库完成') 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,
                    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,
                    E.LEN_ROLL_MAX,
                    E.LEN_ROLL_MIN,
                    Z1.Z_ORDERWEIGHT,
                    Z1.Z_ORDERNUM,
                    ((SELECT TO_CHAR(WM_CONCAT(ORDER_NO || '/' || ORDER_SEQ || '/' ||
                                               DELIVERY_NO))
                        FROM PLN_ORDER_JG
                       WHERE PRO_PLAN_ID IN
                             (SELECT PRO_PLAN_ID
                                FROM PLN_JG_AND_BL
                               WHERE REQ_BL_ID = E.ORD_LN_DLY_PK)) ||
                    (SELECT (ORDER_NO || '/' || ORDER_SEQ || '/' ||
                             DELIVERY_NO)
                        FROM PLN_PORDER_BL_REQ
                       WHERE REQ_BL_ID = E.ORD_LN_DLY_PK
                         AND BLTYPE = '短节备料')) MEMO,
                    E.AIM_OUTDIAMETER,
                    E.FEED_RATE,
                    E.COEFFICIENT,
                    E.COEFFICIENT_MIN,
                    E.PLAN_P_MAIN_MIN,
                    E.AIM_WT_END,
                    E.WEIGHT_KZ_M,
                    NVL((SELECT T1.CHECK_J_VAL
                          FROM COM_MSC_JG T1
                         WHERE T1.CODE_JG = T.CODE_JG
                           AND T1.VALIDFLAG = '1'),
                        0) / 1000 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) / 1000 WEIGHT_JG,
                    E.PROC_DESC_C_RCL RCL_INFO,
                    DECODE(BL.CODE_DJ_BL, '', BL.CODE_JG_BL, BL.CODE_DJ_BL) CODE_BL,
                    DECODE((SELECT GET_PROCESS_STATUS(E.ORD_LN_DLY_PK,

                                                     E.PROCESS_SEQ)
                             FROM DUAL),
                           '0',
                           '计划',
                           '1',
                           '生产中',
                           '2',
                           '生产完成',
                           '3',
                           '关闭A') EXT_STATUS,
                    (SELECT LISTAGG(S1.PRO_PLAN_ID, ',') WITHIN GROUP(ORDER BY S1.PRO_PLAN_ID)
                       FROM (SELECT S.PRO_PLAN_ID,
                                    S.ORD_LN_DLY_PK,
                                    S.PLN_DIVIDE_ID
                               FROM PLN_GX_JG_PROP_S S) S1
                      WHERE S1.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK
                        AND S1.PLN_DIVIDE_ID = E.PLN_DIVIDE_ID
                      GROUP BY S1.ORD_LN_DLY_PK, S1.PLN_DIVIDE_ID) If_Pro_Jg_No
               FROM PLN_SALEORD_PROC E
               LEFT JOIN (SELECT Z.ORD_LN_DLY_PK,
                                Z.PLN_DIVIDE_ID,
                                SUM(Z.ORDERWEIGHT) Z_ORDERWEIGHT,
                                SUM(Z.ORDERNUM) Z_ORDERNUM
                           FROM PLN_ORDER_ZG Z
                          GROUP BY Z.ORD_LN_DLY_PK, Z.PLN_DIVIDE_ID) Z1
                 ON Z1.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK
                AND Z1.PLN_DIVIDE_ID = E.PLN_DIVIDE_ID
               LEFT JOIN PLN_SALEORD T
                 ON T.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK
               LEFT JOIN CRAFT_ORD_DESIGN M
                 ON M.ORD_LN_PK = T.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
               LEFT JOIN PLN_PORDER_BL_REQ BL
                 ON E.ORD_LN_DLY_PK = BL.REQ_BL_ID
              WHERE T.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK
                AND E.ORDER_SOURCE = '备料需求'
                AND E.PLANSTATUS <> '1'
		]]>
	</query>


</queryMap>