<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng  
    $Date: 2017-11-7 上午9:38:53  
    $Revision: 1.0  
    $Purpose: 付款先决条件变更头表
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="HN_PAYMENT_COND_CHANGE_HD">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
        SELECT
            *
        FROM
            (SELECT
                hd.header_id,
                hd.project_id,
                hd.change_req_number,
                hd.req_date,
                hd.wfl_instance_id,
                hd.req_status,
                hd.description,
                pp.project_number,
                pp.project_name,
                pp.bp_id_tenant,
                (SELECT hbm.bp_name FROM hls_bp_master hbm WHERE hbm.bp_id=pp.bp_id_tenant
                ) bp_name, --承租人名称
                pp.employee_id,
                (SELECT ee.name FROM exp_employees ee WHERE ee.employee_id = pp.employee_id
                ) manager --项目经理
            FROM
                hn_payment_cond_change_hd hd,
                prj_project pp
            WHERE
                hd.project_id  = pp.project_id AND
                hd.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))
                )
            ) t1 #WHERE_CLAUSE#
        ORDER BY
            t1.change_req_number
    ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="change_req_number" queryExpression="t1.change_req_number like &apos;%&apos;||${@change_req_number}||&apos;%&apos;"/>
        <bm:query-field name="project_number" queryExpression="t1.project_number like &apos;%&apos;||${@project_number}||&apos;%&apos;"/>
        <bm:query-field name="project_name" queryExpression="t1.project_name like &apos;%&apos;||${@project_name}||&apos;%&apos;"/>
        <bm:query-field name="bp_name" queryExpression="t1.bp_name like &apos;%&apos;||${@bp_name}||&apos;%&apos;"/>
        <bm:query-field name="manager" queryExpression="t1.manager like &apos;%&apos;||${@manager}||&apos;%&apos;"/>
        <bm:query-field name="req_status_n" queryExpression="t1.req_status like &apos;%&apos;||${@req_status}||&apos;%&apos;"/>
    </bm:query-fields>
</bm:model>
