<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2014-11-11 下午05:36:49  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    h.company_id,
                    -- fc.company_code,
                    (
                    SELECT
                        t.kingdee_compnay_code
                    FROM
                        fnd_companies t
                    WHERE
                        t.company_id=h.company_id
                    ) company_code,
                    TO_CHAR(h.journal_date,'yyyy-mm-dd') journal_date,
                    TO_CHAR(h.journal_date,'yyyy-mm-dd') BizDate,
                    h.period_year,
                    h.period_num,
                    '记' vouchertype,
                    h.journal_num,
                    h.attachment_num,
                    l.line_num,
                    h.description,
                    l.account_id,
                    --gav.account_code,
                    l.account_id_n AS account_code,
                    --h.currency_code,
                    'BB01' currency_code,
                    h.exchange_rate,
                    (
                        CASE
                            WHEN l.amount_cr IS NOT NULL AND
                                l.amount_dr  IS NULL
                            THEN -1
                            WHEN l.amount_cr IS NULL AND
                                l.amount_dr  IS NOT NULL
                            THEN 1
                        END) entrydc,
                    NVL(l.amount_dr, l.amount_cr) originalamount,
                    (SELECT
                        COUNT(*)
                    FROM
                        hls_journal_detail dl
                    WHERE
                        dl.journal_header_id = l.journal_header_id
                    ) qty,
                    l.line_description,
                    l.amount_dr,
                    l.amount_cr,
                    l.kingdee_reference1 reference6,
                    l.reference1_n ref_6_n,
                    l.kingdee_reference2 reference7,
                    l.reference2_n ref_7_n,
                    l.kingdee_reference3 reference8,
                    l.reference3_n ref_8_n,
                    l.reference4 reference9,
                    l.reference4_n ref_9_n,
                    l.reference5 reference10,
                    l.reference5_n ref_10_n,
                    l.dr_cr
                FROM
                    hls_journal_header h,
                    hls_journal_detail_lv l
                WHERE
                    h.journal_header_id = l.journal_header_id AND
                    h.journal_header_id = ${@journal_header_id}
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                DECLARE
                    v_flag           VARCHAR2(1);
                    jounal_num_error EXCEPTION;
                BEGIN
                    v_flag   := hls_journal_pkg.update_external_journal_num( p_journal_header_id =>${@journal_header_id},p_batch_id =>${@batch_id}, p_external_journal_num =>${@kingdee_journal_header_num}, p_interface_deal_message =>${@interface_deal_message}, p_itfc_exception =>${@itfc_exception}, p_interface_date =>sysdate, p_json_list =>${@json_list}, p_user_id =>NVL(${/session/@user_id},${@user_id}));
                    IF v_flag = 'N' THEN
                      null;
                   --   raise jounal_num_error;
                    END IF;
                EXCEPTION
                WHEN jounal_num_error THEN
                    sys_raise_app_error_pkg.raise_user_define_error(p_message_code => 'HLS_JOURNAL_PKG.KINGDEE_POST_FAILURE', p_created_by => 1, p_package_name => 'HLS_JOURNAL_PKG', p_procedure_function_name => 'update_external_journal_num');
                    raise_application_error(sys_raise_app_error_pkg.c_error_number, sys_raise_app_error_pkg.g_err_line_id);
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
