<?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 t1.*
                FROM (SELECT li.line_id,
                li.error_message,
                li.status,
                li.header_id,
                li.line_number,
                hd.created_by,
                li.source_table,
                li.attribute_1,
                li.attribute_2,
                li.attribute_3,
                li.attribute_4,
                li.attribute_5,
                li.attribute_6,
                round(li.attribute_7,2) attribute_7,
                round(li.attribute_8,2) attribute_8,
                li.attribute_9,
                li.attribute_10,
                li.attribute_11,
                li.attribute_12,
                nvl((select 'Y' from dual where exists(select 1 from con_lease_item_gps cli,con_contract cc where period = to_char(to_date(li.ATTRIBUTE_6,'yyyy-mm'),'yyyy-mm')
                and cli.contract_id = cc.contract_id and cc.contract_number = li.ATTRIBUTE_1)),'N') exists_flag
                FROM fnd_interface_headers hd, fnd_interface_lines li
                WHERE hd.header_id = li.header_id
                AND hd.template_code = 'HLS_LEASE_ITEM_GPS_IMPORT'
                AND li.line_number > 0
                AND HD.CREATED_BY = ${/session/@user_id}
                AND hd.header_id=${/parameter/@header_id}) t1
                order by t1.line_number
                ]]>
            </bm:query-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
            begin
                con_lease_item_gps_pkg.gps_import_check(p_header_id => ${/model/header/record/@header_id},
                                                        p_user_id => ${/session/@user_id});
            end;
            ]]>
            </bm:update-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
            BEGIN
                con_lease_item_gps_pkg.gps_import(
                        p_header_id => ${@header_id},
                        p_user_id => ${/session/@user_id});
            END;
            ]]>
            </bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="error_message"/>
        <bm:field name="status"/>
        <bm:field name="header_id"/>
        <bm:field name="line_number"/>
        <bm:field name="attribute_1"/>
        <bm:field name="attribute_2"/>
        <bm:field name="attribute_3"/>
        <bm:field name="attribute_4"/>
        <bm:field name="attribute_5"/>
        <bm:field name="attribute_6"/>
        <bm:field name="attribute_7"/>
        <bm:field name="attribute_8"/>
        <bm:field name="attribute_9"/>
        <bm:field name="attribute_10"/>
        <bm:field name="attribute_11"/>
        <bm:field name="attribute_12"/>
        <bm:field name="exists_flag"/>
    </bm:fields>
</bm:model>
