<?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 = 'DIVISION'
                AND EXISTS
                (SELECT 1
                FROM exp_emp_assign_e_v t
                WHERE t.user_id = ${/session/@user_id}
                AND unit_code IN ('9998')
                and PARENT_UNIT_ID = 1544
                AND v.code_value IN ('50'))
                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 = 'DIVISION'
                AND EXISTS (SELECT 1
                FROM exp_emp_assign_e_v t
                WHERE t.user_id = ${/session/@user_id}
                AND unit_code NOT IN ('9998')
                and PARENT_UNIT_ID = 1544
                AND v.code_value IN ('10', '20', '30', '40','91'))
                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 = 'DIVISION'
                AND EXISTS (SELECT 1
                FROM exp_emp_assign_e_v t
                WHERE t.user_id = ${/session/@user_id}
                and PARENT_UNIT_ID <> 1544
                AND v.code_value IN ('10', '20', '30', '40','50','70','80','90','91','92','99','60','95','93'))
                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 = 'DIVISION'
                AND v.code_value IN ('10', '20', '30', '40','50','70','80','90','91','92','99','60','95','93')
                AND NOT EXISTS (SELECT 1
                FROM exp_emp_assign_e_v t
                WHERE t.user_id = ${/session/@user_id}
                )
                ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="value_code" />
        <bm:field name="value_name" />
    </bm:fields>
</bm:model>
