<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng  
    $Date: 2017-12-5 下午5:49:42  
    $Revision: 1.0  
    $Purpose: 项目变更
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t" baseTable="PRJ_PROJECT_CHANGE_REQ">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        t1.change_req_id,
                        t1.change_req_number,
                        t1.company_id,
                        t1.project_id,
                        t1.req_status,
                        t1.req_date,
                        t1.description,
                        t1.wfl_instance_id,
                        t1.owner_user_id,
                        t1.submit_date,
                        t1.approved_date,
                        t1.ref_v01,
                        t1.ref_v02,
                        t1.ref_v03,
                        t1.ref_v04,
                        t1.ref_v05,
                        t1.ref_n01,
                        t1.ref_n02,
                        t1.ref_n03,
                        t1.ref_n04,
                        t1.ref_n05,
                        t1.ref_d01,
                        t1.ref_d02,
                        t1.ref_d03,
                        t1.ref_d04,
                        t1.ref_d05,
                        t1.ccr_type,
                        t1.cdd_list_id,
                        (SELECT
                            v.code_value_name
                        FROM
                            sys_code_values_v v
                        WHERE
                            v.code       = 'CON_CHANGE_REQ_STATUS' AND
                            v.code_value = t1.req_status
                        ) AS req_status_n,
                        pp.project_number,
                        pp.project_name,
                        pp.bp_name,
                        pp.employee_name
                    FROM
                        prj_project_change_req t1,
                        prj_project_v pp
                    WHERE
                        t1.project_id  = pp.project_id AND
                        t1.req_status <> 'CANCEL' AND
                        EXISTS
                        (SELECT
                            1
                        FROM
                            aut_trx_user_authorize a1,
                            aut_owner_user_authorize a2
                        WHERE
                            a1.trx_category = 'PROJECT' AND
                            a1.trx_id       = pp.project_id AND
                            TRUNC(sysdate) BETWEEN a1.start_date AND NVL(a1.end_date, TRUNC(sysdate)) AND
                            a1.user_id            = a2.owner_user_id AND
                            a1.trx_category       = a2.trx_category AND
                            a2.authorized_user_id = ${/session/@user_id} AND
                            TRUNC(sysdate) BETWEEN a2.start_date AND NVL(a2.end_date, TRUNC(sysdate))
                        )
                    ) t #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="req_status"/>
        <bm:field name="req_status_n"/>
        <bm:field name="project_number"/>
        <bm:field name="project_name"/>
        <bm:field name="employee_name"/>
        <bm:field name="change_req_id"/>
        <bm:field name="project_id"/>
        <bm:field name="bp_name"/>
        <bm:field name="req_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="change_req_number"/>
        <bm:field name="description" databaseType="CLOB" datatype="java.sql.Clob" physicalName="DESCRIPTION"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="req_status" queryExpression="t.req_status = ${@req_status}"/>
        <bm:query-field name="project_number" queryExpression="t.project_number = ${@project_number}"/>
        <bm:query-field name="project_name" queryExpression="t.project_name = ${@project_name}"/>
        <bm:query-field name="employee_name" queryExpression="t.employee_name = ${@employee_name}"/>
    </bm:query-fields>
</bm:model>
