<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei
    $Date: 2023-3-16 下午2:20:47
    $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,
			  t.invoice_kind,
              (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,
               t.tax_type_rate
          FROM vat_account_tmp t
          WHERE floor(t.session_id/10)=${/session/@session_id}
       ) t1
        #WHERE_CLAUSE#
         --order by invoice_hd_id,due_date ASC,invoice_line_id asc
		 order by invoice_hd_id, invoice_number asc, due_date ASC
   ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                  hl_cm_vat_report_pkg.vat_quarter_data_process(p_start_period =>${@start_period},
                                     p_end_period  =>${@end_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-field name="vat_6_flag" queryExpression="((${@vat_6_flag}='Y' and t1.tax_type_rate=0.06) or(${@vat_6_flag}!='Y' and t1.tax_type_rate!=0.06))"/>
    </bm:query-fields>
</bm:model>
