<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="合同综合信息">
	<query id="CoreOrderColligateInfomation.getOrderHeadInfo" desc="查询合同头信息">
		<![CDATA[
		SELECT T.ORD_PK,
       T.MANAG_NO,
       T.ORDER_NO,
       T.CUSTM_ORDER_NO,
       T.REVW_RPT_NO,
       T.ORDER_TYP,
       T.ORDER_TYP_DESC,
       T.PROTCL_NO,
       T.CUSTOMER_NO,
       T.CUSTOMER_NM,
       T.MARKET_SYS,
       T.MARKET_SYS_DESC,
       T.ABRVITION,
       (SELECT A.BASENAME
          FROM COM_BASE_INFO A
         WHERE A.BASECODE = T.SUPPLY_UNIT) SUPPLY_UNIT,
       (SELECT A.BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = T.PRICE_FL) PRICE_FL,
       (SELECT A.BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = T.CURRENCY) CURRENCY,
       (SELECT A.BASENAME
          FROM COM_BASE_INFO A
         WHERE A.BASECODE = T.MNY_ASK_TYP) MNY_ASK_TYP,
       T.STLMT_UNIT_NO,
       T.STLMT_UNIT_NM,
       (SELECT A.BASENAME
          FROM COM_BASE_INFO A
         WHERE A.BASECODE = T.FST_DRAWEE_UNIT) FST_DRAWEE_UNIT,
       T.LEGAL_PSN,
       T.AGENT,
       T.ADDRESS,
       T.ZIP_CODE,
       T.BANK,
       T.ACCOUNT,
       T.TAX_ID,
       T.PHONE,
       T.FAX,
       T.ORDER_WGT,
       T.ORDER_MNY_TAX,
       T.ORDER_MNY_NTAX,
       T.MNY_ASK_DESC,
       T.SIGN_PERSON,
       TO_CHAR(T.SIGN_DATE, 'YYYY-MM-DD') SIGN_DATE,
       T.SIGN_ADDRESS,
       T.ORDER_YEAR,
       T.ORDER_BDATE,
       T.ORDER_EDATE,
       T.ORDER_SCAN_NO,
       DECODE(T.CUSTOMER_MODEL_FL,'1','True','False') CUSTOMER_MODEL_FL,
       T.ORDER_MODEL_NO,
       T.ORDER_MODEL_DESC,
       T.SALE_ORG,
       T.SALE_ORG_DESC,
       T.SALE_AREA_NO,
       T.SALE_AREA_DESC,
       T.MEMO,
       T.BE_ORDER_STS,
       T.ORDER_STS,
       T.ORDER_STS_DESC,
       T.OBJ_STS_OP,
       T.APPROVAL_MAN,
       TO_CHAR(T.APPROVAL_TIME, 'YYYY-MM-DD HH24:MI:SS') APPROVAL_TIME,
       T.EFFECT_MAN,
       TO_CHAR(T.EFFECT_TIME, 'YYYY-MM-DD HH24:MI:SS') EFFECT_TIME,
       T.CLOSE_MAN,
       TO_CHAR(T.CLOSE_TIME, 'YYYY-MM-DD HH24:MI:SS') CLOSE_TIME,
       T.VALIDFLAG,
       T.CREATE_NAME,
       T.CREATE_DEPT,
       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.DELETE_NAME,
       TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       T.ORD_PK_OLD,
       T.BE_ORDER_STS_DESC,
       T.PRICE_NO,
       T.PRINT_COUNT,
       TO_CHAR(T.PRINT_TIME,'YYYY-MM-DD HH24:MI:SS') PRINT_TIME,
       T.PRINT_PRICE,
       DECODE((SELECT TO_NUMBER(COUNT(1) -
                               NVL(SUM(TO_NUMBER(A.BALNCE_PRICE_STS)), '0'))
                FROM SLM_ORDER_LINE A
               WHERE T.ORD_PK = A.ORD_PK
                 AND T.VALIDFLAG = '1'
                 AND A.VALIDFLAG = '1'),
              '0',
              '确认',
              '未确认') BALNCE_PRICE_STS
  FROM SLM_ORDER_HEAD T
  WHERE UPPER(T.ORDER_NO) || '&' LIKE UPPER('%' || ? || '%')
   AND T.CREATE_TIME BETWEEN
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') AND
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
   AND T.VALIDFLAG = '1'
   AND T.ORDER_STS  >='12020232'
   AND (SELECT TO_NUMBER(COUNT(1) - NVL(SUM(TO_NUMBER(A.BALNCE_PRICE_STS)), '0')) FROM SLM_ORDER_LINE A
          WHERE T.ORD_PK = A.ORD_PK  AND T.VALIDFLAG = '1' AND A.VALIDFLAG = '1' ) ##NUM##
		]]>
	</query>

	<query id="CoreOrderColligateInfomation.getOrderLineInfo" desc="查询合同行信息">
		<![CDATA[
		SELECT T.ORD_PK,
       T.ORD_LN_PK,
       A.ORDER_NO||'/'||T.ORDER_SEQ ORDER_SEQ,
       T.CUST_ALPHA_NO,
       T.PSC,
       T.PSC_DESC,
       T.MSC,
       T.MSC_DESC,
       DECODE(T.MSC_STYLE,
              'A',
              '钢管(坯)',
              'B',
              '套管+接箍',
              'C',
              '附件短节',
              'D',
              '接箍',
              'E',
              '双公短节',
              '数据异常') MSC_STYLE,
       T.USE_CODE,
       T.USE_DESC,
       T.PRD_CLS,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.ORDER_SPEC_CODE,
       T.ORDER_SPEC_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.DIMATER,
       T.HEIGHT,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.LEN_NO,
       T.LEN_DESC,
       T.LEN_UNIT,
       T.LEN_MIN,
       T.LEN_MAX,
       T.SHRT_LEN_RATO,
       T.SHORTEST,
       T.LONG_LEN_RATO,
       T.LONGEST,
       T.SHRT_STOVE,
       T.AVG_LEN_MIN,
       T.DIFRNC_LEN_MAX,
       T.ENDLEN_SPECSTD,
       TO_CHAR(T.SIGL_LEN, '9990.990') SIGL_LEN,
       T.ORDER_UNIT,
       TO_CHAR(T.ORDER_QTY, '99999990.0') ORDER_QTY,
       TO_CHAR(T.ORD_ENSU_TOTL_LEN, '99999990.0') ORD_ENSU_TOTL_LEN,
       TO_CHAR(T.PRDCT_WGT, '99999990.990') PRDCT_WGT,
       DECODE(T.DELVRY_RANGE_TPE,
              '%',
              '-' || T.DELVRY_RANGE_MIN || '%' || ',' || T.DELVRY_RANGE_MAX || '%',
              '(' || T.DELVRY_RANGE_MIN || ',' || T.DELVRY_RANGE_MAX || ')') DELVRY_RANGE_TPE,
       T.DELVRY_RANGE_MIN,
       T.DELVRY_RANGE_MAX,
       T.FINAL_USER,
       T.FINAL_USER_DESC,
       (SELECT T1.BASENAME
          FROM COM_BASE_INFO T1
         WHERE T1.BASECODE = T.OUTS_BILLET_FL) OUTS_BILLET_FL,
       (SELECT T1.BASENAME
          FROM COM_BASE_INFO T1
         WHERE T1.BASECODE = T.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
       DECODE(T.ASSEL_FL, '1', 'True', 'False') ASSEL_FL,
       DECODE(T.PRODUCER_FL, '1', 'True', 'False') PRODUCER_FL,
       T.PRDCR_NO,
       (SELECT WM_CONCAT(C.BASENAME)
          FROM SLM_ORDER_LINE_PRDCR F, COM_BASE_INFO C
         WHERE C.BASECODE = F.PRDCR_DESC
           AND F.PRDCR_NO = T.PRDCR_NO) PRDCR_DESC,
       DECODE(T.MPS_FL, '1', 'True', 'False') MPS_FL,
       T.MPS_NO,
       T.MPS_DESC,
       T.DELVRY_BDATE,
       T.DELVRY_EDATE,
       T.DELVRY_DESC,
       T.TRANS_DESC,
       T.ADD_ASK_NO,
       T.ORDER_ADD_DESC,
       T.ORDER_SPECIAL_FL,
       T.ORDER_SPECIAL_HEAD,
       T.ORDER_SPECIAL_PATH,
       T.ORDER_SPECIAL_DESC,
       T.ZBS,
       T.ORDER_PRICE,
       T.TRANS_PRICE,
       T.TEST_ID,
       T.TEST_PRICE,
       T.OUT_PRICE,
       T.BALNCE_PRICE,
       (SELECT T1.BASENAME
          FROM COM_BASE_INFO T1
         WHERE T1.BASECODE = T.BE_ORDER_LN_STATUS) BE_ORDER_LN_STATUS,
       T.BE_OBJ_STS_OP,
       (SELECT T1.BASENAME
          FROM COM_BASE_INFO T1
         WHERE T1.BASECODE = T.ORDER_LN_STATUS) ORDER_LN_STATUS,
       T.OBJ_STS_OP,
       T.MEMO,
       T.VALIDFLAG,
       T.CREATE_NAME,
       DECODE(BALNCE_PRICE_STS,'1','确认','未确认') BALNCE_PRICE_STS,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH:MI:SS') UPDATE_TIME,
       T.DELETE_NAME,
       TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH:MI:SS') DELETE_TIME,
       T.ORD_LN_PK_OLD
  FROM SLM_ORDER_LINE T,SLM_ORDER_HEAD A
 WHERE T.ORD_PK = ?
   AND T.VALIDFLAG = '1'
   AND T.ORD_PK = A.ORD_PK
   AND A.VALIDFLAG = '1'
 ORDER BY ORDER_SEQ
		]]>
	</query>

	<query id="CoreOrderColligateInfomation.getOrderPriceInfo" desc="查询定价内容">
		<![CDATA[
		SELECT PRICE_BASE FROM SLM_ORDER_PRICE T WHERE T.PRICE_NO = ?			
		]]>
	</query>

	<query id="CoreOrderColligateInfomation.getOrderPriceDetail"
		desc="查询定价明细">
		<![CDATA[	
		SELECT PRICE_NO,
       ORD_LN_PK,
       OUT_PRICE,
       BLA_PRICE,
       TRS_PRICE,
       PAK_PRICE,
       PRICE_1,
       PRICE_2,
       PRICE_3,
       PRICE_4,
       PRICE_5,
       PRICE_6,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME
  FROM SLM_ORDER_PRICE_LIST T
 WHERE T.ORD_LN_PK = ?		
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.getBaseInfo2002"
		desc="查询工艺文件类型">
		<![CDATA[	
		SELECT T.BASECODE, T.BASENAME
  FROM COM_BASE_INFO T
 WHERE T.SORTCODE = '2002'
   AND T.VALIDFLAG = '1'
		
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.getBaseInfo2003"
		desc="查询工艺文件状态">
		<![CDATA[	
		SELECT T.BASECODE, T.BASENAME
  FROM COM_BASE_INFO T
 WHERE T.SORTCODE = '2003'
   AND T.VALIDFLAG = '1'
		
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.getCraftFileByOrdLnPk"
		desc="查询工艺文件">
		<![CDATA[	
		SELECT T.ORD_LN_PK
  FROM PLN_ORD_CRAFT_FILE T
 WHERE T.ORD_LN_PK = ?		
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.addCraftFile"
		desc="新增工艺文件">
		<![CDATA[	
		INSERT INTO PLN_ORD_CRAFT_FILE
  (ORD_PK,
   ORD_LN_PK,
   ORDER_NO,
   ORDER_SEQ,
   CRAFT_FILE_NO,
   CRAFT_FILE_MAN,
   CRAFT_FILE_TYPE_CODE,
   CRAFT_FILE_TYPE_NM,
   CRAFT_FILE_PATH,
   CRAFT_FILE_FLAG_CODE,
   CRAFT_FILE_FLAG_NM,
   CRAFT_FILE_UPTIME,
   CREATE_NAME,
   CREATE_TIME,
   UPDATE_NAME,
   UPDATE_TIME)
VALUES
  ('#ORD_PK#',
   '#ORD_LN_PK#',
   '#ORDER_NO#',
   '#ORDER_SEQ#',
   '#CRAFT_FILE_NO#',
   '#CRAFT_FILE_MAN#',
   '#CRAFT_FILE_TYPE_CODE#',
   '#CRAFT_FILE_TYPE_NM#',
   '#CRAFT_FILE_PATH#',
   '#CRAFT_FILE_FLAG_CODE#',
   '#CRAFT_FILE_FLAG_NM#',
   SYSDATE,
   '#CREATE_NAME#',
   SYSDATE,
   '#UPDATE_NAME#',
   NULL)
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.updateCraftFile"
		desc="修改工艺文件">
		<![CDATA[	
		UPDATE PLN_ORD_CRAFT_FILE T
   SET T.CRAFT_FILE_NO = '#CRAFT_FILE_NO#',
       T.CRAFT_FILE_MAN       = '#CRAFT_FILE_MAN#',
       T.CRAFT_FILE_TYPE_CODE = '#CRAFT_FILE_TYPE_CODE#',
       T.CRAFT_FILE_TYPE_NM   = '#CRAFT_FILE_TYPE_NM#',
       T.CRAFT_FILE_PATH      = '#CRAFT_FILE_PATH#',
       T.CRAFT_FILE_FLAG_CODE = '#CRAFT_FILE_FLAG_CODE#',
       T.CRAFT_FILE_FLAG_NM   = '#CRAFT_FILE_FLAG_NM#',
       T.CRAFT_FILE_UPTIME    = SYSDATE,
       T.UPDATE_NAME          = '#UPDATE_NAME#',
       T.UPDATE_TIME          = SYSDATE
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'	
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.getOrderLineStatus"
		desc="查询合同行状态">
		<![CDATA[	
		SELECT T.ORDER_LN_STATUS
    FROM SLM_ORDER_LINE T
    WHERE T.ORD_LN_PK = ?
    AND T.VALIDFLAG = '1'
		
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.queryBlaPriceStatus" desc="修改合同头状态">
	<![CDATA[
			
    SELECT COUNT(1) - NVL(SUM(TO_NUMBER(T.BALNCE_PRICE_STS)), '0')
    FROM SLM_ORDER_LINE T
    WHERE T.ORD_PK = ?
    AND T.VALIDFLAG = '1'
			
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.queryOrderHeadStatus" desc="修改合同头状态">
		<![CDATA[
		SELECT 1 FROM SLM_ORDER_HEAD T 
		WHERE T.ORD_PK = ?
		AND T.ORDER_STS >= '12020232'	
 	    AND T.VALIDFLAG = '1'
			
		]]>
	</query>
	
	<query id="CoreOrderColligateInfomation.setPrintTimeAndCount" desc="修改合同头状态">
		<![CDATA[
	 	UPDATE  SLM_ORDER_HEAD T
	 	SET T.PRINT_TIME  = SYSDATE,
	 	    T.PRINT_COUNT = TO_NUMBER(NVL(T.PRINT_COUNT,0))+1
	 	WHERE T.ORD_PK = ?
			
		]]>
	</query>
	

</queryMap>