<?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 t.contract_id,
       t.company_id,
       t.business_type,     
       t.contract_number,
       t.contract_name,
       t.document_type,
       dt.document_type_desc,
       t.document_category,
       dt.document_category_desc,
       t.bp_id_tenant,
       b.bp_name,
       b.bp_code,
       p.project_name,
       to_char(t.inception_of_lease,'yyyy-mm-dd') inception_of_lease,
       p.employee_id,
       (select u.user_name from sys_user_v u where u.user_id=p.employee_id )employee_name,
       /* t.status,
       (select v.code_value_name
          from sys_code_values_v v
         where v.code = 'CON500_CONTRACT_STATUS'
           and v.code_value = t.status) as status_desc, */
           (select decode(count(*),0,'N','Y') from con_contract_cashflow f where f.contract_id =t.contract_id and f.overdue_status='Y') overdue_status
  FROM con_contract          t,
       prj_project           p,
       hls_bp_master         b,
       hls_document_type_v   dt
 #WHERE_CLAUSE#]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" required="true"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID" required="true"/>
        <bm:field name="business_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BUSINESS_TYPE" required="true"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER" required="true"/>
        <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NAME"/>
        <bm:field name="document_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_TYPE" required="true"/>
        <bm:field name="document_type_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_TYPE_DESC"/>
        <bm:field name="document_category" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_CATEGORY" required="true"/>
        <bm:field name="document_category_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_CATEGORY_DESC"/>
        <bm:field name="bp_id_tenant" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_TENANT" required="true"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME"/>
        <bm:field name="bp_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_CODE"/>
        <bm:field name="project_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_NAME"/>
        <bm:field name="inception_of_lease" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INCEPTION_OF_LEASE"/>
        <bm:field name="employee_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EMPLOYEE_ID"/>
        <bm:field name="employee_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EMPLOYEE_NAME"/>
        <bm:field name="overdue_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="OVERDUE_STATUS"/>
    </bm:fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t.project_id = p.project_id(+)    AND t.bp_id_tenant = b.bp_id(+)   and dt.document_type(+) = t.document_type"/>
    </bm:data-filters>
    <bm:query-fields>
        <bm:query-field name="contract_id" queryExpression="t.contract_id = ${@contract_id}"/>
        <bm:query-field name="date_from" datatype="java.lang.String" queryexpression="to_char(t.inception_of_lease,&apos;YYYY-MM-DD&apos;) &gt;= ${@date_from}"/>
        <bm:query-field name="date_to" datatype="java.lang.String" queryexpression="to_char(t.inception_of_lease,&apos;YYYY-MM-DD&apos;) &lt;= ${@date_from}"/>
        <bm:query-field name="contract_number" datatype="java.lang.String" queryexpression="t.contract_number=${@contract_number}"/>
        <bm:query-field name="contract_name" datatype="java.lang.String" queryexpression="t.contract_name=${@contract_name}"/>
        <bm:query-field name="bp_code" datatype="java.lang.String" queryexpression="b.bp_code=${@bp_code}"/>
        <bm:query-field name="project_number" datatype="java.lang.String" queryexpression="p.project_number=${@project_number}"/>
        <bm:query-field name="project_id" datatype="java.lang.String" queryexpression="p.project_id=${@project_id}"/>
        <bm:query-field name="document_category" datatype="java.lang.String" queryexpression="t.document_category=${@document_category}"/>
        <bm:query-field name="document_type" datatype="java.lang.String" queryexpression="t.document_type=${@document_type}"/>
        <bm:query-field name="user_id" datatype="java.lang.String" queryexpression="p.employee_id=${@user_id}"/>
    </bm:query-fields>
</bm:model>
