<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: 38823
    $Date: 2022-01-15
    $Revision: 1
    $Purpose:
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="insert">
            <bm:parameters>
                <bm:parameter name="asset_batch_id" output="true" outputPath="@asset_batch_id"/>
            </bm:parameters>
            <bm:update-sql><![CDATA[
        declare
        v_asset_batch_id  asset_management_fee_batch.asset_batch_id%TYPE := asset_management_fee_batch_s.nextval;
        begin
         ${@asset_batch_id} := v_asset_batch_id;
         insert into asset_management_fee_batch
                         (asset_batch_id,
                          instance_id,
                          wfl_status,
                          created_by,
                          creation_date,
                          last_updated_by,
                          last_update_date)
                          values
                          (v_asset_batch_id,
                           null,
                           null,
                           ${/session/@user_id},
                           sysdate,
                           ${/session/@user_id},
                           sysdate
                          );
        end;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
   update asset_management_fee amf
   set amf.asset_batch_id =${/parameter/@asset_batch_id},
   amf.last_updated_by = ${/session/@user_id},
   amf.last_update_date = sysdate
   where amf.asset_id = ${@asset_id}
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
            begin
              asset_management_fee_wfl_pkg.asset_wfl_start(p_asset_batch_id =>${/parameter/@asset_batch_id},
                                                          p_user_id =>${/session/@user_id});
            end;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="query">
            <bm:query-sql>
                select amf.*,
                (SELECT v.code_value_name
                FROM sys_code_values_v v
                WHERE v.code = 'WFL_STATUS'
                AND v.code_value = amf.wfl_status) AS wfl_status_n
                from asset_management_fee amf where amf.asset_batch_id=${@asset_batch_id}
            </bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
