<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    DECODE(tmp.ln_count,1,tmp.contract_name,tmp.contract_name
                    ||'等') contract_name,
                    DECODE(tmp.ln_count,1,tmp.employee_name,tmp.employee_name
                    ||'等') employee_name,
                    DECODE(tmp.ln_count,1,tmp.unit_name,tmp.unit_name
                    ||'等') unit_name,
                    DECODE(tmp.ln_count,1,tmp.five_class_name,tmp.five_class_name
                    ||'等') five_class_name,
                    DECODE(tmp.ln_count,1,tmp.estimate_date,tmp.estimate_date
                    ||'等') estimate_date,
                    DECODE(tmp.ln_count,1,tmp.overdue_max_days,tmp.overdue_max_days
                    ||'等') overdue_max_days,
                    DECODE(tmp.ln_count,1,tmp.description,tmp.description
                    ||'等') description
                FROM
                    (SELECT
                        c.contract_name,
                        c.employee_name,
                        c.unit_name,
                        (SELECT
                            rfc.description
                        FROM
                            rsc_five_class_code rfc
                        WHERE
                            rfc.five_class_code = r.five_class_code
                        ) five_class_name,
                        c.five_class_code_n original_five_class_name,
                        TO_CHAR(r.estimate_date,'yyyy-mm-dd') estimate_date,
                        TO_CHAR(c.overdue_max_days) overdue_max_days,
                        r.description,
                        (SELECT
                            COUNT(*)
                        FROM
                            rsc_fc_estimate_result rfc
                        WHERE
                            rfc.fc_estimate_id = h.fc_estimate_id
                        ) ln_count
                    FROM
                        rsc_fc_estimate h,
                        rsc_fc_estimate_result r,
                        con_contract_v c
                    WHERE
                        h.fc_estimate_id      = r.fc_estimate_id AND
                        r.contract_id         = c.contract_id AND
                        h.fc_estimate_id      = ${@document_id} AND
                        ${@document_category} = 'RSC_REQ'
                    ORDER BY
                        r.RESULT_ID
                    ) tmp
                WHERE
                    rownum=1
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
