<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="客户订货单位管理">
	<query id="CoreBuyerOrder.doQuery" desc="查询销售区域信息">
		<![CDATA[  
		    SELECT sale_area_no, sale_area_desc
				   FROM slm_base_sale_area_typ
			WHERE sale_org = ? AND validflag = '1'
            ]]>
	</query>
	<query id="CoreBuyerOrder.doQueryBaseInfo" desc="查询客户信息">
		<![CDATA[  
		    SELECT BASECODE,BASENAME FROM COM_BASE_INFO WHERE SORTCODE = ? AND VALIDFLAG='1' ORDER BY BASECODE
            ]]>
	</query>
	<query id="CoreBuyerOrder.doQueryFreight" desc="查询客户货运地址信息">
		<![CDATA[  
		    SELECT customer_no, freight_no, address, station_no, spcl_ln_no, trans_typ,
			       memo, validflag,PORT_NO,PORT_DESC
			  	   FROM slm_base_custm_freight
			 WHERE customer_no = ?  AND SALE_ORG = ? AND validflag = '1'
            ]]>
	</query>
	<query id="CoreBuyerOrder.doDeleteFreight" desc="删除客户货运地址信息">
		<![CDATA[  
		    DELETE slm_base_custm_freight
			 WHERE FREIGHT_NO = ?  
            ]]>
	</query>
	<query id="CoreBuyerOrder.doQueryOrderunit" desc="查询客户定结算信息">
		<![CDATA[  
		    SELECT customer_no, (SELECT max(customer_nm)
                       FROM slm_base_customer
                      WHERE customer_no = it.customer_no)customer_nm, sale_org, custm_use, chn_fl, custm_ctgry,(select BASENAME from com_base_info where BASECODE = it.custm_prpty) custm_prpty,
			       custm_lvl, legal_psn, AGENT, address, bigarea, region_no,
			       zip_code, bank, ACCOUNT, tax_id, phone, fax, memo, validflag,CUSTM_DATA
			  FROM slm_base_order_unit it
			 WHERE customer_no = ? AND sale_org = ? AND custm_use = ? 
            ]]>
	</query>
	<query id="CoreBuyerOrder.doInsertOrderunit" desc="新增客户定结算信息">
		<![CDATA[  
		    INSERT INTO slm_base_order_unit
            (customer_no, sale_org, custm_use, chn_fl, custm_ctgry,
             custm_prpty, custm_lvl, legal_psn, AGENT,address, bigarea, region_no,
             zip_code, bank, ACCOUNT, tax_id, phone, fax, memo, create_name,
             custm_data, create_time
            )
		     VALUES (?, ?, ?, ?, ?,
		             ?, ?, ?, ?, ?, ?,
		             ?, ?, ?, ?, ?, ?, ?, ?,
		             ?,?, SYSDATE
		            )
            ]]>
	</query>
	<query id="CoreBuyerOrder.doInsertCustmFreight" desc="新增客户从数据信息_货运地址">
		<![CDATA[  
			INSERT INTO slm_base_custm_freight
		            (customer_no,
		             SALE_ORG,
		             freight_no,
		             address, station_no, spcl_ln_no, trans_typ, memo, create_name,PORT_NO,PORT_DESC,
		             create_time
		            )
		     VALUES (?,?,
		             (SELECT DECODE (LPAD (MAX (freight_no + 1), 13, '0'),
		                             '', ? || '001',
		                             LPAD (MAX (freight_no + 1), 13, '0')
		                            ) freight_no
		                FROM slm_base_custm_freight
		               WHERE customer_no LIKE ? || '%'),
		             ?, ?, ?, ?, ?, ?, ?, ?,
		             SYSDATE
		            )
            ]]>
	</query>
	<query id="CoreBuyerOrder.doUpdateCustmFreight" desc="更新客户订结地址">
		<![CDATA[  
			UPDATE slm_base_order_unit
				   SET custm_ctgry = ?,
				       custm_prpty = ?,
				       custm_lvl = ?,
				       legal_psn = ?,
				       AGENT = ?,
				       address = ?, 
				       region_no = ?, 
				       zip_code = ?,
				       bank = ?,
				       ACCOUNT = ?,
				       tax_id = ?,
				       phone = ?,
				       fax = ?,
				       memo = ?,
				       update_name = ?,
				       CUSTM_DATA = ?,
				       update_time = SYSDATE
				 WHERE customer_no = ? AND sale_org = ? 
            ]]>
	</query>
	<query id="CoreBuyerOrder.doQueryCustmFreightAll" desc="查询客户订结货运地址">
		<![CDATA[  
SELECT CUSTOMER_NO,
       FREIGHT_NO,
       ADDRESS,
       (SELECT MAX(STATION_NM)
          FROM SLM_BASE_STATION
         WHERE STATION_NO = HT.STATION_NO) STATION_NO,
       (SELECT MAX(SPCL_LN_NM)
          FROM SLM_BASE_SPCL_LN
         WHERE SPCL_LN_NO = HT.SPCL_LN_NO) SPCL_LN_NO,
       A.BASENAME TRANS_TYP,
       HT.MEMO,
       HT.PORT_NO,
       HT.PORT_DESC
  FROM SLM_BASE_CUSTM_FREIGHT HT
  LEFT JOIN COM_BASE_INFO A
    ON A.BASECODE = HT.TRANS_TYP
            ]]>
	</query>
	<query id="CoreBuyerOrder.doSlmBaseStation" desc="查询到站信息">
		<![CDATA[  
			SELECT station_nm, station_no
		    FROM SLM_BASE_STATION
            ]]>
	</query>
	<query id="CoreBuyerOrder.doSlmBasesPclLn" desc="查询专用线信息">
		<![CDATA[  
			SELECT SPCL_LN_NO,SPCL_LN_NM FROM SLM_BASE_SPCL_LN
            ]]>
	</query>
	
	<query id="CoreBuyerOrder.doSlmCustMuseCount" desc="查询用途类型信息">
		<![CDATA[  
			SELECT CUSTOMER_NO  from SLM_BASE_CUSTM_USE where CUSTOMER_NO = ? AND SALE_ORG = ? AND CUSTM_USE = ?
            ]]>
	</query>
	
	<query id="CoreBuyerOrder.getBaseReceiveUnit" desc="查询单位基础信息">
		<![CDATA[
SELECT '修改' UNBOUNDUP,
       '收货扩充信息' TYPEDESC,
       CUSTOMER_NO,
       SALE_ORG,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = SALE_ORG) SALE_ORGNAME,
       CUSTM_USE,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CUSTM_USE) CUSTM_USENAME,
       REGION_NO,
       (SELECT REGION_NM
          FROM SEL_ADMIN_REGION
         WHERE REGION_NO = TS.REGION_NO) REGION_NONAME,
       ADDRESS,
       CONSIGNEE,
       PHONE,
       ZIP_CODE,
       FAX,
       MEMO
  FROM SLM_BASE_RECEIV_UNIT TS
 WHERE VALIDFLAG = '1'
   AND CUSTM_USE = '100203'
   AND EXISTS (SELECT 1
          FROM SLM_BASE_CUSTOMER MER, SLM_BASE_CUSTM_USE USE
         WHERE MER.CUSTOMER_NO IN
               (SELECT CUSTOMER_NO
                  FROM SLM_BASE_CUSTM_RIGHT
                 WHERE SALE_ORG IN (#SALE_ORG#))
           AND USE.CUSTOMER_NO = TS.CUSTOMER_NO
           AND USE.CUSTM_USE = '100203'
           AND USE.SALE_ORG IN (#SALE_ORG#)
           AND MER.CUSTOMER_NO = TS.CUSTOMER_NO
           AND DECODE('#CUSTOMER_NM#', NULL, '1', CUSTOMER_NM) = DECODE('#CUSTOMER_NM#', NULL, '1', '#CUSTOMER_NM#')
           AND MER.VALIDFLAG IN ('1', '#VALIDFLAG#'))
            ]]>
	</query>
	
	<query id="CoreBuyerOrder.getBaseOrderUnit" desc="查询订结单位基础信息">
		<![CDATA[
SELECT '  修改' UNITUP,
       '订/结扩充信息' TYPEDESC,
       CUSTOMER_NO,
       SALE_ORG,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = SALE_ORG) SALE_ORGNAME,
       CUSTM_USE,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CUSTM_USE) CUSTM_USENAME,
       DECODE(CHN_FL, '0', '国外', '国内') CHN_FL,
       CUSTM_CTGRY,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CUSTM_CTGRY) CUSTM_CTGRYNAME,
       CUSTM_PRPTY,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CUSTM_PRPTY) CUSTM_PRPTYNAME,
       LEGAL_PSN,
       AGENT,
       ADDRESS,
       BIGAREA,
       REGION_NO,
       (SELECT REGION_NM
          FROM SEL_ADMIN_REGION
         WHERE REGION_NO = TS.REGION_NO) REGION_NONAME,
       ZIP_CODE,
       BANK,
       ACCOUNT,
       TAX_ID,
       PHONE,
       FAX,
       MEMO
  FROM SLM_BASE_ORDER_UNIT TS
 WHERE VALIDFLAG = '1'
   AND CUSTM_USE = '100202'
   AND EXISTS (SELECT 1
          FROM SLM_BASE_CUSTOMER MER, SLM_BASE_CUSTM_USE USE
         WHERE MER.CUSTOMER_NO IN
               (SELECT CUSTOMER_NO
                  FROM SLM_BASE_CUSTM_RIGHT
                 WHERE SALE_ORG IN (#SALE_ORG#))
           AND USE.CUSTOMER_NO = TS.CUSTOMER_NO
           AND USE.CUSTM_USE = '100202'
           AND USE.SALE_ORG IN (#SALE_ORG#)
           AND MER.CUSTOMER_NO = TS.CUSTOMER_NO
           AND DECODE('#CUSTOMER_NM#', NULL, '1', CUSTOMER_NM) =
               DECODE('#CUSTOMER_NM#', NULL, '1', '#CUSTOMER_NM#')
           AND MER.VALIDFLAG IN ('1', '#VALIDFLAG#'))
            ]]>
	</query>
</queryMap>
