<?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.document_number,
                        t1.contract_id,
                        t1.contract_number,
                        t1.contract_name,
                        t2.cf_item,
                        t2.write_off_flag,
                        t1.total_amount,
                        t1.invoice_title,
                        t1.invoice_kind,
				        t1.invoice_kind_desc,
				        t1.invoice_status,
				        t1.invoice_status_desc,
				        t1.invoice_code,
				        t1.invoice_number,
				        t1.bp_agent_name,
				        t1.vat_invoice_code,
				        TO_CHAR(t1.invoice_date, 'yyyy-mm-dd') as invoice_date,
				        t1.invoice_bp_id,
				        t1.invoice_bp_code,
				        t1.invoice_bp_name,
				        t1.tax_amount,
				        t1.net_amount,
				        t1.currency,
				        t1.created_by_name,
				        t1.created_by,
                        t1.vat_interface_status_desc,
                        t1.vat_interface_status,
                        to_char(t1.accounting_date, 'yyyy-mm-dd') as accounting_date,
                        t1.CREATE_JE_FLAG,
                        t1.bp_tax_registry_num,
                        t1.claim_status,
                        t1.claim_status_n,
                        t2.cf_item_desc,
                        t1.invoice_hd_id
                        FROM acr_invoice_hd_v t1, acr_invoice_contract_cf_v t2
                        #WHERE_CLAUSE#
                ORDER BY t1.invoice_date desc , t1.document_number desc
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
            	    acr_invoice_claim_pkg.apply_invoice(p_invoice_hd_id 	=> ${@invoice_hd_id},
            	    								    p_user_id 			=> ${/session/@user_id});
            	END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="total_amount_f" queryExpression="t1.total_amount &gt;= ${@total_amount_f}"/>
        <bm:query-field name="total_amount_t" queryExpression="t1.total_amount &gt;= ${@total_amount_t}"/>
        <bm:query-field name="invoice_kind_desc" queryExpression="t1.invoice_kind_desc = ${@invoice_kind_desc}"/>
        <bm:query-field name="invoice_status_desc" queryExpression="t1.invoice_status_desc = ${@invoice_status_desc}"/>
        <bm:query-field name="claim_status" queryExpression="t1.claim_status = ${@claim_status}"/>
        <bm:query-field name="claim_status_n" queryExpression="t1.claim_status_n = ${@claim_status_n}"/>

        <bm:query-field name="cf_item_desc" queryExpression="t1.cf_item_desc = ${@cf_item_desc}"/>
        <bm:query-field name="document_number" queryExpression="t1.document_number = ${@document_number}"/>
        <bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/>
        <bm:query-field name="contract_name" queryExpression="t1.contract_name = ${@contract_name}"/>
        <bm:query-field name="invoice_title" queryExpression="t1.invoice_title = ${@invoice_title}"/>
        <bm:query-field name="invoice_code" queryExpression="t1.invoice_code = ${@invoice_code}"/>
        <bm:query-field name="invoice_number" queryExpression="t1.invoice_number = ${@invoice_number}"/>

        <bm:query-field name="query_contract_number" queryExpression="exists     (select 1            from hls_document_flow_all_v df, con_contract cc           where df.contract_id = cc.contract_id             and df.ar_invoice_hd_id = t1.invoice_hd_id             and cc.contract_number between nvl(${@contract_number_f}, cc.contract_number) and nvl(${@contract_number_t}, cc.contract_number))"/>
        <bm:query-field name="query_project_number" queryExpression="exists     (select 1           from hls_document_flow_all_v df, prj_project pp          where df.ar_invoice_hd_id = t1.invoice_hd_id            and df.project_id = pp.project_id            and pp.project_number between nvl(${@project_number_f}, pp.project_number) and nvl(${@project_number_t}, pp.project_number))"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.contract_id = t2.contract_id"/>
        <bm:data-filter enforceOperations="query" expression="t2.write_off_flag = &apos;FULL&apos;"/>
        <bm:data-filter enforceOperations="query" expression="t1.vat_interface_status = &apos;BACK&apos;"/>
<!--        <bm:data-filter name="query" expression="rownum &lt;=1000"/>-->
    </bm:data-filters>
</bm:model>
