<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="BOM界面">

	<query id="FrmMaterialBom.queryOrderInfo" desc="查询合同信息">
             <![CDATA[ 
               SELECT A.ORD_PK,
       A.MANAG_NO,
       A.ORDER_NO,
       A.ORDER_NO || '/' || B.ORDER_SEQ ORDER_SEQ_NO,
       A.CUSTM_ORDER_NO,
       A.REVW_RPT_NO,
       A.ORDER_TYP,
       A.ORDER_TYP_DESC,
       A.PROTCL_NO,
       A.CUSTOMER_NO,
       A.CUSTOMER_NM,
       A.MARKET_SYS,
       A.MARKET_SYS_DESC,
       A.ABRVITION,
       (SELECT C.BASENAME
          FROM COM_BASE_INFO C
         WHERE C.BASECODE = A.SUPPLY_UNIT) SUPPLY_UNIT,
       (SELECT C.BASENAME FROM COM_BASE_INFO C WHERE C.BASECODE = A.PRICE_FL) PRICE_FL,
       (SELECT C.BASENAME FROM COM_BASE_INFO C WHERE C.BASECODE = A.CURRENCY) CURRENCY,
       (SELECT C.BASENAME
          FROM COM_BASE_INFO C
         WHERE C.BASECODE = A.MNY_ASK_TYP) MNY_ASK_TYP,
       A.STLMT_UNIT_NO,
       A.STLMT_UNIT_NM,
       (SELECT C.BASENAME
          FROM COM_BASE_INFO C
         WHERE C.BASECODE = A.FST_DRAWEE_UNIT) FST_DRAWEE_UNIT,
       A.ORDER_WGT,
       A.ORDER_MNY_TAX,
       A.ORDER_MNY_NTAX,
       A.MNY_ASK_DESC,
       A.SIGN_PERSON,
       TO_CHAR(A.SIGN_DATE, 'YYYY-MM-DD ') SIGN_DATE,
       A.SIGN_ADDRESS,
       A.ORDER_YEAR,
       A.ORDER_BDATE,
       A.ORDER_EDATE,
       A.ORDER_SCAN_NO,
       DECODE(A.CUSTOMER_MODEL_FL, '1', '是', '否') CUSTOMER_MODEL_FL,
       A.ORDER_MODEL_NO,
       A.ORDER_MODEL_DESC,
       A.SALE_ORG,
       A.SALE_ORG_DESC,
       A.SALE_AREA_NO,
       A.SALE_AREA_DESC,
       A.MEMO,
       A.ORDER_STS,
       (SELECT C.BASENAME
          FROM COM_BASE_INFO C
         WHERE C.BASECODE = A.ORDER_STS) ORDER_STS_DESC,
       A.APPROVAL_MAN,
       TO_CHAR(A.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
       A.EFFECT_MAN,
       TO_CHAR(A.EFFECT_TIME, 'YYYY-MM-DD HH24:MI:SS') EFFECT_TIME,
       A.CLOSE_MAN,
       A.CLOSE_TIME,
       (SELECT E.DEPARTNAME
          FROM CORE.CORE_APP_DEPARTMENT E
         WHERE E.DEPARTID = A.CREATE_DEPT) CREATE_DEPT,
       A.ORD_PK_OLD,
       A.BE_ORDER_STS_DESC,
       A.PRICE_NO,
       B.ORD_LN_PK,
       B.ORDER_SEQ,
       B.PSC,
       B.PSC_DESC,
       B.PRODUCNAME ||
       DECODE(B.STD_STYLE_DESC, NULL, '', ',' || B.STD_STYLE_DESC) || ',' ||
       B.STEELNAME || ',' || B.SPEC_NAME ||
       DECODE(B.MODEL_DESC, '/', '', ',' || B.MODEL_DESC) PSC_NAME_DESC,
       B.MSC,
       DECODE(B.MSC_STYLE,
              'A',
              '钢管(坯)',
              'B',
              '套管+接箍',
              'C',
              '附件短节',
              'D',
              '接箍',
              'E',
              '双公短节',
              '数据异常') MSC_STYLE,
       B.USE_CODE,
       B.USE_DESC,
       (SELECT C.BASENAME FROM COM_BASE_INFO C WHERE C.BASECODE = B.PRD_CLS) PRD_CLS,
       B.PRODUCCODE,
       B.PRODUCNAME,
       B.STD_CODE,
       B.STD_NAME,
       B.STEELCODE,
       B.STEELNAME,
       B.STD_STYLE,
       B.STD_STYLE_DESC,
       B.ORDER_SPEC_CODE,
       B.ORDER_SPEC_DESC,
       B.SPEC_CODE,
       B.SPEC_NAME,
       B.DIMATER,
       B.HEIGHT,
       B.MODEL_CODE,
       B.MODEL_DESC,
       B.LEN_NO,
       B.LEN_DESC,
       B.LEN_UNIT,
       B.LEN_MIN,
       B.LEN_MAX,
       B.SHRT_LEN_RATO,
       B.SHORTEST,
       B.LONG_LEN_RATO,
       B.LONGEST,
       B.SHRT_STOVE,
       B.AVG_LEN_MIN,
       B.DIFRNC_LEN_MAX,
       B.ENDLEN_SPECSTD,
       TO_CHAR(B.SIGL_LEN, 'FM9990.000') SIGL_LEN,
       B.ORDER_UNIT,
       TO_CHAR(B.ORDER_QTY, 'FM9999990.000') ORDER_QTY,
       DECODE(ORD_ENSU_TOTL_LEN,'0','/',TO_CHAR(B.ORD_ENSU_TOTL_LEN, 'FM99999990.0')) ORD_ENSU_TOTL_LEN,
       TO_CHAR(B.PRDCT_WGT, 'FM9999990.000') PRDCT_WGT,
       DECODE(B.DELVRY_RANGE_TPE,
              '%',
              '-' || B.DELVRY_RANGE_MIN || '%' || ',+' || B.DELVRY_RANGE_MAX || '%',
              '(' || B.DELVRY_RANGE_MIN || ',' || B.DELVRY_RANGE_MAX || ')') DELVRY_RANGE_TPE,
       B.DELVRY_RANGE_MIN,
       B.DELVRY_RANGE_MIN,
       B.DELVRY_RANGE_MAX,
       B.FINAL_USER,
       B.FINAL_USER_DESC,
       Q4.ABRVITION FINAL_ABR,
       (SELECT C.BASENAME
          FROM COM_BASE_INFO C
         WHERE C.BASECODE = B.OUTS_BILLET_FL) OUTS_BILLET_FL,
       (SELECT C.BASENAME
          FROM COM_BASE_INFO C
         WHERE C.BASECODE = B.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
       DECODE(B.ASSEL_FL, '1', 'True', 'False') ASSEL_FL,
       DECODE(B.PRODUCER_FL, '1', 'True', 'False') PRODUCER_FL,
       B.PRDCR_NO,
       Q2.PRDCR_DESC,
       DECODE(B.MPS_FL, '1', 'True', 'False') MPS_FL,
       B.MPS_NO,
       B.MPS_DESC,
       B.DELVRY_BDATE,
       B.DELVRY_EDATE,
       B.DELVRY_DESC,
       B.TRANS_DESC,
       B.ADD_ASK_NO,
       B.ORDER_ADD_DESC,
       B.ORDER_SPECIAL_FL,
       B.ORDER_SPECIAL_HEAD,
       B.ORDER_SPECIAL_PATH,
       B.ORDER_SPECIAL_DESC,
       DECODE(TRIM(B.ORDER_SPECIAL_DESC), NULL, '普通', '特殊') SPECIALTYPE,
       B.ZBS,
       B.ORDER_PRICE,
       B.TRANS_PRICE,
       B.TEST_ID,
       B.TEST_PRICE,
       B.OUT_PRICE,
       B.BALNCE_PRICE,
       (SELECT C.BASENAME
          FROM COM_BASE_INFO C
         WHERE C.BASECODE = B.BE_ORDER_LN_STATUS) BE_ORDER_LN_STATUS,
       B.BE_OBJ_STS_OP,
       (SELECT C.BASENAME
          FROM COM_BASE_INFO C
         WHERE C.BASECODE = B.ORDER_LN_STATUS) ORDER_LN_STATUS,
       B.OBJ_STS_OP,
       B.MEMO,
       B.CREATE_NAME,
       TO_CHAR(B.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       B.UPDATE_NAME,
       TO_CHAR(B.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       B.DELETE_NAME,
       TO_CHAR(B.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       B.ORD_LN_PK_OLD,
       DECODE(A.CONTAIN_TAX, '1', '含税', '不含税') CONTAIN_TAX,
       B.AW,
       DECODE(B.BALNCE_PRICE_STS, '1', '确认', '未确认') BALNCE_PRICE_STS,
       B.PROJECT_NO,
       Q1.REGION_NO

  FROM SLM_ORDER_HEAD A
  LEFT JOIN (SELECT RE.REGION_NM REGION_NO,
                    Q.CUSTOMER_NO
               FROM SLM_BASE_CUSTOMER Q
               LEFT JOIN SEL_ADMIN_REGION RE
                 ON RE.REGION_NO = Q.REGION_NO
              WHERE Q.VALIDFLAG = '1'
                AND RE.VALIDFLAG = '1'
              GROUP BY Q.CUSTOMER_NO, RE.REGION_NM) Q1
    ON Q1.CUSTOMER_NO = A.CUSTOMER_NO, SLM_ORDER_LINE B
  LEFT JOIN (SELECT Q3.ABRVITION,
                    Q3.CUSTOMER_NO
               FROM SLM_BASE_CUSTOMER Q3
               WHERE Q3.VALIDFLAG = '1'
               GROUP BY Q3.CUSTOMER_NO, Q3.ABRVITION) Q4
    ON B.FINAL_USER = Q4.CUSTOMER_NO
  LEFT JOIN (SELECT LISTAGG(C.BASENAME, ',') WITHIN GROUP(ORDER BY PRDCR_NO) PRDCR_DESC,
                    PRDCR_NO
               FROM SLM_ORDER_LINE_PRDCR F, COM_BASE_INFO C
              WHERE C.BASECODE = F.PRDCR_DESC
              GROUP BY F.PRDCR_NO) Q2
    ON Q2.PRDCR_NO = B.PRDCR_NO
 WHERE A.ORD_PK = B.ORD_PK
   AND A.VALIDFLAG = '1'
   AND B.VALIDFLAG = '1'            
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBom" desc="查询主BOM">
             <![CDATA[  
                     SELECT T.MATERIAL_NO,
       T.MATERIAL_DESC,
       T.BOM,
       T.BOM_TYP,
       T.MSC_PLINE,
       T.WHOLE_BACKLOG,
       T.WHOLE_BACKLOG_DESC,
       T.MSC,
       T.MSC_DESC,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE_C,
       T.SPEC_NAME_C,
       T.SPEC_CODE_R,
       T.SPEC_NAME_R,
       T.SPEC_CODE_D,
       T.SPEC_NAME_D,
       T.SPEC_CODE_Z,
       T.SPEC_NAME_Z,
       T.A_IN_MATERIAL_NO,
       T.A_IN_MATERIAL_DESC,
       T.A_OUT_MATERIAL_NO,
       T.A_OUT_MATERIAL_DESC,
       T.B_IN_MATERIAL_NO,
       T.B_IN_MATERIAL_DESC,
       T.B_OUT_MATERIAL_NO,
       T.B_OUT_MATERIAL_DESC,
       T.C_IN_MATERIAL_NO,
       T.C_IN_MATERIAL_DESC,
       T.C_OUT_MATERIAL_NO,
       T.C_OUT_MATERIAL_DESC,
       T.D_IN_MATERIAL_NO,
       T.D_IN_MATERIAL_DESC,
       T.D_OUT_MATERIAL_NO,
       T.D_OUT_MATERIAL_DESC,
       T.E_IN_MATERIAL_NO,
       T.E_IN_MATERIAL_DESC,
       T.E_OUT_MATERIAL_NO,
       T.E_OUT_MATERIAL_DESC,
       T.F_IN_MATERIAL_NO,
       T.F_IN_MATERIAL_DESC,
       T.F_OUT_MATERIAL_NO,
       T.F_OUT_MATERIAL_DESC,
       T.J_IN_MATERIAL_NO,
       T.J_IN_MATERIAL_DESC,
       T.J_OUT_MATERIAL_NO,
       T.J_OUT_MATERIAL_DESC,
       T.I_IN_MATERIAL_NO,
       T.I_IN_MATERIAL_DESC,
       T.I_OUT_MATERIAL_NO,
       T.I_OUT_MATERIAL_DESC,
       T.PROCESS_CODE_CS,
       to_char(T.CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,
       (CASE T2.planstatus
         WHEN '2' THEN
          'true'
         WHEN '3' THEN
          'true'
         ELSE
          'false'
       end) FLAG
  FROM SLM_ORD_DESIGN_BOM T,
       (select t1.bom, max(t1.planstatus) planstatus
          from PLN_SALEORD_PROC t1
         where t1.planstatus in ('2', '3')
         group by t1.bom) t2
 WHERE t.bom = t2.bom(+)
   and 1 = 1 and T.BOM in
       (select t3.bom
          from slm_order_line t1, slm_ord_design_msc t2, slm_ord_line_bom t3
         where t1.ord_ln_pk = t2.ord_ln_pk
           and t2.desgin_key = t3.desgin_key
           and t1.ord_ln_pk = ?
        union
        select t5.bom
          from slm_order_line       t1,
               craft_ord_design_msc t4,
               craft_ord_line_bom   t5
         where t1.ord_ln_pk = t4.ord_ln_pk
           and t4.desgin_key = t5.desgin_key
           and t1.ord_ln_pk = ?) 
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomA" desc="查询炼钢BOM">
             <![CDATA[  
              SELECT 
       T.BOM,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC
 FROM SLM_ORD_DESIGN_BOM_A T
 WHERE
T.BOM =?         
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomB" desc="查询铸造BOM">
             <![CDATA[  
                  SELECT 
       T.BOM,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC
 FROM SLM_ORD_DESIGN_BOM_B T
 WHERE
T.BOM =?                    
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomC" desc="查询锻造BOM">
             <![CDATA[
                  SELECT 
       T.BOM,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC
 FROM SLM_ORD_DESIGN_BOM_C T
 WHERE
T.BOM =?                      
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomD" desc="查询轧管BOM">
             <![CDATA[    
                  SELECT 
       T.BOM,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC
 FROM SLM_ORD_DESIGN_BOM_D T
 WHERE
T.BOM =?                  
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomE" desc="查询镦拔扩BOM">
             <![CDATA[   
                  SELECT 
       T.BOM,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC
 FROM SLM_ORD_DESIGN_BOM_E T
 WHERE
T.BOM =?                   
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomF" desc="查询热处理BOM">
             <![CDATA[  
                  SELECT 
       T.BOM,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC
 FROM SLM_ORD_DESIGN_BOM_F T
 WHERE
T.BOM =?                    
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomK" desc="查询加工BOM">
             <![CDATA[ 
              SELECT 
       T.BOM,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC,
       T.GROUP_NUM,
       DECODE(T.MARK,'1','管体','2','接箍码','3','备料码','')MARK
 FROM SLM_ORD_DESIGN_BOM_K T
 WHERE
T.BOM =?
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomJ" desc="查询接箍加工BOM">
             <![CDATA[    
    SELECT 
       T.BOM,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC
 FROM SLM_ORD_DESIGN_BOM_H T
 WHERE
T.BOM =?
              ]]>
	</query>

	<query id="FrmMaterialBom.queryBomByCondition" desc="查询主BOM">
             <![CDATA[  
SELECT T.MATERIAL_NO,
       T.MATERIAL_DESC,
       T.BOM,
       T.BOM_TYP,
       T.MSC_PLINE,
       T.WHOLE_BACKLOG,
       T.WHOLE_BACKLOG_DESC,
       T.MSC,
       T.MSC_DESC,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE_C,
       T.SPEC_NAME_C,
       T.SPEC_CODE_R,
       T.SPEC_NAME_R,
       T.SPEC_CODE_D,
       T.SPEC_NAME_D,
       T.SPEC_CODE_Z,
       T.SPEC_NAME_Z,
       T.A_IN_MATERIAL_NO,
       T.A_IN_MATERIAL_DESC,
       T.A_OUT_MATERIAL_NO,
       T.A_OUT_MATERIAL_DESC,
       T.B_IN_MATERIAL_NO,
       T.B_IN_MATERIAL_DESC,
       T.B_OUT_MATERIAL_NO,
       T.B_OUT_MATERIAL_DESC,
       T.C_IN_MATERIAL_NO,
       T.C_IN_MATERIAL_DESC,
       T.C_OUT_MATERIAL_NO,
       T.C_OUT_MATERIAL_DESC,
       T.D_IN_MATERIAL_NO,
       T.D_IN_MATERIAL_DESC,
       T.D_OUT_MATERIAL_NO,
       T.D_OUT_MATERIAL_DESC,
       T.E_IN_MATERIAL_NO,
       T.E_IN_MATERIAL_DESC,
       T.E_OUT_MATERIAL_NO,
       T.E_OUT_MATERIAL_DESC,
       T.F_IN_MATERIAL_NO,
       T.F_IN_MATERIAL_DESC,
       T.F_OUT_MATERIAL_NO,
       T.F_OUT_MATERIAL_DESC,
       T.J_IN_MATERIAL_NO,
       T.J_IN_MATERIAL_DESC,
       T.J_OUT_MATERIAL_NO,
       T.J_OUT_MATERIAL_DESC,
       T.I_IN_MATERIAL_NO,
       T.I_IN_MATERIAL_DESC,
       T.I_OUT_MATERIAL_NO,
       T.I_OUT_MATERIAL_DESC,
       T.PROCESS_CODE_CS,
       to_char(T.CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,
       (CASE T2.planstatus
         WHEN '2' THEN
          'true'
         WHEN '3' THEN
          'true'
         ELSE
          'false'
       end) FLAG
  FROM SLM_ORD_DESIGN_BOM T,
       (select t1.bom, max(t1.planstatus) planstatus
          from PLN_SALEORD_PROC t1
         where t1.planstatus in ('2', '3')
         group by t1.bom) t2
 WHERE t.bom = t2.bom(+)
   and 1 = 1
              ]]>
	</query>

</queryMap>