<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2013-10-23 下午05:18:04  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features">
    <bm:features>
        <f:standard-who/>
        <s:bm-script><![CDATA[
            var cx = Packages.leaf.javascript.Context.getCurrentContext();
            Packages.leaf.plugin.script.engine.ScriptImportor.defineExternScript(cx, this, $ctx.getData(), "aut_authority_bm_validate.js");
        ]]></s:bm-script>
    </bm:features>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[select * from (
select p.project_id,
	   p.project_number,
       p.project_name,
       p.project_status,
       (select v.code_value_name
          from sys_code_values_v v
         where v.code = 'PRJ501_PRJ_STATUS'
           and v.code_value = p.project_status) project_status_desc,
       p.lease_organization,
       (select o.description
          from hls_lease_organization o
         where o.lease_organization = p.lease_organization) lease_organization_desc,
       p.employee_id,
       (select e.name
          from exp_employees e
         where e.employee_id = p.employee_id) employee_id_desc,
       p.chance_id,
       (select c.chance_number
          from prj_chance c
         where c.chance_id = p.chance_id) chance_number,
       p.lease_channel,
       (select l.description from hls_lease_channel l where l.lease_channel=p.lease_channel) lease_channel_desc,
       (select l.creation_date from hls_lease_channel l where l.lease_channel=p.lease_channel) lease_channel_create_date,
       p.lease_start_date,
       (select m.meeting_date
          from PRJ_PROJECT_MEETING m
         where m.meeting_id in
               (select a.meeting_id
                  from PRJ_PROJECT_APPROVAL a
                 where a.approval_count = 1
                   and a.project_id = p.project_id)) meeting_date_one,
       (select v.code_value_name
          from sys_code_values_v v
         where v.code='PRJ_PROJECT_APPLY_RESULT' and v.code_value in
               (select a.approval_result
                  from PRJ_PROJECT_APPROVAL a
                 where a.approval_count = 1
                   and a.project_id = p.project_id)) approval_result_one,
       (select m.meeting_date
          from PRJ_PROJECT_MEETING m
         where m.meeting_id in
               (select a.meeting_id
                  from PRJ_PROJECT_APPROVAL a
                 where a.approval_count = 2
                   and a.project_id = p.project_id)) meeting_date_two,
       (select v.code_value_name
          from sys_code_values_v v
         where v.code='PRJ_PROJECT_APPLY_RESULT' and v.code_value in
               (select a.approval_result
                  from PRJ_PROJECT_APPROVAL a
                 where a.approval_count = 2
                   and a.project_id = p.project_id))  approval_result_two,
       
       p.approved_date,
       p.finance_amount finance_amount
  from prj_project p
   ) t1
   #WHERE_CLAUSE#
   order by t1.project_number desc
  ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="project_id"/>
        <bm:field name="project_number"/>
        <bm:field name="project_name"/>
        <bm:field name="project_status"/>
        <bm:field name="project_status_desc"/>
        <bm:field name="lease_organization"/>
        <bm:field name="lease_organization_desc"/>
        <bm:field name="employee_id"/>
        <bm:field name="employee_id_desc"/>
        <bm:field name="chance_id"/>
        <bm:field name="chance_number"/>
        <bm:field name="lease_channel"/>
        <bm:field name="lease_channel_desc"/>
        <bm:field name="lease_channel_create_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="lease_start_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="meeting_date_one" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="approval_result_one"/>
        <bm:field name="meeting_date_two" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="approval_result_two"/>
        <bm:field name="approved_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="finance_amount"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="project_id_from" queryExpression="t1.project_id &gt;= ${@project_id_from}"/>
        <bm:query-field name="project_id_to" queryExpression="t1.project_id &lt;= ${@project_id_to}"/>
        <bm:query-field field="lease_organization" queryOperator="="/>
        <bm:query-field field="employee_id" queryOperator="="/>
        <bm:query-field field="lease_channel" queryOperator="="/>
        <bm:query-field field="project_status" queryOperator="="/>
        <bm:query-field name="chance_id_from" queryExpression="t1.chance_id &gt;= ${@chance_id_from}"/>
        <bm:query-field name="chance_id_to" queryExpression="t1.chance_id &lt;= ${@chance_id_to}"/>
        <bm:query-field name="finance_amount_from" queryExpression="t1.finance_amount &gt;= ${@finance_amount_from}"/>
        <bm:query-field name="finance_amount_to" queryExpression="t1.finance_amount &lt;= ${@finance_amount_to}"/>
        <bm:query-field name="meeting_date_one_from" datatype="java.util.Date" queryexpression="t1.meeting_date_one &gt;= ${@meeting_date_one_from}"/>
        <bm:query-field name="meeting_date_one_to" datatype="java.util.Date" queryexpression="t1.meeting_date_one &lt;= ${@meeting_date_one_to}"/>
    </bm:query-fields>
</bm:model>
