<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="合同法务评审界面查询">
  <query id="CoreOrderReviewLaw.CoreOrderReviewLawQuery" desc="合同法务评审信息">
        <![CDATA[
             SELECT B.ORDER_NO,
			       B.CUSTM_ORDER_NO,
			       B1.REVIEW_F_RS,
			       B.ORD_PK,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = B.ORDER_TYP) ORDER_TYP,
			       B.SALE_AREA_DESC SALE_AREA_NO,
			       B.ORDER_YEAR,
			       B.SIGN_DATE,
			       B.SIGN_ADDRESS,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = B.SUPPLY_UNIT) SUPPLY_UNIT,
			       (SELECT CUSTOMER_NM
			          FROM SLM_BASE_CUSTOMER
			         WHERE CUSTOMER_NO = B.STLMT_UNIT_NO) STLMT_UNIT_NO,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = B.MNY_ASK_TYP) MNY_ASK_TYP,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = B.CURRENCY) CURRENCY,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = DECODE(B.ORDER_STS,'12020251','12020242',B.ORDER_STS)) ORDER_STS,
			       CLOSE_TIME,
			       B.EFFECT_TIME,
			       B.APPROVAL_TIME,
			       B.DELETE_TIME,
			       B.DELETE_NAME,
			       B.UPDATE_TIME,
			       B.UPDATE_NAME,
			       B.CREATE_TIME,
			       B.CREATE_NAME,
			       DECODE(B.VALIDFLAG, '1', '有效', '0', '无效') VALIDFLAG,
			       B.ORDER_MODEL_NO,
			       B.ORDER_MODEL_DESC,
			       B.MNY_ASK_DESC,
			       B.MANAG_NO,
			       B.CUSTOMER_NM CUSTOMER_NO,
			       B.MEMO,
			       (SELECT BASENAME
			          FROM COM_BASE_INFO
			         WHERE BASECODE = B.FST_DRAWEE_UNIT) FST_DRAWEE_UNIT,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = B.PRICE_FL) PRICE_FL,
			       B.CUSTOMER_MODEL_FL,
			       B1.REVIEW_ITM,
			       B1.REVIEW_STATUS
			  FROM 	SLM_ORDER_HEAD B
	          LEFT JOIN SLM_ORDER_REVIEW_ITEM_LIST B1 ON B.ORD_PK = B1.LIST_PK_VAL
			 WHERE 1 =1
			   AND (B1.REVIEW_ITM = 'P' OR (B1.REVIEW_ITM = 'D' AND B.SALE_ORG = '100102')
			        OR (b.SUPPLY_UNIT = '120504' and B1.REVIEW_ITM = 'F' AND B.SALE_ORG = '100102')
			        OR (B1.REVIEW_ITM = 'F' AND B.SALE_ORG = '100102' AND B.ORDER_TYP = '120102')
			        or (B1.REVIEW_ITM IS NULL AND B.SALE_ORG = '100102'))
			   AND (B1.IS_CURT_REVIEW = '1' or (B1.IS_CURT_REVIEW IS NULL AND B.SALE_ORG = '100102') )
			   AND B.VALIDFLAG = '1'
			   AND (B.ORDER_STS IN ('12020232','12020241','12020251','12020242')
			            OR (B.ORDER_STS = '12020222' AND B.SALE_ORG = '100102'))

        ]]>
    </query>
    
    
    <query id="CoreOrderReviewLaw.UpdateOrderModelSts" desc="改变商务条款状态">
        <![CDATA[
            UPDATE SLM_ORDER_MODEL_HEAD
			   SET ORDER_MODEL_STS = ?
			 WHERE ORDER_MODEL_NO =
			       (SELECT ORDER_MODEL_NO
			          FROM SLM_ORDER_HEAD
			         WHERE ORD_PK = ?)

        ]]>
    </query>
    
    <query id="CoreOrderReviewLaw.appStatus" desc="评审状态信息">
        <![CDATA[
            SELECT BASENAME,BASECODE FROM COM_BASE_INFO WHERE (basecode = '12020102' or basecode  like '120202%') order by basecode
        ]]>
    </query>
     <query id="CoreOrderReviewLaw.ordermodelQuery" desc="合同条目信息">
        <![CDATA[
            SELECT MODEL_SEQ, MODEL_ITM,MODEL_ITM_VAL
			  FROM SLM_ORDER_MODEL_ITEM
			 WHERE ORDER_MODEL_NO = ?
			 AND VALIDFLAG = '1'

        ]]>
    </query>
    <query id="CoreOrderReviewLaw.appWorkAdd" desc="合同法务评审合同头信息">
        <![CDATA[
            update SLM_ORDER_HEAD set order_sts = '12020242',order_sts_desc = '法务评审通过',APPROVAL_MAN = ?,APPROVAL_TIME = sysdate,UPDATE_NAME= ? , UPDATE_TIME = sysdate where ORD_PK = ?
        ]]>
    </query>
     <query id="CoreOrderReviewLaw.appWorkAdd2" desc="合同法务评审评审主表">
        <![CDATA[
            update SLM_ORDER_REVIEW set REVIEW_STATUS = 'S',UPDATE_NAME = ?,UPDATE_TIME = sysdate where ORD_PK = ?
        ]]>
    </query>
    <query id="CoreOrderReviewLaw.appWorkAdd3" desc="合同法务评审评审项目表">
        <![CDATA[
            update SLM_ORDER_REVIEW_ITEM set REVIEW_STATUS = 'S',UPDATE_NAME= ?,CREATE_TIME = sysdate where REVIEW_NO = 
            (select t.REVIEW_NO from SLM_ORDER_REVIEW t where t.ORD_PK = ?) and REVIEW_ITM = 'F'
        ]]>
    </query>
     <query id="CoreOrderReviewLaw.appWorkAdd4" desc="合同法务评审评审项目明细表">
        <![CDATA[
            update SLM_ORDER_REVIEW_ITEM_LIST set REVIEW_STATUS = 'S',REVIEW_F_RS = '',REVIEW_MAN = ?,UPDATE_NAME = ?,UPDATE_TIME = sysdate where LIST_PK_VAL = ?
        ]]>
    </query>
    <query id="CoreOrderReviewLaw.appWorkUpdate" desc="合同法务评审不通过业务修改合同主表">
        <![CDATA[
            update SLM_ORDER_HEAD set order_sts = '12020241',order_sts_desc = '法务评审失败',APPROVAL_MAN = '',APPROVAL_TIME = '',UPDATE_NAME= '' , UPDATE_TIME = '' where ord_pk = ?
        ]]>
    </query>
    <query id="CoreOrderReviewLaw.appWorkUpdate2" desc="合同法务评审不通过业务填写不合格原因">
        <![CDATA[
            update SLM_ORDER_REVIEW_ITEM_LIST set REVIEW_F_RS = ?,review_status = 'F',REVIEW_MAN = '',UPDATE_NAME = '',UPDATE_TIME = ''  where list_pk_val = ? and review_itm = 'F'
        ]]>
    </query>
     <query id="CoreOrderReviewLaw.appWorkUpdate3" desc="合同法务评审不通过写评审主表">
        <![CDATA[
            update SLM_ORDER_REVIEW set REVIEW_STATUS = 'F',UPDATE_NAME = '',UPDATE_TIME = '' where ord_pk = ?
        ]]>
    </query>
     <query id="CoreOrderReviewLaw.appWorkUpdate4" desc="合同法务评审不通过写评审项目表">
        <![CDATA[
            update SLM_ORDER_REVIEW_ITEM set REVIEW_STATUS = 'F',UPDATE_NAME= '',CREATE_TIME = '' where REVIEW_NO = 
            (select t.REVIEW_NO from SLM_ORDER_REVIEW t where ord_pk = ?) and REVIEW_ITM = 'F'
        ]]>
    </query>
    <query id="CoreOrderReviewLaw.customerdbQuery" desc="根据客户名称显示客户信息">
        <![CDATA[
            select (select basename from com_base_info where basecode = t.CUSTM_CTGRY) CUSTM_CTGRY,
       (select basename from com_base_info where basecode = t.CUSTM_PRPTY) CUSTM_PRPTY,
       (select basename from com_base_info where basecode = t.CUSTM_LVL) CUSTM_LVL,
       t.MEMO,
       t.LEGAL_PSN,
       t.AGENT,
       t.TAX_ID,
       t.BIGAREA,
       (select region_nm from sel_admin_region where region_no = t.REGION_NO) REGION_NO,
       t.ADDRESS,
       t.BANK,
       t.ACCOUNT,
       t.SALE_ORG,
       t.ZIP_CODE,
       t.PHONE,
       t.FAX,
       t1.customer_nm,
       (select basename from com_base_info where basecode = t1.market_sys) market_sys
  from SLM_BASE_ORDER_UNIT t, SLM_BASE_CUSTOMER t1
 where t.customer_no = t1.customer_no
   and t1.customer_nm = ?

        ]]>
    </query>
    
     <query id="CoreOrderReviewLaw.queryLineAPrice" desc="查询合同行价格">
        <![CDATA[
          SELECT T2.PRICE_NO,
       T2.ORD_LN_PK,
       T2.OUT_PRICE,
       T2.BLA_PRICE,
       T2.TRS_PRICE,
       T2.PAK_PRICE,
       T2.TON_PRICE,
       T2.DDZY,
       DECODE(T2.KEEP_TYPE,'0','保单价','1','保总价') KEEP_TYPE,
       T1.PSC_DESC,
       T1.ORDER_SEQ,
       T1.MODEL_DESC,
       T1.ORDER_SPEC_DESC,
       T1.LEN_DESC,
       T1.SPEC_NAME,
       TO_CHAR(T1.ORDER_QTY, 'FM9999990.000') ORDER_QTY,
       T1.ORDER_UNIT,
       TO_CHAR(T1.PRDCT_WGT, 'FM9999990.000') PRDCT_WGT,
       DECODE(T1.DELVRY_RANGE_TPE,
              '%',
              '-' || T1.DELVRY_RANGE_MIN || '%' || ',+' ||
              T1.DELVRY_RANGE_MAX || '%',
              '(' || T1.DELVRY_RANGE_MIN || ',' || T1.DELVRY_RANGE_MAX || ')') DELVRY_RANGE_TPE,
        ( SELECT ORDER_NO || '/' || ORDER_SEQ FROM PLN_ORDER_ZG_S WHERE TH_ORDER_NO_SEQ = (SELECT ORDER_NO||'/'||T1.ORDER_SEQ FROM SLM_ORDER_HEAD WHERE ORD_PK = T1.ORD_PK) ) ORDER_TH_BC,
        (
        SELECT
            BALNCE_PRICE
        FROM
            SLM_ORDER_LINE
        WHERE
            VALIDFLAG = '1'
            AND ORD_LN_PK = (
                SELECT substr( ORD_LN_DLY_PK, 0, LENGTH( ORD_LN_DLY_PK ) - 3 ) FROM PLN_ORDER_ZG_S
                WHERE TH_ORDER_NO_SEQ = (SELECT ORDER_NO||'/'||T1.ORDER_SEQ FROM SLM_ORDER_HEAD WHERE ORD_PK = T1.ORD_PK)
                )
        ) ORDER_TH_BC_PRICE,t2.BLA_PRICE_ORG
  FROM SLM_ORDER_LINE T1, SLM_ORDER_PRICE_LIST T2
 WHERE T1.ORD_LN_PK = T2.ORD_LN_PK(+)
   AND T1.ORD_PK = ?
   AND T1.VALIDFLAG = '1'
   ORDER BY T1.ORDER_SEQ
        ]]>
    </query>
    
   <query id="CoreOrderReviewLaw.queryPriceInfo" desc="查询合同行价格">
        <![CDATA[
  SELECT T2.PRICE_BASE
  FROM SLM_ORDER_HEAD T1, SLM_ORDER_PRICE T2
 WHERE T1.PRICE_NO = T2.PRICE_NO
   AND T1.ORD_PK = ?
   AND T1.VALIDFLAG = '1'
        ]]>
    </query>
    
   <query id="CoreOrderReviewLaw.addLawRecord" desc="查询合同行价格">
        <![CDATA[
   			INSERT INTO SLM_LAW_REVIEW_RECORD
  (RECORD_ID,
   ORDER_NO,
   ORD_PK,
   CUSTOMER_NO,
   CUSTOMER_NM,
   SALE_ORG,
   SALE_ORG_DESC,
   SALE_AREA_NO,
   SALE_AREA_DESC,
   CREATE_NAME,
   CREATE_TIME)
VALUES
  ((SELECT 'FW' || ? || LPAD(TO_NUMBER(NVL(SUBSTR(MAX(RECORD_ID), 11, 3), 0)) + 1,
                            3,
                            '0')
     FROM SLM_LAW_REVIEW_RECORD T
    WHERE SUBSTR(RECORD_ID, 1, 10) = 'FW' || ?),
   (SELECT A.ORDER_NO
      FROM SLM_ORDER_HEAD A
     WHERE A.ORD_PK = ?
       AND A.VALIDFLAG = '1'),
   ?,
   (SELECT A.CUSTOMER_NO
      FROM SLM_ORDER_HEAD A
     WHERE A.ORD_PK = ?
       AND A.VALIDFLAG = '1'),
   (SELECT A.CUSTOMER_NM
      FROM SLM_ORDER_HEAD A
     WHERE A.ORD_PK = ?
       AND A.VALIDFLAG = '1'),
   (SELECT A.SALE_ORG
      FROM SLM_ORDER_HEAD A
     WHERE A.ORD_PK = ?
       AND A.VALIDFLAG = '1'),
   (SELECT A.SALE_ORG_DESC
      FROM SLM_ORDER_HEAD A
     WHERE A.ORD_PK = ?
       AND A.VALIDFLAG = '1'),
   (SELECT A.SALE_AREA_NO
      FROM SLM_ORDER_HEAD A
     WHERE A.ORD_PK = ?
       AND A.VALIDFLAG = '1'),
   (SELECT A.SALE_AREA_DESC
      FROM SLM_ORDER_HEAD A
     WHERE A.ORD_PK = ?
       AND A.VALIDFLAG = '1'),
   ?,
   SYSDATE
   )
   			
        ]]>
   </query>
   
    <query id="CoreOrderReviewLaw.clearLawRecord" desc="查询合同行价格">
        <![CDATA[
  		DELETE FROM SLM_LAW_REVIEW_RECORD T WHERE T.ORD_PK = ?
        ]]>
    </query>
    
    <query id="CoreOrderReviewLaw.queryLawRecore" desc="查询合同行价格">
        <![CDATA[
  		 SELECT RECORD_ID,
       ORDER_NO,
       ORD_PK,
       CUSTOMER_NO,
       CUSTOMER_NM,
       SALE_ORG,
       SALE_ORG_DESC,
       SALE_AREA_NO,
       SALE_AREA_DESC,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       DECODE(IS_SEAL, '1', '已盖章', '未盖章') IS_SEAL,
       CONFIRM_NAME,
       TO_CHAR(CONFIRM_TIME,'YYYY-MM-DD HH24:MI:SS') CONFIRM_TIME
       FROM SLM_LAW_REVIEW_RECORD T
       WHERE T.ORDER_NO LIKE '%'||?||'%'
  		 
        ]]>
    </query>
    
    <query id="CoreOrderReviewLaw.queryRecordLaw" desc="查询合同行价格">
        <![CDATA[
  		  SELECT  T.IS_SEAL FROM SLM_LAW_REVIEW_RECORD T
  		  WHERE  T.RECORD_ID = ?
  		       
        ]]>
    </query>
    
    <query id="CoreOrderReviewLaw.confirmLawRecord" desc="查询合同行价格">
        <![CDATA[
  		  UPDATE SLM_LAW_REVIEW_RECORD T
  		  SET  T.IS_SEAL = '1',
  		       T.CONFIRM_NAME = ?,
  		       T.CONFIRM_TIME = SYSDATE
  		  WHERE T.RECORD_ID = ?
  		       
        ]]>
    </query>
    
    
</queryMap>