<?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
                    *
                FROM
                    (SELECT
                    	pp.project_id,
                        pp.bp_id_tenant,
                        (SELECT hbm.bp_name FROM hls_bp_master hbm WHERE hbm.bp_id = pp.bp_id_tenant
                        ) bp_name,
                        pp.project_number,
                        pp.project_name,
                        pp.employee_id,
                        (SELECT ee.name FROM exp_employees ee WHERE ee.employee_id = pp.employee_id
                        ) employee_name,
                        hn_csh_payment_req_pkg.get_prj_hn_payment_cond_status(p_project_id => pp.project_id) wfl_status,
                        (SELECT
                            v.code_value_name
                        FROM
                            sys_code_values_v v
                        WHERE
                            v.code       = 'CSH900_PRJ_CONDITION_STATUS' AND
                            v.code_value = hn_csh_payment_req_pkg.get_prj_hn_payment_cond_status(p_project_id => pp.project_id)
                        ) wfl_status_n
                    FROM
                        prj_project pp
                    WHERE
                        pp.project_status = 'APPROVED' AND
                        pp.data_class = 'NORMAL' 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.project_id desc
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
            begin
            hn_csh_payment_req_pkg.hn_payment_conditions_submit(p_hd_id =>${@hd_id},
                                         p_company_id =>${/session/@company_id},
                                         p_user_id    =>${/session/@user_id});
            end;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="contract_number" queryExpression="t1.contract_number like &apos;%&apos;||${@contract_number}||&apos;%&apos;"/>
        <bm:query-field name="contract_name" queryExpression="t1.contract_name like &apos;%&apos;||${@contract_name}||&apos;%&apos;"/>
        <bm:query-field name="bp_name" queryExpression="t1.bp_name like &apos;%&apos;||${@bp_name}||&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="employee_name" queryExpression="t1.employee_name like &apos;%&apos;||${@employee_name}||&apos;%&apos;"/>
        <bm:query-field name="wfl_status" queryExpression="t1.wfl_status=${@wfl_status}"/>
    </bm:query-fields>
</bm:model>
