<?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
                    *
                FROM
                    (SELECT
                        hd.invoice_hd_id,
                        ln.invoice_line_id,
                        hd.invoice_code,
                        hd.invoice_number,
                        cc.contract_number,
                        cc.contract_name,
                        hci.description cf_item_desc,
                        ccc.times,
                        ln.product_name,
                        hd.invoice_kind,
                        (SELECT
                            v.code_value_name
                        FROM
                            sys_code_values_v v
                        WHERE
                            v.code       = 'ACR510_INVOICE_KIND' AND
                            v.code_value = hd.invoice_kind
                        ) invoice_kind_desc,
                        hd.invoice_date,
                        hd.accounting_date,
                        hd.bp_id,
                        hbm.bp_name,
                        ccc.billing_amount,
                        hd.description
                    FROM
                        acp_invoice_hd hd,
                        acp_invoice_ln ln,
                        con_contract cc,
                        con_contract_cashflow ccc,
                        hls_cashflow_item hci,
                        hls_bp_master hbm
                    WHERE
                        hd.invoice_hd_id           = ln.invoice_header_id AND
                        hd.contract_id             = cc.contract_id AND
                        ln.cashflow_id             = ccc.cashflow_id AND
                        ccc.cf_item                = hci.cf_item AND
                        hd.bp_id                   = hbm.bp_id AND
                        NVL(hd.reversed_flag, 'N') = 'N' AND
                        cc.data_class              = 'NORMAL'
                    ) t1 #WHERE_CLAUSE#
                ORDER BY
                    t1.contract_number ,
                    t1.invoice_number DESC
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="invoice_hd_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="INVOICE_HD_ID"/>
        <bm:field name="invoice_date" databaseType="DATE" datatype="java.util.Date" physicalName="INVOICE_DATE"/>
        <bm:field name="invoice_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INVOICE_NUMBER"/>
        <!-- <bm:field name="document_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_NUMBER"/> -->
        <bm:field name="bp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME"/>
        <bm:field name="product_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PRODUCT_NAME"/>
        <!-- <bm:field name="total_amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TOTAL_AMOUNT"/> -->
        <!-- <bm:field name="net_amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="NET_AMOUNT"/> -->
        <!-- <bm:field name="tax_type_rate" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TAX_TYPE_RATE"/> -->
        <!-- <bm:field name="tax_amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TAX_AMOUNT"/> -->
        <!-- <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID"/> -->
        <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NAME"/>
        <bm:field name="contract_number"/>
        <bm:field name="invoice_line_id"/>
        <bm:field name="invoice_code"/>
        <bm:field name="cf_item_desc"/>
        <bm:field name="times"/>
        <bm:field name="invoice_kind_desc"/>
        <bm:field name="accounting_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="billing_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="description"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="bp_name" queryExpression="t1.bp_name like &apos;%&apos;||${@bp_name}||&apos;%&apos;"/>
        <bm:query-field name="invoice_code" queryExpression="t1.invoice_code like &apos;%&apos;||${@invoice_code}||&apos;%&apos;"/>
        <bm:query-field name="invoice_number" queryExpression="t1.invoice_number like &apos;%&apos;||${@invoice_number}||&apos;%&apos;"/>
        <bm:query-field name="cf_item_desc" queryExpression="t1.cf_item_desc like &apos;%&apos;||${@cf_item_desc}||&apos;%&apos;"/>
        <bm:query-field name="invoice_date_from" queryExpression="t1.invoice_date &gt;=to_date(${@invoice_date_from},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="invoice_date_to" queryExpression="t1.invoice_date &lt;=to_date(${@invoice_date_to},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="contract_name" queryExpression="t1.contract_name like &apos;%&apos;||${@contract_name}||&apos;%&apos;"/>
        <bm:query-field name="contract_number" queryExpression="t1.contract_number like ${@contract_number}"/>
        <bm:query-field name="billing_amount_from" queryExpression="t1.net_amount &gt;=${@net_amount_from}"/>
        <bm:query-field name="billing_amount_to" queryExpression="t1.net_amount &lt;=${@net_amount_to}"/>
        <bm:query-field name="accounting_date_from" queryExpression="t1.accounting_date &gt;=to_date(${@accounting_date_from},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="accounting_date_to" queryExpression="t1.accounting_date &lt;=to_date(${@accounting_date_to},&apos;yyyy-mm-dd&apos;)"/>
    </bm:query-fields>
</bm:model>
