<?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
                        hd.description,
                        hd.hd_id,
                        hd.note,
                        decode(hd.record_type,'CONTRACT','支付表'||hd.hd_detail,hd.hd_detail ) hd_detail,
                        hd.project_id,
                        hd.valid_from,
                        hd.valid_to,
                        hd.contract_id,
                        pp.bp_id_tenant,
                        hd.record_type,
                        (SELECT v.code_value_name FROM sys_code_values_v v WHERE v.code = 'PAYMENT_CON_HD_TYPE'
                        AND v.code_value = hd.record_type
                        ) record_type_n,
                        (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,
                        hd.wfl_status,
                        (SELECT
                            v.code_value_name
                        FROM
                            sys_code_values_v v
                        WHERE
                            v.code       = 'CSH900_CONDITION_STATUS' AND
                            v.code_value = hd.wfl_status
                        ) wfl_status_n FROM hn_con_payment_con_hd hd,
                        prj_project pp WHERE hd.data_class = 'NORMAL' AND pp.data_class = 'NORMAL' AND hd.project_id = pp.project_id AND pp.project_id = ${@project_id}
                    ) t1 #WHERE_CLAUSE# order by t1.hd_detail
            ]]></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="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>
