<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="合同审批功能表查询">

	<query id="CoreOrderApproval.GetOrderPriceList" desc="查询价格明细表">
		<![CDATA[ 
			SELECT A.ORD_PK,
			       A.ORDER_NO,
			       B.ORD_LN_PK,
			       B.ORDER_SEQ,
			       C.PRICE_NO,
			       C.OUT_PRICE,
			       C.BLA_PRICE,
			       C.TRS_PRICE,
			       C.PAK_PRICE,
			       c.TON_PRICE,
			       DECODE(c.KEEP_TYPE,'0','保单价','1','保总价') KEEP_TYPE,
			       C.PRICE_1,
			       C.PRICE_2,
			       C.PRICE_3,
			       C.PRICE_4,
			       C.PRICE_5,
			       C.PRICE_6,
			       C.CREATE_NAME,
			       C.CREATE_TIME
			  FROM SLM_ORDER_HEAD A, SLM_ORDER_LINE B, SLM_ORDER_PRICE_LIST C
			 WHERE A.ORD_PK = B.ORD_PK
			   AND B.ORD_LN_PK = C.ORD_LN_PK
			   AND A.PRICE_NO = C.PRICE_NO
			   AND A.PRICE_NO = ?
			   AND A.ORD_PK = ?
			 ORDER BY A.ORDER_NO, B.ORDER_SEQ
		]]>
	</query>
	
	<query id="CoreOrderApproval.GetQuery" desc="查询合同头">
		<![CDATA[ 
			SELECT MANAG_NO,
			'FALSE' CHK,
       ORDER_NO,
       CUSTM_ORDER_NO,
       ORDER_TYP,
       ORDER_TYP_DESC,
       PROTCL_NO,
       CUSTOMER_NO,
       CUSTOMER_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = SUPPLY_UNIT) SUPPLY_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = PRICE_FL) PRICE_FL_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CURRENCY) CURRENCY_NM,
       STLMT_UNIT_NO,
       STLMT_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = FST_DRAWEE_UNIT) FST_DRAWEE_UNIT_NM,
       LEGAL_PSN,
       AGENT,
       ADDRESS,
       ZIP_CODE,
       BANK,
       ACCOUNT,
       TAX_ID,
       PHONE,
       FAX,
       ORDER_WGT,
       ORDER_MNY_TAX,
       ORDER_MNY_NTAX,
       MNY_ASK_DESC,
       SIGN_PERSON,
       TO_CHAR(SIGN_DATE, 'YYYY-MM-DD') SIGN_DATE,
       ORDER_BDATE,
       ORDER_EDATE,
       ORDER_SCAN_NO,
       DECODE(CUSTOMER_MODEL_FL, '1', 'true', 'false') CUSTOMER_MODEL_FL,
       ORDER_MODEL_NO,
       SALE_ORG,
       SALE_ORG_DESC,
       SALE_AREA_NO,
       SALE_AREA_DESC,
       MEMO,
       ORDER_STS,
		--CASE
		--WHEN SUPPLY_UNIT = '120504' and ORDER_STS >= 12020210 and ORDER_STS <= 12020212 THEN
		--	(SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = ORDER_STS AND VALIDFLAG = '1' ) || DECODE(TH_EXAMINE_STATUS,'1','(计划审批通过)','2','(部门领导审批通过)','(分管领导审批通过)')
		--ELSE
		--	(SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = ORDER_STS AND VALIDFLAG = '1' )
		--END ORDER_STS_DESC,
		(SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = ORDER_STS AND VALIDFLAG = '1' ) ORDER_STS_DESC,
       APPROVAL_MAN,
       APPROVAL_TIME,
       VALIDFLAG,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME, 'YYYY-MM-DD') CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       ORDER_YEAR,
       EFFECT_TIME,
       EFFECT_MAN,
       CLOSE_TIME,
       CLOSE_MAN,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = MNY_ASK_TYP) MNY_ASK_TYP_NM,
       SIGN_ADDRESS,
       SUPPLY_UNIT,
       PRICE_FL,
       CURRENCY,
       FST_DRAWEE_UNIT,
       MNY_ASK_TYP,
       NVL(ORDER_MODEL_DESC, ' ') ORDER_MODEL_DESC,
       ORD_PK,
       CREATE_DEPT,
       MARKET_SYS,
       MARKET_SYS_DESC,
       ABRVITION,
       PRICE_NO,
       (SELECT PRICE_STATUS  FROM SLM_ORDER_PRICE C WHERE A.PRICE_NO = C.PRICE_NO) PRICE_STATUS_CODE,
       (SELECT DECODE(PRICE_STATUS,'L','封锁','W','待审','S','通过','F','不通过','D','无效')
         FROM SLM_ORDER_PRICE C WHERE A.PRICE_NO = C.PRICE_NO) PRICE_STATUS
  FROM SLM_ORDER_HEAD A
 WHERE ORDER_STS IN (?, ?, ?, ?, ?, ?, ?)
   AND LOWER(ORDER_NO) LIKE '%' || LOWER(?) || '%'
   AND SALE_ORG = ?
   AND CREATE_TIME BETWEEN TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') AND
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
   AND VALIDFLAG = '1'
 
		]]>
	</query>
	
	<query id="CoreOrderApproval.GetQueryAll" desc="查询合同头">
		<![CDATA[ 
			SELECT MANAG_NO,
			'FALSE' CHK,
       ORDER_NO,
       CUSTM_ORDER_NO,
       ORDER_TYP,
       ORDER_TYP_DESC,
       PROTCL_NO,
       CUSTOMER_NO,
       CUSTOMER_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = SUPPLY_UNIT) SUPPLY_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = PRICE_FL) PRICE_FL_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CURRENCY) CURRENCY_NM,
       STLMT_UNIT_NO,
       STLMT_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = FST_DRAWEE_UNIT) FST_DRAWEE_UNIT_NM,
       LEGAL_PSN,
       AGENT,
       ADDRESS,
       ZIP_CODE,
       BANK,
       ACCOUNT,
       TAX_ID,
       PHONE,
       FAX,
       ORDER_WGT,
       ORDER_MNY_TAX,
       ORDER_MNY_NTAX,
       MNY_ASK_DESC,
       SIGN_PERSON,
       TO_CHAR(SIGN_DATE, 'YYYY-MM-DD') SIGN_DATE,
       ORDER_BDATE,
       ORDER_EDATE,
       ORDER_SCAN_NO,
       DECODE(CUSTOMER_MODEL_FL, '1', 'true', 'false') CUSTOMER_MODEL_FL,
       ORDER_MODEL_NO,
       SALE_ORG,
       SALE_ORG_DESC,
       SALE_AREA_NO,
       SALE_AREA_DESC,
       MEMO,
       ORDER_STS,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = ORDER_STS AND VALIDFLAG = '1' ) ORDER_STS_DESC,
       APPROVAL_MAN,
       APPROVAL_TIME,
       VALIDFLAG,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME, 'YYYY-MM-DD') CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       ORDER_YEAR,
       EFFECT_TIME,
       EFFECT_MAN,
       CLOSE_TIME,
       CLOSE_MAN,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = MNY_ASK_TYP) MNY_ASK_TYP_NM,
       SIGN_ADDRESS,
       SUPPLY_UNIT,
       PRICE_FL,
       CURRENCY,
       FST_DRAWEE_UNIT,
       MNY_ASK_TYP,
       NVL(ORDER_MODEL_DESC, ' ') ORDER_MODEL_DESC,
       ORD_PK,
       CREATE_DEPT,
       MARKET_SYS,
       MARKET_SYS_DESC,
       ABRVITION,
       PRICE_NO,
        (SELECT DECODE(PRICE_STATUS,'L','封锁','W','待审','S','通过','F','不通过','D','无效')
         FROM SLM_ORDER_PRICE C WHERE B.PRICE_NO = C.PRICE_NO) PRICE_STATUS
  FROM SLM_ORDER_HEAD B
  WHERE ORDER_STS >= '12020212' AND  ORDER_STS < '12020301'
   AND LOWER(ORDER_NO) LIKE '%' || LOWER(?) || '%'
   AND SALE_ORG = ?
   AND CREATE_TIME BETWEEN TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') AND
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
   AND VALIDFLAG = '1'
 
		]]>
	</query>
	
	<query id="CoreOrderApproval.GetQueryPass" desc="查询合同头">
		<![CDATA[ 
			SELECT MANAG_NO,
			'FALSE' CHK,
       ORDER_NO,
       CUSTM_ORDER_NO,
       ORDER_TYP,
       ORDER_TYP_DESC,
       PROTCL_NO,
       CUSTOMER_NO,
       CUSTOMER_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = SUPPLY_UNIT) SUPPLY_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = PRICE_FL) PRICE_FL_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CURRENCY) CURRENCY_NM,
       STLMT_UNIT_NO,
       STLMT_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = FST_DRAWEE_UNIT) FST_DRAWEE_UNIT_NM,
       LEGAL_PSN,
       AGENT,
       ADDRESS,
       ZIP_CODE,
       BANK,
       ACCOUNT,
       TAX_ID,
       PHONE,
       FAX,
       ORDER_WGT,
       ORDER_MNY_TAX,
       ORDER_MNY_NTAX,
       MNY_ASK_DESC,
       SIGN_PERSON,
       TO_CHAR(SIGN_DATE, 'YYYY-MM-DD') SIGN_DATE,
       ORDER_BDATE,
       ORDER_EDATE,
       ORDER_SCAN_NO,
       DECODE(CUSTOMER_MODEL_FL, '1', 'true', 'false') CUSTOMER_MODEL_FL,
       ORDER_MODEL_NO,
       SALE_ORG,
       SALE_ORG_DESC,
       SALE_AREA_NO,
       SALE_AREA_DESC,
       MEMO,
       ORDER_STS,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = ORDER_STS AND VALIDFLAG = '1' ) ORDER_STS_DESC,
       APPROVAL_MAN,
       APPROVAL_TIME,
       VALIDFLAG,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME, 'YYYY-MM-DD') CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       ORDER_YEAR,
       EFFECT_TIME,
       EFFECT_MAN,
       CLOSE_TIME,
       CLOSE_MAN,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = MNY_ASK_TYP) MNY_ASK_TYP_NM,
       SIGN_ADDRESS,
       SUPPLY_UNIT,
       PRICE_FL,
       CURRENCY,
       FST_DRAWEE_UNIT,
       MNY_ASK_TYP,
       NVL(ORDER_MODEL_DESC, ' ') ORDER_MODEL_DESC,
       ORD_PK,
       CREATE_DEPT,
       MARKET_SYS,
       MARKET_SYS_DESC,
       ABRVITION,
       PRICE_NO,
       (SELECT PRICE_STATUS  FROM SLM_ORDER_PRICE C WHERE B.PRICE_NO = C.PRICE_NO) PRICE_STATUS_CODE,
       (SELECT DECODE(PRICE_STATUS,'L','封锁','W','待审','S','通过','F','不通过','D','无效')
         FROM SLM_ORDER_PRICE C WHERE B.PRICE_NO = C.PRICE_NO) PRICE_STATUS
  FROM SLM_ORDER_HEAD B
  WHERE ORDER_STS >= '12020232'  
   AND LOWER(ORDER_NO) LIKE '%' || LOWER(?) || '%'
   AND SALE_ORG = ?
   AND CREATE_TIME BETWEEN TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') AND
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
   AND VALIDFLAG = '1'
 
		]]>
	</query>
	
	<query id="CoreOrderApproval.GetLineOrder" desc="查询合同行">
		<![CDATA[ 
			SELECT ORD_PK,
			       ORD_LN_PK,
			       ORDER_SEQ,
			       CUST_ALPHA_NO,
			       PSC,
			       PSC_DESC,
			       PRD_CLS,
			       PRODUCCODE,
			       PRODUCNAME,
			       STD_CODE,
			       STD_NAME,
			       STEELCODE,
			       STEELNAME,
			       ORDER_SPEC_CODE,
			       ORDER_SPEC_DESC,
			       SPEC_CODE,
			       SPEC_NAME,
			       DIMATER,
			       HEIGHT,
			       MODEL_CODE,
			       MODEL_DESC,
			       LEN_NO,
			       LEN_DESC,
			       LEN_UNIT,
			       LEN_MIN,
			       LEN_MAX,
			       SHRT_LEN_RATO,
			       SHORTEST,
			       LONG_LEN_RATO,
			       LONGEST,
			       SHRT_STOVE,
			       AVG_LEN_MIN,
			       DIFRNC_LEN_MAX,
			       SIGL_LEN,
			       ORDER_UNIT,
			       ORDER_QTY,
			       ORD_ENSU_TOTL_LEN,
			       ROUND(PRDCT_WGT,3) PRDCT_WGT,
			       DELVRY_RANGE_TPE,
			       DELVRY_RANGE_MIN,
			       DELVRY_RANGE_MAX,
			       FINAL_USER,
			       FINAL_USER_DESC,
			       OUTS_BILLET_FL OUTS_BILLET_FL_ID,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = OUTS_BILLET_FL) OUTS_BILLET_FL,
			       OUTS_STL_PIPE_FL OUTS_STL_PIPE_FL_ID,
			       (SELECT BASENAME
			          FROM COM_BASE_INFO
			         WHERE BASECODE = LE.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
			       DECODE(ASSEL_FL,'1','TRUE','FALSE') ASSEL_FL,
			       TO_CHAR(DELVRY_BDATE, 'YYYY-MM-DD') DELVRY_BDATE,
			       TO_CHAR(DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       DELVRY_DESC,
			       TRANS_DESC,
			       ADD_ASK_NO,
			       ORDER_SPECIAL_DESC,
			       ORDER_ADD_DESC,
			       ORDER_PRICE,
			       TRANS_PRICE,
			       TEST_ID,
			       TEST_PRICE,
			       OUT_PRICE,
			       BALNCE_PRICE,
			       ORDER_LN_STATUS,
			       MEMO,
			       DECODE(VALIDFLAG,'1','TRUE','FALSE') VALIDFLAG,
			       CREATE_NAME,
			       CREATE_TIME,
			       UPDATE_NAME,
			       UPDATE_TIME,
			       DELETE_NAME,
			       DELETE_TIME,
			       MSC,
			       MSC_DESC,
			       DECODE(PRODUCER_FL,'1','TRUE','FALSE') PRODUCER_FL,
			       (SELECT ORDER_NO FROM SLM_ORDER_HEAD WHERE ORD_PK = LE.ORD_PK) ORDER_NO,
			       (SELECT BASENAME
			          FROM COM_BASE_INFO
			         WHERE BASECODE = LE.OUTS_BILLET_FL) OUTS_BILLET_DESC,
			       (SELECT BASENAME
			          FROM COM_BASE_INFO
			         WHERE BASECODE = LE.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_DESC,
			       '(-' || TO_CHAR(DELVRY_RANGE_MIN) ||
			       DECODE(DELVRY_RANGE_TPE, '%', '%', ORDER_UNIT) || ',' ||
			       TO_CHAR(DELVRY_RANGE_MAX) ||
			       DECODE(DELVRY_RANGE_TPE, '%', '%', ORDER_UNIT) || ')' MIN_MAX_TPE
			  FROM SLM_ORDER_LINE LE
			 WHERE ORD_PK = ?
			   AND VALIDFLAG = '1'
	      ]]>
	</query>
	<query id="CoreOrderApproval.GetModelItem" desc="查询合同行条目">
	<![CDATA[ 
		SELECT ORDER_MODEL_NO, MODEL_SEQ_NO, MODEL_SEQ, MODEL_INDEX, MODEL_CLS,
			       MODEL_ITM, MODEL_ITM_VAL, VALIDFLAG
			  FROM SLM_ORDER_MODEL_ITEM
			 WHERE ORDER_MODEL_NO = ?
			 ]]>
	</query>
	<query id="CoreOrderApproval.GetOrderPrice" desc="查询定价内容">
	<![CDATA[
			SELECT ORD_PK,PRICE_NO,PRICE_BASE,CREATE_NAME,CREATE_TIME FROM SLM_ORDER_PRICE WHERE ORD_PK = ?
	]]>
	</query>
	<query id="CoreOrderApproval.UpdateHeadOrder" desc="修改合同头状态">
	<![CDATA[
		UPDATE SLM_ORDER_HEAD SET ORDER_STS = ?,ORDER_STS_DESC = ?,APPROVAL_MAN = ?,APPROVAL_TIME = SYSDATE WHERE ORD_PK = ?
	]]>
	</query>
	<query id="CoreOrderApproval.UpdateHeadOrderMeMo" desc="修改合同头状态\备注">
	<![CDATA[
		UPDATE SLM_ORDER_HEAD SET ORDER_STS = ?,ORDER_STS_DESC = ?,APPROVAL_MAN = '',APPROVAL_TIME = '',MEMO = ? WHERE ORD_PK = ?
	]]>
	</query>
	
	
	
	<query id="CoreOrderApproval.doUpdateHeadSts" desc="修改合同头状态">
		<![CDATA[ 
			 UPDATE SLM_ORDER_HEAD SET ORDER_STS=?,ORDER_STS_DESC=?,APPROVAL_MAN=?,APPROVAL_TIME = SYSDATE WHERE ORD_PK=?
		]]>
	</query>
	
	<query id="CoreOrderApproval.doUpdateLnStatus" desc="修改合同行状态">
		<![CDATA[ 
			 UPDATE SLM_ORDER_LINE SET ORDER_LN_STATUS=? WHERE ORD_PK=?
		]]>
	</query>
	
	<query id="CoreOrderApproval.doUpdateDelStatus" desc="修改交货行状态">
		<![CDATA[ 
			 UPDATE SLM_ORDER_LINE_DELIVERY SET DELIVERY_STATUS=? WHERE ORD_PK=?
		]]>
	</query>
	
	<query id="CoreOrderApproval.getOrdPkStatus" desc="查询合同头状态">
		<![CDATA[ 
			SELECT T.ORDER_STS, T.PRICE_NO
              FROM SLM_ORDER_HEAD T
             WHERE T.ORD_PK = ?
               AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CoreOrderApproval.updateOrderHeadStatus" desc="修改合同头状态">
		<![CDATA[ 
			UPDATE SLM_ORDER_HEAD T
               SET T.ORDER_STS      = ?,
                   T.ORDER_STS_DESC = ?,
                   T.BE_ORDER_STS   = T.ORDER_STS
             WHERE T.ORD_PK = ?
		]]>
	</query>
	
	<query id="CoreOrderApproval.updateOrderLineStatus" desc="修改合同行状态">
		<![CDATA[ 
			UPDATE SLM_ORDER_LINE T
               SET T.BE_ORDER_LN_STATUS = T.ORDER_LN_STATUS,
                   T.ORDER_LN_STATUS    = ?
             WHERE T.ORD_PK = ?
               AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CoreOrderApproval.updateOrderDeliveryStatus" desc="修改交货行状态">
		<![CDATA[ 
			UPDATE SLM_ORDER_LINE_DELIVERY T
               SET T.BE_DELIVERY_STATUS = T.DELIVERY_STATUS,
                   T.DELIVERY_STATUS    = ?
             WHERE T.ORD_PK = ?
               AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CoreOrderApproval.updateOrderReviewItem" desc="修改评审项目表中价格评审状态">
		<![CDATA[ 
			UPDATE SLM_ORDER_REVIEW_ITEM T
               SET T.REVIEW_STATUS = 'W'
             WHERE T.REVIEW_NO = (SELECT B.REVIEW_NO
                                    FROM SLM_ORDER_REVIEW B
                                   WHERE B.ORD_PK = ?
                                     AND B.VALIDFLAG = '1')
               AND T.REVIEW_ITM = 'P'
               AND T.VALIDFLAG = '1'
		]]>
	</query>
	
		<query id="CoreOrderApproval.updateOrderReviewItemlist" desc="修改评审明细项目表中价格评审状态">
		<![CDATA[ 
			UPDATE SLM_ORDER_REVIEW_ITEM_LIST T
               SET T.REVIEW_STATUS = 'W',
                   REVIEW_F_RS   =   ?,
                   REVIEW_MAN    =  ?,
                   REVIEW_DEPT   = ?,
                   RT_REVIEW_ITM = ?,
                   REVIEW_EDATE  = SYSDATE 
             WHERE T.REVIEW_NO = (SELECT B.REVIEW_NO
                                    FROM SLM_ORDER_REVIEW B
                                   WHERE B.ORD_PK = ?
                                     AND B.VALIDFLAG = '1')
               AND T.REVIEW_ITM = 'P'
               AND T.IS_CURT_REVIEW = '1'
		]]>
	</query>
	
	<query id="CoreOrderApproval.getOrderPriceStatus" desc="修改交货行状态">
		<![CDATA[ 
			 SELECT PRICE_STATUS FROM SLM_ORDER_PRICE T
			 WHERE  T.PRICE_NO = ?
		]]>
	</query>


	<query id="CoreOrderApproval.getOrderHeadStatusByCustm" desc="查询合同头状态">
		<![CDATA[
                SELECT
                	t.ORDER_NO,t.ORD_PK,t.ORDER_STS,t.ORD_PK ORDER_PK,T.CUSTM_ORDER_NO
                FROM
                	SLM_ORDER_HEAD T
                WHERE
                	T.CUSTM_ORDER_NO = ( SELECT ORDER_NO FROM SLM_ORDER_HEAD WHERE ORD_PK = {0} and VALIDFLAG = '1' ) and t.VALIDFLAG = '1'
		]]>
	</query>
	
</queryMap>