<?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,con_contract cc
         WHERE t.record_id = ${/parameter/@record_id}
         and cc.contract_id=t.contract_id
          AND cc.business_type !='LEASEBACK'
           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,con_contract cc
         WHERE t.record_id = ${/parameter/@record_id}
          AND cc.business_type !='LEASEBACK'
           AND t.invoice_type = 'ECT'
           and cc.contract_id=t.contract_id
           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,con_contract cc
         WHERE t.record_id = ${/parameter/@record_id}
          AND cc.business_type !='LEASEBACK'
           AND t.invoice_type not in ('PAPER', 'ECT')
           and cc.contract_id=t.contract_id
           AND v.code_value IN ('RECEIPT'))
           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,con_contract cc
         WHERE t.record_id = ${/parameter/@record_id}
         and cc.contract_id=t.contract_id
           AND cc.business_type='LEASEBACK'
           AND v.code_value IN ('PAPER_GENERAL','ELECTRONIC_GENERAL'))
                ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="value_code" />
        <bm:field name="value_name" />
    </bm:fields>
</bm:model>