<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: jack  
    $Date: 2014-6-6 下午3:58:51  
    $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 * from(
            SELECT a.*,
         round(a.amount,2)           amount1,
       round(b.amount,2)             amount2,
       round(c.amount,2)             amount3,
       round(d.amount,2)             amount4
  FROM (SELECT a.*,
               c.amount,
               c.line_number,
               c.fin_statement_type,
               c.fin_statement_item
          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_statement_prj_hds b
                 WHERE a.bp_id = b.bp_id) a,
               rsc_fin_statement_prj_hds b,
               rsc_fin_statement_prj_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_statement_id = c.fin_statement_id
                AND A.BP_CATEGORY='TENANT'
               AND A.BP_CLASS='HOS'
    
               AND a.project_id = ${@project_id}) a,
       (SELECT a.*,
               c.amount,
               c.fin_statement_type,
               c.fin_statement_item
          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_statement_prj_hds b
                 WHERE a.bp_id = b.bp_id) a,
               rsc_fin_statement_prj_hds b,
               rsc_fin_statement_prj_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_statement_id = c.fin_statement_id
                AND A.BP_CATEGORY='TENANT'
               AND A.BP_CLASS='HOS'
               AND a.project_id = ${@project_id}) b,
       (SELECT a.*,
               c.amount,
               c.fin_statement_type,
               c.fin_statement_item
          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_statement_prj_hds b
                 WHERE a.bp_id = b.bp_id) a,
               rsc_fin_statement_prj_hds b,
               rsc_fin_statement_prj_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_statement_id = c.fin_statement_id
                AND A.BP_CATEGORY='TENANT'
               AND A.BP_CLASS='HOS'
               AND a.project_id = ${@project_id}) c,
       (SELECT a.*,
               c.amount,
               c.fin_statement_type,
               c.fin_statement_item
          FROM (SELECT DISTINCT b.fin_statement_templet_id,
                                b.bp_id,
                                a.bp_category,
                                A.BP_TYPE,
                                a.bp_class,
                                a.project_id
                  FROM prj_project_bp            a,
                       rsc_fin_statement_prj_hds b
                 WHERE a.bp_id = b.bp_id) a,
               rsc_fin_statement_prj_hds b,
               rsc_fin_statement_prj_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_statement_id = c.fin_statement_id
                 AND A.BP_CATEGORY='TENANT'
               AND A.BP_CLASS='HOS'
               AND a.project_id = ${@project_id}) d
 WHERE a.fin_statement_type = b.fin_statement_type
       AND a.fin_statement_item = b.fin_statement_item
       AND a.bp_id = b.bp_id
       AND b.fin_statement_item = c.fin_statement_item
       AND b.fin_statement_type = c.fin_statement_type
       AND b.bp_id = c.bp_id
       AND c.fin_statement_item = d.fin_statement_item
       AND c.fin_statement_type = d.fin_statement_type
       AND c. bp_id = d.bp_id order by a.line_number ) t1  ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
