<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: syj  
    $Date: 2015年7月16日10:47:10
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (
                    SELECT 
                       p.chance_id, 
			      	   m.legal_person,
				       m.actual_controller,
				       m.business_license_num,
				       m.organization_code,
				        
				       
				       nvl(DECODE(to_char(m.registered_capital, 'FM999,999,999,999.00'),
			                  '.00',
			                  '0',
			                  to_char(m.registered_capital, 'FM999,999,999,999.00')),
			           0) registered_capital,
				       
				       nvl(DECODE(to_char(m.paid_up_capital, 'FM999,999,999,999.00'),
			                  '.00',
			                  '0',
			                  to_char(m.paid_up_capital, 'FM999,999,999,999.00')),
			           0) paid_up_capital,
				       
				       extract(YEAR FROM m.founded_date) || '年' ||
				       extract(MONTH FROM m.founded_date) || '月' ||
				       extract(DAY FROM m.founded_date) || '日' founded_date,
				       (SELECT v.code_value_name
				          FROM sys_code_values_v v
				         WHERE v.code = 'PRJ_NATURE_OF_BUSINESS'
				           AND v.code_enabled_flag = 'Y'
				           AND v.code_value_enabled_flag = 'Y'
				           AND v.code_value = m.company_nature) company_nature_n,
				       m.workers_number,
				       p.regular_customer,
				       decode(p.regular_customer, 'N', '否', 'Y', '是') regular_customer_n,
				       TO_CHAR(ROUND(NVL(m.technical_person_rate, 0) * 100.0, 2)) technical_person_rate,
				       m.bussiness_scope,
				       m.primary_business,
				       (SELECT A.CITY_ID_N || A.DISTRICT_ID_N || A.ADDRESS
				          FROM HLS_BP_MASTER_ADDRESS_LV A
				         WHERE A.ADDRESS_TYPE = 'COMPANY_ADDRESS'
				           AND a.bp_id = m.bp_id
				           AND rownum = 1) registered_place,
				       m.bp_id,
				       decode(b.bp_type, 'TENANT', 1, 'TENANT_SEC', 2) order_num
				  FROM prj_chance_bp b, hls_bp_master m,prj_chance p
				 WHERE b.bp_id = m.bp_id
				   AND b.bp_category = 'TENANT'
				   AND b.bp_type IN ('TENANT', 'TENANT_SEC')
				   and b.chance_id = p.chance_id
				 ORDER BY order_num) t 
                    #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="chance_id" queryExpression="t.chance_id=${@chance_id}"/>
    </bm:query-fields>
</bm:model>
