<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="定价维护查询">

	<query id="CoreOrderPriceDetails.getOrdLineByOrdPk" desc="查询合同行">
		<![CDATA[
	SELECT A.ORD_PK,
       A.ORD_LN_PK,
       B.MANAG_NO,
       B.ORDER_NO,
       B.CUSTM_ORDER_NO,
       B.REVW_RPT_NO,
       B.ORDER_TYP_DESC,
       B.SALE_ORG_DESC,
       B.SALE_AREA_DESC,
       A.ORDER_SEQ,
       C.OUT_PRICE,
       C.BLA_PRICE,
       C.TRS_PRICE,
       C.PAK_PRICE,
       A.ORDER_SPEC_DESC,
       A.SPEC_NAME,
       A.MODEL_DESC,
       A.LEN_DESC,
       A.ORDER_QTY,
       A.ORDER_UNIT,
       A.ORD_ENSU_TOTL_LEN,
       A.DELVRY_RANGE_MIN,
       A.DELVRY_RANGE_MAX,
       '(-'|| A.DELVRY_RANGE_MIN||DECODE(A.DELVRY_RANGE_TPE,'%','%','')||','||A.DELVRY_RANGE_MAX||DECODE(A.DELVRY_RANGE_TPE,'%','%','')||')'  DELVRY_RANGE_TPE,
       A.ORDER_ADD_DESC,
       A.ORDER_SPECIAL_DESC,
       (SELECT E.BASENAME
          FROM COM_BASE_INFO E
         WHERE E.BASECODE = A.OUTS_BILLET_FL) OUTS_BILLET_FL,
       (SELECT E.BASENAME
          FROM COM_BASE_INFO E
         WHERE E.BASECODE = A.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
       DECODE(A.ASSEL_FL,'1','允许','不允许') ASSEL_FL,
       DECODE(A.PRODUCER_FL,'1','有','无') PRODUCER_FL,
       A.FINAL_USER_DESC,
       B.CUSTOMER_NM,
       B.STLMT_UNIT_NM,
       B.PROTCL_NO,
       (SELECT E.BASENAME FROM COM_BASE_INFO E WHERE E.BASECODE = B.PRICE_FL) PRICE_FL,
       (SELECT E.BASENAME FROM COM_BASE_INFO E WHERE E.BASECODE = B.CURRENCY) CURRENCY,
       (SELECT E.BASENAME
          FROM COM_BASE_INFO E
         WHERE E.BASECODE = B.MNY_ASK_TYP) MNY_ASK_TYP,
       B.MNY_ASK_DESC,
       decode(trim(B.PRICE_NO),null,'未维护','已维护')PRICE_NOH,
       decode(trim(C.PRICE_NO),null,'未维护','已维护')PRICE_NOL 
  FROM SLM_ORDER_LINE A, SLM_ORDER_HEAD B, SLM_ORDER_PRICE_LIST C
 WHERE A.ORD_PK = B.ORD_PK
   AND A.ORD_LN_PK = C.ORD_LN_PK(+)
   AND A.ORD_PK = ?
   AND A.VALIDFLAG = '1'
   AND B.VALIDFLAG = '1'
   ORDER BY A.ORDER_SEQ
		]]>
	</query>

	<query id="CoreOrderPriceDetails.getPriceBase" desc="查询定价内容">
		<![CDATA[
	         SELECT T.PRICE_BASE　FROM SLM_ORDER_PRICE T WHERE T.PRICE_NO IN (
                                                               
                                                               SELECT DISTINCT C.PRICE_NO
                                                                 FROM SLM_ORDER_HEAD       A,
                                                                       SLM_ORDER_LINE       B,
                                                                       SLM_ORDER_PRICE_LIST C
                                                                WHERE B.ORD_PK =
                                                                      A.ORD_PK
                                                                  AND B.ORD_LN_PK =
                                                                      C.ORD_LN_PK
                                                                  AND A.ORD_PK = ?
                                                                  AND A.VALIDFLAG = '1'
                                                                  AND B.VALIDFLAG = '1')	         
		]]>
	</query>

	<query id="CoreOrderPriceDetails.getOrdHeadPriceNo" desc="查询合同头定价编号">
		<![CDATA[
	        SELECT T.PRICE_NO FROM SLM_ORDER_HEAD T WHERE T.ORD_PK = ? AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CoreOrderPriceDetails.getPriceNoByOrdLnPk" desc="查询合同号所有合同行的定价明细编号">
		<![CDATA[
	       SELECT C.ORD_LN_PK, D.PRICE_NO
  FROM (SELECT B.ORD_LN_PK
          FROM SLM_ORDER_HEAD A, SLM_ORDER_LINE B
         WHERE B.ORD_PK = A.ORD_PK
           AND A.Ord_Pk = ?
           AND A.VALIDFLAG = '1'
           AND B.VALIDFLAG = '1') C
  LEFT JOIN SLM_ORDER_PRICE_LIST D
    ON C.ORD_LN_PK = D.ORD_LN_PK
		]]>
	</query>

	<query id="CoreOrderPriceDetails.addPriceA" desc="新增定价信息">
		<![CDATA[
	         INSERT INTO SLM_ORDER_PRICE_LIST
  (PRICE_NO,
   ORD_LN_PK,
   OUT_PRICE,
   BLA_PRICE,
   TRS_PRICE,
   PAK_PRICE,
   CREATE_NAME,
   CREATE_TIME)
VALUES
  ((SELECT DECODE(A.PRICE_NO,
              NULL,
              TO_CHAR(SUBSTR(TO_CHAR(SYSDATE, 'YY-MM'), 1, 2) ||
                      SUBSTR(TO_CHAR(SYSDATE, 'YY-MM'), 4, 5)) || '000001',
              SUBSTR(A.PRICE_NO, 1, 4) ||
              LPAD(TO_CHAR(TO_NUMBER(SUBSTR(A.PRICE_NO, 5, 11)) + 1), 6, '0')) PRICE_NO
  FROM (SELECT MAX(T.PRICE_NO) PRICE_NO
          FROM SLM_ORDER_PRICE_LIST T
         WHERE T.PRICE_NO LIKE
               SUBSTR(TO_CHAR(SYSDATE, 'YY-MM'), 1, 2) ||
               SUBSTR(TO_CHAR(SYSDATE, 'YY-MM'), 4, 5) || '%') A)
, ?, ?, ?, ?, ?, ?, SYSDATE)
		]]>
	</query>

	<query id="CoreOrderPriceDetails.addPriceB" desc="新增定价信息">
		<![CDATA[
	         INSERT INTO SLM_ORDER_PRICE_LIST
  (PRICE_NO,
   ORD_LN_PK,
   OUT_PRICE,
   BLA_PRICE,
   TRS_PRICE,
   PAK_PRICE,
   CREATE_NAME,
   CREATE_TIME)
VALUES
  (?, ?, ?, ?, ?, ?, ?, SYSDATE)
		]]>
	</query>

	<query id="CoreOrderPriceDetails.updatePrice" desc="修改定价信息">
		<![CDATA[
	        UPDATE SLM_ORDER_PRICE_LIST
   SET OUT_PRICE   = ?,
       BLA_PRICE   = ?,
       TRS_PRICE   = ?,
       PAK_PRICE   = ?,
       UPDATE_NAME = ?,
       UPDATE_TIME = SYSDATE
 WHERE PRICE_NO = ?
   AND ORD_LN_PK = ?
		]]>
	</query>

	<query id="CoreOrderPriceDetails.checkPriceNo" desc="合同是否存在定价编号">
		<![CDATA[
	       SELECT DISTINCT C.PRICE_NO
  FROM SLM_ORDER_HEAD A, SLM_ORDER_LINE B, SLM_ORDER_PRICE_LIST C
 WHERE B.ORD_PK = A.ORD_PK
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND A.ORD_PK = ?
   AND A.VALIDFLAG = '1'
   AND B.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CoreOrderPriceDetails.updateHeadPriceNo" desc="修改合同头定价编号">
		<![CDATA[
	       UPDATE SLM_ORDER_HEAD T SET T.PRICE_NO = ? WHERE T.ORD_PK = ?
		]]>
	</query>

	<query id="CoreOrderPriceDetails.addOrderPrice" desc="新增定价说明">
		<![CDATA[
	      INSERT INTO SLM_ORDER_PRICE
  (PRICE_NO, PRICE_BASE, CREATE_NAME, CREATE_TIME,ORD_PK)
VALUES
  (?, ?, ?, SYSDATE,?)
		]]>
	</query>

	<query id="CoreOrderPriceDetails.updateOrderPrice" desc="修改定价说明">
		<![CDATA[
	       UPDATE SLM_ORDER_PRICE
   SET PRICE_BASE = ?, UPDATE_NAME = ?, UPDATE_TIME = SYSDATE
 WHERE PRICE_NO = ?
		]]>
	</query>

	<query id="CoreOrderPriceDetails.checkOrderPrice" desc="验证定价说明">
		<![CDATA[
	      SELECT PRICE_NO, PRICE_BASE
  FROM SLM_ORDER_PRICE T
 WHERE T.PRICE_NO = ?
		]]>
	</query>

	<query id="CoreOrderPriceDetails.deleteHeadPriceNo" desc="删除合同头定价编号">
		<![CDATA[
	    UPDATE SLM_ORDER_HEAD T SET T.PRICE_NO='' WHERE T.ORD_PK=? AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CoreOrderPriceDetails.deleteListPriceNo" desc="删除定价明细定价编号">
		<![CDATA[
	      DELETE FROM SLM_ORDER_PRICE_LIST T WHERE T.ORD_LN_PK=? 
		]]>
	</query>

	<query id="CoreOrderPriceDetails.updateItemListP" desc="修改价格评审明细">
		<![CDATA[	      
          UPDATE SLM_ORDER_REVIEW_ITEM_LIST B
             SET B.IS_CURT_REVIEW = '0' , B.REVIEW_STATUS = 'L'
           WHERE B.REVIEW_NO =  (SELECT A.REVIEW_NO
            FROM SLM_ORDER_REVIEW A
           WHERE A.ORD_PK = ?
             AND A.VALIDFLAG = '1')
             AND B.REVIEW_ITM = 'P'
		]]>
	</query>

	<query id="CoreOrderPriceDetails.updateItemP" desc="修改价格评审明细">
		<![CDATA[	      
                 UPDATE SLM_ORDER_REVIEW_ITEM B
             SET   B.REVIEW_STATUS = 'L'
           WHERE B.REVIEW_NO =  (SELECT A.REVIEW_NO
            FROM SLM_ORDER_REVIEW A
           WHERE A.ORD_PK = ?
             AND A.VALIDFLAG = '1')
             AND B.REVIEW_ITM = 'P'
		]]>
	</query>


	<query id="CoreOrderPriceDetails.addItemListP" desc="新增价格评审明细">
		<![CDATA[	      
         INSERT INTO SLM_ORDER_REVIEW_ITEM_LIST
  (REVIEW_NO,
   REVIEW_ITM,
   LIST_TYP,
   LIST_PK_VAL,
   REVIEW_TIMES,
   IS_CURT_REVIEW,
   REVIEW_STATUS,
   REVIEW_F_RS,
   RT_REVIEW_ITM,
   REVIEW_MAN,
   REVIEW_DEPT,
   REVIEW_BDATE,
   REVIEW_EDATE,
   CREATE_NAME,
   CREATE_TIME)
VALUES
  ((SELECT A.REVIEW_NO
     FROM SLM_ORDER_REVIEW A
    WHERE A.ORD_PK = ?
      AND A.VALIDFLAG = '1'),
   'P',
   'H',
   ?,
   (SELECT LPAD(TO_NUMBER(NVL(MAX(TO_NUMBER(REVIEW_TIMES)), '0')) + 1,
                4,
                '0')
      FROM SLM_ORDER_REVIEW_ITEM_LIST
     WHERE REVIEW_NO = (SELECT A.REVIEW_NO
                          FROM SLM_ORDER_REVIEW A
                         WHERE A.ORD_PK = ?
                           AND A.VALIDFLAG = '1')
       AND REVIEW_ITM = 'P'
       AND LIST_TYP = 'H'
       AND LIST_PK_VAL = ?),
   '1',
   'L',
   '',
   '',
   '',
   '',
   NULL,
   NULL,
   ?,
   SYSDATE)
		]]>
	</query>

	<query id="CoreOrderPriceDetails.checkPriceListByOldLnPk" desc="验证价格明细是否存在合同行">
		<![CDATA[	      
           SELECT COUNT(1) COUNT FROM SLM_ORDER_PRICE_LIST T WHERE T.ORD_LN_PK=? 
		]]>
	</query>

</queryMap>