<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT v.code_value AS value_code, v.code_value_name AS value_name
                FROM sys_code_values_v v
                WHERE v.code_enabled_flag = 'Y'
                AND v.code_value_enabled_flag = 'Y'
                AND v.code = 'ACR512_INVOICE_KIND_TYPE'
                AND EXISTS
                (SELECT 1
                FROM acr_invoice_create_tmp t
                WHERE t.record_id = ${/parameter/@record_id}
                AND t.invoice_type = 'PAPER'
                AND v.code_value IN ('PAPER_GENERAL','PAPER_SPECIAL'))
                UNION ALL
                SELECT v.code_value AS value_code, v.code_value_name AS value_name
                FROM sys_code_values_v v
                WHERE v.code_enabled_flag = 'Y'
                AND v.code_value_enabled_flag = 'Y'
                AND v.code = 'ACR512_INVOICE_KIND_TYPE'
                AND EXISTS (SELECT 1
                FROM acr_invoice_create_tmp t
                WHERE t.record_id = ${/parameter/@record_id}
                AND t.invoice_type = 'ECT'
                AND v.code_value IN ('ELECTRONIC_GENERAL','ELECTRONIC_SPECIAL'))
                UNION ALL
                SELECT v.code_value AS value_code, v.code_value_name AS value_name
                FROM sys_code_values_v v
                WHERE v.code_enabled_flag = 'Y'
                AND v.code_value_enabled_flag = 'Y'
                AND v.code = 'ACR512_INVOICE_KIND_TYPE'
                AND EXISTS (SELECT 1
                FROM acr_invoice_create_tmp t
                WHERE t.record_id = ${/parameter/@record_id}
                AND t.invoice_type not in('PAPER','ECT')
                AND v.code_value IN ('RECEIPT'))
                ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="value_code" />
        <bm:field name="value_name" />
    </bm:fields>
</bm:model>