<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LR  
    $Date: 2013-7-17 下午01:25:56  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT t1.invoice_hd_id,
				       t1.document_number,
				        (select HB.INVOICE_SEND_ADDRESS from con_contract_bp ccb,hls_bp_master hb 
                where ccb.contract_id=t1.contract_id and ccb.bp_category='TENANT' 
                AND CCB.BP_ID=HB.BP_ID ) INVOICE_SEND_ADDRESS,
				       to_char(t1.invoice_date, 'yyyy-mm-dd') invoice_date,
				       t1.document_category,
				       t1.contract_id,
				       t1.contract_number,
				       t1.contract_name,
				       t1.project_id,
				       t1.project_number,
				       t1.project_name,
				       t1.invoice_bp_id,
				       t1.invoice_bp_code,
				       t1.invoice_bp_name,
				       t1.invoice_title,
				       t1.invoice_number,
				       t1.invoice_status,
				       t1.currency,
				       t1.business_type,
				       t1.business_type_desc,
				       t1.invoice_kind,
				       t1.invoice_kind_desc,
				       t1.document_type,
				       t1.created_by_name,
				       t1.created_by,
				       to_char(t1.accounting_date, 'yyyy-mm-dd') as accounting_date,
				       t1.total_amount,
				       t1.tax_amount,
				       t1.billing_method,
				       t1.lease_organization,
				       t1.lease_channel,
				       t1.division,
				       t1.company_id,
				       to_char(t1.express_date, 'yyyy-mm-dd') as express_date,
				       t1.express_status,
				       t1.express_status_desc,
				       t1.express_num,
				       t1.express_company,
				       t1.express_by,
				       t1.express_note,
				       t1.express_by_name,
				       t1.confirmed_by,
				       t1.confirmed_by_name
				  FROM acr_invoice_hd_v t1
                #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[
                DECLARE
				  r_acr_invoice_hd_rec acr_invoice_hd%rowtype;
				BEGIN
				  SELECT *
				    INTO r_acr_invoice_hd_rec
				    FROM acr_invoice_hd
				   WHERE invoice_hd_id = ${@invoice_hd_id}
				     FOR UPDATE nowait;
				  UPDATE acr_invoice_hd t1
				     SET t1.express_date     = to_date(${@express_date}, 'yyyy-mm-dd'),
				         t1.express_status   = ${@express_status},
				         t1.express_num      = ${@express_num},
				         t1.express_company  = ${@express_company},
				         t1.express_by       = ${@express_by},
				         t1.express_note     = ${@express_note},
				         t1.last_updated_by  = ${/session/@user_id},
				         t1.last_update_date = sysdate
				   WHERE t1.invoice_hd_id = ${@invoice_hd_id};
				END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="document_number_f" queryExpression="t1.document_number &gt;= ${@document_number_f}"/>
        <bm:query-field name="document_number_t" queryExpression="t1.document_number &lt;= ${@document_number_t}"/>
        <bm:query-field name="invoice_number_f" queryExpression="t1.invoice_number &gt;= ${@invoice_number_f}"/>
        <bm:query-field name="invoice_number_t" queryExpression="t1.invoice_number &lt;= ${@invoice_number_t}"/>
        <bm:query-field name="invoice_date_f" queryExpression="t1.invoice_date &gt;= to_date(${@invoice_date_f},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="invoice_date_t" queryExpression="t1.invoice_date &lt;= to_date(${@invoice_date_t},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="express_date_f" queryExpression="t1.express_date &gt;= to_date(${@express_date_f},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="express_date_t" queryExpression="t1.express_date &lt;= to_date(${@express_date_t},&apos;yyyy-mm-dd&apos;)"/>
        <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 &lt;= ${@total_amount_t}"/>
        <bm:query-field name="project_number_f" queryExpression="t1.project_number &gt;= ${@project_number_f}"/>
        <bm:query-field name="project_number_t" queryExpression="t1.project_number &lt;= ${@project_number_t}"/>
        <bm:query-field name="contract_number_f" queryExpression="t1.contract_number &gt;= ${@contract_number_f}"/>
        <bm:query-field name="contract_number_t" queryExpression="t1.contract_number &lt;= ${@contract_number_t}"/>
        <bm:query-field name="invoice_bp_code_f" queryExpression="t1.invoice_bp_code &gt;= ${@invoice_bp_code_f}"/>
        <bm:query-field name="invoice_bp_code_t" queryExpression="t1.invoice_bp_code &lt;= ${@invoice_bp_code_t}"/>
        <bm:query-field name="currency" queryExpression="t1.currency = ${@currency}"/>
        <bm:query-field name="business_type" queryExpression="t1.business_type = ${@business_type}"/>
        <bm:query-field name="invoice_kind" queryExpression="t1.invoice_kind = ${@invoice_kind}"/>
        <bm:query-field name="invoice_title" queryExpression="t1.invoice_title like ${@invoice_title}"/>
        <bm:query-field name="created_by" queryExpression="t1.created_by = ${@created_by}"/>
        <bm:query-field name="confirmed_by" queryExpression="t1.confirmed_by = ${@confirmed_by}"/>
        <bm:query-field name="received_flag" queryExpression="(nvl(t1.express_status,&apos;UNDELIVERED&apos;) !=&apos;RECEIVED&apos; or ${@received_flag}=&apos;Y&apos;)"/>
        <bm:query-field name="express_status" queryExpression="t1.express_status = ${@express_status}"/>
        <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.company_id =${/session/@company_id}"/>
        <bm:data-filter enforceOperations="query" expression="t1.invoice_status IN (&apos;CONFIRM&apos;, &apos;POST&apos;)"/>
        <bm:data-filter enforceOperations="query" expression="NVL(t1.reversed_flag, &apos;N&apos;) IN (&apos;N&apos;, &apos;R&apos;)"/>
        <bm:data-filter enforceOperations="query" expression="((t1.invoice_kind IN (&apos;0&apos;, &apos;2&apos;) AND t1.vat_interface_status = &apos;UNTRANSFERED&apos;) OR t1.invoice_kind = &apos;RECEIPT&apos;)"/>
    </bm:data-filters>
</bm:model>