<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="合同评审价格界面查询">
<query id="CorePriceConfirm.GetOrderInfo" desc="合同价格评审信息">
        <![CDATA[
 SELECT A.ORDER_NO || '/' || B.ORDER_SEQ ORDER_NO,
 	  'FALSE' CHK,
       A.ORD_PK,
       B.ORD_LN_PK,
       B.ORDER_SEQ,
       B.PRODUCNAME,
       B.STD_NAME,
       B.STEELNAME,
       B.STD_STYLE_DESC,
       B.MODEL_DESC,
       B.ORDER_SPEC_DESC,
       B.SPEC_NAME,
       B.DIMATER,
       B.HEIGHT,
       B.ORDER_UNIT,
       B.ORDER_QTY,
       B.ORD_ENSU_TOTL_LEN,
       ROUND(B.PRDCT_WGT, 3) PRDCT_WGT,
       C.BLA_PRICE BALNCE_PRICE,
       C.BLA_PRICE_ORG BALNCE_PRICE_ORG,
       C.OUT_PRICE,
       A.STLMT_UNIT_NM,
       A.SALE_AREA_DESC,
       A.SUPPLY_UNIT,
       DECODE(A.CONTAIN_TAX, '1', '含税', '不含税') CONTAIN_TAX,
       C.TRS_PRICE TRANS_PRICE,
       C.PAK_PRICE,
       C.TON_PRICE,
       C.KEEP_TYPE,
       DECODE(LENGTH(D.PRICE_NO), 15, D.PRICE_NO, '') PRICE_NO,
       DECODE(LENGTH(D.PRICE_NO),
              15,
              DECODE(PRICE_STATUS,
                     'L',
                     '封锁',
                     'D',
                     '无效',
                     'W',
                     '待审',
                     'S',
                     '通过',
                     'F',
                     '不通过'),
              '') PRICE_STATUS,
       DECODE(LENGTH(D.PRICE_NO), 15, PRICE_STATUS, '') PRICE_STATUS_CODE,
       D.PRICE_BASE,
       B.AW,
       B.LEN_DESC,
       1 RN

  FROM SLM_ORDER_HEAD       A,
       SLM_ORDER_LINE       B,
       SLM_ORDER_PRICE_LIST C,
       SLM_ORDER_PRICE      D
 WHERE B.ORD_PK = ?
   AND B.ORD_PK = A.ORD_PK
   AND A.PRICE_NO = D.PRICE_NO
   AND D.PRICE_NO = C.PRICE_NO
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND A.VALIDFLAG = '1'
   AND B.VALIDFLAG = '1'
   AND A.PRICE_NO IS NOT NULL
   AND LENGTH(A.PRICE_NO) > 10

  UNION ALL

  SELECT Q.*
  FROM (SELECT A.ORDER_NO || '/' || B.ORDER_SEQ ORDER_NO,
              'FALSE' CHK,
               A.ORD_PK,
               B.ORD_LN_PK,
               B.ORDER_SEQ,
               B.PRODUCNAME,
               B.STD_NAME,
               B.STEELNAME,
               B.STD_STYLE_DESC,
               B.MODEL_DESC,
               B.ORDER_SPEC_DESC,
               B.SPEC_NAME,
               B.DIMATER,
               B.HEIGHT,
               B.ORDER_UNIT,
               B.ORDER_QTY,
               B.ORD_ENSU_TOTL_LEN,
               ROUND(B.PRDCT_WGT, 3) PRDCT_WGT,
               C.BLA_PRICE BALNCE_PRICE,
               C.BLA_PRICE_ORG BALNCE_PRICE_ORG,
               C.OUT_PRICE,
               A.STLMT_UNIT_NM,
               A.SALE_AREA_DESC,
               A.SUPPLY_UNIT,
               DECODE(A.CONTAIN_TAX, '1', '含税', '不含税') CONTAIN_TAX,
               C.TRS_PRICE TRANS_PRICE,
               C.PAK_PRICE,
               C.TON_PRICE,
               C.KEEP_TYPE,
               DECODE(LENGTH(D.PRICE_NO), 15, D.PRICE_NO, '') PRICE_NO,
               DECODE(LENGTH(D.PRICE_NO),
                      15,
                      DECODE(PRICE_STATUS,
                             'L',
                             '封锁',
                             'D',
                             '无效',
                             'W',
                             '待审',
                             'S',
                             '通过',
                             'F',
                             '不通过'),
                      '') PRICE_STATUS,
               DECODE(LENGTH(D.PRICE_NO), 15, PRICE_STATUS, '') PRICE_STATUS_CODE,
               D.PRICE_BASE,
               B.AW,
               B.LEN_DESC,
               ROW_NUMBER() OVER(PARTITION BY B.ORD_LN_PK ORDER BY B.ORD_LN_PK DESC) RN
        
          FROM SLM_ORDER_HEAD       A,
               SLM_ORDER_LINE       B,
               SLM_ORDER_PRICE_LIST C,
               SLM_ORDER_PRICE      D
         WHERE B.ORD_PK = ?
           AND B.ORD_PK = A.ORD_PK
           AND A.PRICE_NO = D.PRICE_NO(+)
           AND B.ORD_LN_PK = C.ORD_LN_PK(+)
           AND A.VALIDFLAG = '1'
           AND B.VALIDFLAG = '1'
           AND (LENGTH(A.PRICE_NO) <= 10 OR A.PRICE_NO IS NULL)) Q
         WHERE Q.RN = 1
 ORDER BY ORDER_NO
 
        ]]>
    </query>
    
    <query id="CorePriceConfirm.UpdateOrderLinePrice" desc="合同价格说明信息">
        <![CDATA[
             UPDATE SLM_ORDER_LINE T
       SET T.BALNCE_PRICE        =
       (SELECT A.BLA_PRICE
          FROM SLM_ORDER_PRICE_LIST A
         WHERE PRICE_NO = ?
           AND T.ORD_LN_PK = A.ORD_LN_PK),
       T.BALNCE_PRICE_STS     = '1',
       T.BALNCE_PRICE_ORG = (SELECT A.BLA_PRICE_ORG
          FROM SLM_ORDER_PRICE_LIST A
         WHERE PRICE_NO = ?
           AND T.ORD_LN_PK = A.ORD_LN_PK),
       T.BALNCE_PRICE_ORG_STS = '1',
       T.OUT_PRICE           =
       (SELECT A.OUT_PRICE
          FROM SLM_ORDER_PRICE_LIST A
         WHERE PRICE_NO = ?
           AND T.ORD_LN_PK = A.ORD_LN_PK),
       TRANS_PRICE           =
       (SELECT A.TRS_PRICE
          FROM SLM_ORDER_PRICE_LIST A
         WHERE PRICE_NO = ?
           AND T.ORD_LN_PK = A.ORD_LN_PK),
       T.PAK_PRICE           =
       (SELECT A.PAK_PRICE
          FROM SLM_ORDER_PRICE_LIST A
         WHERE PRICE_NO = ?
           AND T.ORD_LN_PK = A.ORD_LN_PK),
       T.TON_PRICE           =
       (SELECT A.TON_PRICE
          FROM SLM_ORDER_PRICE_LIST A
         WHERE PRICE_NO = ?
           AND T.ORD_LN_PK = A.ORD_LN_PK),
       T.KEEP_TYPE           =
       (SELECT A.KEEP_TYPE
          FROM SLM_ORDER_PRICE_LIST A
         WHERE PRICE_NO = ?
           AND T.ORD_LN_PK = A.ORD_LN_PK)
       WHERE T.ORD_LN_PK IN
       (SELECT ORD_LN_PK FROM SLM_ORDER_PRICE_LIST WHERE PRICE_NO = ?)
             
        ]]>
    </query>
     
    <query id="CorePriceConfirm.isExistsPriceNo" desc="合同价格说明信息">
        <![CDATA[
           SELECT  TRIM(T.PRICE_NO) FROM SLM_ORDER_HEAD T
           WHERE T.ORD_PK = ? AND LENGTH(T.PRICE_NO)>10
        ]]>
    </query>
    
     <query id="CorePriceConfirm.getPriceNoStatus" desc="合同价格说明信息">
        <![CDATA[
           SELECT  PRICE_STATUS FROM SLM_ORDER_PRICE T
           WHERE   T.PRICE_NO = ? AND PRICE_STATUS !='D'
        ]]>
    </query>
    
    
     <query id="CorePriceConfirm.UpdateOrderPrice" desc="合同价格说明信息">
        <![CDATA[
          UPDATE SLM_ORDER_PRICE
      SET PRICE_BASE = ?, UPDATE_NAME = ?, UPDATE_TIME = SYSDATE
      WHERE PRICE_NO = ?
          
        ]]>
    </query>
    
   <query id="CorePriceConfirm.UpdateOrderPriceList" desc="合同价格说明信息">
        <![CDATA[
    	
		UPDATE SLM_ORDER_PRICE_LIST
       SET BLA_PRICE   = ?,
         OUT_PRICE   = ?,
         TRS_PRICE   = ?,
       	 PAK_PRICE   = ?,
     	 UPDATE_NAME = ?,
         UPDATE_TIME = SYSDATE,
         BLA_PRICE_ORG   = ?,
         TON_PRICE = ?,
         KEEP_TYPE   = ?,
         DDZY =  ?
         WHERE PRICE_NO = ?
         AND ORD_LN_PK = ?
    	 
        ]]>
    </query>
    
    <query id="CorePriceConfirm.GeneratePriceNo" desc="合同价格说明信息">
        <![CDATA[
      
      SELECT ? ||
      LPAD(TO_NUMBER(NVL(MAX(SUBSTR(PRICE_NO, 10, 6)), '0')) + 1, 6, '0')
      FROM SLM_ORDER_PRICE
      WHERE SUBSTR(PRICE_NO, 1, 9) = ?
      AND LENGTH(PRICE_NO) > 10
        
        ]]>
    </query>
    
    <query id="CorePriceConfirm.InsertOrderPrice" desc="合同价格说明信息">
        <![CDATA[
        INSERT INTO SLM_ORDER_PRICE
        (PRICE_NO, PRICE_BASE, CREATE_NAME, CREATE_TIME, ORD_PK)
        VALUES    (?, ?, ?, SYSDATE, ?)
         
        ]]>
    </query>
    
    <query id="CorePriceConfirm.InsertOrderPriceList" desc="合同价格说明信息">
        <![CDATA[
      INSERT INTO SLM_ORDER_PRICE_LIST
  (PRICE_NO,
   ORD_LN_PK,
   BLA_PRICE,
   OUT_PRICE,
   TRS_PRICE,
   PAK_PRICE,
   CREATE_NAME,
   CREATE_TIME,
   BLA_PRICE_ORG,
   TON_PRICE,KEEP_TYPE)
   VALUES
   (?, ?, ?, ?, ?, ?, ?, SYSDATE,?,?,?)
      
          
        ]]>
    </query>
    
    <query id="CorePriceConfirm.UpdateOrderHeadPriceNo" desc="合同价格说明信息">
        <![CDATA[
  		UPDATE SLM_ORDER_HEAD T
  		SET T.PRICE_NO = ?
  		WHERE T.ORD_PK = ?
          
        ]]>
    </query>
    
      <query id="CorePriceConfirm.ConfirmPrice" desc="确认价格">
        <![CDATA[
  	 	 UPDATE SLM_ORDER_PRICE
    SET PRICE_STATUS   = 'W',
       REPORT_DEPTCODE = ?,
       REPORT_DEPTDESC = ?,
       REPORT_UNITCODE = ?,
       REPORT_UNITDESC = ?,
       REPORT_NAME     = ?,
       REPORT_TIME     = SYSDATE

     WHERE PRICE_NO = ?
  		  
        ]]>
    </query>
    
     <query id="CorePriceConfirm.DeletePrice" desc="确认价格">
        <![CDATA[
  	 	 UPDATE SLM_ORDER_PRICE
    SET PRICE_STATUS   = 'D',
        DELETE_NAME    = ?,
        DELETE_TIME    = SYSDATE 

     WHERE PRICE_NO = ?
  		  
        ]]>
    </query>
    
     <query id="CorePriceConfirm.DeletePriceCLearOrderHead" desc="确认价格">
        <![CDATA[
  	 	UPDATE SLM_ORDER_HEAD
        SET PRICE_NO   = ''
        WHERE ORD_PK = ?
  		  
        ]]>
    </query>
    
     <query id="CorePriceConfirm.PassOrBackPrice" desc="确认价格">
        <![CDATA[
  		  UPDATE SLM_ORDER_PRICE
   SET PRICE_STATUS  = ?,
       DEAL_NAME     = ?,
       DEAL_TIME     = SYSDATE,
       DEAL_DEPTCODE = ?,
       DEAL_DEPTDESC = ?,
       DEAL_UNITCODE = ?,
       DEAL_UNITDESC = ?

    WHERE PRICE_NO = ?
  		  
        ]]>
    </query>
    
    <query id="CorePriceConfirm.UpdateOrderConfirmTime" desc="合同价格评审不通过写评审项目表">
        <![CDATA[
          UPDATE SLM_ORDER_HEAD T 
          SET T.CONFIRM_TIME = SYSDATE
          WHERE T.ORD_PK = ?  AND T.VALIDFLAG = '1'
        ]]>
    </query>
     
     
</queryMap>
