<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: jack  
    $Date: 2014-6-6 下午4:37:14  
    $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.* from(  select year_1.*,  f.percent_flag, 
       decode(f.percent_flag,
              'Y',
              year_1.indicator_value * 100 || '%',
              'N',
              year_1.indicator_value) first_year_change_rate,
        decode(f.percent_flag,
              'Y',
              year_2.indicator_value * 100 || '%',
              'N',
              year_2.indicator_value) second_year_change_rate,
        decode(f.percent_flag,
              'Y',
              year_3.indicator_value * 100 || '%',
              'N',
              year_3.indicator_value) third_year_change_rate,
       decode(f.percent_flag,
              'Y',
              year_4.indicator_value * 100 || '%',
              'N',
              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/@compnay_id},
                                                                                   a.bp_id,
                                                                                   1)
               AND b.fin_indicator_id = c.fin_indicator_id
                AND A.BP_CATEGORY='TENANT'
               AND A.BP_CLASS='HOS'
               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/@compnay_id},
                                                                                   a.bp_id,
                                                                                   2)
               AND b.fin_indicator_id = c.fin_indicator_id
               AND A.BP_CATEGORY='TENANT'
               AND A.BP_CLASS='HOS'
               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/@compnay_id},
                                                                                   a.bp_id,
                                                                                   3)
               AND b.fin_indicator_id = c.fin_indicator_id
                AND A.BP_CATEGORY='TENANT'
               AND A.BP_CLASS='HOS'
               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/@compnay_id},
                                                                                   a.bp_id,
                                                                                   4)
               AND b.fin_indicator_id = c.fin_indicator_id
               AND A.BP_CATEGORY='TENANT'
               AND A.BP_CLASS='HOS'
               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(+)
             ) t1  #WHERE_CLAUSE#    ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
