<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-6-7 下午03:31:05  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="RSC_FIN_STATEMENT_PRJ_LNS_V" defaultOrderBy="fin_statement_type,line_number">
    <!-- <bm:fields>
        <bm:field name="fin_statement_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FIN_STATEMENT_ID" prompt="RSC_FIN_STATEMENT_PRJ_LNS_V.FIN_STATEMENT_ID"/>
        <bm:field name="fin_statement_templet_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FIN_STATEMENT_TEMPLET_ID" prompt="RSC_FIN_STATEMENT_PRJ_LNS_V.FIN_STATEMENT_TEMPLET_ID"/>
        <bm:field name="fin_statement_templet_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FIN_STATEMENT_TEMPLET_CODE" prompt="RSC_FIN_STATEMENT_TMPLT_HDS.FIN_STATEMENT_TEMPLET_CODE"/>
        <bm:field name="fin_statement_templet_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FIN_STATEMENT_TEMPLET_NAME" prompt="RSC_FIN_STATEMENT_TMPLT_HDS.FIN_STATEMENT_TEMPLET_NAME"/>
        <bm:field name="bp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID" prompt="RSC_FIN_STATEMENT_PRJ_LNS_V.BP_ID"/>
        <bm:field name="bp_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_CODE" prompt="HLS.BP_CODE"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME" prompt="HLS.BP_NAME"/>
        <bm:field name="bp_category" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_CATEGORY" prompt="RSC_FIN_STATEMENT_PRJ_LNS_V.BP_CATEGORY"/>
        <bm:field name="bp_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_TYPE" prompt="RSC_FIN_STATEMENT_PRJ_LNS_V.BP_TYPE"/>
        <bm:field name="fin_statement_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FIN_STATEMENT_TYPE" prompt="RSC_FIN_STATEMENT_TMPLT_LNS.FIN_STATEMENT_TYPE"/>
        <bm:field name="amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="AMOUNT" prompt="HLS.AMOUNT"/>
        <bm:field name="fin_statement_item" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FIN_STATEMENT_ITEM" prompt="RSC_FIN_STATEMENT_TMPLT_LNS.FIN_STATEMENT_ITEM"/>
        <bm:field name="is_asset" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="IS_ASSET" prompt="RSC_FIN_STATEMENT_TMPLT_LNS.IS_ASSET"/>
        <bm:field name="item_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ITEM_TYPE" prompt="RSC_FIN_STATEMENT_TMPLT_LNS.ITEM_TYPE"/>
        <bm:field name="line_number" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LINE_NUMBER" prompt="RSC_FIN_STATEMENT_TMPLT_LNS.LINE_NUMBER"/>
        <bm:field name="plus_minus" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PLUS_MINUS" prompt="RSC_FIN_STATEMENT_TMPLT_LNS.PLUS_MINUS"/>
        <bm:field name="project_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PROJECT_ID" prompt="RSC_FIN_STATEMENT_TMPLT_LNS.PROJECT_ID"/>
        <bm:field name="project_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_NUMBER" prompt="RSC501.PRJ_PROJECT.PROJECT_NUMBER"/>
        <bm:field name="project_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_NAME" prompt="RSC501.PRJ_PROJECT.PROJECT_NAME"/>
        
        <bm:field name="creation_date" databaseType="DATA" datatype="java.util.Date" physicalName="CREATION_DATE"/>
        <bm:field name="fiscal_year" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FISCAL_YEAR"/>
    </bm:fields> -->
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                
 select ${@fin_statement_templet_id} fin_statement_templet_id,${@bp_id} bp_id,tl.line_number,tl.fin_statement_item,tl.fin_statement_type,tl.account_type,tl.item_desc,
       year_1.amount as first_year_amount,
       year_1.amount_adj as first_year_amount_adj,
       year_1.amount_after_adj as first_year_amount_after_adj,
       year_1.description  as first_year_description,
       year_2.amount as second_year_amount,
       year_2.amount_adj as second_year_amount_adj,
       year_2.amount_after_adj as second_year_amount_after_adj,
       year_2.description  as second_year_description,
       year_3.amount as third_year_amount,
       year_3.amount_adj as third_year_amount_adj,
       year_3.amount_after_adj as third_year_amount_after_adj,
       year_3.description  as third_year_description,
       year_4.amount as fourth_year_amount  ,
       year_4.amount_adj as fourth_year_amount_adj,
       year_4.amount_after_adj as fourth_year_amount_after_adj,
       year_4.description  as fourth_year_description,
       tl.item_type   
  from rsc_fin_statement_tmplt_lns tl,
  (select *
    from rsc_fin_statement_prj_lns l
   where l.fin_statement_id = rsc_fin_statement_prj_pkg.get_fin_statement_id(${@fin_statement_templet_id},${/session/@company_id},${@bp_id},1,${@project_id}) ) year_4,
   (select *
    from rsc_fin_statement_prj_lns l
   where l.fin_statement_id = rsc_fin_statement_prj_pkg.get_fin_statement_id(${@fin_statement_templet_id},${/session/@company_id},${@bp_id},2,${@project_id}) ) year_3,
   (select *
    from rsc_fin_statement_prj_lns l
   where l.fin_statement_id = rsc_fin_statement_prj_pkg.get_fin_statement_id(${@fin_statement_templet_id},${/session/@company_id},${@bp_id},3,${@project_id}) ) year_2,
   (select *
    from rsc_fin_statement_prj_lns l 
   where l.fin_statement_id = rsc_fin_statement_prj_pkg.get_fin_statement_id(${@fin_statement_templet_id},${/session/@company_id},${@bp_id},4,${@project_id}) ) year_1
 where tl.fin_statement_templet_id = ${@fin_statement_templet_id}
   and tl.fin_statement_type = ${@fin_statement_type}
   and tl.fin_statement_type = year_1.fin_statement_type(+)
   and tl.fin_statement_item = year_1.fin_statement_item(+)
   and tl.fin_statement_item = year_2.fin_statement_item(+)
   and tl.fin_statement_type = year_2.fin_statement_type(+)
   and tl.fin_statement_item = year_3.fin_statement_item(+)
   and tl.fin_statement_type = year_3.fin_statement_type(+)
   and tl.fin_statement_item = year_4.fin_statement_item(+)
   and tl.fin_statement_type = year_4.fin_statement_type(+)
   order by  tl.line_number

            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
        		begin
        		
				  rsc_fin_statement_prj_pkg.upd_fin_statement_prj_amount( p_fin_statement_templet_id=>${@fin_statement_templet_id},
              p_bp_id=>${@bp_id},
              p_user_id=>${/session/@user_id},
              p_company_id => ${/session/@company_id},
              p_fin_statement_item=>${@fin_statement_item},
              p_first_year_amount_adj=>${@first_year_amount_adj},
              p_first_year_amount_after_adj=>${@first_year_amount_after_adj},
              p_second_year_amount_adj=>${@second_year_amount_adj},
              p_second_year_amount_after_adj=>${@second_year_amount_after_adj},
              p_third_year_amount_adj=>${@third_year_amount_adj},
              p_third_year_amount_after_adj=>${@third_year_amount_after_adj},
              p_fourth_year_amount_adj=>${@fourth_year_amount_adj},
              p_fourth_year_amount_after_adj=>${@fourth_year_amount_after_adj},
              p_first_year_description=>${@first_year_description},
              p_second_year_description=>${@second_year_description},
              p_third_year_description=>${@third_year_description},
              p_fourth_year_description=>${@fourth_year_description});

				end;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <!-- <bm:query-fields>
        <bm:query-field field="fin_statement_templet_id" queryOperator="="/>
        <bm:query-field field="bp_id" queryOperator="="/>
        <bm:query-field field="fin_statement_type" queryOperator="="/>
    </bm:query-fields> -->
</bm:model>
