<?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
  -- Call the procedure
  hn_csh_payment_req_hd_pkg.create_condition_change_req(p_project_id => ${@project_id},
                                                        p_req_date => sysdate,
                                                        p_description => ${@description},
                                                        p_user_id => ${/session/@user_id},
                                                        p_header_id => ${@header_id});
end;
            ]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="header_id" dataType="java.lang.Long" input="false" inputPath="@header_id" output="true" outputPath="/parameter/@header_id"/>
            </bm:parameters>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
          begin
  -- Call the procedure
  hn_csh_payment_req_hd_pkg.insert_change_req_ln(p_header_id => ${../../@header_id},
                                                 p_hd_id => ${@hd_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>
