<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: WangYu  
    $Date: 2015-5-4 下午04:11:47  
    $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
                	t1.prj_instro,
			       t1.lease_item_short_name, --租赁物
			       t1.business_type_n, --租赁方式
			       t1.REPAY_RESOURCE, --还款来源
			       to_char(t3.lease_item_amount, 'FM999,999,999,999.00') lease_item_amount, --租赁本金
			       to_char(t3.lease_term,'FM9990.00')lease_term, --租赁年限
			       t3.pay_type_n, --支付类型
			       DECODE(to_char(t3.deposit, 'FM999,999,999,999.00'),
			              '.00',
			              '0',
			              to_char(t3.deposit, 'FM999,999,999,999.00')) deposit, --保证金
			       
			       to_char(round(nvl(t3.int_rate, 0) * 100.0, 2)) || '%' int_rate, --利率
			       DECODE(to_char(t3.LEASE_CHARGE, 'FM999,999,999,999.00'),
			              '.00',
			              '0',
			              to_char(t3.LEASE_CHARGE, 'FM999,999,999,999.00')) lease_charge, --手续费
			       to_char(t3.pmt, 'FM999,999,999,999.00') pmt, --每期租金
			       (select to_char(sum(h.rental), 'FM999,999,999,999.00')
          from hls_fin_calculator_ln h
         where h.calc_session_id = t3.calc_session_id) contract_amount, --合同金额
         TO_CHAR(t3.finance_amount, 'FM999,999,999,999.00') finance_amount,--计息金额
			       to_char(nvl(round(t3.irr * 100.0, 2), 0)) || '%' irr, --irr
			       DECODE(to_char(t3.residual_value, 'FM999,999,999,999.00'),
			              '.00',
			              '0',
			              to_char(t3.residual_value, 'FM999,999,999,999.00'))residual_value, --优惠留购金
			              
			       DECODE(to_char(t3.hd_user_col_n03, 'FM999,999,999,999.00'),
			              '.00',
			              '0',
			              to_char(t3.hd_user_col_n03, 'FM999,999,999,999.00'))hd_user_col_n03,--留购金
			              
			       t1.RISK_CTM, --项目主要风险和应对方案
			       t1.L_INCERESE_M, --增信措施
                    
                    t1.project_type_n,
                    t1.division_n,
                    t1.chance_source_n,
                    t1.lease_start_date,
                    t1.object_description,
                    t1.business_description,
                    t1.fund_purpose_description,
                    t1.lease_programme_description,
                    t1.lease_identification_basis,
                    t1.nominal_price,
                    to_char(nvl(round(T3.IRR_RESERVED2*100.0,2),0))||'%' xirr
                    
                FROM
                    prj_chance_lv t1,
                    prj_quotation t2,
                    hls_fin_calculator_hd_lv t3
                WHERE
                    t1.chance_id        =t2.document_id AND
                    t2.document_category='CHANCE' AND
                    t2.enabled_flag     ='Y' AND
                    t2.quotation_type   ='MAJOR' and
                    t3.calc_session_id  =t2.calc_session_id and 
                    t1.chance_id = ${@chance_id}
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
