<?xml version="1.0" encoding="UTF-8"?>
<ns1:model xmlns:ns2="leaf.database.local.oracle" xmlns:ns1="http://www.leaf-framework.org/schema/bm">
    <ns1:operations>
        <ns1:operation name="execute">
            <ns1:parameters>
                <ns1:parameter name="type_code" dataType="java.lang.String" input="false" inputPath="@type_code" output="true" outputPath="/parameter/@type_code"/>
                <ns1:parameter name="attachment_id" dataType="java.lang.Long" input="false" inputPath="@attachment_id" output="true" outputPath="/parameter/@attachment_id"/>
            </ns1:parameters>
            <ns1:update-sql><![CDATA[
            	declare
            	    p_multi_attachment_id integer;
            	    p_attachment_id integer;
                begin
                    p_multi_attachment_id := fnd_fileupload.get_multi_attachment_id(
                        p_source_type        => ${/parameter/@source_type},
                        p_source_record_id   => ${/parameter/@pkvalue},
                        p_user_id            => nvl(${/session/@user_id},${@user_id})
                    );
                    p_attachment_id := fnd_fileupload.get_attachment_id(
                        p_source_type        => 'fnd_atm_attachment_multi',
                        p_pkvalue            => p_multi_attachment_id,
                        p_user_id            => nvl(${/session/@user_id},${@user_id})
                    );
                    ${@attachment_id} := p_attachment_id;
                    fnd_fileupload.set_attachment_file(
                        p_record_id        => p_attachment_id,
                        p_file_name        => ${/parameter/@file_name},
                        p_type_code        => ${@type_code}
                    );
                    update fnd_atm_attachment_multi set attachment_id = p_attachment_id where record_id = p_multi_attachment_id;
                    update fnd_atm_attachment t set t.file_size = ${/parameter/@file_size},t.created_by = nvl(${/session/@user_id},${@user_id}) where t.attachment_id = p_attachment_id;
                end;
            ]]></ns1:update-sql>
        </ns1:operation>
    </ns1:operations>
</ns1:model>
