<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        hac.record_id,
                        hac.config_id,
                        hac.document_id,
                        hac.document_id project_id,
                        hac.status,
                        (SELECT
                            v.code_value_name
                        FROM
                            sys_code_values_v v
                        WHERE
                            v.code      ='HN_ATM_COMPLEMENT_STATUS' AND
                            v.code_value=hac.status
                        ) status_desc,
                        hacs.screen_url,
                        hacs.url_desc,
                        hacc.function_code,
                        hacc.function_description,
                        hacc.document_category,
                        (SELECT
                            pp.project_number document_number
                        FROM
                            prj_project pp
                        WHERE
                            pp.project_id = hac.document_id
                            and pp.data_class='NORMAL'
                        UNION
                        SELECT
                            pp.virtual_con_number document_number
                        FROM
                            prj_project pp
                        WHERE
                            pp.project_id = hac.document_id
                            and pp.data_class='VIRTUAL_CON'
                        UNION
                        SELECT
                            cc.contract_number document_number
                        FROM
                            con_contract cc
                        WHERE
                            cc.contract_id = hac.document_id
                        UNION
                        SELECT
                            pc.chance_number document_number
                        FROM
                            prj_chance pc
                        WHERE
                            pc.chance_id = hac.document_id
                        ) document_number,
                        (SELECT
                            pp.project_name document_name
                        FROM
                            prj_project pp
                        WHERE
                            pp.project_id = hac.document_id
                            and pp.data_class='NORMAL'
                        UNION
                        SELECT
                            pp.virtual_con_name document_name
                        FROM
                            prj_project pp
                        WHERE
                            pp.project_id = hac.document_id
                            and pp.data_class='VIRTUAL_CON'
                        UNION
                        SELECT
                            cc.contract_name document_name
                        FROM
                            con_contract cc
                        WHERE
                            cc.contract_id = hac.document_id
                        UNION
                        SELECT
                            pc.project_name document_name
                        FROM
                            prj_chance pc
                        WHERE
                            pc.chance_id = hac.document_id
                        ) document_name,
                        (SELECT
                            '项目' document_type_desc
                        FROM
                            prj_project pp
                        WHERE
                            pp.project_id = hac.document_id
                            and pp.data_class='NORMAL'
                        UNION
                        SELECT
                            '合同' document_type_desc
                        FROM
                            prj_project pp
                        WHERE
                            pp.project_id = hac.document_id
                            and pp.data_class='VIRTUAL_CON'
                        UNION
                        SELECT
                            '支付表' document_type_desc
                        FROM
                            con_contract cc
                        WHERE
                            cc.contract_id = hac.document_id
                        UNION
                        SELECT
                            '立项' document_type_desc
                        FROM
                            prj_chance pc
                        WHERE
                            pc.chance_id = hac.document_id
                        ) document_type_desc,
                        hacc.approval_method,
                        hacc.table_name
                    FROM
                        hn_atm_complement hac,
                        hn_atm_complement_screen hacs,
                        hn_atm_complement_config hacc
                    WHERE
                        hacc.screen_id = hacs.screen_id AND
                        hacc.config_id = hac.config_id
                    ) t1 #WHERE_CLAUSE#
                    order by  record_id desc
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
                begin
                    hn_atm_complement_pkg.hn_atm_complement_insert(p_config_id =>${@config_id},
                                  p_document_id =>${@document_id},
                                  p_user_id     =>${/session/@user_id});
                end;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                begin
                    hn_atm_complement_pkg.hn_atm_complement_update(p_record_id =>${@record_id},
                                     p_config_id   =>${@config_id},
                                     p_document_id =>${@document_id},
                                     p_user_id     =>${/session/@user_id});
                end;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
                begin
                    hn_atm_complement_pkg.hn_atm_complement_delete(p_record_id =>${@record_id},
                                                                   p_user_id =>${/session/@user_id});
                end;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
                begin
                    hn_atm_complement_pkg.hn_atm_complement_submit(p_record_id =>${@record_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="config_id" queryExpression="t1.config_id=${@config_id}"/>
        <bm:query-field name="function_description" queryExpression="t1.function_description like &apos;%&apos;||${@function_description}||&apos;%&apos;"/>
        <bm:query-field name="document_number" queryExpression="t1.document_number like &apos;%&apos;||${@document_number}||&apos;%&apos;"/>
        <bm:query-field name="document_name" queryExpression="t1.document_name like &apos;%&apos;||${@document_name}||&apos;%&apos;"/>
        <bm:query-field name="status" queryExpression="t1.status=${@status}"/>
    </bm:query-fields>
    <bm:features>
        <s:bm-script><![CDATA[
            var cx = Packages.leaf.javascript.Context.getCurrentContext();
            Packages.leaf.plugin.script.engine.ScriptImportor.defineExternScript(cx, this, $ctx.getData(), "aut_authority_bm_validate.js");
        ]]></s:bm-script>
    </bm:features>
</bm:model>
