<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: DJ  
    $Date: 2014-2-13 下午2:42:08  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
  select t1.* from (select to_number(to_char(sysdate, 'YYYYMM')) internal_period_num,
         to_char(sysdate, 'YYYY') || '-' || to_char(sysdate, 'MM') period_name,
         trunc(last_day(sysdate))end_date
  from dual
  union
  select to_number(to_char(add_months(sysdate, -1), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -1), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -1), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-1)))end_date
  from dual
   union
  select to_number(to_char(add_months(sysdate, -2), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -2), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -2), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-2)))end_date
  from dual
   union
  select to_number(to_char(add_months(sysdate, -3), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -3), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -3), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-3)))end_date
  from dual
  union
  select to_number(to_char(add_months(sysdate, -4), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -4), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -4), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-4)))end_date
  from dual
  union
  select to_number(to_char(add_months(sysdate, -5), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -5), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -5), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-5)))end_date
  from dual
  union
  select to_number(to_char(add_months(sysdate, -6), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -6), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -6), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-6)))end_date
  from dual
   union
  select to_number(to_char(add_months(sysdate, -7), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -7), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -7), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-7)))end_date
  from dual
   union
  select to_number(to_char(add_months(sysdate, -8), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -8), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -8), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-8)))end_date
  from dual
   union
  select to_number(to_char(add_months(sysdate, -9), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -9), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -9), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-9)))end_date
  from dual
   union
  select to_number(to_char(add_months(sysdate, -10), 'YYYYMM')) internal_period_num,
         to_char(add_months(sysdate, -10), 'YYYY') || '-' ||
         to_char(add_months(sysdate, -10), 'MM')  period_name,
         trunc(last_day(add_months(sysdate,-10)))end_date
  from dual
  order by internal_period_num desc) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>

        <bm:field name="period_name" displayWidth="120" forDisplay="true" forQuery="true" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PERIOD_NAME" prompt="GLD_PERIODS.PERIOD_NAME"/>
        <bm:field name="internal_period_num"  displayWidth="120" forDisplay="true" forQuery="true"  physicalName="INTERNAL_PERIOD_NUM" prompt="期间号"/>
        <bm:field name="end_date"  databaseType="DATE" datatype="java.util.Date" physicalName="END_DATE" prompt="截止日期"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="internal_period_num" queryExpression="t1.internal_period_num=${@internal_period_num}"/>
        <bm:query-field name="period_name" queryExpression="t1.period_name=${@period_name}"/>
    </bm:query-fields>
</bm:model>
