<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: jack  
    $Date: 2014-6-3 下午4:42:15  
    $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 t1.*,decode (dense_rank() over (partition by t1.indicator_type,t1.bp_id order by t1.line_number),1,'restart','continue') rownums from(  select year_1.*,  f.percent_flag,f.line_number, f.indicator_type,
 decode(year_1.indicator_value,'','',decode(f.percent_flag,
              'Y',
              year_1.indicator_value * 100 || '%',
              'N',
              to_number(year_1.indicator_value))) first_year_change_rate,
decode(year_2.indicator_value,'','',decode(f.percent_flag,
              'Y',
              year_2.indicator_value * 100 || '%',
              'N',
              to_number(year_2.indicator_value))) second_year_change_rate,
decode(year_3.indicator_value,'','',decode(f.percent_flag,
              'Y',
              year_3.indicator_value * 100 || '%',
              'N',
              to_number(year_3.indicator_value))) third_year_change_rate,
decode(year_4.indicator_value,'','',decode(f.percent_flag,
              'Y',
              year_4.indicator_value * 100 || '%',
              'N',
              to_number(year_4.indicator_value))) fourth_year_change_rate from 
(SELECT a.*,c.indicator_code,c.indicator_name,c.indicator_value
          FROM (SELECT DISTINCT b.fin_statement_templet_id,
                                b.bp_id,
                                a.bp_category,
                                a.bp_class,
                                a.bp_type,
                                a.project_id
                  FROM prj_project_bp            a,
                       rsc_fin_indicator_hds b
                 WHERE a.bp_id = b.bp_id) a,
               rsc_fin_indicator_hds b,
               rsc_fin_indicator_lns c
         WHERE b.fin_statement_id = rsc_fin_statement_prj_pkg.get_fin_statement_id(a.fin_statement_templet_id,
                                                                                   ${/session/@company_id},
                                                                                   a.bp_id,
                                                                                   1)
               AND b.fin_indicator_id = c.fin_indicator_id
                AND A.BP_CATEGORY='GUARANTOR'
               AND A.BP_CLASS='ORG'
               AND A.BP_TYPE='GUTA_ORG'
               AND a.project_id = ${@project_id}) year_1,
 (SELECT a.*,c.indicator_code,c.indicator_name,c.indicator_value
          FROM (SELECT DISTINCT b.fin_statement_templet_id,
                                b.bp_id,
                                a.bp_category,
                                a.bp_class,
                                a.bp_type,
                                a.project_id
                  FROM prj_project_bp            a,
                       rsc_fin_indicator_hds b
                 WHERE a.bp_id = b.bp_id) a,
               rsc_fin_indicator_hds b,
               rsc_fin_indicator_lns c
         WHERE b.fin_statement_id = rsc_fin_statement_prj_pkg.get_fin_statement_id(a.fin_statement_templet_id,
                                                                                   ${/session/@company_id},
                                                                                   a.bp_id,
                                                                                   2)
               AND b.fin_indicator_id = c.fin_indicator_id
                AND A.BP_CATEGORY='GUARANTOR'
               AND A.BP_CLASS='ORG'
               AND A.BP_TYPE='GUTA_ORG'
               AND a.project_id = ${@project_id}) year_2,
 (SELECT a.*,c.indicator_code,c.indicator_name,c.indicator_value
          FROM (SELECT DISTINCT b.fin_statement_templet_id,
                                b.bp_id,
                                a.bp_category,
                                a.bp_class,
                                a.bp_type,
                                a.project_id
                  FROM prj_project_bp            a,
                       rsc_fin_indicator_hds b
                 WHERE a.bp_id = b.bp_id) a,
               rsc_fin_indicator_hds b,
               rsc_fin_indicator_lns c
         WHERE b.fin_statement_id = rsc_fin_statement_prj_pkg.get_fin_statement_id(a.fin_statement_templet_id,
                                                                                  ${/session/@company_id},
                                                                                   a.bp_id,
                                                                                   3)
               AND b.fin_indicator_id = c.fin_indicator_id
                AND A.BP_CATEGORY='GUARANTOR'
               AND A.BP_CLASS='ORG'
               AND A.BP_TYPE='GUTA_ORG'
               AND a.project_id = ${@project_id}) year_3,
(SELECT a.*,c.indicator_code,c.indicator_name,c.indicator_value
          FROM (SELECT DISTINCT b.fin_statement_templet_id,
                                b.bp_id,
                                a.bp_category,
                                a.bp_class,
                                a.bp_type,
                                a.project_id
                  FROM prj_project_bp            a,
                       rsc_fin_indicator_hds b
                 WHERE a.bp_id = b.bp_id) a,
               rsc_fin_indicator_hds b,
               rsc_fin_indicator_lns c
         WHERE b.fin_statement_id = rsc_fin_statement_prj_pkg.get_fin_statement_id(a.fin_statement_templet_id,
                                                                                   ${/session/@company_id},
                                                                                   a.bp_id,
                                                                                   4)
               AND b.fin_indicator_id = c.fin_indicator_id
                AND A.BP_CATEGORY='GUARANTOR'
               AND A.BP_CLASS='ORG'
               AND A.BP_TYPE='GUTA_ORG'
               AND a.project_id = ${@project_id}) year_4,
              rsc_fin_indicator_formula f
       where f.fin_statement_templet_id=year_1.fin_statement_templet_id
             and f.indicator_code=year_1.indicator_code(+)
             and f.indicator_code=year_2.indicator_code(+)
             and f.indicator_code=year_3.indicator_code(+)
             and f.indicator_code=year_4.indicator_code(+)
             order by f.line_number
             ) t1 #WHERE_CLAUSE#
             ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
