<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ZLF  
    $Date: 2015-1-21 下午3:09:38  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
           select * from (
              SELECT t.contract_id,
              t.invoice_hd_id,
              t.invoice_line_id,
              (SELECT v.code_value_name
                               FROM sys_code_values_v v
                              WHERE v.code = 'ACR510_INVOICE_KIND'
                                AND v.code_value = t.invoice_kind)invoice_kind_n,
               t.cashflow_id,
               t.tax_apply_month    invoice_month,
               t.invoice_date,
               t.invoice_number,
               t.invoice_tax_amount total_amount,
               t.apply_flag         for_invoice_flag,
               t.tenant_name        bp_name,
               t.contract_number,
               t.acr_tax_amount     return_tax_amount,
               t.journal_tax_amount amount_cr,
               t.journal_month      je_month,
               t.journal_date       je_date,
               t.journal_num,
               t.times,
               t.due_date,
               t.due_amount,
               t.principal,
               t.interest,
               t.tax_amount         vat_due_amount,
               t.created_by,
               t.creation_date,
               t.last_updated_by,
               t.last_update_date
          FROM vat_account_tmp t
          WHERE t.session_id=${/session/@session_id}
       ) t1
        #WHERE_CLAUSE#
         order by invoice_hd_id,due_date ASC,invoice_line_id asc
   ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                  acr_invoice_pkg.vat_account_data_process(p_base_period => ${@base_period},
                                                           p_session_id =>  ${/session/@session_id},
                                                           p_user_id => ${/session/@user_id}  );
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:data-filters>
<!--        <bm:data-filter enforceOperations="query" expression="to_char(t1.invoice_date,'yyyymm') = ${@base_period}"/>-->
    </bm:data-filters>
    <bm:query-fields>
        <bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/>
        <bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/>
<!--        <bm:query-field name="journal_date" queryExpression="to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"/>-->
        <bm:query-field name="invoice_date" queryExpression="to_char(t1.invoice_date,'yyyy-mm-dd') = ${@invoice_date}"/>
        <bm:query-field name="invoice_kind" queryExpression="t1.invoice_kind = ${@invoice_kind}"/>

    </bm:query-fields>
</bm:model>
