<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
    	        SELECT
    	            *
    	        FROM
    	            (SELECT
    	                t1.contract_number,
    	                t1.search_term_1,
    	                (SELECT
    	                    a.bp_name
    	                FROM
    	                    hls_bp_master a
    	                WHERE
    	                    a.bp_id = t1.bp_id_tenant
    	                ) AS bp_name,
    	                (SELECT
                            bp_name
                        FROM
                            hls_bp_master
                        WHERE
                            bp_id =
                            (SELECT
                                bp_id
                            FROM
                                con_contract_bp
                            WHERE
                                bp_category = 'VENDER' AND
                                contract_id = t1.contract_id AND
                                rownum      =1
                            )
                        ) AS bp_name_vender,
    	                (SELECT
                            a.code_value_name
                        FROM
                            sys_code_values_v a
                        WHERE
                            a.code_value = t1.delivery_cycle and a.code = 'ACR522_AR_DELIVERY_CYCLE'
                            and code_value_enabled_flag = 'Y' and code_enabled_flag = 'Y'
                        ) AS express_cycle,
                        t1.contract_id
    	            FROM
    	                con_contract t1
                  where t1.data_class = 'NORMAL'
    	            ) t #WHERE_CLAUSE#
	        ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:parameters>
                <bm:parameter name="delivery_cycle" dataType="java.lang.Long" forInsert="true" forUpdate="true" required="true"/>
                <bm:parameter name="contract_id" dataType="java.lang.Long" required="true"/>
            </bm:parameters>
            <bm:update-sql><![CDATA[
                UPDATE
                    con_contract
                SET
                    delivery_cycle   = ${@delivery_cycle},
                    creation_date    = sysdate,
                    created_by	     = ${/session/@user_id},
                    last_update_date = sysdate,
                    last_updated_by  = ${/session/@user_id}
                WHERE
                    contract_id = ${@contract_id}
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
            begin
                acr_invoice_pkg.import_maintain_info(p_batch_id	 =>${@header_id},
                									 p_user_id	 =>${/session/@user_id});
            end;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="search_term_1" queryExpression="t.search_term_1 = ${@search_term_1}"/>
        <bm:query-field name="bp_name" queryExpression="t.bp_name = ${@bp_name}"/>
        <bm:query-field name="bp_name_vender" queryExpression="t.bp_name_vender = ${@bp_name_vender}"/>
        <bm:query-field name="express_cycle" queryExpression="t.express_cycle = ${@express_cycle}"/>
        <bm:query-field name="serial_number" queryExpression="t.contract_id in (select contract_id from con_contract_lease_item where serial_number = ${@serial_number})"/>
    </bm:query-fields>
</bm:model>
