<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                select fin_statement_id,
                       fin_statement_templet_id,
                       fin_statement_templet_code,
                       fin_statement_templet_name,
                       bp_id,
                       bp_code,
                       bp_name,
                       bp_category,
                       bp_type,
                       project_id,
                       project_number,
                       project_name,
                       currency_code,
                       currency_name,
                       fiscal_year,
                       fiscal_month,
                       (fiscal_year || '年' || fiscal_month || '月') fiscal_date,
                       '审批通过' status
                  from RSC_FIN_STATEMENT_PRJ_HDS_V t
                 where t.bp_id is not null
                   and exists
                 (select 1
                          from RSC_FIN_STATEMENT_PRJ_HDS_V t1
                         where t1.bp_code = t.bp_code
                           and t1.project_id = ${/parameter/@project_id}
                           and to_char(to_date(t1.fiscal_year || t1.fiscal_month, 'yyyymm'),
                                       'yyyymm') =
                               to_char(add_months(to_date(t.fiscal_year || t.fiscal_month,
                                                          'yyyymm'),
                                                  1),
                                       'yyyymm'))
                   and not exists
                 (select 1
                          from RSC_FIN_STATEMENT_PRJ_HDS_V t1
                         where t1.bp_code = t.bp_code
                           and t1.project_id = ${/parameter/@project_id}
                           and to_char(to_date(t1.fiscal_year || t1.fiscal_month, 'yyyymm'),
                                       'yyyymm') =
                               to_char(to_date(t.fiscal_year || t.fiscal_month, 'yyyymm'),
                                       'yyyymm'))
                 order by fiscal_year,fiscal_month
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
