<?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
                    t1.project_number,
                    t1.project_id,
                    t2.cdd_item_id,
                    t3.check_id,
                    t1.bp_name,
                    t2.description,
                    (SELECT
                        COUNT(1)
                    FROM
                        fnd_atm_attachment_multi t,
                        fnd_atm_attachment faa
                    WHERE
                        t.table_name          = 'PRJ_CDD_ITEM_CHECK' AND
                        t.attachment_id       = faa.attachment_id AND
                        upper(faa.mime_type) IN ('IMAGE/PNG', 'IMAGE/JPEG', 'IMAGE/JPG', 'IMAGE/BMP', 'IMAGE/GIF') AND
                        t.table_pk_value     IN
                        (SELECT
                            b.check_id
                        FROM
                            prj_cdd_item_check b
                        WHERE
                            b.cdd_item_id = t2.cdd_item_id
                        )
                    ) cdd_count
                FROM
                    prj_project_v t1,
                    prj_cdd_item t2,
                    prj_cdd_item_check t3
                WHERE
                    t1.cdd_list_id = t2.cdd_list_id AND
                    t2.cdd_item_id =t3.cdd_item_id AND
                    t1.project_id  = ${@project_id}
                ORDER BY
                    t1.project_id DESC
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="project_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_NUMBER"/>
        <bm:field name="project_id" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_ID"/>
        <bm:field name="cdd_item_id" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CDD_ITEM_ID"/>
        <bm:field name="check_id" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CHECK_ID"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION"/>
        <bm:field name="cdd_count" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CDD_COUNT"/>
    </bm:fields>
</bm:model>
