<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm  
    $Date: 2013-7-24 下午7:37:27  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:update-sql><![CDATA[
                select f.indicator_type ,
       f.indicator_name ,
       f.line_number rnum,
       f.percent_flag,
       (select t.code_value_name from sys_code_values_v t where t.code ='INDICATOR_TYPE' and t.code_value=f.indicator_type ) indicator_type_desc,
       decode(f.percent_flag,'Y',to_char(year_1.indicator_value*100,'FM99999999990.00')||decode(year_1.indicator_value,null,'','%'),to_char(year_1.indicator_value,'FM99999999990.00')) first_year_value ,
       decode(f.percent_flag,'Y',to_char(year_2.indicator_value*100,'FM99999999990.00')||decode(year_2.indicator_value,null,'','%'),to_char(year_2.indicator_value,'FM99999999990.00')) second_year_value ,
       decode(f.percent_flag,'Y',to_char(year_3.indicator_value*100,'FM99999999990.00')||decode(year_3.indicator_value,null,'','%'),to_char(year_3.indicator_value,'FM99999999990.00')) third_year_value ,
       decode(f.percent_flag,'Y',to_char(year_4.indicator_value*100,'FM99999999990.00')||decode(year_4.indicator_value,null,'','%'),to_char(year_4.indicator_value,'FM99999999990.00')) fourth_year_value ,
       year_1.description
      
  from rsc_fin_indicator_formula f,
       (select l.*
          from rsc_fin_indicator_lns l, rsc_fin_indicator_hds h
         where h.fin_indicator_id = l.fin_indicator_id
           and h.fin_statement_id =rsc_fin_statement_prj_pkg.get_fin_statement_id(${@fin_statement_templet_id}, ${/session/@company_id}, ${@bp_id}, 1)) year_1,
        (select l.*
          from rsc_fin_indicator_lns l, rsc_fin_indicator_hds h
         where h.fin_indicator_id = l.fin_indicator_id
           and h.fin_statement_id =rsc_fin_statement_prj_pkg.get_fin_statement_id(${@fin_statement_templet_id}, ${/session/@company_id}, ${@bp_id}, 2)) year_2,
           (select l.*
          from rsc_fin_indicator_lns l, rsc_fin_indicator_hds h
         where h.fin_indicator_id = l.fin_indicator_id
           and h.fin_statement_id =rsc_fin_statement_prj_pkg.get_fin_statement_id(${@fin_statement_templet_id}, ${/session/@company_id}, ${@bp_id}, 3)) year_3,
           (select l.*
          from rsc_fin_indicator_lns l, rsc_fin_indicator_hds h
         where h.fin_indicator_id = l.fin_indicator_id
           and h.fin_statement_id =rsc_fin_statement_prj_pkg.get_fin_statement_id(${@fin_statement_templet_id}, ${/session/@company_id}, ${@bp_id}, 4)) year_4   
 where f.fin_statement_templet_id = ${@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
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
