<?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
                    t.*
                FROM
                    (SELECT
                        pm.description,
                        pf.check_id,
                        pf.document_table,
                        hls_sys_upload_pkg.get_atm_file_href(p_table_pk_value => pf.check_id, p_source_type => 'CSH_PAYMENT_DOC', p_user_id => ${/session/@user_id}) AS file_name,
                        pm.chance_required_flag,
                        pf.document_id,
                        pm.cdd_item_id,
                        pm.cdd_list_id,
                        pm.cdd_item,
                        pm.enabled_flag,
                        pm.note,
                        pm.note1,
                        pm.note3,
                        pf.created_by AS owner_id,
                        'N' AS delete_flag
                    FROM
                        PRJ_CDD_ITEM_TPLT_TAB_GROUP pp,
                        prj_cdd_item pm,
                        prj_cdd_item_tab_group gg,
                        con_contract ct,
                        prj_cdd_item_check ck,
                        prj_cdd_item_doc_ref pf
                    WHERE
                        gg.tab_group    = 'CSH_PAYMENT_DOC' AND
                        gg.tab_group_id = pp.tab_group_id AND
                        gg.enabled_flag = 'Y' AND
                        pp.cdd_item     = pm.cdd_item AND
                        ck.cdd_item_id  = pm.cdd_item_id AND
                        ct.cdd_list_id  = pm.cdd_list_id AND
                        ct.contract_id  = pf.document_id AND
                        pf.check_id     = ck.check_id AND
                        ct.contract_id  = ${@contract_id}
                    UNION ALL
                    SELECT
                        pm.description,
                        pf.check_id,
                        pf.document_table,
                        hls_sys_upload_pkg.get_atm_file_href(p_table_pk_value => pf.check_id, p_source_type => 'CSH_PAYMENT_DOC', p_user_id => ${/session/@user_id}) AS file_name,
                        pm.chance_required_flag,
                        pf.document_id,
                        pm.cdd_item_id,
                        pm.cdd_list_id,
                        pm.cdd_item,
                        pm.enabled_flag,
                        pm.note,
                        pm.note1,
                        pm.note3,
                        pf.created_by AS owner_id,
                        'Y' AS delete_flag
                    FROM
                        prj_cdd_item pm,
                        con_contract ct,
                        prj_cdd_item_check ck,
                        prj_cdd_item_doc_ref pf
                    WHERE
                        ck.cdd_item_id    = pm.cdd_item_id AND
                        ct.contract_id    = pf.document_id AND
                        pf.check_id       = ck.check_id AND
                        pf.document_table = 'CSH_PAYMENT_DOC' AND
                        ct.contract_id    = ${@contract_id}
                    )t
                ORDER BY
                    t.check_id
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            	BEGIN
            	    prj_cdd_item_pkg.prj_cdd_item_doc_ref_save(p_document_table =>${@document_table},
                                      p_document_id           =>${@document_id},
                                      p_attachment_tab_group_id=>${@tab_group_id},
                                      p_cdd_list_id           =>${@cdd_list_id},
                                      p_cdd_item              =>${@cdd_item},
                                      p_description           =>${@description},
                                      p_line_type             =>'FILE',
                                      p_order_seq             =>${@order_seq},
                                      p_show_seq              =>${@show_seq},
                                      p_enabled_flag          =>'Y',
                                      p_chance_required_flag=>${@chance_required_flag},
							          p_chance_display_flag=>${@chance_display_flag},
							          p_project_required_flag=>${@project_required_flag},
							          p_project_display_flag=>${@project_display_flag},
							          p_contract_required_flag=>${@contract_required_flag},
							          p_contract_display_flag=>${@contract_display_flag},
							          p_sign_required_flag=>${@sign_required_flag},
							          p_sign_display_flag=>${@sign_display_flag},
							          p_incept_required_flag=>${@incept_required_flag},
							          p_incept_display_flag=>${@incept_display_flag},
							          p_lender_required_flag=>${@lender_required_flag},
							          p_lender_display_flag=>${@lender_display_flag},
							          p_chance_tab_group=>${@chance_tab_group},
							          p_project_tab_group=>${@project_tab_group},
							          p_contract_tab_group=>${@contract_tab_group},
							          p_sign_tab_group=>${@sign_tab_group},
							          p_incept_tab_group=>${@incept_tab_group},
							          p_lender_tab_group=>${@lender_tab_group},
                                      p_sys_flag              =>${@sys_flag},
                                      p_note                  =>${@note},
                                      p_send_flag             =>${@send_flag},
                                      p_paper_required        =>${@paper_required},
                                      p_attachment_required   =>${@attachment_required},
                                      p_not_applicable        =>${@not_applicable},
                                      p_cdd_item_id           =>${@cdd_item_id},
                                      p_check_id              =>${@check_id},
                                      p_user_id  =>${/session/@user_id});
            	END;
        	]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="cdd_item_id" input="true" inputPath="@cdd_item_id" output="true" outputPath="@cdd_item_id"/>
                <bm:parameter name="check_id" input="true" inputPath="@check_id" output="true" outputPath="@check_id"/>
            </bm:parameters>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
            	BEGIN
            	    prj_cdd_item_pkg.prj_cdd_item_doc_ref_save(p_document_table =>${@document_table},
                                      p_document_id           =>${@document_id},
                                      p_attachment_tab_group_id=>${@tab_group_id},
                                      p_cdd_list_id           =>${@cdd_list_id},
                                      p_cdd_item              =>${@cdd_item},
                                      p_description           =>${@description},
                                      p_line_type             =>'FILE',
                                      p_order_seq             =>${@order_seq},
                                      p_show_seq              =>${@show_seq},
                                      p_enabled_flag          =>'Y',
                                      p_chance_required_flag=>${@chance_required_flag},
						              p_chance_display_flag=>${@chance_display_flag},
						              p_project_required_flag=>${@project_required_flag},
						              p_project_display_flag=>${@project_display_flag},
						              p_contract_required_flag=>${@contract_required_flag},
						              p_contract_display_flag=>${@contract_display_flag},
						              p_sign_required_flag=>'Y',
						              p_sign_display_flag=>'Y',
						              p_incept_required_flag=>${@incept_required_flag},
						              p_incept_display_flag=>${@incept_display_flag},
						              p_lender_required_flag=>${@lender_required_flag},
						              p_lender_display_flag=>${@lender_display_flag},
						              p_chance_tab_group=>${@chance_tab_group},
						              p_project_tab_group=>${@project_tab_group},
						              p_contract_tab_group=>${@contract_tab_group},
						              p_sign_tab_group=>${@sign_tab_group},
						              p_incept_tab_group=>${@incept_tab_group},
						              p_lender_tab_group=>${@lender_tab_group},
                                      p_sys_flag              =>'N',
                                      p_note                  =>${@note},
                                      p_send_flag             =>${@send_flag},
                                      p_paper_required        =>${@paper_required},
                                      p_attachment_required   =>${@attachment_required},
                                      p_not_applicable        =>${@not_applicable},
                                      p_cdd_item_id           =>${@cdd_item_id},
                                      p_check_id              =>${@check_id},
                                      p_user_id  =>${/session/@user_id});
            	END;
        	]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="cdd_item_id" input="true" inputPath="@cdd_item_id" output="true" outputPath="@cdd_item_id"/>
                <bm:parameter name="check_id" input="true" inputPath="@check_id" output="true" outputPath="@check_id"/>
            </bm:parameters>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
            	BEGIN
            	    prj_cdd_item_pkg.prj_cdd_item_doc_ref_delete(p_document_table =>${@document_table},
                                        p_document_id    =>${@document_id},
                                        p_attachment_tab_group_id=>${@tab_group_id},
                                        p_cdd_item_id    =>${@cdd_item_id},
                                        p_check_id       =>${@check_id},
                                        p_user_id        =>${/session/@user_id});
            	END;
        	]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="cdd_item_id" input="true" inputPath="@cdd_item_id" output="true" outputPath="@cdd_item_id"/>
                <bm:parameter name="check_id" input="true" inputPath="@check_id" output="true" outputPath="@check_id"/>
            </bm:parameters>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="document_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="DOCUMENT_ID"/>
        <bm:field name="document_table" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_TABLE"/>
        <bm:field name="cdd_item_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CDD_ITEM_ID"/>
        <bm:field name="cdd_list_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CDD_LIST_ID"/>
        <bm:field name="cdd_item" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CDD_ITEM"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION"/>
        <bm:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENABLED_FLAG"/>
        <bm:field name="note" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="NOTE"/>
        <bm:field name="note1" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="NOTE1"/>
        <bm:field name="note3" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="NOTE3"/>
        <bm:field name="check_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CHECK_ID"/>
        <bm:field name="file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_NAME"/>
        <!--  <bm:field name="sign_required_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SIGN_REQUIRED_FLAG"/>
        <bm:field name="contract_required_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_REQUIRED_FLAG"/>
        <bm:field name="lender_required_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LENDER_REQUIRED_FLAG"/>
        <bm:field name="incept_required_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INCEPT_REQUIRED_FLAG"/>
        <bm:field name="project_required_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_REQUIRED_FLAG"/> -->
        <bm:field name="owner_id"/>
        <bm:field name="delete_flag"/>
        <bm:field name="chance_required_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CHANCE_REQUIRE_FLAG"/>
    </bm:fields>
</bm:model>
