<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: weiwuzhen  
    $Date: 2016-5-22 下午9:57:53  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[select trim((to_char(max_date, 'yyyy') - to_char(min_date, 'yyyy')) * 12 +
            (to_char(max_date, 'mm') - to_char(min_date, 'mm'))) sum_month --租赁月份
  from (select p.project_id,
               (select ln.times
                  from hls_fin_calculator_ln ln
                 where ln.calc_session_id = hd.calc_session_id
                   and ln.times =
                       (select max(to_number(ln1.times))
                          from hls_fin_calculator_ln ln1
                         where ln1.calc_session_id = hd.calc_session_id)) max_times,
               to_date((select ln.calc_date
                         from hls_fin_calculator_ln ln
                        where ln.calc_session_id = hd.calc_session_id
                          and ln.times =
                              (select max(to_number(ln1.times))
                                 from hls_fin_calculator_ln ln1
                                where ln1.calc_session_id =
                                      hd.calc_session_id)),
                       'yyyy-mm-dd') max_date
          from prj_quotation q, Prj_Project P, hls_fin_calculator_hd hd
         where q.document_category = 'PROJECT'
           AND q.DOCUMENT_ID = P.PROJECT_ID(+)
           and q.calc_session_id = hd.calc_session_id(+)) t1,
       (select p.project_id,
               (select ln.times
                  from hls_fin_calculator_ln ln
                 where ln.calc_session_id = hd.calc_session_id
                   and ln.times =
                       (select min(to_number(ln1.times))
                          from hls_fin_calculator_ln ln1
                         where ln1.calc_session_id = hd.calc_session_id)) min_times,
               to_date((select ln.calc_date
                         from hls_fin_calculator_ln ln
                        where ln.calc_session_id = hd.calc_session_id
                          and ln.times =
                              (select min(to_number(ln1.times))
                                 from hls_fin_calculator_ln ln1
                                where ln1.calc_session_id =
                                      hd.calc_session_id)),
                       'yyyy-mm-dd') min_date
          from prj_quotation q, Prj_Project P, hls_fin_calculator_hd hd
         where q.document_category = 'PROJECT'
           AND q.DOCUMENT_ID = P.PROJECT_ID(+)
           and q.calc_session_id = hd.calc_session_id(+)) t2
 where t1.project_id = t2.project_id
 and t1.project_id=${/parameter/@project_id}
 ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
