<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            begin

                csh_transaction_interface_pkg.post_interface(p_transaction_id =>${@transaction_id},
                                                            p_user_id =>${/session/@user_id},
                                                             p_err_count =>${@err_count});
            end;
            ]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="err_count" dataType="java.lang.Long" output="true" outputPath="@err_count"/>
            </bm:parameters>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
           declare
               v_transaction_num  varchar2(400);
            begin
                if ${@flag} = 'SUBMIT' then
				  csh_transaction_interface_pkg.check_operat_flag(p_transaction_id =>${@transaction_id} );
                    update CSH_TRANSACTION
                    set confirmed_flag = 'WF_APPROVING'
                    where transaction_id = ${@transaction_id};
                elsif ${@flag} = 'RETURN' then
                    update CSH_TRANSACTION
                    set confirmed_flag = 'WF_REJECTED'
                    where transaction_id = ${@transaction_id};
                end if;
            end;
            ]]></bm:update-sql>
        </bm:operation>
		<bm:operation name="query">
                <bm:query-sql><![CDATA[
            Select decode(Count(t1.transaction_id), Count(t1.csh_confirm), 'Y', 'N') As csh_confirm_flag
              From (Select t.transaction_date,
                           t.transaction_id,
                           (Select c2.transaction_id
                              From csh_transaction c2
                             Where c2.transaction_id = t.transaction_id
                               And nvl(c2.business_monthly_flag, 'N') = 'Y') As csh_confirm
                      From csh_transaction t
                     Where t.confirmed_flag in
                           ('ACCAUDITED', 'APPROVED', 'WF_REJECTED', 'WF_APPROVING')
                       And t.transaction_type not in ('DEPOSIT', 'PAYMENT')
                       And t.returned_flag not in ('RETURN', 'FULL')
                       And nvl(t.reversed_flag, 'N') = 'N') t1
             Where to_char(t1.transaction_date, 'yyyymm') =
                   to_char(to_date(${@transaction_date},'yyyy/mm/dd'), 'yyyymm')
            		]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
