<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:fields>
        <bm:field name="ce_num"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                select count(cf.ele_flow_id) ce_num
                  from con_contract_ele_flow cf
                 where cf.contract_id = ${@contract_id}
                   and cf.ele_flow_type = 'CE'
                   and cf.ele_flow_id is not null
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            BEGIN
                insert into con_contract_ele_flow
                   (con_ele_flow_id,
                    contract_id,
                    ele_flow_type,
                    ele_flow_id,
                    creation_date,
                    created_by,
                    last_updated_by,
                    last_update_date)
                values
                   (CON_CONTRACT_ELE_FLOW_S.NEXTVAL,
                    ${@contract_id},
                    ${@esign_type},
                    ${@flow_id},
                    sysdate,
                    nvl(${/session/@user_id},1),
                    nvl(${/session/@user_id},1),
                    sysdate);
              END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
                  BEGIN
                    UPDATE CON_CONTRACT c
                       SET c.ec_sign_type         = 'INITIATE',
                           c.sign_contract_status = 'SIGNING',
                           c.sign_type            = 'ELE_SIGN',
                           c.last_updated_by      = nvl(${/session/@user_id},1),
                           c.last_update_date     = sysdate
                     WHERE c.contract_id = ${@contract_id};
                  end;
                ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
              begin
                hl_sms_send_pkg.send_mobile_remind_info(p_contract_id => ${@contract_id},
                                                        p_user_id     => nvl(${/session/@user_id},1));
              end;
                ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
